/* ==========================================================================
   Executive Management Dashboard — purple / violet theme
   ========================================================================== */
:root {
    /* ── Brand / primary ── */
    --primary: #7c3aed;
    --primary-600: #6d28d9;
    --primary-700: #5b21b6;
    --primary-050: #f5f3ff;
    --primary-100: #ede9fe;

    /* ── Ink ── */
    --ink: #1e1b4b;
    --ink-2: #4c4980;
    --muted: #9896c8;

    /* ── Surfaces ── */
    --line: #e4e1f5;
    --line-2: #eeecf9;
    --bg: #f0effe;
    --card: #ffffff;

    /* ── State colours ── */
    --success: #059669;
    --success-bg: #d1fae5;
    --danger: #dc2626;
    --danger-bg: #fee2e2;
    --warn: #d97706;
    --warn-bg: #fef3c7;

    /* ── Accents (charts / tags) ── */
    --accent-pink: #ec4899;
    --accent-teal: #0d9488;
    --accent-amber: #f59e0b;
    --accent-indigo: #6366f1;

    /* ── Shape ── */
    --radius: 16px;
    --radius-sm: 10px;

    /* ── Shadows (violet-tinted) ── */
    --shadow: 0 2px 4px rgba(109,40,217,.06), 0 10px 30px rgba(109,40,217,.10);
    --shadow-sm: 0 1px 2px rgba(109,40,217,.04), 0 3px 10px rgba(109,40,217,.07);

    /* ── Typography ── */
    --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

    /* ── Sidebar palette (light) ── */
    --sb-bg: #ffffff;
    --sb-bg-2: #f5f3ff;
    --sb-border: var(--line);
    --sb-text: var(--ink-2);
    --sb-text-active: var(--primary-700);
    --sb-hover: var(--primary-050);
    --sb-active: var(--primary-100);
    --sb-muted: var(--muted);
    --sb-brand: var(--ink);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    color: var(--ink);
    background: var(--bg);
    font-size: 15px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-700); }
h1, h2, h3 { color: var(--ink); }

/* ---------- Auth screen --------------------------------------------------- */
.auth-center {
    min-height: 100vh;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    padding: 32px 20px;
    background: radial-gradient(900px 500px at 50% -120px, #ede9fe 0%, transparent 70%), var(--bg);
}
.auth-box { width: 100%; max-width: 420px; }
.auth-head { text-align: center; margin-bottom: 24px; }
.auth-head .logo-badge { display: inline-flex; align-items: center; justify-content: center; margin-bottom: 16px; }
.auth-head .sys-name { font-size: 13px; font-weight: 700; letter-spacing: .14em; text-transform: uppercase; color: var(--primary); }
.auth-head .sys-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.auth-card {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 32px 30px;
}
.auth-card h2 { margin: 0 0 4px; font-size: 21px; font-weight: 650; }
.auth-card .sub { color: var(--ink-2); margin: 0 0 24px; font-size: 14px; }
.auth-foot { text-align: center; color: var(--muted); font-size: 12.5px; margin-top: 22px; }

/* ---------- Forms ---------------------------------------------------------- */
.field { margin-bottom: 17px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; color: var(--ink); }
.field .req { color: var(--danger); font-weight: 700; }
.input, select.input, textarea.input {
    width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: var(--radius-sm);
    font-size: 14.5px; font-family: inherit; color: var(--ink); background: #fff;
    transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: #b8b4d8; }
.input:focus, select.input:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(124,58,237,.15);
}
.input.error { border-color: var(--danger); }
.input-group { position: relative; display: flex; align-items: center; }
.input-group .input { padding-right: 70px; }
.toggle-pw {
    position: absolute; right: 6px; border: none; background: transparent;
    color: var(--primary); font-size: 12.5px; font-weight: 600; cursor: pointer;
    padding: 6px 10px; border-radius: 7px;
}
.toggle-pw:hover { background: var(--primary-050); }
.err-msg { color: var(--danger); font-size: 12.5px; margin-top: 6px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 6px; }
.row-between { display: flex; align-items: center; justify-content: space-between; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--ink-2); cursor: pointer; user-select: none; }
.checkbox input { width: 16px; height: 16px; accent-color: var(--primary); }

