/* ============================================================
   FinacctERP UI theme v6 - Material Design 3 (content section)
   - Shell (sidebar menu + top bar) keeps the v5 reference look:
     detached rounded panels, blue-gradient topbar, white 260px
     sidebar with 35px glow, menu hover #6c757d -> #00327d.
   - Content section (article.content + overlays it renders)
     uses a full MD3 token system: tonal color scheme generated
     from the brand navy seed #00327d (Material color utilities,
     baseline tone mapping), MD3 type scale, shape corners,
     elevation-as-tonal-surface, MD3 motion easing, state layers.
   - Legacy v5 variable names are re-declared inside
     article.content so the existing page-scoped stylesheets
     resolve to MD3 roles automatically; the shell keeps the
     original values.
   - Theme toggle: body.dark-theme (user-controlled, persisted);
     auto dark also honored on first paint via prefers-color-scheme.
   ============================================================ */

:root {
    --paper: #f5f6f8;
    --surface: #ffffff;
    --raised: #f8f9fb;
    --ink: #171923;
    --muted: #5f6570;
    --faint: #8a9099;
    --line: #e7e8ec;
    --line-strong: #d5d7dd;
    --accent: #00327d;
    --accent-hover: #0047ab;
    --accent-active: #002a68;
    --accent-soft: #e4ebfa;
    --accent-ink: #ffffff;
    --ok: #15803d;
    --ok-soft: #e8f6ec;
    --warn: #b45309;
    --warn-soft: #fdf1e0;
    --danger: #dc2626;
    --danger-soft: #fdecec;
    --font-sans: 'Open Sans', system-ui, 'Segoe UI', Arial, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, Consolas, monospace;
    --topbar-h: 70px;
    --menu-item-color: #6c757d;
    --menu-hover-bg: rgba(0, 50, 125, 0.08);
    --menu-active-bg: rgba(0, 50, 125, 0.12);
    --r-in: 8px;
    --r-card: 12px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 32, 0.05);
    --shadow-md: 0 1px 2px rgba(16, 24, 32, 0.04), 0 10px 28px rgba(16, 24, 32, 0.07);
    --ring: 0 0 0 3px rgba(0, 50, 125, 0.2);

    /* Bootstrap component radius scale (soft, modern) */
    --bs-border-radius: 8px;
    --bs-border-radius-sm: 6px;
    --bs-border-radius-lg: 12px;
    --bs-border-radius-xl: 14px;
    --bs-border-radius-2xl: 16px;
    --bs-border-radius-pill: 999px;

    /* ---------- MD3 color scheme: light (seed #00327d) ---------- */
    --md-sys-color-primary: #395ca7;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-primary-container: #dae2ff;
    --md-sys-color-on-primary-container: #001946;
    --md-sys-color-secondary: #585e71;
    --md-sys-color-on-secondary: #ffffff;
    --md-sys-color-secondary-container: #dce2f9;
    --md-sys-color-on-secondary-container: #151b2c;
    --md-sys-color-tertiary: #86458b;
    --md-sys-color-on-tertiary: #ffffff;
    --md-sys-color-tertiary-container: #ffd6fb;
    --md-sys-color-on-tertiary-container: #36003d;
    --md-sys-color-error: #ba1a1a;
    --md-sys-color-on-error: #ffffff;
    --md-sys-color-error-container: #ffdad6;
    --md-sys-color-on-error-container: #410002;
    /* Semantic (own seeds: success #15803d, warning #b45309) */
    --md-sys-color-success: #006d30;
    --md-sys-color-on-success: #ffffff;
    --md-sys-color-success-container: #95f8a7;
    --md-sys-color-on-success-container: #00210a;
    --md-sys-color-warning: #9b4500;
    --md-sys-color-on-warning: #ffffff;
    --md-sys-color-warning-container: #ffdbca;
    --md-sys-color-on-warning-container: #331200;
    /* Surfaces */
    --md-sys-color-surface: #fbf8fd;
    --md-sys-color-on-surface: #1b1b1f;
    --md-sys-color-surface-variant: #e1e2ec;
    --md-sys-color-on-surface-variant: #44464f;
    --md-sys-color-surface-dim: #dbd9dd;
    --md-sys-color-surface-bright: #fbf8fd;
    --md-sys-color-surface-container-lowest: #ffffff;
    --md-sys-color-surface-container-low: #f5f3f7;
    --md-sys-color-surface-container: #efedf1;
    --md-sys-color-surface-container-high: #e9e7ec;
    --md-sys-color-surface-container-highest: #e4e2e6;
    --md-sys-color-outline: #757780;
    --md-sys-color-outline-variant: #c5c6d0;
    --md-sys-color-inverse-surface: #303034;
    --md-sys-color-inverse-on-surface: #f2f0f4;
    --md-sys-color-inverse-primary: #b1c5ff;

    /* ---------- MD3 shape ---------- */
    --md-sys-shape-corner-extra-small: 4px;
    --md-sys-shape-corner-small: 8px;
    --md-sys-shape-corner-medium: 12px;
    --md-sys-shape-corner-large: 16px;
    --md-sys-shape-corner-extra-large: 28px;
    --md-sys-shape-corner-full: 999px;

    /* ---------- MD3 motion (legacy easing for transitions) ---------- */
    --md-sys-motion-easing-standard: cubic-bezier(0.2, 0, 0, 1);
    --md-sys-motion-easing-emphasized: cubic-bezier(0.2, 0, 0, 1);
    --md-sys-motion-easing-emphasized-decelerate: cubic-bezier(0.05, 0.7, 0.1, 1);
    --md-sys-motion-easing-emphasized-accelerate: cubic-bezier(0.3, 0, 0.8, 0.15);
    --md-sys-motion-duration-short: 200ms;
    --md-sys-motion-duration-medium: 300ms;
    --md-sys-motion-duration-long: 500ms;

    /* ---------- MD3 state layers ---------- */
    --md-sys-state-hover-opacity: 8%;
    --md-sys-state-pressed-opacity: 12%;
}

