/* Dashboard Monitoring Stock — design tokens + components.
   Every component references tokens only; raw colour literals live in the
   :root blocks below so light/dark stay in sync. */

:root {
    /* Type scale */
    --text-xs: 11px;
    --text-sm: 12px;
    --text-md: 13px;
    --text-base: 14px;
    --text-lg: 16px;
    --text-xl: 20px;
    --text-2xl: 24px;
    --text-3xl: 30px;

    /* Surfaces & text */
    --color-bg: #f6f8fa;
    --color-surface: #ffffff;
    --color-surface-subtle: #f8fafc;
    --color-border: #e2e8f0;
    --color-border-strong: #cbd5e1;
    --color-text: #0f172a;
    /* #64748b measured 4.47:1 on --color-bg — just under AA for 13px text.
       This lands at 5.08:1 while still reading as muted. */
    --color-muted: #5e6b7e;

    /* Brand */
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-on-primary: #ffffff;

    /* Destructive */
    --color-danger: #dc2626;
    --color-danger-dark: #b91c1c;
    --color-error-tint: #fef2f2;

    /* Semantic pairs */
    --color-success-bg: #dcfce7;
    --color-success-text: #166534;
    --color-error-bg: #fee2e2;
    --color-error-text: #991b1b;
    --color-warning-bg: #fef3c7;
    --color-warning-text: #92400e;
    --color-info-bg: #dbeafe;
    --color-info-text: #1e40af;

    /* Sidebar */
    --color-sidebar: #1e293b;
    --color-sidebar-text: #cbd5e1;
    --color-sidebar-active: #334155;
    --color-sidebar-strong: #ffffff;
    --color-sidebar-heading: #94a3b8;

    /* Shape & elevation */
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 1px rgba(15, 23, 42, .03);
    --shadow-md: 0 4px 12px rgba(15, 23, 42, .08);
}

:root[data-theme="dark"] {
    --color-bg: #0b1220;
    --color-surface: #151d2e;
    --color-surface-subtle: #1a2334;
    --color-border: #2a3446;
    --color-border-strong: #3b4759;
    --color-text: #e2e8f0;
    --color-muted: #94a3b8;

    --color-primary: #3b82f6;
    --color-primary-dark: #60a5fa;
    --color-on-primary: #ffffff;

    --color-danger: #ef4444;
    --color-danger-dark: #dc2626;
    --color-error-tint: rgba(239, 68, 68, .08);

    /* Translucent so semantic chips sit on any surface */
    --color-success-bg: rgba(34, 197, 94, .15);
    --color-success-text: #4ade80;
    --color-error-bg: rgba(239, 68, 68, .15);
    --color-error-text: #f87171;
    --color-warning-bg: rgba(245, 158, 11, .15);
    --color-warning-text: #fbbf24;
    --color-info-bg: rgba(59, 130, 246, .15);
    --color-info-text: #60a5fa;

    --color-sidebar: #111827;
    --color-sidebar-text: #cbd5e1;
    --color-sidebar-active: #1f2937;
    --color-sidebar-strong: #f8fafc;
    --color-sidebar-heading: #94a3b8;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .35);
    --shadow-md: 0 6px 16px rgba(0, 0, 0, .45);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: var(--text-base);
    color: var(--color-text);
    background: var(--color-bg);
    min-height: 100vh;
    /* Scoped to body only — a global transition makes theme switching feel laggy */
    transition: background-color .15s, color .15s;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== App layout: sidebar + content ===== */
.app-wrapper { display: flex; min-height: 100vh; }

/* Sidebar stays put while the content area scrolls */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 240px;
    height: 100vh;
    flex-shrink: 0;
    background: var(--color-sidebar);
    color: var(--color-sidebar-text);
    display: flex;
    flex-direction: column;
    z-index: 20;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 14px 18px;
    font-size: var(--text-base);
    font-weight: 600;
    color: var(--color-sidebar-strong);
    border-bottom: 1px solid var(--color-sidebar-active);
}

/* Menu is compact enough to fit without a visible scrollbar; if a very short
   viewport still overflows it scrolls silently (bar hidden on all engines). */
.sidebar-nav {
    padding: 6px 0;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: none;      /* Firefox */
    -ms-overflow-style: none;   /* legacy Edge */
}