/* ---------- Buttons -------------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 11px 17px; border: 1px solid transparent; border-radius: var(--radius-sm);
    font-size: 14.5px; font-weight: 600; font-family: inherit; cursor: pointer;
    transition: background .15s, border-color .15s, box-shadow .15s, transform .04s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); color: #fff; }
.btn-block { width: 100%; }
.btn-ghost { background: #fff; border-color: var(--line); color: var(--ink-2); }
.btn-ghost:hover { background: var(--primary-050); border-color: #d4ccf5; color: var(--ink); }
.btn-danger { background: #fff; border-color: #f0c4bf; color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-sm { padding: 7px 11px; font-size: 12.5px; border-radius: 7px; }
.btn-link { background: none; border: none; color: var(--primary); cursor: pointer; font: inherit; padding: 0; }

/* ---------- Alerts --------------------------------------------------------- */
.alert { padding: 11px 15px; border-radius: var(--radius-sm); font-size: 13.5px; margin-bottom: 18px; border: 1px solid transparent; }
.alert-success { background: var(--success-bg); color: var(--success); border-color: #a7f3d0; }
.alert-danger  { background: var(--danger-bg);  color: var(--danger);  border-color: #fca5a5; }
.alert-warn    { background: var(--warn-bg);    color: var(--warn);    border-color: #fcd34d; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }

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

/* ── Sidebar (light) ─────────────────────────────────────────────────────── */
.sidebar {
    width: 256px; flex: none;
    background: var(--sb-bg);
    border-right: 1px solid var(--sb-border);
    display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
    overflow: hidden;
    transition: width .18s ease, left .2s ease;
    box-shadow: 2px 0 12px rgba(109,40,217,.06);
}
html.nav-collapsed .sidebar { width: 0; border-right-color: transparent; box-shadow: none; }

.sidebar .brand {
    padding: 20px; display: flex; align-items: center; gap: 11px;
    border-bottom: 1px solid var(--sb-border);
}
.sidebar .brand strong { font-size: 14px; line-height: 1.15; color: var(--sb-brand); }
.sidebar .brand span   { font-size: 10.5px; color: var(--sb-muted); text-transform: uppercase; letter-spacing: .1em; }

.nav { padding: 14px 10px; flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.nav::-webkit-scrollbar { width: 8px; }
.nav::-webkit-scrollbar-thumb { background: var(--sb-border); border-radius: 8px; }
.nav { scrollbar-width: thin; scrollbar-color: var(--sb-border) transparent; }
.nav .nav-label {
    padding: 14px 10px 6px; font-size: 10px; text-transform: uppercase;
    letter-spacing: .10em; color: var(--sb-muted); font-weight: 700;
}
/* Collapsible nav group (e.g. Reports) */
.nav .nav-label.nav-group-toggle {
    display: flex; align-items: center; justify-content: space-between;
    cursor: pointer; user-select: none; border-radius: var(--radius-sm);
    transition: background .13s, color .13s;
}
.nav .nav-label.nav-group-toggle:hover { background: var(--sb-hover); color: var(--sb-text-active); }
.nav .nav-label.nav-group-toggle .chev { transition: transform .18s ease; opacity: .7; flex: none; }
.nav .nav-label.nav-group-toggle.collapsed .chev { transform: rotate(-90deg); }
.nav .nav-group { overflow: hidden; }
.nav .nav-group.collapsed { display: none; }
.nav a {
    display: flex; align-items: center; gap: 11px;
    padding: 10px 12px; margin-bottom: 2px;
    border-radius: var(--radius-sm); color: var(--sb-text); font-size: 13.5px; font-weight: 500;
    transition: background .13s, color .13s;
}
.nav a:hover { background: var(--sb-hover); color: var(--sb-text-active); }
.nav a.active {
    background: var(--primary-100);
    color: var(--primary-700); font-weight: 700;
    box-shadow: none;
}
.nav a.active svg { opacity: 1; }
.nav a svg { color: currentColor; opacity: .75; }

.sidebar-foot { padding: 14px; border-top: 1px solid var(--sb-border); }
.sidebar-foot .btn-link { color: var(--sb-text); font-size: 13.5px; }
.sidebar-foot .btn-link:hover { color: var(--primary); }

/* ── Topbar ──────────────────────────────────────────────────────────────── */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
    height: 64px;
    background: rgba(255,255,255,.92); backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 26px; position: sticky; top: 0; z-index: 5;
    box-shadow: 0 1px 0 var(--line-2);
}
.topbar .page-title { font-size: 16.5px; font-weight: 650; color: var(--ink); }
.user-chip { display: flex; align-items: center; gap: 11px; }
.avatar {
    width: 36px; height: 36px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--accent-indigo));
    color: #fff;
    display: grid; place-items: center; font-weight: 700; font-size: 13px;
    box-shadow: 0 2px 8px rgba(124,58,237,.35);
}
.user-chip .meta { line-height: 1.25; text-align: right; }
.user-chip .meta strong { font-size: 13.5px; }
.user-chip .meta small { color: var(--muted); font-size: 12px; }

.content { padding: 26px; max-width: 1280px; width: 100%; }

/* ---------- Generic cards / grid ------------------------------------------ */
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); margin-bottom: 22px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 20px 22px; }
.card h3 { margin: 0 0 16px; font-size: 15px; font-weight: 650; }
.stat .label { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 27px; font-weight: 700; margin-top: 8px; color: var(--ink); letter-spacing: -.01em; }
.stat .value.sm { font-size: 17px; }