/* ---------- Dark theme (toggle: body.dark-theme) ---------- */
body.dark-theme {
    --paper: #101214;
    --surface: #17191d;
    --raised: #1d2025;
    --ink: #e7e9ee;
    --muted: #a4abb5;
    --faint: #7b828c;
    --line: #262a30;
    --line-strong: #343a42;
    --accent: #8ab4f8;
    --accent-hover: #a5c6fa;
    --accent-active: #bfd6fb;
    --accent-soft: rgba(138, 180, 248, 0.16);
    --accent-ink: #0c1512;
    --ok: #4ade80;
    --ok-soft: rgba(74, 222, 128, 0.12);
    --warn: #fbbf24;
    --warn-soft: rgba(251, 191, 36, 0.12);
    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.12);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 1px 2px rgba(0, 0, 0, 0.35), 0 10px 28px rgba(0, 0, 0, 0.35);
    --ring: 0 0 0 3px rgba(138, 180, 248, 0.28);
    --menu-item-color: #94a3b8;
    --menu-hover-bg: rgba(148, 163, 184, 0.09);
    --menu-active-bg: rgba(138, 180, 248, 0.14);
    color-scheme: dark;

    /* ---------- MD3 color scheme: dark (seed #00327d) ---------- */
    --md-sys-color-primary: #b1c5ff;
    --md-sys-color-on-primary: #002c70;
    --md-sys-color-primary-container: #1d438e;
    --md-sys-color-on-primary-container: #dae2ff;
    --md-sys-color-secondary: #c0c6dc;
    --md-sys-color-on-secondary: #2a3042;
    --md-sys-color-secondary-container: #404659;
    --md-sys-color-on-secondary-container: #dce2f9;
    --md-sys-color-tertiary: #f9acfa;
    --md-sys-color-on-tertiary: #521459;
    --md-sys-color-tertiary-container: #6b2d71;
    --md-sys-color-on-tertiary-container: #ffd6fb;
    --md-sys-color-error: #ffb4ab;
    --md-sys-color-on-error: #690005;
    --md-sys-color-error-container: #93000a;
    --md-sys-color-on-error-container: #ffdad6;
    /* Semantic */
    --md-sys-color-success: #79db8d;
    --md-sys-color-on-success: #003916;
    --md-sys-color-success-container: #005323;
    --md-sys-color-on-success-container: #95f8a7;
    --md-sys-color-warning: #ffb68e;
    --md-sys-color-on-warning: #532200;
    --md-sys-color-warning-container: #763300;
    --md-sys-color-on-warning-container: #ffdbca;
    /* Surfaces */
    --md-sys-color-surface: #121316;
    --md-sys-color-on-surface: #e4e2e6;
    --md-sys-color-surface-variant: #44464f;
    --md-sys-color-on-surface-variant: #c5c6d0;
    --md-sys-color-surface-dim: #121316;
    --md-sys-color-surface-bright: #39393c;
    --md-sys-color-surface-container-lowest: #0d0e11;
    --md-sys-color-surface-container-low: #1b1b1f;
    --md-sys-color-surface-container: #1f1f23;
    --md-sys-color-surface-container-high: #292a2d;
    --md-sys-color-surface-container-highest: #343438;
    --md-sys-color-outline: #8f9099;
    --md-sys-color-outline-variant: #44464f;
    --md-sys-color-inverse-surface: #e4e2e6;
    --md-sys-color-inverse-on-surface: #303034;
    --md-sys-color-inverse-primary: #395ca7;
}

html {
    font-family: var(--font-sans);
}

body {
    background: var(--paper);
    color: var(--ink);
    font-size: 14.5px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    color-scheme: light;
}

body.dark-theme {
    color-scheme: dark;
}

/* Reference dark sidebar (Finacct Plus): slate panel, muted items */
body.dark-theme .sidebar {
    background: #1e293b;
    box-shadow: 0 0 35px rgba(0, 0, 0, 0.35);
}

body.dark-theme .sidebar .top-row {
    background: #1e293b;
}