.sidebar-nav::-webkit-scrollbar { width: 0; height: 0; display: none; }

.sidebar-brand,
.sidebar-footer { flex-shrink: 0; }

/* 9px vertical is the most room the 14 menu items can take and still fit a
   720px-tall window without scrolling. The inset rounded highlight buys
   perceived breathing room at zero height cost. */
.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 8px;
    padding: 9px 12px;
    border-radius: 6px;
    font-size: var(--text-md);
    line-height: 1.35;
    color: var(--color-sidebar-text);
    text-decoration: none;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: var(--color-sidebar-active);
    color: var(--color-sidebar-strong);
}

.sidebar-section {
    padding: 12px 20px 6px;
    font-size: var(--text-xs);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--color-sidebar-heading);
}

/* The first group needs no extra gap above it */
.sidebar-nav > .sidebar-section:first-child { padding-top: 6px; }

.sidebar-footer {
    padding: 10px 18px 12px;
    border-top: 1px solid var(--color-sidebar-active);
}

.sidebar-user { margin-bottom: 8px; }

.sidebar-user-name { font-weight: 600; font-size: var(--text-md); color: var(--color-sidebar-strong); }

.sidebar-user-branch { font-size: var(--text-xs); color: var(--color-sidebar-heading); }

/* Offset by the fixed sidebar's width */
.main-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin-left: 240px;
}

/* ===== Topbar / page header ===== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 10;
    min-height: 56px;
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: 8px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.page-heading { display: flex; flex-direction: column; gap: 1px; min-width: 0; }

.page-title {
    font-size: var(--text-lg);
    font-weight: 600;
    line-height: 1.3;
}

.page-subtitle {
    font-size: var(--text-sm);
    color: var(--color-muted);
    line-height: 1.3;
}

.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.content { padding: 24px; flex: 1; }

/* Hamburger and overlay are display-controlled at the end of this file, after
   .btn-icon — otherwise .btn-icon's display:inline-flex wins on source order
   and the hamburger shows up on desktop too. */

@media (max-width: 768px) {
    /* Previously the sidebar became a full-width static block, so all 14 menu
       items, the profile block and Log Out stacked above the content and the
       first KPI was a long scroll away on every page. It is a drawer now. */
    .sidebar {
        width: 280px;
        max-width: 85vw;
        transform: translateX(-100%);
        transition: transform .2s ease;
    }

    .nav-open .sidebar { transform: translateX(0); }

    .nav-overlay {
        position: fixed;
        inset: 0;
        z-index: 15;
        background: rgba(15, 23, 42, .5);
        opacity: 0;
        pointer-events: none;
        transition: opacity .2s ease;
    }

    .nav-open .nav-overlay { opacity: 1; pointer-events: auto; }

    .main-area { margin-left: 0; }
}

/* A drawer that only opens with JS would be a nav nobody can reach if the
   script fails, so without JS it falls back to the old stacked layout. */
@media (max-width: 768px) {
    .no-js .sidebar {
        position: static;
        width: 100%;
        max-width: none;
        height: auto;
        transform: none;
    }

    .no-js .sidebar-nav { overflow-y: visible; }
    .no-js .nav-toggle { display: none; }
    .no-js .nav-overlay { display: none; }
}

/* ===== Guest layout ===== */
.guest-body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.guest-container { width: 100%; max-width: 460px; }

.guest-card { text-align: center; padding: 36px 32px; }

.guest-title { font-size: var(--text-xl); margin-bottom: 8px; }

.guest-subtitle { color: var(--color-muted); margin-bottom: 16px; }

.error-code {
    font-size: 56px;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 8px;
}

/* Stack trace on the 500 page; only ever rendered when APP_DEBUG=true */
.error-detail {
    text-align: left;
    font-size: 12px;
    line-height: 1.5;
    max-height: 320px;
    overflow: auto;
    padding: 12px;
    margin-bottom: 16px;
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    white-space: pre-wrap;
    word-break: break-all;
}

/* ===== Cards ===== */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 20px;
    margin-bottom: 20px;
}

.card-title { font-size: var(--text-lg); font-weight: 600; margin-bottom: 14px; }