/* ---------- Tables --------------------------------------------------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
table.data th { background: #faf9fe; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: #faf9fe; }
.table-actions { display: flex; gap: 6px; }

/* ---------- Badges --------------------------------------------------------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 600; }
.badge-active   { background: var(--success-bg); color: var(--success); }
.badge-inactive { background: var(--danger-bg);  color: var(--danger); }
.badge-role     { background: var(--primary-100); color: var(--primary-700); }
.dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ---------- Page header ---------------------------------------------------- */
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.page-head h2 { margin: 0; font-size: 20px; font-weight: 650; }
.page-head .crumb { color: var(--muted); font-size: 13px; margin-top: 4px; }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .input { width: auto; min-width: 220px; }
.toolbar .perpage { display: inline-flex; align-items: center; gap: 7px; margin-left: auto; font-size: 13px; color: var(--muted); }
.toolbar .perpage .input { min-width: auto; width: auto; padding: 8px 10px; }

.table-meta { font-size: 13px; color: var(--muted); margin: 0 2px 10px; }
.table-meta strong { color: var(--ink); }
a.sort-link { display: inline-flex; align-items: center; gap: 5px; color: inherit; text-transform: inherit; font: inherit; letter-spacing: inherit; }
a.sort-link:hover { color: var(--ink); text-decoration: none; }
a.sort-link.active { color: var(--primary); }
a.sort-link .arrow { font-size: 9px; opacity: .5; line-height: 1; }
a.sort-link.active .arrow { opacity: 1; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 22px; }
.form-grid .full { grid-column: 1 / -1; }