body.dark-theme .sidebar .navbar-brand { color: #e2e8f0; }
body.dark-theme .sidebar .navbar-brand:hover { color: #e2e8f0; }
body.dark-theme .menu-search { background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.16); color: #e2e8f0; }
body.dark-theme .menu-search:focus { background: rgba(255, 255, 255, 0.14); }
body.dark-theme .menu-search::placeholder { color: #64748b; }

h1:focus { outline: none; }

h1, h2, h3, h4, h5, h6, .h1, .h2, .h3, .h4, .h5, .h6 {
    font-weight: 700;
    letter-spacing: -0.02em;
}

a, .btn-link { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: none; }

:focus-visible {
    outline: none;
    box-shadow: var(--ring);
    border-radius: 4px;
}

.text-muted { color: var(--muted) !important; }

.page-title {
    font: 400 24px/1.33 var(--font-sans);
    letter-spacing: -0.01em;
    margin-bottom: 1rem;
}

/* ---------- numbers ---------- */
.num, .kpi-big, .kpi-mid, .stat-num {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}

/* ============================================================
   MD3 content scope
   article.content re-declares the legacy variable names as MD3
   roles. Every page stylesheet resolves var(--surface),
   var(--line), var(--accent) ... to tonal MD3 values without
   touching the shell, which keeps the original definitions.
   ============================================================ */

article.content {
    /* MD3 type roles used across the content section */
    --md-type-headline-small: 400 24px/1.33 var(--font-sans);
    --md-type-title-large: 400 21px/1.35 var(--font-sans);
    --md-type-title-medium: 500 15px/1.45 var(--font-sans);
    --md-type-body-large: 400 15.5px/1.55 var(--font-sans);
    --md-type-body-medium: 400 14px/1.5 var(--font-sans);
    --md-type-label-large: 500 13.5px/1.4 var(--font-sans);
    --md-type-label-medium: 500 12px/1.35 var(--font-sans);

    /* MD3 focus indicator */
    --ring: 0 0 0 3px color-mix(in srgb, var(--md-sys-color-primary) 45%, transparent);

    /* Elevation as tonal surface + whisper of shadow */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.08);
    --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.09), 0 6px 18px rgba(0, 0, 0, 0.08);
    --md-elevation-3: 0 4px 4px rgba(0, 0, 0, 0.3), 0 8px 12px 6px rgba(0, 0, 0, 0.15), 0 24px 38px 3px rgba(0, 0, 0, 0.2);
}

/* Legacy alias -> MD3 role (light) */
article.content {
    --surface: var(--md-sys-color-surface-container-lowest);
    --raised: var(--md-sys-color-surface-container-low);
    --ink: var(--md-sys-color-on-surface);
    --muted: var(--md-sys-color-on-surface-variant);
    --faint: var(--md-sys-color-outline);
    --line: var(--md-sys-color-outline-variant);
    --line-strong: var(--md-sys-color-outline);
    --accent: var(--md-sys-color-primary);
    --accent-hover: color-mix(in srgb, var(--md-sys-color-primary) 85%, var(--md-sys-color-on-primary-container));
    --accent-active: var(--md-sys-color-on-primary-container);
    --accent-soft: var(--md-sys-color-primary-container);
    --accent-ink: var(--md-sys-color-on-primary);
    --ok: var(--md-sys-color-success);
    --ok-soft: var(--md-sys-color-success-container);
    --warn: var(--md-sys-color-warning);
    --warn-soft: var(--md-sys-color-warning-container);
    --danger: var(--md-sys-color-error);
    --danger-soft: var(--md-sys-color-error-container);
}

/* Legacy alias -> MD3 role (dark): containers lift toward bright */
body.dark-theme article.content {
    --surface: var(--md-sys-color-surface-container-low);
    --raised: var(--md-sys-color-surface-container-high);
    --accent-soft: color-mix(in srgb, var(--md-sys-color-primary) 18%, var(--md-sys-color-surface-container));
    --ok-soft: color-mix(in srgb, var(--md-sys-color-success) 16%, var(--md-sys-color-surface-container));
    --warn-soft: color-mix(in srgb, var(--md-sys-color-warning) 16%, var(--md-sys-color-surface-container));
    --danger-soft: color-mix(in srgb, var(--md-sys-color-error) 16%, var(--md-sys-color-surface-container));
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 1px 3px rgba(0, 0, 0, 0.4), 0 6px 18px rgba(0, 0, 0, 0.35);
    --md-elevation-3: 0 4px 4px rgba(0, 0, 0, 0.4), 0 8px 12px 6px rgba(0, 0, 0, 0.3), 0 24px 38px 3px rgba(0, 0, 0, 0.3);
}

/* ---------- MD3 components (content section only) ---------- */

/* Page headline: MD3 headline-small (scoped page styles set sizes; unify) */
article.content h1 {
    font-size: 24px !important;
    font-weight: 500 !important;
    letter-spacing: -0.01em;
    line-height: 1.3;
}

/* ---------- buttons: full corners, state layers, MD3 heights ---------- */
article.content .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 40px;
    padding: 0 22px;
    border-radius: var(--md-sys-shape-corner-full);
    font: 500 14px/1 var(--font-sans);
    letter-spacing: 0.1px;
    border: 0;
    box-shadow: none;
    transform: none;
    white-space: nowrap;
    transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
        box-shadow var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
        color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
        border-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

article.content .btn:active { transform: none; }

article.content .btn .material-symbols-outlined { font-size: 18px; }

article.content .btn-sm {
    height: 34px;
    padding: 0 16px;
    font-size: 13px;
}

/* MD3 focus indicator on content buttons (base rule flattens box-shadow) */
article.content .btn:focus-visible {
    box-shadow: var(--ring);
}

/* Compact fields keep the outlined-field treatment at 32px height */
article.content .form-control-sm,
article.content .form-select-sm {
    min-height: 32px;
    padding: 5px 11px;
    font-size: 13px;
    border-radius: var(--md-sys-shape-corner-small);
}

/* Filled (btn-primary) */
article.content .btn-primary {
    --bs-btn-color: var(--md-sys-color-on-primary);
    --bs-btn-bg: var(--md-sys-color-primary);
    --bs-btn-border-color: transparent;
    --bs-btn-hover-color: var(--md-sys-color-on-primary);
    --bs-btn-hover-bg: var(--md-sys-color-primary);
    --bs-btn-hover-border-color: transparent;
    --bs-btn-active-color: var(--md-sys-color-on-primary);
    --bs-btn-active-bg: var(--md-sys-color-primary);
    --bs-btn-active-border-color: transparent;
    --bs-btn-disabled-color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
    --bs-btn-disabled-bg: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
    --bs-btn-disabled-border-color: transparent;
    background-image: none;
}

article.content .btn-primary:hover:not(:disabled) {
    background-image: linear-gradient(color-mix(in srgb, var(--md-sys-color-on-primary) var(--md-sys-state-hover-opacity), transparent),
            color-mix(in srgb, var(--md-sys-color-on-primary) var(--md-sys-state-hover-opacity), transparent));
}

article.content .btn-primary:active:not(:disabled) {
    background-image: linear-gradient(color-mix(in srgb, var(--md-sys-color-on-primary) var(--md-sys-state-pressed-opacity), transparent),
            color-mix(in srgb, var(--md-sys-color-on-primary) var(--md-sys-state-pressed-opacity), transparent));
}

/* Outlined (outline-secondary / outline-primary) */
article.content .btn-outline-secondary,
article.content .btn-outline-primary {
    --bs-btn-color: var(--md-sys-color-primary);
    --bs-btn-border-color: var(--md-sys-color-outline);
    --bs-btn-bg: transparent;
    --bs-btn-hover-color: var(--md-sys-color-primary);
    --bs-btn-hover-bg: transparent;
    --bs-btn-hover-border-color: var(--md-sys-color-outline);
    --bs-btn-active-color: var(--md-sys-color-primary);
    --bs-btn-active-bg: transparent;
    --bs-btn-active-border-color: var(--md-sys-color-outline);
    --bs-btn-disabled-color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
    --bs-btn-disabled-bg: transparent;
    --bs-btn-disabled-border-color: color-mix(in srgb, var(--md-sys-color-on-surface) 12%, transparent);
    background-image: none;
    border: 1px solid var(--md-sys-color-outline);
}

article.content .btn-outline-secondary:hover:not(:disabled),
article.content .btn-outline-primary:hover:not(:disabled) {
    background-image: linear-gradient(color-mix(in srgb, var(--md-sys-color-primary) var(--md-sys-state-hover-opacity), transparent),
            color-mix(in srgb, var(--md-sys-color-primary) var(--md-sys-state-hover-opacity), transparent));
    border-color: var(--md-sys-color-outline);
    color: var(--md-sys-color-primary);
}

article.content .btn-outline-secondary:active:not(:disabled),
article.content .btn-outline-primary:active:not(:disabled) {
    background-image: linear-gradient(color-mix(in srgb, var(--md-sys-color-primary) var(--md-sys-state-pressed-opacity), transparent),
            color-mix(in srgb, var(--md-sys-color-primary) var(--md-sys-state-pressed-opacity), transparent));
}

/* Outlined semantic */
article.content .btn-outline-danger,
article.content .btn-outline-success,
article.content .btn-outline-warning {
    background-color: transparent;
    background-image: none;
    border: 1px solid var(--md-sys-color-outline);
}

article.content .btn-outline-danger { color: var(--md-sys-color-error); }
article.content .btn-outline-success { color: var(--md-sys-color-success); }
article.content .btn-outline-warning { color: var(--md-sys-color-warning); }

article.content .btn-outline-danger:hover:not(:disabled),
article.content .btn-outline-success:hover:not(:disabled),
article.content .btn-outline-warning:hover:not(:disabled) {
    border-color: var(--md-sys-color-outline);
}

article.content .btn-outline-danger:hover:not(:disabled) {
    background-image: linear-gradient(color-mix(in srgb, var(--md-sys-color-error) var(--md-sys-state-hover-opacity), transparent),
            color-mix(in srgb, var(--md-sys-color-error) var(--md-sys-state-hover-opacity), transparent));
}

article.content .btn-outline-success:hover:not(:disabled) {
    background-image: linear-gradient(color-mix(in srgb, var(--md-sys-color-success) var(--md-sys-state-hover-opacity), transparent),
            color-mix(in srgb, var(--md-sys-color-success) var(--md-sys-state-hover-opacity), transparent));
}

article.content .btn-outline-warning:hover:not(:disabled) {
    background-image: linear-gradient(color-mix(in srgb, var(--md-sys-color-warning) var(--md-sys-state-hover-opacity), transparent),
            color-mix(in srgb, var(--md-sys-color-warning) var(--md-sys-state-hover-opacity), transparent));
}

/* Filled error (btn-danger) */
article.content .btn-danger {
    background: var(--md-sys-color-error);
    color: var(--md-sys-color-on-error);
    border-color: transparent;
}

article.content .btn-danger:hover:not(:disabled) {
    background-image: linear-gradient(color-mix(in srgb, var(--md-sys-color-on-error) var(--md-sys-state-hover-opacity), transparent),
            color-mix(in srgb, var(--md-sys-color-on-error) var(--md-sys-state-hover-opacity), transparent));
}

/* Filled tonal (btn-light) */
article.content .btn-light {
    background: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
    border-color: transparent;
}

article.content .btn-light:hover:not(:disabled) {
    background-image: linear-gradient(color-mix(in srgb, var(--md-sys-color-on-secondary-container) var(--md-sys-state-hover-opacity), transparent),
            color-mix(in srgb, var(--md-sys-color-on-secondary-container) var(--md-sys-state-hover-opacity), transparent));
}

/* Text button (btn-link) */
article.content .btn-link,
article.content .btn-group .btn-link {
    color: var(--md-sys-color-primary);
    padding: 0 12px;
    background: transparent;
    border: 0;
}

article.content .btn-link:hover:not(:disabled) {
    background-image: linear-gradient(color-mix(in srgb, var(--md-sys-color-primary) var(--md-sys-state-hover-opacity), transparent),
            color-mix(in srgb, var(--md-sys-color-primary) var(--md-sys-state-hover-opacity), transparent));
    color: var(--md-sys-color-primary);
}

/* Connected button group */
article.content .btn-group { gap: 0; }

article.content .btn-group > .btn { border-radius: 0; }

article.content .btn-group > .btn:first-child {
    border-top-left-radius: var(--md-sys-shape-corner-full);
    border-bottom-left-radius: var(--md-sys-shape-corner-full);
}

article.content .btn-group > .btn:last-child {
    border-top-right-radius: var(--md-sys-shape-corner-full);
    border-bottom-right-radius: var(--md-sys-shape-corner-full);
}

article.content .btn-group > .btn + .btn { margin-left: 1px; }

/* ---------- forms: MD3 outlined text fields ---------- */
article.content .form-control,
article.content .form-select {
    background-color: transparent;
    color: var(--md-sys-color-on-surface);
    border: 1px solid var(--md-sys-color-outline);
    border-radius: var(--md-sys-shape-corner-small);
    font-size: 14px;
    padding: 8px 14px;
    min-height: 40px;
    transition: border-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
        box-shadow var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

article.content .form-control:hover,
article.content .form-select:hover {
    border-color: var(--md-sys-color-on-surface);
}

article.content .form-control:focus,
article.content .form-select:focus {
    background-color: transparent;
    color: var(--md-sys-color-on-surface);
    border-color: var(--md-sys-color-primary);
    box-shadow: inset 0 0 0 1px var(--md-sys-color-primary);
}

article.content .form-control::placeholder { color: var(--md-sys-color-on-surface-variant); }

article.content .form-select {
    padding-right: 40px;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%2344464f' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
    background-position: right 12px center;
    background-size: 16px 16px;
}

body.dark-theme article.content .form-select {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%23c5c6d0' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='m2 5 6 6 6-6'/%3e%3c/svg%3e");
}

article.content textarea.form-control { min-height: 0; }

article.content .form-label,
article.content label.form-label,
article.content .form-check-label {
    color: var(--md-sys-color-on-surface-variant);
    font: var(--md-type-label-medium);
    letter-spacing: 0.1px;
    margin-bottom: 6px;
}

article.content .form-check-input {
    border-color: var(--md-sys-color-outline);
    background-color: transparent;
}

article.content .form-check-input:checked {
    background-color: var(--md-sys-color-primary);
    border-color: var(--md-sys-color-primary);
}

article.content .form-check-input:focus {
    border-color: var(--md-sys-color-primary);
    box-shadow: var(--ring);
}

article.content .form-switch .form-check-input:checked {
    background-color: var(--md-sys-color-primary);
    border-color: var(--md-sys-color-primary);
}

article.content .input-group-text {
    background: var(--md-sys-color-surface-container);
    border-color: var(--md-sys-color-outline-variant);
    color: var(--md-sys-color-on-surface-variant);
    border-radius: var(--md-sys-shape-corner-small);
    font-size: 13.5px;
}

article.content .valid.modified:not([type=checkbox]) { outline: 1px solid var(--md-sys-color-success); }
article.content .invalid { outline: 1px solid var(--md-sys-color-error); }
article.content .validation-message {
    color: var(--md-sys-color-error);
    font: var(--md-type-label-medium);
}

/* ---------- cards: tonal filled cards, flat elevation ---------- */
.card {
    --bs-card-bg: var(--md-sys-color-surface-container-lowest);
    --bs-card-border-color: var(--md-sys-color-outline-variant);
    --bs-card-border-radius: var(--md-sys-shape-corner-medium);
    --bs-card-inner-border-radius: calc(var(--md-sys-shape-corner-medium) - 1px);
    --bs-card-cap-bg: var(--md-sys-color-surface-container-low);
    box-shadow: none;
}

body.dark-theme .card {
    --bs-card-bg: var(--md-sys-color-surface-container-low);
    --bs-card-cap-bg: var(--md-sys-color-surface-container);
}

.card-header {
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    background: transparent;
    font: var(--md-type-title-medium);
    letter-spacing: 0.1px;
    font-size: 14.5px;
    color: var(--md-sys-color-on-surface);
}

/* ---------- tables: MD3 data panel ---------- */
article.content .table {
    --bs-table-bg: var(--md-sys-color-surface-container-lowest);
    --bs-table-color: var(--md-sys-color-on-surface);
    --bs-table-border-color: var(--md-sys-color-outline-variant);
    --bs-table-hover-bg: transparent;
    --bs-table-hover-color: var(--md-sys-color-on-surface);
    margin-bottom: 0;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-medium);
    overflow: hidden;
    box-shadow: none;
}

body.dark-theme article.content .table {
    --bs-table-bg: var(--md-sys-color-surface-container-low);
}

article.content .table > :not(caption) > * > * {
    padding: 0.72rem 0.85rem;
    border-bottom-color: var(--md-sys-color-outline-variant);
    box-shadow: none;
}

article.content .table thead th {
    font: var(--md-type-label-medium);
    font-size: 12.5px;
    letter-spacing: 0.1px;
    text-transform: none;
    color: var(--md-sys-color-on-surface-variant);
    background: var(--md-sys-color-surface-container-low);
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    white-space: nowrap;
}

body.dark-theme article.content .table thead th {
    background: var(--md-sys-color-surface-container);
}

article.content .table tbody td { font-size: 13.5px; }

article.content .table tbody tr { transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard); }