/* ===== KPI cards ===== */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}

.kpi {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 0;
    padding: 18px 20px 16px 22px;
    overflow: hidden;
}

/* Thin left accent bar — the one decorative element the design calls for */
.kpi::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 3px;
    height: 100%;
    background: var(--color-border-strong);
    border-radius: var(--radius) 0 0 var(--radius);
}

.kpi--primary::before { background: var(--color-primary); }
.kpi--warn::before    { background: var(--color-warning-text); }
.kpi--ok::before      { background: var(--color-success-text); }
.kpi--info::before    { background: var(--color-info-text); }

.kpi-label {
    font-size: var(--text-sm);
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: .04em;
}

.kpi-value {
    font-size: var(--text-3xl);
    font-weight: 700;
    letter-spacing: -.02em;
    line-height: 1.1;
    color: var(--color-text);
    font-variant-numeric: tabular-nums;
}

.kpi-meta { font-size: var(--text-sm); color: var(--color-muted); min-height: 1.2em; }

.kpi-meta--up { color: var(--color-success-text); }
.kpi-meta--down { color: var(--color-error-text); }

/* Clickable variant */
a.kpi { text-decoration: none; color: inherit; }

a.kpi:hover {
    text-decoration: none;
    box-shadow: var(--shadow-md);
    border-color: var(--color-border-strong);
}

a.kpi::after {
    content: '\203A';
    position: absolute;
    top: 12px;
    right: 16px;
    color: var(--color-muted);
    font-size: var(--text-lg);
    line-height: 1;
}

/* ===== Charts ===== */
.chart-box { position: relative; height: 300px; }

/* Shown instead of an axis-only chart when every value is zero */
.chart-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 0 16px;
    font-size: var(--text-sm);
    color: var(--color-muted);
}

/* ===== Ranked list (top products) ===== */
.rank-list { display: flex; flex-direction: column; gap: 14px; }

.rank-item { display: flex; flex-direction: column; gap: 6px; }

.rank-row { display: flex; align-items: baseline; gap: 10px; }

.rank-num {
    flex-shrink: 0;
    width: 18px;
    font-size: var(--text-sm);
    color: var(--color-muted);
    font-variant-numeric: tabular-nums;
}

.rank-name {
    flex: 1;
    min-width: 0;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.rank-value {
    flex-shrink: 0;
    font-size: var(--text-md);
    color: var(--color-muted);
    font-variant-numeric: tabular-nums;
}

.rank-bar {
    height: 4px;
    border-radius: 999px;
    background: var(--color-surface-subtle);
    overflow: hidden;
}

.rank-bar-fill {
    height: 100%;
    border-radius: 999px;
    background: var(--color-primary);
    opacity: .5;
}

/* ===== Activity feed ===== */
.activity { display: flex; flex-direction: column; }

.activity-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--color-border);
}

.activity-item:first-child { padding-top: 0; }
.activity-item:last-child { padding-bottom: 0; border-bottom: none; }

.activity-qty {
    flex-shrink: 0;
    min-width: 52px;
    text-align: right;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--color-muted);
}

.activity-qty--up { color: var(--color-success-text); }
.activity-qty--down { color: var(--color-error-text); }

.activity-body { flex: 1; min-width: 0; }

.activity-main { font-weight: 500; }

.activity-branch { color: var(--color-muted); font-weight: 400; }

.activity-meta {
    font-size: var(--text-sm);
    color: var(--color-muted);
    margin-top: 2px;
}

.activity-empty { font-size: var(--text-sm); color: var(--color-muted); }

/* ===== Skeleton loading ===== */
.skeleton {
    display: inline-block;
    background: var(--color-surface-subtle);
    border-radius: 4px;
    animation: skeleton-pulse 1.4s ease-in-out infinite;
}

.skeleton-value { height: 30px; width: 90px; }
.skeleton-text { height: 12px; width: 100%; }

@keyframes skeleton-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .45; }
}

@media (prefers-reduced-motion: reduce) {
    .skeleton { animation: none; }
    body { transition: none; }
    .sidebar { transition: none; }
    .nav-overlay { transition: none; }
}

/* ===== Tables ===== */
.table-wrapper { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--color-surface);
}

