/* =========================================================
   MK Control Center — Design System
   Palette:  Indigo primary #5B5FEF · Ink #0F172A · Mist #F5F6FA
   Signature: glass stat cards + gradient rail sidebar + canvas sparklines
   ========================================================= */

:root {
    --primary: #5B5FEF;
    --primary-dark: #4347C4;
    --primary-light: #EEF0FF;
    --success: #10B981;
    --success-light: #E7FBF3;
    --danger: #EF4444;
    --danger-light: #FDECEC;
    --warning: #F59E0B;
    --warning-light: #FEF6E7;
    --info: #06B6D4;
    --info-light: #E5FAFD;

    --bg: #F5F6FA;
    --surface: #FFFFFF;
    --surface-glass: rgba(255, 255, 255, 0.72);
    --text: #0F172A;
    --text-muted: #64748B;
    --text-faint: #94A3B8;
    --border: #E7E9F2;
    --border-strong: #D8DBEA;

    --radius-sm: 8px;
    --radius: 14px;
    --radius-lg: 20px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.10);
    --sidebar-w: 264px;
    --header-h: 68px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --transition: 180ms cubic-bezier(.4, 0, .2, 1);
}

[data-theme="dark"] {
    --bg: #0B0E14;
    --surface: #131722;
    --surface-glass: rgba(19, 23, 34, 0.72);
    --text: #E7E9F2;
    --text-muted: #97A0B5;
    --text-faint: #626B80;
    --border: #232838;
    --border-strong: #2E3448;
    --primary-light: #1B1D3A;
    --success-light: #0E2A24;
    --danger-light: #2E1618;
    --warning-light: #2E2410;
    --info-light: #0E2730;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    transition: background var(--transition), color var(--transition);
}
a { color: inherit; text-decoration: none; }
ul { list-style: none; margin: 0; padding: 0; }
button { font-family: inherit; cursor: pointer; }
img { max-width: 100%; display: block; }
::selection { background: var(--primary); color: #fff; }

/* Focus visibility for accessibility */
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------- App Shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; bottom: 0; left: 0;
    z-index: 40;
    transition: transform var(--transition);
}
.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 20px 22px;
    border-bottom: 1px solid var(--border);
}
.sidebar-brand .logo-mark {
    width: 34px; height: 34px; border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), #8B8FFF);
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 15px;
    box-shadow: 0 4px 12px rgba(91, 95, 239, 0.35);
}
.sidebar-brand .brand-text { font-weight: 700; font-size: 15px; letter-spacing: -0.2px; }
.sidebar-brand .brand-sub { font-size: 11px; color: var(--text-faint); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.nav-section-title {
    font-size: 10.5px; font-weight: 700; letter-spacing: 0.08em;
    color: var(--text-faint); text-transform: uppercase;
    padding: 14px 10px 6px;
}
.nav-item {
    display: flex; align-items: center; gap: 11px;
    padding: 9px 12px; border-radius: 10px;
    color: var(--text-muted); font-size: 13.5px; font-weight: 500;
    position: relative; margin-bottom: 2px;
    transition: background var(--transition), color var(--transition);
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { background: var(--primary-light); color: var(--primary); }
.nav-item.active { background: var(--primary-light); color: var(--primary); font-weight: 600; }
.nav-item.active::before {
    content: ''; position: absolute; left: -12px; top: 50%; transform: translateY(-50%);
    width: 3px; height: 18px; border-radius: 3px;
    background: linear-gradient(180deg, var(--primary), #8B8FFF);
}
.nav-item .badge-count {
    margin-left: auto; font-size: 10.5px; font-weight: 700;
    background: var(--danger); color: #fff; padding: 1px 6px; border-radius: 20px;
}

.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); }
.mini-profile { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; }
.mini-profile:hover { background: var(--bg); }
.avatar-circle {
    width: 34px; height: 34px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), #8B8FFF);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.mini-profile .mp-name { font-size: 13px; font-weight: 600; }
.mini-profile .mp-role { font-size: 11px; color: var(--text-faint); text-transform: capitalize; }

/* ---------- Main ---------- */
.main {
    margin-left: var(--sidebar-w);
    flex: 1;
    min-width: 0;
    display: flex; flex-direction: column;
}
.topbar {
    height: var(--header-h);
    background: var(--surface-glass);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 16px;
    padding: 0 24px;
    position: sticky; top: 0; z-index: 30;
}
.hamburger { display: none; background: none; border: none; color: var(--text); padding: 6px; }
.search-box {
    flex: 1; max-width: 420px; position: relative;
}
.search-box input {
    width: 100%; padding: 9px 14px 9px 36px; border-radius: 10px;
    border: 1px solid var(--border); background: var(--bg); color: var(--text);
    font-size: 13.5px;
}
.search-box svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--text-faint); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.icon-btn {
    width: 38px; height: 38px; border-radius: 10px; border: 1px solid transparent;
    background: transparent; display: flex; align-items: center; justify-content: center;
    color: var(--text-muted); position: relative; transition: background var(--transition);
}
.icon-btn:hover { background: var(--bg); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
.dot-indicator {
    position: absolute; top: 7px; right: 7px; width: 7px; height: 7px;
    border-radius: 50%; background: var(--danger); border: 2px solid var(--surface);
}

.page { padding: 24px; flex: 1; }
.page-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-title { font-size: 21px; font-weight: 700; letter-spacing: -0.3px; }
.page-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 3px; }
.breadcrumbs { font-size: 12.5px; color: var(--text-faint); margin-bottom: 4px; }
.breadcrumbs a:hover { color: var(--primary); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    padding: 9px 16px; border-radius: 10px; border: 1px solid transparent;
    font-size: 13.5px; font-weight: 600; transition: all var(--transition);
    white-space: nowrap;
}
.btn svg { width: 15px; height: 15px; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 4px 12px rgba(91, 95, 239, 0.3); }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); }
.btn-outline { background: transparent; border-color: var(--border-strong); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-success { background: var(--success-light); color: var(--success); }
.btn-success:hover { background: var(--success); color: #fff; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none !important; }
.btn-icon-only { padding: 8px; }

/* ---------- Cards ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
}
.card-body { padding: 20px; }
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.card-title { font-size: 14.5px; font-weight: 700; }

/* Stat cards — the signature glass treatment */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card {
    position: relative; overflow: hidden;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-lg); padding: 18px 20px; box-shadow: var(--shadow-sm);
    transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-card::after {
    content: ''; position: absolute; top: -30px; right: -30px; width: 100px; height: 100px;
    border-radius: 50%; background: radial-gradient(circle, var(--stat-color, var(--primary)) 0%, transparent 70%);
    opacity: 0.12;
}
.stat-icon {
    width: 38px; height: 38px; border-radius: 10px;
    background: var(--stat-bg, var(--primary-light)); color: var(--stat-color, var(--primary));
    display: flex; align-items: center; justify-content: center; margin-bottom: 12px;
}
.stat-icon svg { width: 19px; height: 19px; }
.stat-value { font-size: 24px; font-weight: 800; letter-spacing: -0.5px; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }
.stat-trend { font-size: 11.5px; font-weight: 700; margin-top: 8px; display: inline-flex; align-items: center; gap: 3px; }
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; min-width: 720px; }
.data-table thead th {
    text-align: left; padding: 12px 16px; background: var(--bg);
    color: var(--text-muted); font-weight: 700; font-size: 11.5px; text-transform: uppercase; letter-spacing: 0.04em;
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table tbody td { padding: 13px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr { transition: background var(--transition); }
.data-table tbody tr:hover { background: var(--bg); }
.cell-primary { font-weight: 600; color: var(--text); }
.cell-muted { color: var(--text-muted); font-size: 12.5px; }
.table-actions { display: flex; gap: 6px; }

/* ---------- Badges ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 700; text-transform: capitalize;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-neutral { background: var(--bg); color: var(--text-muted); }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }
label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
input:not([type=checkbox]):not([type=radio]), select, textarea {
    width: 100%; padding: 10px 12px; border-radius: 10px;
    border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
    font-size: 13.5px; font-family: inherit; transition: border-color var(--transition), box-shadow var(--transition);
}
input:focus, select:focus, textarea:focus {
    border-color: var(--primary); box-shadow: 0 0 0 3px rgba(91, 95, 239, 0.14); outline: none;
}
textarea { resize: vertical; min-height: 80px; }
.field-error { color: var(--danger); font-size: 11.5px; margin-top: 5px; }
.input-error { border-color: var(--danger) !important; }
.help-text { font-size: 11.5px; color: var(--text-faint); margin-top: 5px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

/* ---------- Toolbar (search/filter above tables) ---------- */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .search-box { max-width: 280px; }
.filter-select { min-width: 140px; }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 4px; flex-wrap: wrap; }
.pagination-info { font-size: 12.5px; color: var(--text-muted); }
.pagination-pages { display: flex; gap: 4px; }
.page-btn {
    min-width: 32px; height: 32px; padding: 0 8px; border-radius: 8px;
    border: 1px solid var(--border); background: var(--surface); color: var(--text-muted);
    font-size: 12.5px; font-weight: 600;
}
.page-btn:hover { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5); backdrop-filter: blur(2px);
    display: flex; align-items: center; justify-content: center; z-index: 100;
    opacity: 0; pointer-events: none; transition: opacity var(--transition);
    padding: 20px;
}
.modal-overlay.show { opacity: 1; pointer-events: auto; }
.modal {
    background: var(--surface); border-radius: var(--radius-lg); width: 100%; max-width: 560px;
    max-height: 88vh; display: flex; flex-direction: column;
    box-shadow: var(--shadow-lg); transform: translateY(12px) scale(0.98); transition: transform var(--transition);
}
.modal-overlay.show .modal { transform: translateY(0) scale(1); }
.modal-header { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 15.5px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-faint); padding: 4px; border-radius: 6px; }
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 22px; overflow-y: auto; }
.modal-footer { padding: 16px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }
.modal-lg { max-width: 760px; }