article.content .table tbody tr:hover td {
    background: color-mix(in srgb, var(--md-sys-color-on-surface) 4%, transparent);
}

article.content .table tbody tr:last-child td { border-bottom: 0; }

article.content .table-striped > tbody > tr:nth-of-type(odd) > * {
    --bs-table-accent-bg: color-mix(in srgb, var(--md-sys-color-surface-container-low) 55%, transparent);
    color: var(--md-sys-color-on-surface);
}

article.content .table-sm > :not(caption) > * > * { padding: 0.45rem 0.65rem; }

/* ---------- badges & chips: tonal containers, small corners ---------- */
article.content .badge {
    border-radius: var(--md-sys-shape-corner-small);
    font: var(--md-type-label-medium);
    font-size: 11.5px;
    padding: 0.35em 0.7em;
    letter-spacing: 0.2px;
}

article.content .bg-success {
    background-color: var(--md-sys-color-success-container) !important;
    color: var(--md-sys-color-on-success-container) !important;
}

article.content .bg-warning {
    background-color: var(--md-sys-color-warning-container) !important;
    color: var(--md-sys-color-on-warning-container) !important;
}

article.content .bg-danger {
    background-color: var(--md-sys-color-error-container) !important;
    color: var(--md-sys-color-on-error-container) !important;
}

article.content .bg-primary {
    background-color: var(--md-sys-color-primary-container) !important;
    color: var(--md-sys-color-on-primary-container) !important;
}

/* ---------- status chips (StatusBadge component) ---------- */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font: var(--md-type-label-medium);
    font-size: 11.5px;
    padding: 0.25em 0.7em;
    border-radius: var(--md-sys-shape-corner-small);
    white-space: nowrap;
}

.status-badge .material-symbols-outlined { font-size: 13px; }