/* No global nowrap — columns opt in with .nowrap so long text can wrap */
th, td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
}

th {
    background: var(--color-bg);
    font-weight: 600;
    font-size: var(--text-md);
    color: var(--color-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* Footer totals keep normal casing (currency prefixes like "Rp") */
tfoot th {
    text-transform: none;
    font-size: var(--text-base);
    color: var(--color-text);
    font-weight: 700;
}

tr:hover td { background: var(--color-surface-subtle); }

/* ===== Forms ===== */
.form-group { margin-bottom: 16px; }

label { display: block; font-weight: 500; margin-bottom: 6px; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font: inherit;
    background: var(--color-surface);
    color: var(--color-text);
}

input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: -1px;
    border-color: var(--color-primary);
}

.form-error { color: var(--color-error-text); font-size: var(--text-md); margin-top: 4px; }

/* Element+class selectors so these beat the input[type="..."] base rules above */
input.is-invalid,
select.is-invalid,
textarea.is-invalid {
    border-color: var(--color-danger);
    background: var(--color-error-tint);
}

input.is-invalid:focus,
select.is-invalid:focus,
textarea.is-invalid:focus {
    outline-color: var(--color-danger);
    border-color: var(--color-danger);
}

.form-hint { color: var(--color-muted); font-size: var(--text-md); margin-top: 4px; }

/* ===== Buttons ===== */
.btn {
    display: inline-block;
    padding: 9px 18px;
    border: 1px solid transparent;
    border-radius: var(--radius);
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover { text-decoration: none; }

.btn-primary { background: var(--color-primary); color: var(--color-on-primary); }
.btn-primary:hover { background: var(--color-primary-dark); }

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border-color: var(--color-border);
}
.btn-secondary:hover { background: var(--color-bg); }

.btn-danger { background: var(--color-danger); color: var(--color-on-primary); }
.btn-danger:hover { background: var(--color-danger-dark); }

.btn-sm { padding: 5px 12px; font-size: var(--text-md); }

/* Borderless square button (theme toggle) */
.btn-icon {
    width: 34px;
    height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 1px solid transparent;
    border-radius: var(--radius);
    background: transparent;
    color: var(--color-text);
    font-size: var(--text-lg);
    line-height: 1;
    cursor: pointer;
}

.btn-icon:hover { background: var(--color-surface-subtle); border-color: var(--color-border); }

/* Glyph follows data-theme, so the correct one is painted on first render */
.theme-glyph-dark { display: none; }
:root[data-theme="dark"] .theme-glyph-dark { display: inline; }
:root[data-theme="dark"] .theme-glyph-light { display: none; }

/* ===== Badges ===== */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: var(--text-sm);
    font-weight: 600;
}

.badge-success { background: var(--color-success-bg); color: var(--color-success-text); }
.badge-danger  { background: var(--color-error-bg); color: var(--color-error-text); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning-text); }
.badge-info    { background: var(--color-info-bg); color: var(--color-info-text); }
/* --color-muted on --color-border measured 4.39:1 — under AA for a 12px/600
   badge. The chip already reads as muted from its grey ground, so the text
   itself doesn't need to be dimmed. Now 14.48:1 light / 10.15:1 dark. */
.badge-muted   { background: var(--color-border); color: var(--color-text); }

/* ===== Alerts ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.alert-success { background: var(--color-success-bg); color: var(--color-success-text); }
.alert-error   { background: var(--color-error-bg); color: var(--color-error-text); }

/* ===== Dashboard secondary grid ===== */
.stat-grid-2 {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
    gap: 16px;
}

/* ===== Empty states ===== */
.empty-state {
    text-align: center;
    padding: 40px 24px;
}

.empty-state-icon {
    font-size: 40px;
    line-height: 1;
    margin-bottom: 12px;
}

.empty-state-title {
    font-size: var(--text-lg);
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--color-text);
}

.empty-state-message {
    color: var(--color-muted);
    max-width: 460px;
    margin: 0 auto 18px;
    line-height: 1.6;
}

.empty-state-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    flex-wrap: wrap;
}

/* ===== Onboarding checklist ===== */
.checklist { list-style: none; }

.checklist-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 0;
    border-bottom: 1px solid var(--color-border);
}