/* ---------- Toasts ---------- */
.toast-container { position: fixed; top: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 10px; }
.toast {
    display: flex; align-items: flex-start; gap: 10px;
    background: var(--surface); border: 1px solid var(--border); border-left: 4px solid var(--primary);
    border-radius: 10px; padding: 12px 14px; min-width: 280px; max-width: 340px;
    box-shadow: var(--shadow-lg); transform: translateX(120%); transition: transform 260ms cubic-bezier(.4,0,.2,1), opacity 260ms;
    opacity: 0;
}
.toast.show { transform: translateX(0); opacity: 1; }
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast-icon { width: 18px; height: 18px; flex-shrink: 0; margin-top: 1px; }
.toast.success .toast-icon { color: var(--success); }
.toast.error .toast-icon { color: var(--danger); }
.toast.warning .toast-icon { color: var(--warning); }
.toast.info .toast-icon { color: var(--info); }
.toast-msg { font-size: 13px; font-weight: 500; flex: 1; }
.toast-close { background: none; border: none; color: var(--text-faint); }

/* ---------- Loader ---------- */
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; }
.spinner-dark { border-color: var(--border-strong); border-top-color: var(--primary); }
@keyframes spin { to { transform: rotate(360deg); } }
.page-loader { position: fixed; inset: 0; background: var(--bg); display: flex; align-items: center; justify-content: center; z-index: 300; }
.skeleton { background: linear-gradient(90deg, var(--border) 25%, var(--bg) 37%, var(--border) 63%); background-size: 400% 100%; animation: skeleton 1.4s ease infinite; border-radius: 6px; }
@keyframes skeleton { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Misc ---------- */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state svg { width: 44px; height: 44px; color: var(--text-faint); margin: 0 auto 12px; }
.empty-state-title { font-weight: 700; color: var(--text); margin-bottom: 4px; }
.chart-card canvas { width: 100%; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
.text-muted { color: var(--text-muted); }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.mt-16 { margin-top: 16px; }
.dropdown-menu {
    position: absolute; top: calc(100% + 6px); right: 0; background: var(--surface);
    border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg);
    min-width: 180px; padding: 6px; z-index: 60; display: none;
}
.dropdown-menu.show { display: block; }
.dropdown-item {
    display: flex; align-items: center; gap: 9px; padding: 8px 10px; border-radius: 8px;
    font-size: 13px; color: var(--text); font-weight: 500;
}
.dropdown-item:hover { background: var(--bg); }
.dropdown-item svg { width: 15px; height: 15px; color: var(--text-muted); }
.dropdown-item.text-danger { color: var(--danger); }
.dropdown-item.text-danger svg { color: var(--danger); }

/* Theme toggle switch */
.theme-toggle {
    width: 44px; height: 24px; border-radius: 20px; background: var(--bg); border: 1px solid var(--border);
    position: relative; flex-shrink: 0;
}
.theme-toggle-knob {
    position: absolute; top: 2px; left: 2px; width: 18px; height: 18px; border-radius: 50%;
    background: var(--primary); transition: transform var(--transition);
    display: flex; align-items: center; justify-content: center; color: #fff;
}
.theme-toggle-knob svg { width: 11px; height: 11px; }
[data-theme="dark"] .theme-toggle-knob { transform: translateX(20px); }

/* Responsive */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .main { margin-left: 0; }
    .hamburger { display: flex; align-items: center; justify-content: center; }
    .sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(15,23,42,0.4); z-index: 39; }
    .sidebar-backdrop.show { display: block; }
}
@media (max-width: 640px) {
    .page { padding: 16px; }
    .grid-2, .grid-3 { grid-template-columns: 1fr; }
    .search-box { display: none; }
    .modal { max-height: 100vh; border-radius: var(--radius-lg) var(--radius-lg) 0 0; align-self: flex-end; }
}