.status-neutral {
    background: var(--md-sys-color-surface-container-high);
    color: var(--md-sys-color-on-surface-variant);
    border: 1px solid var(--md-sys-color-outline-variant);
}

.status-ok {
    background: var(--md-sys-color-success-container);
    color: var(--md-sys-color-on-success-container);
}

.status-warn {
    background: var(--md-sys-color-warning-container);
    color: var(--md-sys-color-on-warning-container);
}

.status-danger {
    background: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
}

.status-accent {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
}

/* ---------- alerts: MD3 tonal containers ---------- */
article.content .alert {
    border: 0;
    border-radius: var(--md-sys-shape-corner-medium);
    padding: 0.9rem 1.1rem;
    font-size: 14px;
    --bs-alert-color: var(--md-sys-color-on-surface);
    --bs-alert-bg: var(--md-sys-color-surface-container);
    --bs-alert-border-color: transparent;
    background: var(--md-sys-color-surface-container);
    color: var(--md-sys-color-on-surface);
}

article.content .alert a { text-decoration: underline; font-weight: 600; }

article.content .alert-danger,
article.content .alert-danger > * {
    background: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
    --bs-alert-color: var(--md-sys-color-on-error-container);
}

article.content .alert-danger a { color: var(--md-sys-color-on-error-container); }

article.content .alert-success,
article.content .alert-success > * {
    background: var(--md-sys-color-success-container);
    color: var(--md-sys-color-on-success-container);
    --bs-alert-color: var(--md-sys-color-on-success-container);
}

article.content .alert-success a { color: var(--md-sys-color-on-success-container); }

article.content .alert-warning,
article.content .alert-warning > * {
    background: var(--md-sys-color-warning-container);
    color: var(--md-sys-color-on-warning-container);
    --bs-alert-color: var(--md-sys-color-on-warning-container);
}

article.content .alert-warning a { color: var(--md-sys-color-on-warning-container); }

article.content .alert-primary,
article.content .alert-info,
article.content .alert-primary > *,
article.content .alert-info > * {
    background: var(--md-sys-color-secondary-container);
    color: var(--md-sys-color-on-secondary-container);
    --bs-alert-color: var(--md-sys-color-on-secondary-container);
}

article.content .alert-primary a,
article.content .alert-info a { color: var(--md-sys-color-on-secondary-container); }

/* ---------- tabs: MD3 primary tabs ---------- */
article.content .nav-tabs {
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    gap: 4px;
}