.checklist-item:last-child { border-bottom: none; }

.checklist-num {
    flex-shrink: 0;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--color-primary);
    color: var(--color-on-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-md);
    font-weight: 700;
}

.checklist-num-done { background: var(--color-success-text); }

.checklist-body { flex: 1; min-width: 0; }

.checklist-label { display: block; font-weight: 600; }

.checklist-desc {
    display: block;
    font-size: var(--text-md);
    color: var(--color-muted);
    margin-top: 2px;
}

.checklist-done .checklist-label { color: var(--color-muted); }

.checklist-action { flex-shrink: 0; }

.alert-info-card { border-left: 4px solid var(--color-primary); }

/* ===== Action strip =====
   An aging task is not a measurement: a KPI tile can state "3 pending" but not
   "the oldest has been sitting for 6 days", and the age is what decides whether
   anyone needs to act. Rendered only when there is something to act on — the
   absence of the strip is the all-clear. The 3px left rule deliberately echoes
   .kpi::before so the two read as one family. */
.action-strip {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 16px;
    margin-bottom: 20px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-left: 3px solid var(--color-border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    color: var(--color-text);
    text-decoration: none;
}

/* display:flex on a component beats the UA stylesheet's [hidden] rule, so every
   flex component that can be hidden needs this. Kept together so the next one
   added inherits the fix instead of rediscovering the bug. */
.action-strip[hidden],
.kpi[hidden],
.scope-bar[hidden] { display: none; }

.action-strip:hover {
    text-decoration: none;
    border-color: var(--color-border-strong);
    box-shadow: var(--shadow-md);
}

/* 3px rules on --color-surface: warning 7.09:1 light / 10.09:1 dark,
   danger 4.83:1 light / 4.47:1 dark — all past the 3:1 graphic minimum. */
.action-strip--warn   { border-left-color: var(--color-warning-text); }
.action-strip--danger { border-left-color: var(--color-danger); }

.action-strip-icon { flex-shrink: 0; font-size: var(--text-2xl); line-height: 1; }
.action-strip-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.action-strip-title { font-weight: 600; }
.action-strip-desc { font-size: var(--text-md); color: var(--color-muted); }
.action-strip-cta { flex-shrink: 0; align-self: center; }

/* Status chip leads the row, mirroring the signed qty in the activity feed, so
   the two side-by-side feeds read as different instruments at a glance. */
.activity-badge { flex-shrink: 0; min-width: 76px; }

/* ===== Page-level scope selector =====
   Not .toolbar: that treatment is a submitted filter form everywhere else in
   the app (fields + Terapkan/Reset), and this applies on change. Same chrome
   would promise a submit that never comes. */
.scope-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}

/* label is display:block with a bottom margin globally; both are undone here */
.scope-bar-label {
    margin-bottom: 0;
    font-size: var(--text-md);
    font-weight: 500;
    color: var(--color-muted);
}

.scope-bar-control { width: 240px; max-width: 100%; }
.scope-bar-status { font-size: var(--text-md); color: var(--color-muted); }

/* Pairs with .card-title.mb-0 — the title's bottom margin moves down here */
.card-subtitle {
    margin-bottom: 14px;
    font-size: var(--text-sm);
    color: var(--color-muted);
}

/* ===== Searchable dropdown (combobox) =====
   The native <select> stays in the DOM as the submitted control; JS hides it.
   Without JS none of these classes are applied and the select renders normally. */
.combobox { position: relative; }

/* element+class so it outranks utilities like .w-auto that the select may also
   carry — otherwise the hidden native control keeps its width and, being
   absolutely positioned, pushes the page into horizontal overflow. */
select.combobox-native {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* Matches the native control's metrics so toolbars don't reflow when enhanced */
.combobox-input {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font: inherit;
    background: var(--color-surface);
    color: var(--color-text);
    cursor: text;
}

.combobox-input:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: -1px;
    border-color: var(--color-primary);
}

.combobox-input.is-invalid {
    border-color: var(--color-danger);
    background: var(--color-error-tint);
}

.combobox-list {
    position: absolute;
    z-index: 30;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 260px;
    overflow-y: auto;
    padding: 4px;
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
}

