/* ==========================================================================
   VSLA Management Portal — Admin Design System
   Primary brand: #00308F (Project Transform)
   ========================================================================== */

:root {
    --primary: #00308F;
    --primary-dark: #00205e;
    --primary-darker: #001640;
    --primary-mid: #0a45b0;
    --primary-soft: #e8eef9;
    --primary-softer: #f4f7fc;

    --accent: #00a651;
    --accent-soft: #e3f8ec;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --danger: #c0392b;
    --danger-soft: #fdecea;
    --info: #0369a1;
    --info-soft: #e0f2fe;
    --purple: #6d28d9;
    --purple-soft: #f0e9ff;

    --text: #16203a;
    --text-soft: #475069;
    --muted: #6b7280;
    --faint: #9aa2b1;

    --border: #e3e7ee;
    --border-strong: #cfd5e0;
    --bg: #f4f6fa;
    --card: #ffffff;

    --sidebar-w: 258px;
    --sidebar-w-collapsed: 68px;
    --topbar-h: 60px;

    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 14px;

    --shadow-xs: 0 1px 2px rgba(16, 24, 40, .05);
    --shadow-sm: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
    --shadow: 0 4px 12px rgba(16, 24, 40, .07), 0 1px 3px rgba(16, 24, 40, .05);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, .13);

    --font: 'Inter', 'Segoe UI', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    --mono: 'JetBrains Mono', 'Consolas', 'SF Mono', monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-mid); }

::selection { background: var(--primary); color: #fff; }

/* Scrollbars ------------------------------------------------------------- */
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 9px; }
::-webkit-scrollbar-thumb:hover { background: var(--faint); }

/* ==========================================================================
   Layout shell
   ========================================================================== */

.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-w);
    flex-shrink: 0;
    background: linear-gradient(178deg, var(--primary) 0%, var(--primary-dark) 62%, var(--primary-darker) 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    z-index: 40;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: 0 1.15rem;
    height: var(--topbar-h);
    flex-shrink: 0;
    border-bottom: 1px solid rgba(255, 255, 255, .11);
}
.sidebar-logo {
    width: 34px; height: 34px; flex-shrink: 0;
    border-radius: 9px;
    background: rgba(255, 255, 255, .16);
    display: grid; place-items: center;
    font-weight: 800; font-size: .78rem; letter-spacing: .04em;
}
.sidebar-brand-text { min-width: 0; }
.sidebar-brand-text strong { display: block; font-size: .93rem; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.sidebar-brand-text span { display: block; font-size: .68rem; opacity: .68; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }

.sidebar-scroll { flex: 1; overflow-y: auto; overflow-x: hidden; padding: .85rem 0 1.25rem; }
.sidebar-scroll::-webkit-scrollbar { width: 5px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, .22); }