article.content .nav-tabs .nav-link {
    border: 0;
    border-bottom: 3px solid transparent;
    border-radius: 0;
    color: var(--md-sys-color-on-surface-variant);
    font: var(--md-type-label-large);
    padding: 10px 16px;
    margin-bottom: -1px;
    background: transparent;
    transition: color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
        border-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

article.content .nav-tabs .nav-link:hover {
    color: var(--md-sys-color-on-surface);
    border: 0;
    border-bottom: 3px solid transparent;
    border-radius: 0;
    isolation: isolate;
}

article.content .nav-tabs .nav-link.active {
    background: transparent;
    color: var(--md-sys-color-primary);
    font-weight: 600;
    border: 0;
    border-bottom: 3px solid var(--md-sys-color-primary);
    border-radius: 0;
}

/* ---------- pagination ---------- */
article.content .pagination { gap: 4px; }

article.content .page-link {
    border: 0;
    border-radius: var(--md-sys-shape-corner-small);
    background: transparent;
    color: var(--md-sys-color-primary);
    font: var(--md-type-label-large);
    min-width: 36px;
    text-align: center;
    transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

article.content .page-link:hover {
    background: color-mix(in srgb, var(--md-sys-color-primary) var(--md-sys-state-hover-opacity), transparent);
    color: var(--md-sys-color-primary);
    border-color: transparent;
}

article.content .page-item.active .page-link {
    background: var(--md-sys-color-primary-container);
    color: var(--md-sys-color-on-primary-container);
    font-weight: 600;
}

article.content .page-item.disabled .page-link {
    background: transparent;
    color: color-mix(in srgb, var(--md-sys-color-on-surface) 38%, transparent);
}

/* ---------- spinners: MD3 circular progress ---------- */
article.content .spinner-border {
    color: var(--md-sys-color-primary);
    vertical-align: middle;
}

/* ---------- snackbars (toast overlay) ---------- */
.toast-container .toast {
    background: var(--md-sys-color-inverse-surface) !important;
    color: var(--md-sys-color-inverse-on-surface) !important;
    border-radius: var(--md-sys-shape-corner-small);
    box-shadow: var(--md-elevation-3, 0 4px 8px rgba(0, 0, 0, 0.25));
    overflow: hidden;
    min-height: 48px;
}

.toast-container .toast .toast-body,
.toast-container .toast .toast-body.text-white {
    color: var(--md-sys-color-inverse-on-surface) !important;
    font-size: 14px;
}

.toast-container .toast.bg-warning .toast-body,
.toast-container .toast.bg-warning .toast-body.text-dark {
    color: var(--md-sys-color-inverse-on-surface) !important;
}

/* ============================================================
   App shell (unchanged from v5)
   ============================================================ */

.page {
    position: relative;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

main { flex: 1; min-width: 0; }

/* Sidebar (reference .app-menu: white panel with 35px glow, no border) */
.sidebar {
    background: var(--surface);
    box-shadow: 0 0 35px 0 rgba(0, 0, 0, 0.1);
}

/* Brand bar (reference .logo-box: topbar-height, borderless white) */
.sidebar .top-row {
    background: var(--surface);
    height: var(--topbar-h);
    min-height: var(--topbar-h);
    display: flex;
    align-items: center;
}

.sidebar .navbar { padding-top: 0; padding-bottom: 0; width: 100%; }

.sidebar .navbar-brand {
    padding: 0;
    margin: 0;
    display: inline-flex;
    align-items: center;
    text-decoration: none;
}

.sidebar-logo-full {
    height: 34px;
    width: auto;
    max-width: 175px;
    object-fit: contain;
    display: block;
}

.sidebar-logo-mark {
    height: 34px;
    width: 34px;
    object-fit: contain;
    display: none;
}

/* Light / dark logo switching */
.sidebar-logo-full.logo-dark {
    display: none;
}

body.dark-theme .sidebar-logo-full.logo-light {
    display: none;
}

body.dark-theme .sidebar-logo-full.logo-dark {
    display: block;
}

.sidebar .navbar-toggler {
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    padding: 0.3rem 0.55rem;
}

.navbar-dark .navbar-toggler-icon { filter: invert(1); opacity: .8; }

/* Group headers: FINANCE / BILLING / ... */
.sidebar small.text-uppercase {
    display: block;
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 500;
    letter-spacing: 0.14em;
    color: var(--faint);
    padding: 1rem 1.5rem 0.25rem;
    white-space: nowrap;
}

.sidebar .nav-item { font-size: 0.92rem; padding-bottom: 0; }

/* Reference .menu-link: full-bleed row, 12px/24px padding, gray item that
   turns navy on a light navy tint */
.sidebar .nav-link {
    color: var(--menu-item-color);
    font-size: 13.5px;
    font-weight: 500;
    border-radius: 0;
    margin: 1px 0;
    padding: 0.68rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    text-decoration: none;
    line-height: 1.5;
    height: auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background-color .15s ease, color .15s ease;
}

.sidebar .nav-link:hover {
    color: var(--accent);
    background: var(--menu-hover-bg);
}

.sidebar .nav-link.active {
    color: var(--accent);
    background: var(--menu-active-bg);
    font-weight: 600;
}

.nav-ic {
    width: 16px;
    height: 16px;
    flex: none;
    opacity: 0.72;
}

.sidebar .nav-link:hover .nav-ic { opacity: 1; }
.sidebar .nav-link.active .nav-ic { opacity: 1; }

/* Main column top row: reference-brand gradient bar (Finacct Plus) */
/* Reference .navbar-custom: gradient bar with drop shadow */
main .top-row {
    background: linear-gradient(135deg, #6379c3 0%, #546ee5 60%);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-bottom: none;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.75rem;
    color: #fff;
}

main .top-row .topbar-date {
    font-size: 13px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.92);
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

main .top-row .topbar-date .material-symbols-outlined { font-size: 19px; }

main .top-row .text-muted { color: rgba(255, 255, 255, 0.85) !important; }

/* Shell button keeps its pre-MD3 weight (MD3 button rules are content-scoped) */
main .top-row .btn { font-weight: 600; }

main .top-row .btn-outline-secondary {
    --bs-btn-color: #fff;
    --bs-btn-border-color: rgba(255, 255, 255, 0.55);
    --bs-btn-hover-color: #fff;
    --bs-btn-hover-bg: rgba(255, 255, 255, 0.16);
    --bs-btn-hover-border-color: #fff;
    --bs-btn-active-color: #fff;
    --bs-btn-active-bg: rgba(255, 255, 255, 0.22);
    --bs-btn-active-border-color: #fff;
}

main .top-row .form-select {
    background-color: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.45);
    color: #fff;
}

main .top-row .form-select:focus {
    background-color: rgba(255, 255, 255, 0.22);
    box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.18);
}

main .top-row svg { stroke: #fff; }

.icon-btn-top {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    background: transparent;
    color: rgba(255, 255, 255, 0.92);
    border-radius: 8px;
    padding: 0;
}

.icon-btn-top:hover { background: rgba(255, 255, 255, 0.16); color: #fff; }
.icon-btn-top .material-symbols-outlined { font-size: 21px; }

/* Reference .button-toggle-menu: 40x40 translucent white block */
.icon-btn-top.sidebar-toggle {
    width: 40px;
    height: 40px;
    background: rgba(255, 255, 255, 0.15);
}

/* ---------- Top bar user menu (avatar + details dropdown) ---------- */
.user-menu {
    position: relative;
    display: inline-flex;
}

.user-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    height: 40px;
    padding: 0 10px 0 4px;
    border: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    cursor: pointer;
    font: inherit;
}

.user-btn:hover,
.user-btn[aria-expanded="true"] { background: rgba(255, 255, 255, 0.24); }

.user-avatar {
    width: 32px;
    height: 32px;
    flex: none;
    border-radius: 50%;
    background: #fff;
    color: #546ee5;
    font-size: 12.5px;
    font-weight: 700;
    letter-spacing: 0.02em;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    user-select: none;
}

.user-avatar-lg { width: 44px; height: 44px; font-size: 15px; }

.user-name {
    font-size: 13.5px;
    font-weight: 600;
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-caret { font-size: 20px; }

.user-menu-overlay {
    position: fixed;
    inset: 0;
    z-index: 1040;
}

.user-menu-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 1050;
    width: 300px;
    background: var(--paper, #fff);
    color: var(--ink, #1e293b);
    border: 1px solid rgba(100, 116, 139, 0.22);
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(15, 23, 42, 0.22);
    overflow: hidden;
}

.user-menu-head {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: linear-gradient(135deg, #6379c3 0%, #546ee5 60%);
    color: #fff;
}

.user-menu-head .user-avatar { background: rgba(255, 255, 255, 0.92); }

.user-menu-head-text { min-width: 0; }

.user-menu-name {
    font-size: 14px;
    font-weight: 700;
    line-height: 1.3;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-menu-email {
    font-size: 12px;
    opacity: 0.88;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-menu-badge {
    margin-top: 4px;
    font-size: 10.5px;
    font-weight: 600;
}

.user-menu-body { padding: 8px 6px; }

.user-menu-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 10px;
    border-radius: 8px;
    font-size: 13px;
}

.user-menu-row .material-symbols-outlined {
    font-size: 18px;
    color: var(--muted, #64748b);
}

.user-menu-label { color: var(--muted, #64748b); }

.user-menu-value {
    margin-left: auto;
    font-weight: 600;
}

.user-menu-signout {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 11px 16px;
    border: 0;
    border-top: 1px solid rgba(100, 116, 139, 0.18);
    background: transparent;
    color: #dc2626;
    font: inherit;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
}

.user-menu-signout:hover { background: rgba(220, 38, 38, 0.07); }
.user-menu-signout .material-symbols-outlined { font-size: 19px; }

body.dark-theme .user-menu-panel {
    background: #263248;
    border-color: rgba(148, 163, 184, 0.25);
}

body.dark-theme .user-menu-row .material-symbols-outlined,
body.dark-theme .user-menu-label { color: #94a3b8; }

body.dark-theme .user-menu-signout:hover { background: rgba(220, 38, 38, 0.16); }

.content { padding-top: 1.5rem; }

article.content {
    padding: 1.6rem 2rem 3rem;
    max-width: 1440px;
    width: 100%;
    margin-inline: auto;
}

/* Wide layout: detached panels (reference .detached-layout, >=992px there;
   we apply from the >=768px breakpoint where the sidebar column appears) */
@media (min-width: 768px) {
    .page { flex-direction: row; padding: 15px 15px 0; }

    .sidebar {
        width: 260px;
        height: calc(100vh - 30px);
        position: sticky;
        top: 15px;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        border-radius: 12px;
        transition: width .3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar .nav-scrollable {
        height: auto;
        flex: 1;
        overflow-y: auto;
        overflow-x: hidden;
        padding-bottom: 1.5rem;
    }

    /* Never collapse the sidebar for the nav-toggle; the topbar
       button drives the icon-rail collapse instead. */
    .sidebar .collapse { display: block; }

    .sidebar .top-row .navbar-toggler { display: none; }

    main .top-row {
        position: sticky;
        top: 15px;
        z-index: 5;
        border-radius: 12px;
    }

    main { padding-left: 15px; }

    article.content {
        padding-left: 2rem !important;
        padding-right: 2rem !important;
    }
}

/* Collapsed icon rail (topbar toggle, desktop only) */
@media (min-width: 768px) {
    .page.sidebar-collapsed .sidebar { width: 74px; }

    .page.sidebar-collapsed .sidebar .top-row {
        justify-content: center;
        padding-left: 0 !important;
        padding-right: 0 !important;
    }

    .page.sidebar-collapsed .sidebar .navbar-brand {
        margin: 0 auto;
        justify-content: center;
    }

    .page.sidebar-collapsed .sidebar .sidebar-logo-full {
        display: none !important;
    }

    .page.sidebar-collapsed .sidebar .sidebar-logo-mark {
        display: block !important;
    }

    .page.sidebar-collapsed .sidebar .menu-search-wrap,
    .page.sidebar-collapsed .sidebar small.text-uppercase,
    .page.sidebar-collapsed .sidebar .nav-link span:last-child { display: none; }

    .page.sidebar-collapsed .sidebar .nav-link {
        justify-content: center;
        padding: 0.5rem 0;
        margin: 2px auto;
        width: calc(100% - 24px);
    }

    .page.sidebar-collapsed .sidebar .nav-link .material-symbols-outlined { font-size: 21px; }
}

@media (max-width: 767.98px) {
    main .top-row { justify-content: space-between; }
    .icon-btn-top.sidebar-toggle { display: none; }
    article.content { padding: 1.1rem 1rem 3rem !important; }
}

/* ============================================================
   Dashboard (Home) - MD3 tonal surfaces
   ============================================================ */

.dash-hero {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 12px;
}

.dash-hero-main {
    padding: 1.5rem 1.7rem;
    background: var(--md-sys-color-surface-container-lowest);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-large);
    box-shadow: none;
}

body.dark-theme .dash-hero-main {
    background: var(--md-sys-color-surface-container-low);
}

.kpi-lbl {
    font: var(--md-type-label-medium);
    font-size: 11px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--md-sys-color-on-surface-variant);
}

.kpi-big {
    font-size: 2.5rem;
    font-weight: 500;
    line-height: 1.12;
    margin: 0.45rem 0 0.25rem;
}

.kpi-note { font-size: 0.83rem; color: var(--md-sys-color-outline); }

.dash-hero-side {
    display: grid;
    grid-template-rows: 1fr 1fr;
    gap: 12px;
}

.dash-hero-side > div {
    padding: 1.05rem 1.5rem;
    background: var(--md-sys-color-surface-container-lowest);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-large);
    box-shadow: none;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

body.dark-theme .dash-hero-side > div {
    background: var(--md-sys-color-surface-container-low);
}

.kpi-mid { font-size: 1.5rem; font-weight: 500; line-height: 1.2; }

.dash-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.dash-stats > div {
    background: var(--md-sys-color-surface-container-lowest);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-medium);
    box-shadow: none;
    padding: 0.95rem 1.15rem;
    transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

body.dark-theme .dash-stats > div {
    background: var(--md-sys-color-surface-container-low);
}

.dash-stats > div:hover {
    background: var(--md-sys-color-surface-container-low);
}

body.dark-theme .dash-stats > div:hover {
    background: var(--md-sys-color-surface-container);
}

.stat-num { font-size: 1.32rem; font-weight: 500; margin-top: 0.3rem; }
.stat-note { font-size: 0.78rem; color: var(--md-sys-color-outline); margin-top: 0.1rem; }
.stat-num.text-warn { color: var(--md-sys-color-warning); }

@media (max-width: 991.98px) {
    .dash-hero { grid-template-columns: 1fr; }
}

/* ============================================================
   Loading & error surfaces
   ============================================================ */

.loading-progress {
    position: fixed;
    inset: 0;
    margin: auto;
    width: 8rem;
    height: 8rem;
    display: block;
}

.loading-progress circle {
    fill: none;
    stroke: var(--line);
    stroke-width: 0.6rem;
    stroke-origin: center;
}

.loading-progress circle:last-of-type {
    stroke: var(--accent);
    stroke-dasharray: calc(3.141deg * var(--blazor-load-percentage, 0%) * 0.8), 0%;
    transition: stroke-dasharray 0.3s ease-in-out;
}

.loading-progress-text {
    position: fixed;
    inset: 0;
    top: calc(50% + 4.4rem);
    text-align: center;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--faint);
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}

#blazor-error-ui {
    color-scheme: light dark;
    background: var(--surface);
    border-top: 1px solid var(--danger);
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(16, 24, 32, 0.12);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    color: var(--danger);
    font-size: 0.9rem;
}

#blazor-error-ui .dismiss { cursor: pointer; position: absolute; right: 0.75rem; top: 0.5rem; }

.blazor-error-boundary { background: var(--danger-soft); }
.blazor-error-boundary::after { content: "An error has occurred."; color: var(--danger); }

.code-mono { font-family: var(--font-mono); }

/* ---------- Material Symbols (reference icon language) ---------- */
/* Self-hosted (full ligature set, ~4 MB): without it every icon renders as
   its literal name and blows up the layout. font-display: block hides the
   raw ligature text during load instead of flashing it. */
@font-face {
    font-family: 'Material Symbols Outlined';
    font-style: normal;
    font-weight: 100 700;
    font-display: block;
    src: url('../fonts/material-symbols-outlined.woff2') format('woff2');
}

.material-symbols-outlined {
    font-family: 'Material Symbols Outlined';
    font-weight: normal;
    font-style: normal;
    font-size: 20px;
    line-height: 1;
    display: inline-block;
    white-space: nowrap;
    letter-spacing: normal;
    text-transform: none;
    direction: ltr;
    -webkit-font-smoothing: antialiased;
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
}

.sidebar .nav-link .material-symbols-outlined { font-size: 20px; opacity: 0.85; }
.sidebar .nav-link:hover .material-symbols-outlined,
.sidebar .nav-link.active .material-symbols-outlined { opacity: 1; }

/* ---------- Sidebar menu search (reference .menu-search-box) ---------- */
.menu-search-wrap { padding: 0.55rem 0.875rem 0.3rem; position: relative; }

.menu-search {
    width: 100%;
    height: 36px;
    border-radius: 8px;
    font-size: 13px;
    padding: 0.35rem 0.75rem 0.35rem 2.1rem;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    color: var(--ink);
    background-image: none;
}

.menu-search:focus {
    border-color: var(--accent);
    background: var(--surface);
    box-shadow: 0 0 0 1px var(--accent);
}

.menu-search-icon {
    position: absolute;
    left: 1.4rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 18px;
    color: var(--menu-item-color);
    opacity: 0.8;
    pointer-events: none;
}

.no-match { color: var(--faint); font-size: 12.5px; padding: 0.6rem 0.9rem; }

/* Login card gets the soft-depth treatment */
.card.shadow-sm { box-shadow: var(--shadow-md) !important; }

/* ============================================================
   Supply chain - KPI strip, item catalog, thumbs, drawer (MD3)
   ============================================================ */

.sc-kpi {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 14px;
}

.sc-kpi-card {
    padding: 0.8rem 1.1rem;
    background: var(--md-sys-color-surface-container-lowest);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-medium);
    box-shadow: none;
}

body.dark-theme .sc-kpi-card {
    background: var(--md-sys-color-surface-container-low);
}

.sc-kpi-num {
    font-family: var(--font-mono);
    font-size: 1.55rem;
    font-weight: 500;
    line-height: 1.2;
    margin-top: 0.2rem;
}

.sc-kpi-danger .sc-kpi-num { color: var(--md-sys-color-error); }
.sc-kpi-danger { border-color: var(--md-sys-color-error); }

.sc-search { max-width: 320px; }
.sc-category { max-width: 200px; }

.item-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.item-card {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 0.85rem;
    background: var(--md-sys-color-surface-container-lowest);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-medium);
    box-shadow: none;
    cursor: pointer;
    transition: background-color var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard),
        box-shadow var(--md-sys-motion-duration-short) var(--md-sys-motion-easing-standard);
}

body.dark-theme .item-card {
    background: var(--md-sys-color-surface-container-low);
}

.item-card:hover {
    background: var(--md-sys-color-surface-container-low);
    box-shadow: var(--shadow-sm);
    transform: none;
}

body.dark-theme .item-card:hover {
    background: var(--md-sys-color-surface-container);
}

.item-card-media { position: relative; }

.item-card-img {
    width: 100%;
    aspect-ratio: 4 / 3;
    border-radius: var(--md-sys-shape-corner-small);
    object-fit: cover;
    border: 1px solid var(--md-sys-color-outline-variant);
    background: var(--md-sys-color-surface-container);
    display: flex;
    align-items: center;
    justify-content: center;
}

.item-card-img-fallback {
    font-family: var(--font-mono);
    font-size: 1.4rem;
    font-weight: 600;
    color: var(--md-sys-color-on-primary-container);
    background: var(--md-sys-color-primary-container);
}

.item-card-flag { position: absolute; top: 8px; right: 8px; }

.item-card-name {
    font-weight: 600;
    font-size: 0.92rem;
    line-height: 1.25;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

.item-card-price { font-size: 0.9rem; font-weight: 600; }

.chip {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: var(--md-sys-shape-corner-small);
    font: var(--md-type-label-medium);
    font-size: 11.5px;
    color: var(--md-sys-color-on-primary-container);
    background: var(--md-sys-color-primary-container);
    white-space: nowrap;
}

.pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 2px 9px;
    border-radius: var(--md-sys-shape-corner-small);
    font: var(--md-type-label-medium);
    font-size: 11.5px;
    border: 1px solid transparent;
    white-space: nowrap;
}

.pill-ok {
    color: var(--md-sys-color-on-success-container);
    background: var(--md-sys-color-success-container);
    border-color: color-mix(in srgb, var(--md-sys-color-success) 25%, transparent);
}

.pill-danger {
    color: var(--md-sys-color-on-error-container);
    background: var(--md-sys-color-error-container);
    border-color: color-mix(in srgb, var(--md-sys-color-error) 25%, transparent);
}

.pill-warn {
    color: var(--md-sys-color-on-warning-container);
    background: var(--md-sys-color-warning-container);
    border-color: color-mix(in srgb, var(--md-sys-color-warning) 25%, transparent);
}

.pill-off {
    color: var(--md-sys-color-on-surface-variant);
    background: var(--md-sys-color-surface-container-high);
    border-color: var(--md-sys-color-outline-variant);
}

.sc-cell-thumb { display: inline-block; line-height: 0; }

.item-thumb {
    width: 42px;
    height: 42px;
    border-radius: var(--md-sys-shape-corner-small);
    object-fit: cover;
    border: 1px solid var(--md-sys-color-outline-variant);
    background: var(--md-sys-color-surface-container);
}

.item-thumb-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--md-sys-color-on-primary-container);
    background: var(--md-sys-color-primary-container);
}

.sc-drawer-backdrop,
.ret-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.32);
    z-index: 1050;
}

.sc-drawer {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 380px;
    max-width: 92vw;
    padding: 1.25rem;
    overflow-y: auto;
    background: var(--md-sys-color-surface-container-low);
    border-left: 1px solid var(--md-sys-color-outline-variant);
    box-shadow: var(--md-elevation-3, var(--shadow-md));
    z-index: 1051;
    animation: md3-sheet-in var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-emphasized-decelerate);
}