.combobox-option {
    padding: 7px 10px;
    border-radius: 6px;
    font-size: var(--text-md);
    color: var(--color-text);
    cursor: pointer;
}

/* Keyboard cursor */
.combobox-option.is-active {
    background: var(--color-surface-subtle);
    box-shadow: inset 2px 0 0 var(--color-primary);
}

/* The info pair is tuned per theme; solid --color-primary with white text only
   reaches 3.68:1 in dark mode, which fails AA. */
.combobox-option.is-selected {
    background: var(--color-info-bg);
    color: var(--color-info-text);
    font-weight: 600;
}

.combobox-option.is-placeholder { color: var(--color-muted); }
.combobox-option.is-selected.is-placeholder { color: var(--color-info-text); }

.combobox-empty {
    padding: 10px;
    font-size: var(--text-md);
    color: var(--color-muted);
}

/* ===== Filter toolbar =====
   A filter row is a control surface, not data. Giving it .card made it carry
   the same visual weight as the results below it. */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 12px;
    padding: 12px 16px;
    margin-bottom: 20px;
    background: var(--color-surface-subtle);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
}

/* Fields sit on one line inside the toolbar, so their stacking margin goes */
.toolbar .form-group { margin-bottom: 0; }

.toolbar label {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--color-muted);
    margin-bottom: 4px;
}

.toolbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: auto;
}

/* Search-style field that should absorb the leftover width */
.toolbar-grow { flex: 1; min-width: 200px; }

/* ===== Utilities ===== */
.num { font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.text-muted { color: var(--color-muted); }
.text-right { text-align: right; }
.text-left { text-align: left; }
.text-md { font-size: var(--text-md); }

/* Inline add form: the field takes the leftover width. Set from the parent so
   the input keeps a single class attribute for invalid_attrs() to own. */
.category-form input[type="text"] { flex: 1; }

/* Emoji marker on empty-state cards */
.empty-glyph { font-size: var(--text-2xl); line-height: 1; }

/* Signed stock movements — tokenised so they survive a theme switch */
.text-pos { color: var(--color-success-text); font-weight: 600; }
.text-neg { color: var(--color-error-text); font-weight: 600; }

.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-0 { margin-bottom: 0; }
.mb-4 { margin-bottom: 16px; }
.flex { display: flex; gap: 12px; align-items: center; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-start { align-items: flex-start; }
.flex-1 { flex: 1; }
.gap-sm { gap: 6px; }
.w-auto { width: auto; }
.w-full { width: 100%; }
.font-normal { font-weight: 400; }

/* Single-column forms read better constrained; wider variants for detail pages */
.max-w-sm { max-width: 560px; }
.max-w-md { max-width: 620px; }
.max-w-lg { max-width: 720px; }
.max-w-xl { max-width: 760px; }
.max-w-2xl { max-width: 860px; }

/* Explicit column widths, previously inline on <th> */
.col-xs { width: 50px; }
.col-sm { width: 60px; }
.col-md { width: 100px; }
.col-lg { width: 120px; }
.col-xl { width: 140px; }
.col-2xl { width: 150px; }
.col-3xl { width: 180px; }
.col-4xl { width: 300px; }

/* ===== Mobile component overrides =====
   Deliberately last in the file: these target components declared further up
   (.kpi-grid, .chart-box, .stat-grid-2), and at equal specificity the later
   rule wins. Putting them in the layout media query near the top silently
   lost to the base declarations. */
@media (max-width: 768px) {
    /* Two-up, so four KPIs don't occupy a whole screen before any content */
    .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpi-value { font-size: var(--text-2xl); }

    /* 300px is tall and narrow once the viewport is 375px wide */
    .chart-box { height: 220px; }

    .stat-grid-2 { grid-template-columns: 1fr; }

    /* Filter fields stack rather than squeezing side by side */
    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar-actions { margin-left: 0; }
}

/* Drawer chrome visibility — last, so it outranks .btn-icon's display */
.nav-toggle,
.nav-overlay { display: none; }

@media (max-width: 768px) {
    .nav-toggle { display: inline-flex; }
    .no-js .nav-toggle { display: none; }

    .nav-overlay { display: block; }
    .no-js .nav-overlay { display: none; }
}