.nav-section { margin-bottom: .3rem; }
.nav-heading {
    padding: .8rem 1.35rem .35rem;
    font-size: .655rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: rgba(255, 255, 255, .42);
    white-space: nowrap;
}

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .53rem 1.35rem;
    color: rgba(255, 255, 255, .8);
    font-size: .855rem;
    font-weight: 500;
    border-left: 3px solid transparent;
    transition: background .13s, color .13s, border-color .13s;
    white-space: nowrap;
}
.sidebar nav a svg { width: 17px; height: 17px; flex-shrink: 0; opacity: .82; }
.sidebar nav a:hover { background: rgba(255, 255, 255, .09); color: #fff; }
.sidebar nav a.active {
    background: rgba(255, 255, 255, .13);
    color: #fff;
    border-left-color: #fff;
    font-weight: 600;
}
.sidebar nav a.active svg { opacity: 1; }
.nav-badge {
    margin-left: auto;
    background: rgba(255, 255, 255, .2);
    border-radius: 999px;
    padding: .05rem .42rem;
    font-size: .68rem;
    font-weight: 700;
}

.sidebar-footer {
    flex-shrink: 0;
    padding: .8rem 1.15rem;
    border-top: 1px solid rgba(255, 255, 255, .11);
    font-size: .78rem;
}
.sidebar-user { display: flex; align-items: center; gap: .6rem; min-width: 0; }
.sidebar-user .avatar {
    width: 32px; height: 32px; flex-shrink: 0; border-radius: 50%;
    background: rgba(255, 255, 255, .18);
    display: grid; place-items: center;
    font-weight: 700; font-size: .78rem;
}
.sidebar-user-meta { min-width: 0; flex: 1; }
.sidebar-user-meta strong { display: block; font-size: .8rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-user-meta span { display: block; font-size: .68rem; opacity: .62; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-logout {
    background: rgba(255, 255, 255, .12); border: none; color: #fff; cursor: pointer;
    width: 30px; height: 30px; border-radius: var(--radius-sm); display: grid; place-items: center;
    flex-shrink: 0; transition: background .13s;
}
.sidebar-logout:hover { background: rgba(255, 255, 255, .26); }
.sidebar-logout svg { width: 15px; height: 15px; }

/* Collapsed sidebar ------------------------------------------------------ */
body.sidebar-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
body.sidebar-collapsed .sidebar-brand-text,
body.sidebar-collapsed .nav-heading,
body.sidebar-collapsed .sidebar nav a span,
body.sidebar-collapsed .nav-badge,
body.sidebar-collapsed .sidebar-user-meta { display: none; }
body.sidebar-collapsed .sidebar nav a { justify-content: center; padding-inline: 0; }
body.sidebar-collapsed .sidebar-brand { justify-content: center; padding-inline: 0; }
body.sidebar-collapsed .nav-heading { display: block; height: 1px; padding: .5rem 0; overflow: hidden; color: transparent; }
body.sidebar-collapsed .sidebar-footer { padding-inline: .5rem; }
body.sidebar-collapsed .sidebar-user { justify-content: center; }

/* Main ------------------------------------------------------------------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
    height: var(--topbar-h);
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 1.35rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 30;
}
.topbar-toggle {
    background: transparent; border: 1px solid var(--border); border-radius: var(--radius-sm);
    width: 32px; height: 32px; cursor: pointer; color: var(--text-soft);
    display: grid; place-items: center; flex-shrink: 0; transition: background .13s;
}
.topbar-toggle:hover { background: var(--bg); }
.topbar-toggle svg { width: 16px; height: 16px; }

.topbar-titles { min-width: 0; flex: 1; }
.topbar-titles h1 { font-size: 1.02rem; font-weight: 700; color: var(--text); letter-spacing: -.01em; line-height: 1.2; }
.breadcrumb { display: flex; align-items: center; gap: .32rem; font-size: .74rem; color: var(--muted); margin-top: .08rem; flex-wrap: wrap; }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--primary); }
.breadcrumb .sep { opacity: .5; }
.breadcrumb .current { color: var(--text-soft); font-weight: 500; }

.topbar-actions { display: flex; align-items: center; gap: .6rem; flex-shrink: 0; }
.topbar-search { position: relative; }
.topbar-search input {
    width: 230px; padding: .42rem .7rem .42rem 2rem;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    font-family: inherit; font-size: .82rem; background: var(--bg); color: var(--text);
}
.topbar-search input:focus { outline: none; border-color: var(--primary); background: var(--card); box-shadow: 0 0 0 3px var(--primary-soft); }
.topbar-search svg { position: absolute; left: .6rem; top: 50%; transform: translateY(-50%); width: 14px; height: 14px; color: var(--faint); pointer-events: none; }
.topbar-date { font-size: .78rem; color: var(--muted); white-space: nowrap; }

.content { padding: 1.35rem; flex: 1; min-width: 0; }

/* ==========================================================================
   Page header
   ========================================================================== */

.page-head {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 1rem; margin-bottom: 1.15rem; flex-wrap: wrap;
}
.page-head-text h2 { font-size: 1.28rem; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.page-head-text p { font-size: .845rem; color: var(--muted); margin-top: .12rem; max-width: 62ch; }
.page-head-actions { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

/* ==========================================================================
   Cards
   ========================================================================== */

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-xs);
    margin-bottom: 1.15rem;
}
.card-head {
    padding: .85rem 1.1rem;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap;
}
.card-head h3 { font-size: .92rem; font-weight: 650; color: var(--text); letter-spacing: -.01em; }
.card-head p { font-size: .78rem; color: var(--muted); margin-top: .05rem; }
.card-head-actions { display: flex; align-items: center; gap: .45rem; flex-wrap: wrap; }
.card-body { padding: 1.1rem; }
.card-body.tight { padding: .75rem 1.1rem; }
.card-body.flush { padding: 0; }
.card-foot {
    padding: .75rem 1.1rem; border-top: 1px solid var(--border);
    background: var(--primary-softer); border-radius: 0 0 var(--radius) var(--radius);
    display: flex; align-items: center; justify-content: space-between; gap: .75rem; flex-wrap: wrap;
}
.card.flat { box-shadow: none; }

/* ==========================================================================
   Stat tiles
   ========================================================================== */

.stat {
    background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: .95rem 1.05rem; box-shadow: var(--shadow-xs);
    display: flex; flex-direction: column; gap: .5rem; min-width: 0;
    position: relative; overflow: hidden;
}
.stat::before {
    content: ''; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--primary);
    opacity: .85;
}
.stat.stat-accent::before { background: var(--accent); }
.stat.stat-warn::before { background: var(--warn); }
.stat.stat-danger::before { background: var(--danger); }
.stat.stat-info::before { background: var(--info); }
.stat.stat-purple::before { background: var(--purple); }

.stat-top { display: flex; align-items: flex-start; justify-content: space-between; gap: .6rem; }
.stat-label { font-size: .715rem; font-weight: 650; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.stat-icon {
    width: 32px; height: 32px; border-radius: 9px; flex-shrink: 0;
    display: grid; place-items: center; background: var(--primary-soft); color: var(--primary);
}
.stat-icon svg { width: 16px; height: 16px; }
.stat.stat-accent .stat-icon { background: var(--accent-soft); color: #067a41; }
.stat.stat-warn .stat-icon { background: var(--warn-soft); color: var(--warn); }
.stat.stat-danger .stat-icon { background: var(--danger-soft); color: var(--danger); }
.stat.stat-info .stat-icon { background: var(--info-soft); color: var(--info); }
.stat.stat-purple .stat-icon { background: var(--purple-soft); color: var(--purple); }

.stat-value { font-size: 1.5rem; font-weight: 750; letter-spacing: -.03em; color: var(--text); line-height: 1.1; }
.stat-value small { font-size: .82rem; font-weight: 600; color: var(--muted); letter-spacing: 0; }
.stat-meta { font-size: .755rem; color: var(--muted); display: flex; align-items: center; gap: .3rem; }
.stat-trend { font-weight: 650; }
.stat-trend.up { color: #067a41; }
.stat-trend.down { color: var(--danger); }

/* ==========================================================================
   Grids
   ========================================================================== */

.grid { display: grid; gap: 1.1rem; margin-bottom: 1.15rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(205px, 1fr)); }
.grid-5 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-6 { grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); }
.grid-sidebar { grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); }
.grid-sidebar-left { grid-template-columns: minmax(280px, 1fr) minmax(0, 2fr); }
.grid > .card, .grid > .stat { margin-bottom: 0; }
@media (max-width: 1100px) {
    .grid-sidebar, .grid-sidebar-left { grid-template-columns: 1fr; }
}

/* ==========================================================================
   Tables
   ========================================================================== */

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .845rem; }
table.data thead th {
    background: var(--primary-softer);
    color: var(--text-soft);
    text-align: left;
    padding: .62rem .9rem;
    font-weight: 650;
    font-size: .715rem;
    letter-spacing: .055em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    position: sticky; top: 0; z-index: 1;
}
table.data tbody td { padding: .68rem .9rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover td { background: var(--primary-softer); }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data td.actions, table.data th.actions { text-align: right; white-space: nowrap; width: 1%; }
table.data td.actions .btn + .btn, table.data td.actions .btn + form { margin-left: .3rem; }
table.data td.actions form { display: inline-block; }
table.data .strong { font-weight: 600; color: var(--text); }
table.data .sub { display: block; font-size: .755rem; color: var(--muted); font-weight: 400; }
table.data tfoot td {
    padding: .7rem .9rem; font-weight: 700; background: var(--primary-softer);
    border-top: 2px solid var(--border-strong); font-variant-numeric: tabular-nums;
}
table.data.compact tbody td, table.data.compact thead th { padding: .45rem .7rem; }
table.data.striped tbody tr:nth-child(even) td { background: #fafbfd; }
table.data.striped tbody tr:hover td { background: var(--primary-softer); }

/* Key/value definition table */
table.kv { width: 100%; border-collapse: collapse; font-size: .855rem; }
table.kv th {
    text-align: left; padding: .5rem .85rem .5rem 0; width: 42%;
    font-weight: 500; color: var(--muted); vertical-align: top;
    border-bottom: 1px solid var(--border); white-space: nowrap;
}
table.kv td { padding: .5rem 0; border-bottom: 1px solid var(--border); font-weight: 550; color: var(--text); }
table.kv tr:last-child th, table.kv tr:last-child td { border-bottom: none; }

.empty-state { padding: 2.6rem 1.2rem; text-align: center; }
.empty-state svg { width: 38px; height: 38px; color: var(--border-strong); margin-bottom: .6rem; }
.empty-state h4 { font-size: .93rem; font-weight: 650; color: var(--text-soft); margin-bottom: .22rem; }
.empty-state p { font-size: .82rem; color: var(--muted); max-width: 40ch; margin: 0 auto .85rem; }

/* ==========================================================================
   Badges & pills
   ========================================================================== */

.badge {
    display: inline-flex; align-items: center; gap: .28rem;
    padding: .16rem .5rem; border-radius: 999px;
    font-size: .715rem; font-weight: 650; letter-spacing: .01em;
    text-transform: capitalize; white-space: nowrap; line-height: 1.5;
    border: 1px solid transparent;
}
.badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.badge.no-dot::before { display: none; }

.badge-green,
.badge-active, .badge-completed, .badge-present, .badge-paid, .badge-approved,
.badge-disbursed, .badge-finalized, .badge-shared_out
{ background: var(--accent-soft); color: #067a41; border-color: #b7ecd0; }

.badge-red,
.badge-inactive, .badge-cancelled, .badge-absent, .badge-rejected, .badge-overdue,
.badge-written_off, .badge-suspended, .badge-reversed, .badge-failed, .badge-dissolved
{ background: var(--danger-soft); color: #a02a1d; border-color: #f6c9c3; }

.badge-blue,
.badge-scheduled, .badge-requested, .badge-estimated, .badge-excused, .badge-closed
{ background: var(--info-soft); color: #075985; border-color: #bae6fd; }

.badge-amber,
.badge-in_progress, .badge-late, .badge-pending, .badge-partial, .badge-partially_paid,
.badge-under_review, .badge-outstanding, .badge-assigned, .badge-exited
{ background: var(--warn-soft); color: #92400e; border-color: #fde68a; }

.badge-grey, .badge-waived, .badge-reported, .badge-null
{ background: #f1f3f7; color: var(--text-soft); border-color: var(--border); }

.badge-purple { background: var(--purple-soft); color: var(--purple); border-color: #ddd0fb; }

.badge-lg { padding: .28rem .7rem; font-size: .78rem; }

.chip {
    display: inline-flex; align-items: center; gap: .3rem;
    background: var(--primary-soft); color: var(--primary-dark);
    padding: .16rem .55rem; border-radius: var(--radius-sm);
    font-size: .755rem; font-weight: 600;
}
.chip-muted { background: #f1f3f7; color: var(--text-soft); }

.mono { font-family: var(--mono); font-size: .8rem; letter-spacing: -.02em; }

/* ==========================================================================
   Buttons
   ========================================================================== */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: .38rem;
    padding: .46rem .9rem; border-radius: var(--radius-sm);
    font-family: inherit; font-size: .845rem; font-weight: 600; line-height: 1.35;
    border: 1px solid transparent; cursor: pointer; white-space: nowrap;
    transition: background .13s, border-color .13s, color .13s, box-shadow .13s;
    text-decoration: none;
}
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn:disabled, .btn.disabled { opacity: .55; pointer-events: none; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-mid); color: #fff; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: #008d45; color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #a02a1d; color: #fff; }
.btn-warn { background: var(--warn); color: #fff; }
.btn-warn:hover { background: #92400e; color: #fff; }

.btn-outline { background: var(--card); border-color: var(--border-strong); color: var(--text-soft); }
.btn-outline:hover { background: var(--bg); border-color: var(--faint); color: var(--text); }
.btn-outline-primary { background: var(--card); border-color: var(--primary); color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary-soft); color: var(--primary-dark); }
.btn-outline-danger { background: var(--card); border-color: #f0b8b1; color: var(--danger); }
.btn-outline-danger:hover { background: var(--danger-soft); color: #a02a1d; }

.btn-ghost { background: transparent; color: var(--text-soft); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }

.btn-sm { padding: .3rem .62rem; font-size: .785rem; }
.btn-sm svg { width: 13px; height: 13px; }
.btn-xs { padding: .2rem .48rem; font-size: .735rem; }
.btn-xs svg { width: 12px; height: 12px; }
.btn-lg { padding: .6rem 1.25rem; font-size: .92rem; }
.btn-icon { padding: .38rem; }
.btn-block { width: 100%; }

.btn-group { display: inline-flex; gap: 0; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.btn-group .btn:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
.btn-group .btn + .btn { margin-left: -1px; }

.btn-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }

/* ==========================================================================
   Forms
   ========================================================================== */

.form-section { margin-bottom: 1.4rem; }
.form-section:last-child { margin-bottom: 0; }
.form-section > legend,
.form-section-title {
    display: block; width: 100%;
    font-size: .755rem; font-weight: 700; letter-spacing: .075em; text-transform: uppercase;
    color: var(--primary); padding-bottom: .45rem; margin-bottom: .95rem;
    border-bottom: 1px solid var(--border);
}
.form-section-title small { display: block; text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--muted); font-size: .78rem; margin-top: .2rem; }

.form-grid { display: grid; gap: .9rem 1.05rem; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); }
.form-grid-2 { grid-template-columns: repeat(auto-fit, minmax(270px, 1fr)); }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-full { grid-column: 1 / -1; }
@media (max-width: 640px) {
    .form-grid, .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
    .form-grid .span-2 { grid-column: span 1; }
}

.field { display: flex; flex-direction: column; gap: .28rem; min-width: 0; }
.field > label {
    font-size: .795rem; font-weight: 600; color: var(--text-soft);
    display: flex; align-items: center; gap: .25rem;
}
.field > label .req { color: var(--danger); font-weight: 700; }
.field .hint { font-size: .745rem; color: var(--muted); line-height: 1.45; }
.field .err { font-size: .755rem; color: var(--danger); font-weight: 550; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=time], input[type=tel], input[type=url],
input[type=datetime-local], input[type=search], input[type=file],
select, textarea {
    width: 100%;
    padding: .48rem .68rem;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-family: inherit; font-size: .855rem; color: var(--text);
    background: var(--card);
    transition: border-color .13s, box-shadow .13s;
}
select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5' stroke-linecap='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right .55rem center;
    background-size: 15px;
    padding-right: 2rem;
}
textarea { min-height: 78px; resize: vertical; line-height: 1.55; }
input:focus, select:focus, textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
input:disabled, select:disabled, textarea:disabled, input[readonly] {
    background: var(--bg); color: var(--muted); cursor: not-allowed;
}
input.is-invalid, select.is-invalid, textarea.is-invalid { border-color: var(--danger); }
input.is-invalid:focus, select.is-invalid:focus, textarea.is-invalid:focus { box-shadow: 0 0 0 3px var(--danger-soft); }
input[type=file] { padding: .34rem .5rem; font-size: .8rem; }
input::placeholder, textarea::placeholder { color: var(--faint); }

.input-prefix { position: relative; display: flex; align-items: center; }
.input-prefix > span {
    position: absolute; left: .6rem; font-size: .82rem; color: var(--muted); font-weight: 600; pointer-events: none;
}
.input-prefix input { padding-left: 2.1rem; }
.input-suffix { position: relative; display: flex; align-items: center; }
.input-suffix > span { position: absolute; right: .68rem; font-size: .8rem; color: var(--muted); font-weight: 600; pointer-events: none; }
.input-suffix input { padding-right: 2.4rem; }

.check { display: flex; align-items: flex-start; gap: .5rem; font-size: .845rem; cursor: pointer; }
.check input[type=checkbox], .check input[type=radio] {
    width: 15px; height: 15px; margin-top: .17rem; flex-shrink: 0; accent-color: var(--primary); cursor: pointer;
}
.check span { color: var(--text-soft); }
.check strong { display: block; font-weight: 600; color: var(--text); font-size: .845rem; }
.check small { display: block; color: var(--muted); font-size: .75rem; }

.check-grid { display: grid; gap: .5rem .95rem; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

.switch { display: inline-flex; align-items: center; gap: .55rem; cursor: pointer; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .track {
    width: 36px; height: 20px; border-radius: 999px; background: var(--border-strong);
    position: relative; transition: background .16s; flex-shrink: 0;
}
.switch .track::after {
    content: ''; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px;
    border-radius: 50%; background: #fff; transition: transform .16s; box-shadow: var(--shadow-xs);
}
.switch input:checked + .track { background: var(--accent); }
.switch input:checked + .track::after { transform: translateX(16px); }
.switch input:focus-visible + .track { box-shadow: 0 0 0 3px var(--primary-soft); }
.switch .switch-label { font-size: .845rem; font-weight: 550; color: var(--text-soft); }

.form-actions {
    display: flex; align-items: center; justify-content: flex-end; gap: .6rem;
    padding-top: 1.1rem; margin-top: 1.1rem; border-top: 1px solid var(--border); flex-wrap: wrap;
}
.form-actions.split { justify-content: space-between; }

/* Filter bar ------------------------------------------------------------- */
.filters {
    display: flex; align-items: flex-end; gap: .6rem; flex-wrap: wrap;
    padding: .85rem 1.1rem; border-bottom: 1px solid var(--border); background: var(--primary-softer);
    border-radius: var(--radius) var(--radius) 0 0;
}
.filters .field { flex: 1 1 160px; min-width: 140px; max-width: 260px; }
.filters .field > label { font-size: .7rem; font-weight: 650; letter-spacing: .045em; text-transform: uppercase; color: var(--muted); }
.filters input, .filters select { padding: .38rem .6rem; font-size: .82rem; }
.filters select { padding-right: 1.9rem; }
.filters .filter-actions { display: flex; gap: .4rem; flex-shrink: 0; }

/* ==========================================================================
   Tabs
   ========================================================================== */

.tabs {
    display: flex; gap: .15rem; border-bottom: 1px solid var(--border);
    margin-bottom: 1.15rem; overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
    padding: .58rem .9rem; font-size: .855rem; font-weight: 600; color: var(--muted);
    border-bottom: 2px solid transparent; white-space: nowrap; margin-bottom: -1px;
    transition: color .13s, border-color .13s; display: flex; align-items: center; gap: .38rem;
}
.tabs a:hover { color: var(--text); }
.tabs a.active { color: var(--primary); border-bottom-color: var(--primary); }
.tabs a .count {
    background: var(--bg); color: var(--muted); border-radius: 999px;
    padding: .02rem .38rem; font-size: .7rem; font-weight: 700;
}
.tabs a.active .count { background: var(--primary-soft); color: var(--primary); }

/* ==========================================================================
   Alerts & flash
   ========================================================================== */

.alert {
    display: flex; align-items: flex-start; gap: .6rem;
    padding: .72rem .95rem; border-radius: var(--radius-sm);
    font-size: .855rem; margin-bottom: 1rem; border: 1px solid transparent;
}
.alert svg { width: 17px; height: 17px; flex-shrink: 0; margin-top: .09rem; }
.alert-body { min-width: 0; flex: 1; }
.alert strong { font-weight: 650; }
.alert ul { margin: .3rem 0 0; padding-left: 1.1rem; }
.alert li { margin-top: .12rem; }
.alert-close { background: none; border: none; cursor: pointer; color: inherit; opacity: .55; padding: 0; line-height: 1; }
.alert-close:hover { opacity: 1; }

.alert-success { background: var(--accent-soft); color: #056136; border-color: #b7ecd0; }
.alert-error, .alert-danger { background: var(--danger-soft); color: #8f2419; border-color: #f6c9c3; }
.alert-warning { background: var(--warn-soft); color: #7c2d12; border-color: #fde68a; }
.alert-info { background: var(--info-soft); color: #075985; border-color: #bae6fd; }

/* ==========================================================================
   Pagination
   ========================================================================== */

.pagination-wrap {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: .8rem 1.1rem; border-top: 1px solid var(--border); flex-wrap: wrap;
}
.pagination-info { font-size: .8rem; color: var(--muted); }
.pagination { display: flex; align-items: center; gap: .25rem; flex-wrap: wrap; list-style: none; }
.pagination li { display: block; }
.pagination a, .pagination span {
    display: block; min-width: 30px; text-align: center;
    padding: .28rem .55rem; border: 1px solid var(--border);
    border-radius: var(--radius-sm); font-size: .81rem; font-weight: 550;
    color: var(--text-soft); background: var(--card);
}
.pagination a:hover { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }
.pagination .active span, .pagination li.active span {
    background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 650;
}
.pagination .disabled span { color: var(--faint); background: var(--bg); }
.pagination svg { width: 13px; height: 13px; display: inline-block; vertical-align: -2px; }

/* ==========================================================================
   Charts
   ========================================================================== */

.chart-box { position: relative; width: 100%; height: 280px; }
.chart-box.sm { height: 205px; }
.chart-box.lg { height: 340px; }
.chart-legend { display: flex; gap: 1rem; flex-wrap: wrap; margin-top: .8rem; font-size: .795rem; color: var(--text-soft); }
.chart-legend span { display: inline-flex; align-items: center; gap: .4rem; }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* ==========================================================================
   Misc components
   ========================================================================== */

.progress { height: 6px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; transition: width .3s; }
.progress.accent > span { background: var(--accent); }
.progress.warn > span { background: var(--warn); }
.progress.danger > span { background: var(--danger); }

.timeline { position: relative; padding-left: 1.5rem; }
.timeline::before { content: ''; position: absolute; left: 5px; top: .4rem; bottom: .4rem; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: 1.05rem; }
.timeline-item:last-child { padding-bottom: 0; }
.timeline-item::before {
    content: ''; position: absolute; left: -1.5rem; top: .32rem; width: 12px; height: 12px;
    border-radius: 50%; background: var(--card); border: 2px solid var(--primary);
}
.timeline-item.done::before { background: var(--accent); border-color: var(--accent); }
.timeline-item.muted::before { border-color: var(--border-strong); }
.timeline-item .t-title { font-size: .855rem; font-weight: 600; color: var(--text); }
.timeline-item .t-meta { font-size: .765rem; color: var(--muted); }

.avatar-lg {
    width: 76px; height: 76px; border-radius: var(--radius); object-fit: cover;
    background: var(--primary-soft); color: var(--primary);
    display: grid; place-items: center; font-size: 1.5rem; font-weight: 700; flex-shrink: 0;
    border: 1px solid var(--border);
}

.profile-head { display: flex; gap: 1.1rem; align-items: flex-start; flex-wrap: wrap; }
.profile-head-meta { flex: 1; min-width: 200px; }
.profile-head-meta h2 { font-size: 1.22rem; font-weight: 700; letter-spacing: -.02em; }
.profile-head-meta .sub { font-size: .84rem; color: var(--muted); margin-top: .1rem; }
.profile-head-meta .tags { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .55rem; }

.step-list { display: grid; gap: .6rem; }
.step {
    display: flex; gap: .8rem; align-items: flex-start;
    padding: .85rem 1rem; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--card); transition: border-color .13s, box-shadow .13s;
}
.step:hover { border-color: var(--primary); box-shadow: var(--shadow-xs); }
.step-num {
    width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
    background: var(--primary-soft); color: var(--primary);
    display: grid; place-items: center; font-size: .775rem; font-weight: 700;
}
.step.done .step-num { background: var(--accent); color: #fff; }
.step.locked { opacity: .58; }
.step-body { flex: 1; min-width: 0; }
.step-body h4 { font-size: .885rem; font-weight: 650; }
.step-body p { font-size: .795rem; color: var(--muted); margin-top: .1rem; }
.step-side { flex-shrink: 0; display: flex; align-items: center; gap: .45rem; }

.callout {
    padding: .8rem 1rem; border-radius: var(--radius-sm);
    background: var(--primary-softer); border: 1px solid var(--border);
    border-left: 3px solid var(--primary); font-size: .835rem; color: var(--text-soft);
}
.callout strong { color: var(--text); }

.report-card {
    display: flex; gap: .85rem; align-items: flex-start;
    padding: 1rem; border: 1px solid var(--border); border-radius: var(--radius);
    background: var(--card); box-shadow: var(--shadow-xs);
    transition: border-color .13s, box-shadow .13s, transform .13s;
}
.report-card:hover { border-color: var(--primary); box-shadow: var(--shadow); transform: translateY(-1px); }
.report-card .r-icon {
    width: 36px; height: 36px; border-radius: 9px; flex-shrink: 0;
    background: var(--primary-soft); color: var(--primary); display: grid; place-items: center;
}
.report-card .r-icon svg { width: 18px; height: 18px; }
.report-card h4 { font-size: .885rem; font-weight: 650; color: var(--text); }
.report-card p { font-size: .79rem; color: var(--muted); margin-top: .15rem; }
.report-card .r-links { display: flex; gap: .4rem; margin-top: .6rem; flex-wrap: wrap; }

/* Ranking list */
.rank-list { display: grid; gap: .1rem; }
.rank-row {
    display: flex; align-items: center; gap: .7rem;
    padding: .55rem .3rem; border-bottom: 1px solid var(--border); font-size: .855rem;
}
.rank-row:last-child { border-bottom: none; }
.rank-pos {
    width: 22px; height: 22px; border-radius: 6px; flex-shrink: 0;
    background: var(--bg); color: var(--text-soft);
    display: grid; place-items: center; font-size: .73rem; font-weight: 700;
}
.rank-row:nth-child(1) .rank-pos { background: #fef3c7; color: #92400e; }
.rank-row:nth-child(2) .rank-pos { background: #eef1f6; color: #475069; }
.rank-row:nth-child(3) .rank-pos { background: #fdece0; color: #9a3412; }
.rank-main { flex: 1; min-width: 0; }
.rank-main strong { display: block; font-weight: 600; font-size: .855rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-main small { color: var(--muted); font-size: .755rem; }
.rank-val { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ==========================================================================
   Modal (CSS-only, :target based fallback + JS driven)
   ========================================================================== */

.modal-backdrop {
    position: fixed; inset: 0; background: rgba(16, 24, 40, .5);
    display: none; align-items: center; justify-content: center; padding: 1.25rem; z-index: 100;
}
.modal-backdrop.open { display: flex; }
.modal {
    background: var(--card); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    width: 100%; max-width: 520px; max-height: 90vh; display: flex; flex-direction: column;
}
.modal.wide { max-width: 780px; }
.modal-head {
    padding: 1rem 1.2rem; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between; gap: .75rem;
}
.modal-head h3 { font-size: 1rem; font-weight: 650; }
.modal-body { padding: 1.2rem; overflow-y: auto; }
.modal-foot { padding: .9rem 1.2rem; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: .55rem; }

/* ==========================================================================
   Utilities
   ========================================================================== */

.text-muted { color: var(--muted); }
.text-faint { color: var(--faint); }
.text-danger { color: var(--danger); }
.text-accent { color: #067a41; }
.text-warn { color: var(--warn); }
.text-primary { color: var(--primary); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-sm { font-size: .8rem; }
.text-xs { font-size: .74rem; }
.text-lg { font-size: 1rem; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }
.nums { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mt-0 { margin-top: 0 !important; }
.mt-1 { margin-top: .35rem; }
.mt-2 { margin-top: .7rem; }
.mt-3 { margin-top: 1.1rem; }
.mt-4 { margin-top: 1.6rem; }
.mb-0 { margin-bottom: 0 !important; }
.mb-1 { margin-bottom: .35rem; }
.mb-2 { margin-bottom: .7rem; }
.mb-3 { margin-bottom: 1.1rem; }
.mb-4 { margin-bottom: 1.6rem; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.items-end { align-items: flex-end; }
.justify-between { justify-content: space-between; }
.justify-end { justify-content: flex-end; }
.justify-center { justify-content: center; }
.gap-1 { gap: .35rem; }
.gap-2 { gap: .7rem; }
.gap-3 { gap: 1.1rem; }
.wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; min-width: 0; }
.hidden { display: none !important; }
.w-full { width: 100%; }

.divider { height: 1px; background: var(--border); margin: 1.1rem 0; border: none; }

/* ==========================================================================
   Login page
   ========================================================================== */

.auth-shell {
    min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr;
    background: var(--bg);
}
.auth-aside {
    background: linear-gradient(150deg, var(--primary) 0%, var(--primary-dark) 55%, var(--primary-darker) 100%);
    color: #fff; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between;
    position: relative; overflow: hidden;
}
.auth-aside::after {
    content: ''; position: absolute; right: -140px; bottom: -160px; width: 420px; height: 420px;
    border-radius: 50%; background: rgba(255, 255, 255, .05);
}
.auth-aside::before {
    content: ''; position: absolute; right: 40px; top: -180px; width: 320px; height: 320px;
    border-radius: 50%; background: rgba(255, 255, 255, .04);
}
.auth-aside .a-brand { display: flex; align-items: center; gap: .75rem; position: relative; }
.auth-aside .a-brand .sidebar-logo { width: 40px; height: 40px; font-size: .85rem; }
.auth-aside .a-brand strong { font-size: 1.05rem; font-weight: 700; }
.auth-aside .a-brand span { display: block; font-size: .72rem; opacity: .7; text-transform: uppercase; letter-spacing: .06em; }
.auth-aside .a-copy { position: relative; max-width: 34ch; }
.auth-aside .a-copy h2 { font-size: 1.85rem; font-weight: 750; letter-spacing: -.03em; line-height: 1.2; }
.auth-aside .a-copy p { margin-top: .7rem; opacity: .82; font-size: .93rem; line-height: 1.6; }
.auth-aside .a-feats { position: relative; display: grid; gap: .55rem; }
.auth-aside .a-feats div { display: flex; align-items: center; gap: .55rem; font-size: .875rem; opacity: .88; }
.auth-aside .a-feats svg { width: 16px; height: 16px; flex-shrink: 0; }

.auth-main { display: grid; place-items: center; padding: 2rem; }
.auth-card { width: 100%; max-width: 388px; }
.auth-card h1 { font-size: 1.45rem; font-weight: 750; letter-spacing: -.025em; }
.auth-card > p { font-size: .875rem; color: var(--muted); margin-top: .3rem; margin-bottom: 1.5rem; }
.auth-card form { display: grid; gap: .95rem; }
.auth-foot { margin-top: 1.6rem; font-size: .765rem; color: var(--faint); text-align: center; }

@media (max-width: 900px) {
    .auth-shell { grid-template-columns: 1fr; }
    .auth-aside { display: none; }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 980px) {
    .sidebar {
        position: fixed; inset: 0 auto 0 0; transform: translateX(-100%);
        transition: transform .2s ease; box-shadow: var(--shadow-lg);
    }
    body.sidebar-open .sidebar { transform: translateX(0); }
    body.sidebar-collapsed .sidebar { width: var(--sidebar-w); }
    body.sidebar-collapsed .sidebar-brand-text,
    body.sidebar-collapsed .nav-heading,
    body.sidebar-collapsed .sidebar nav a span,
    body.sidebar-collapsed .sidebar-user-meta { display: block; }
    body.sidebar-collapsed .sidebar nav a { justify-content: flex-start; padding-inline: 1.35rem; }
    body.sidebar-collapsed .sidebar-brand { justify-content: flex-start; padding-inline: 1.15rem; }
    .sidebar-scrim { position: fixed; inset: 0; background: rgba(16, 24, 40, .45); z-index: 39; display: none; }
    body.sidebar-open .sidebar-scrim { display: block; }
    .topbar-search { display: none; }
    .topbar-date { display: none; }
}

@media (max-width: 620px) {
    .content { padding: .95rem; }
    .topbar { padding: 0 .95rem; }
    .page-head-text h2 { font-size: 1.12rem; }
    .stat-value { font-size: 1.28rem; }
}

@media print {
    .sidebar, .topbar, .page-head-actions, .filters, .pagination-wrap, .card-foot { display: none !important; }
    body { background: #fff; }
    .content { padding: 0; }
    .card { box-shadow: none; border-color: #ccc; break-inside: avoid; }
}

fieldset{
    display: contents;
}