@keyframes md3-sheet-in {
    from { transform: translateX(24px); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.sc-drawer-img {
    width: 100%;
    aspect-ratio: 16 / 10;
    border-radius: var(--md-sys-shape-corner-medium);
    object-fit: cover;
    border: 1px solid var(--md-sys-color-outline-variant);
    background: var(--md-sys-color-surface-container);
    display: flex;
    align-items: center;
    justify-content: center;
}

.sc-drawer-img-fallback {
    font-family: var(--font-mono);
    font-size: 2rem;
    font-weight: 600;
    color: var(--md-sys-color-on-primary-container);
    background: var(--md-sys-color-primary-container);
}

.sc-facts {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-medium);
    overflow: hidden;
}

.sc-facts > div {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 0.45rem 0.8rem;
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    font-size: 0.85rem;
    background: var(--md-sys-color-surface-container-lowest);
}

body.dark-theme .sc-facts > div {
    background: var(--md-sys-color-surface-container-low);
}

.sc-facts > div:last-child { border-bottom: none; }

.sc-facts span { color: var(--md-sys-color-on-surface-variant); }

.sc-facts b {
    font-weight: 600;
    text-align: right;
    overflow-wrap: anywhere;
}

.mono { font-family: var(--font-mono); }

/* ============================================================
   Return / exchange (credit note) modal - MD3 dialog
   ============================================================ */

.ret-modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(620px, calc(100vw - 32px));
    max-height: calc(100vh - 64px);
    overflow: auto;
    background: var(--md-sys-color-surface-container-high);
    border: 0;
    border-radius: var(--md-sys-shape-corner-extra-large);
    box-shadow: var(--md-elevation-3, 0 18px 48px rgba(0, 0, 0, .25));
    padding: 24px;
    z-index: 1051;
    display: flex;
    flex-direction: column;
    gap: 12px;
    animation: md3-dialog-in var(--md-sys-motion-duration-medium) var(--md-sys-motion-easing-emphasized-decelerate);
}