.pagination { display: flex; gap: 4px; margin-top: 18px; flex-wrap: wrap; }
.pagination a, .pagination span { padding: 7px 12px; border: 1px solid var(--line); border-radius: 8px; font-size: 13px; background: #fff; color: var(--ink-2); }
.pagination a:hover { background: var(--primary-050); }
.pagination span[aria-current] { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination span[aria-disabled] { color: #c2c9d6; }

.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.muted { color: var(--muted); }

/* Role permission picker */
.perm-group { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 14px; margin-bottom: 12px; }
.perm-group:last-child { margin-bottom: 0; }
.perm-group-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.perm-group-head span { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--ink); }
.perm-items { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px 16px; }
.perm-item { font-weight: 500; }
.perm-list { columns: 2; font-size: 13.5px; color: var(--ink-2); list-style: none; padding: 0; }
.perm-list li { margin-bottom: 7px; display: flex; gap: 8px; align-items: center; }
.perm-list li svg { color: var(--success); flex: none; }

/* ---------- Menu toggle / responsive -------------------------------------- */
.menu-toggle {
    display: inline-flex; align-items: center; justify-content: center;
    background: none; border: 1px solid var(--line); border-radius: 8px;
    padding: 7px 8px; cursor: pointer; color: var(--ink-2);
}
.menu-toggle:hover { background: var(--primary-050); color: var(--primary); }
@media (max-width: 900px) {
    .form-grid { grid-template-columns: 1fr; }
    .perm-list { columns: 1; }
}
#sidebar-overlay { display: none; }
@media (max-width: 760px) {
    .sidebar,
    html.nav-collapsed .sidebar { width: 256px; position: fixed; left: -280px; z-index: 50; border-right: none; box-shadow: var(--shadow); }
    .sidebar.open { left: 0; }
    #sidebar-overlay.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; }
    .menu-toggle { display: inline-flex; }
    .user-chip .meta { display: none; }
    .content { padding: 18px; }
}

/* ==========================================================================
   Executive dashboard
   ========================================================================== */
.content--wide { max-width: 1480px; }

/* ── Filter bar ─────────────────────────────────────────────────────────── */
.dash-filters {
    display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end;
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); padding: 14px 16px; margin-bottom: 22px;
}
.dash-filters .filter { display: flex; flex-direction: column; gap: 5px; min-width: 150px; flex: 1 1 150px; }
.dash-filters .filter label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.dash-filters .filter .input { padding: 9px 11px; font-size: 13.5px; }
.dash-filters .filter-actions { display: flex; gap: 8px; }

/* ── KPI row ─────────────────────────────────────────────────────────────── */
.kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 8px; }
.kpi {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); padding: 16px;
    display: flex; flex-direction: column; gap: 10px;
    position: relative; overflow: hidden;
}
.kpi::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--accent-indigo));
    border-radius: var(--radius) var(--radius) 0 0;
}
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; line-height: 1.3; }
.kpi-ic {
    width: 36px; height: 36px; flex: none; border-radius: 10px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, var(--primary-050), var(--primary-100));
    color: var(--primary);
}
.kpi-ic.is-green  { background: linear-gradient(135deg, #d1fae5, #a7f3d0); color: var(--success); }
.kpi-ic.is-orange { background: linear-gradient(135deg, #fef3c7, #fde68a); color: var(--warn); }
.kpi-ic.is-blue   { background: linear-gradient(135deg, var(--primary-050), var(--primary-100)); color: var(--primary); }
/* Clickable KPI icon (drill-down to a detail page). */
.kpi-ic-link { cursor: pointer; text-decoration: none; transition: transform .12s ease, box-shadow .12s ease; }
.kpi-ic-link:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(0,0,0,.14); }
.kpi-value { font-size: 22px; font-weight: 750; letter-spacing: -.02em; color: var(--ink); overflow-wrap: anywhere; }
.kpi .delta, .delta { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 600; }
.delta.up   { color: var(--success); }
.delta.down { color: var(--danger); }
.delta .sub { color: var(--muted); font-weight: 500; }

/* ── Sections ────────────────────────────────────────────────────────────── */
.section { margin-top: 28px; }
.section-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.section-head .ic {
    width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
    font-size: 18px;
    background: linear-gradient(135deg, var(--primary-050), var(--primary-100));
    border: 1px solid var(--line);
}
.section-head h3 { margin: 0; font-size: 17px; font-weight: 700; }
.section-head .sub { font-size: 12.5px; color: var(--muted); margin-top: 1px; }

/* ── 12-col widget grid ──────────────────────────────────────────────────── */
.widgets { display: grid; grid-template-columns: repeat(12, 1fr); gap: 16px; }
.span-3  { grid-column: span 3; }
.span-4  { grid-column: span 4; }
.span-5  { grid-column: span 5; }
.span-6  { grid-column: span 6; }
.span-7  { grid-column: span 7; }
.span-8  { grid-column: span 8; }
.span-12 { grid-column: span 12; }

/* ── Panels ──────────────────────────────────────────────────────────────── */
.panel {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); padding: 16px 18px; display: flex; flex-direction: column;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.panel-head h4 { margin: 0; font-size: 14px; font-weight: 700; color: var(--ink); }
.panel-head .tag {
    font-size: 10.5px; font-weight: 700; color: var(--primary-700);
    background: var(--primary-050); padding: 2px 8px; border-radius: 999px;
    text-transform: uppercase; letter-spacing: .04em;
}
.chart-wrap    { position: relative; width: 100%; height: 260px; }
.chart-wrap.sm { height: 200px; }
.chart-wrap.lg { height: 300px; }

/* ── Mini stat cards ─────────────────────────────────────────────────────── */
.minis { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 16px; }
.mini {
    background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
    box-shadow: var(--shadow-sm); padding: 16px 18px;
}
.mini .label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.mini .value { font-size: 22px; font-weight: 750; margin: 8px 0 5px; color: var(--ink); letter-spacing: -.01em; }

/* ── Rankings ────────────────────────────────────────────────────────────── */
.rank { list-style: none; margin: 0; padding: 0; }
.rank li { display: flex; align-items: center; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line-2); }
.rank li:last-child { border-bottom: none; }
.rank-no {
    width: 24px; height: 24px; flex: none; border-radius: 7px;
    display: grid; place-items: center; font-size: 12px; font-weight: 700;
    background: var(--primary-100); color: var(--primary-700);
}
.rank-no.top {
    background: linear-gradient(135deg, var(--primary), var(--accent-indigo));
    color: #fff; box-shadow: 0 2px 6px rgba(124,58,237,.35);
}
.rank-main { flex: 1; min-width: 0; }
.rank-name { font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-sub  { font-size: 11.5px; color: var(--muted); }
.rank-val  { font-size: 13.5px; font-weight: 700; white-space: nowrap; color: var(--ink); }
.rank-bar  { height: 5px; border-radius: 4px; background: var(--line); margin-top: 6px; overflow: hidden; }
.rank-bar > span         { display: block; height: 100%; border-radius: 4px; background: linear-gradient(90deg, var(--primary), var(--accent-indigo)); }
.rank-bar > span.green   { background: linear-gradient(90deg, var(--success), #34d399); }
.rank-bar > span.teal    { background: linear-gradient(90deg, var(--accent-teal), #2dd4bf); }
.rank-bar > span.orange  { background: linear-gradient(90deg, var(--accent-amber), #fbbf24); }
.rank-bar > span.red     { background: linear-gradient(90deg, var(--danger), #f87171); }

/* ── Achievement chips ───────────────────────────────────────────────────── */
.ach-pill { display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 700; }
.ach-good { background: var(--success-bg); color: var(--success); }
.ach-warn { background: var(--warn-bg);    color: var(--warn); }
.ach-bad  { background: var(--danger-bg);  color: var(--danger); }

/* ── Insights ────────────────────────────────────────────────────────────── */
.insight-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 14px; }
.insight {
    background: var(--card); border: 1px solid var(--line); border-left-width: 4px;
    border-radius: var(--radius); box-shadow: var(--shadow-sm);
    padding: 14px 16px; display: flex; gap: 12px;
}
.insight .ic { width: 34px; height: 34px; flex: none; border-radius: 9px; display: grid; place-items: center; }
.insight .it-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.insight .it-text  { font-size: 13.5px; font-weight: 500; margin-top: 3px; line-height: 1.45; }
.insight.is-positive { border-left-color: var(--success); }
.insight.is-positive .ic { background: var(--success-bg); color: var(--success); }
.insight.is-negative { border-left-color: var(--danger); }
.insight.is-negative .ic { background: var(--danger-bg); color: var(--danger); }
.insight.is-warning  { border-left-color: var(--accent-amber); }
.insight.is-warning .ic { background: var(--warn-bg); color: var(--warn); }
.insight.is-info     { border-left-color: var(--primary); }
.insight.is-info .ic { background: var(--primary-050); color: var(--primary); }

/* ── Responsive collapses ────────────────────────────────────────────────── */
@media (max-width: 1200px) {
    .kpi-row { grid-template-columns: repeat(3, 1fr); }
    .span-3, .span-4, .span-5 { grid-column: span 6; }
    .span-7, .span-8 { grid-column: span 12; }
}
@media (max-width: 720px) {
    .dash-filters { flex-direction: column; align-items: stretch; }
    .dash-filters .filter { flex: 0 0 auto; min-width: 0; width: 100%; }
    .dash-filters .filter-actions { width: 100%; }
    .dash-filters .filter-actions .btn { flex: 1 1 auto; }
    .kpi-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .minis { grid-template-columns: 1fr; }
    .widgets > [class*="span-"] { grid-column: span 12; }
    .kpi-value { font-size: 15px; letter-spacing: -.01em; }
    .kpi-label { font-size: 11px; }
    .kpi { padding: 10px; gap: 6px; }
    .kpi-ic { width: 28px; height: 28px; }
}

/* ── PWA installed (standalone) mode: respect device safe areas (notches) ── */
@media (display-mode: standalone) {
    /* Already installed -> never show the install button. */
    #pwa-install { display: none !important; }
    .topbar { padding-top: env(safe-area-inset-top); height: auto; min-height: 56px; }
    .content { padding-bottom: calc(26px + env(safe-area-inset-bottom)); }
    .sidebar { padding-top: env(safe-area-inset-top); }
    @supports (padding: max(0px)) {
        .topbar  { padding-left: max(26px, env(safe-area-inset-left)); padding-right: max(26px, env(safe-area-inset-right)); }
        .content { padding-left: max(26px, env(safe-area-inset-left)); padding-right: max(26px, env(safe-area-inset-right)); }
    }

    /* Installed PWA is ALWAYS the mobile layout (CSS-only, no JS needed), so the
       app ignores any domain-wide "Request desktop site" setting. */
    .app { display: block; }
    .main { width: 100%; }
    .sidebar,
    html.nav-collapsed .sidebar { width: 256px; position: fixed; left: -280px; z-index: 50; border-right: none; box-shadow: var(--shadow); }
    .sidebar.open { left: 0; }
    #sidebar-overlay.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; }
    .menu-toggle { display: inline-flex; }
    .user-chip .meta { display: none; }
    .content, .content--wide { max-width: 100%; padding-left: 16px; padding-right: 16px; }
    .dash-filters { flex-direction: column; align-items: stretch; }
    .dash-filters .filter { flex: 0 0 auto; min-width: 0; width: 100%; }
    .dash-filters .filter-actions { width: 100%; }
    .dash-filters .filter-actions .btn { flex: 1 1 auto; }
    .kpi-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .kpi-value { font-size: 15px; letter-spacing: -.01em; }
    .kpi-label { font-size: 11px; }
    .kpi { padding: 10px; gap: 6px; }
    .kpi-ic { width: 28px; height: 28px; }
    .minis, .insight-grid, .stats, .perm-items, .form-grid { grid-template-columns: 1fr; }
    .widgets > [class*="span-"] { grid-column: span 12; }
}

/* ── Force mobile layout on real phones (even in Chrome "Request desktop site")
   Mirrors the max-width:760/720 rules, but triggered by a JS-added class so it
   applies regardless of the (desktop-overridden) viewport width. ────────────── */
html.force-mobile .sidebar,
html.force-mobile.nav-collapsed .sidebar { width: 256px; position: fixed; left: -280px; z-index: 50; border-right: none; box-shadow: var(--shadow); }
html.force-mobile .sidebar.open { left: 0; }
html.force-mobile #sidebar-overlay.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; }
html.force-mobile .menu-toggle { display: inline-flex; }
html.force-mobile .user-chip .meta { display: none; }
html.force-mobile .content { padding: 18px; max-width: 100%; }
html.force-mobile .content--wide { max-width: 100%; }
html.force-mobile .dash-filters { flex-direction: column; align-items: stretch; }
html.force-mobile .dash-filters .filter { flex: 0 0 auto; min-width: 0; width: 100%; }
html.force-mobile .dash-filters .filter-actions { width: 100%; }
html.force-mobile .dash-filters .filter-actions .btn { flex: 1 1 auto; }
html.force-mobile .kpi-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
html.force-mobile .minis { grid-template-columns: 1fr; }
html.force-mobile .widgets > [class*="span-"] { grid-column: span 12; }
html.force-mobile .kpi-value { font-size: 15px; letter-spacing: -.01em; }
html.force-mobile .kpi-label { font-size: 11px; }
html.force-mobile .kpi { padding: 10px; gap: 6px; }
html.force-mobile .kpi-ic { width: 28px; height: 28px; }
/* Stack every remaining grid so the whole page is single-column on a phone,
   regardless of the (possibly desktop-overridden) viewport width. */
html.force-mobile .insight-grid { grid-template-columns: 1fr; }
html.force-mobile .stats { grid-template-columns: 1fr; }
html.force-mobile .perm-items { grid-template-columns: 1fr; }
html.force-mobile .form-grid { grid-template-columns: 1fr; }
html.force-mobile .app { display: block; }
html.force-mobile .main { width: 100%; }

/* ============================================================================
   PRIMARY MOBILE RULE — keyed on the physical input device.
   "hover: none and pointer: coarse" = a touch phone/tablet. These are HARDWARE
   media features, so they stay true even when Chrome's "Request desktop site"
   widens the viewport or swaps the User-Agent. This forces the mobile layout on
   the phone in a browser tab OR the installed PWA, independent of viewport width.
   ============================================================================ */
@media (hover: none) and (pointer: coarse) {
    .app { display: block; }
    .main { width: 100%; }
    .sidebar,
    html.nav-collapsed .sidebar { width: 256px; position: fixed; left: -280px; z-index: 50; border-right: none; box-shadow: var(--shadow); }
    .sidebar.open { left: 0; }
    #sidebar-overlay.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; }
    .menu-toggle { display: inline-flex; }
    .user-chip .meta { display: none; }
    .content, .content--wide { max-width: 100%; padding-left: 16px; padding-right: 16px; }
    .dash-filters { flex-direction: column; align-items: stretch; }
    .dash-filters .filter { flex: 0 0 auto; min-width: 0; width: 100%; }
    .dash-filters .filter-actions { width: 100%; }
    .dash-filters .filter-actions .btn { flex: 1 1 auto; }
    .kpi-row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
    .kpi-value { font-size: 15px; letter-spacing: -.01em; }
    .kpi-label { font-size: 11px; }
    .kpi { padding: 10px; gap: 6px; }
    .kpi-ic { width: 28px; height: 28px; }
    .minis, .insight-grid, .stats, .perm-items, .form-grid { grid-template-columns: 1fr; }
    .widgets > [class*="span-"] { grid-column: span 12; }
}