@keyframes md3-dialog-in {
    from { transform: translate(-50%, -48%) scale(0.97); opacity: 0; }
    to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.ret-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.ret-head h2 {
    font: var(--md-type-title-large);
    font-size: 18px;
    font-weight: 500;
    letter-spacing: 0;
    margin: 0;
}

.ret-sub {
    margin: 3px 0 0;
    font-size: 12.5px;
    color: var(--md-sys-color-on-surface-variant);
}

.ret-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 14px;
}

.ret-field-wide {
    grid-column: 1 / -1;
}

.ret-field label {
    font: var(--md-type-label-medium);
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 4px;
    display: block;
}

.ret-req {
    color: var(--md-sys-color-error);
}

.ret-hint {
    display: block;
    font-size: 11.5px;
    color: var(--md-sys-color-on-surface-variant);
    margin-top: 3px;
}

.ret-prior {
    border: 1px dashed var(--md-sys-color-outline-variant);
    border-radius: var(--md-sys-shape-corner-small);
    padding: 8px 10px;
    font-size: 12.5px;
}

.ret-prior-label {
    display: block;
    font: var(--md-type-label-medium);
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--md-sys-color-on-surface-variant);
    margin-bottom: 5px;
}

.ret-prior-row {
    display: flex;
    gap: 10px;
    align-items: baseline;
    padding: 2px 0;
}

.ret-prior-type {
    font-size: 11.5px;
    font-weight: 600;
    color: var(--md-sys-color-on-surface-variant);
}

.ret-prior-reason {
    margin-left: auto;
    color: var(--md-sys-color-on-surface-variant);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 55%;
}

.ret-summary {
    border-top: 1px solid var(--md-sys-color-outline-variant);
    padding-top: 8px;
    font-size: 13px;
}

.ret-sumrow {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
}

.ret-sumrow .num {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

.ret-sumrow-total {
    font-weight: 700;
    border-top: 1px solid var(--md-sys-color-outline);
    margin-top: 4px;
    padding-top: 6px;
}

.ret-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.ret-warn {
    font-size: 11.5px;
    color: var(--md-sys-color-on-surface-variant);
    max-width: 70%;
}
