/* =============================================================================
   Price & Supplier Library — "Ledger" design system
   Navy sidebar, warm paper work area, calm teal highlights, IBM Plex Sans for text
   and IBM Plex Mono for every price and number. Light and dark themes share the
   same tokens (dark values under :root[data-theme="dark"]).
   ========================================================================== */

/* IBM Plex (SIL Open Font License, see assets/fonts/Plex-LICENSE.txt). */
@font-face {
    font-family: "IBM Plex Sans"; font-style: normal; font-weight: 100 700; font-display: swap;
    src: url("../assets/fonts/plex-sans-latin-wght.woff2") format("woff2-variations"), url("../assets/fonts/plex-sans-latin-wght.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
    font-family: "IBM Plex Sans"; font-style: normal; font-weight: 100 700; font-display: swap;
    src: url("../assets/fonts/plex-sans-latin-ext-wght.woff2") format("woff2-variations"), url("../assets/fonts/plex-sans-latin-ext-wght.woff2") format("woff2");
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face { font-family: "IBM Plex Mono"; font-weight: 500; font-display: swap; src: url("../assets/fonts/plex-mono-latin-500.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-weight: 600; font-display: swap; src: url("../assets/fonts/plex-mono-latin-600.woff2") format("woff2"); }

:root {
    color-scheme: light;
    --bg: #f4f2ec;
    --surface: #ffffff;
    --surface-2: #faf8f4;
    --surface-3: #efece4;
    --border: #e3dfd4;
    --border-strong: #cdc6b6;
    --text: #0f1b2d;
    --text-2: #354256;
    --muted: #5f6779;             /* 5.1:1 on the page background (WCAG AA for small text) */
    --muted-2: #737a8a;           /* placeholders and field icons: 4.3:1 on white */

    --primary: #1b2a4a;          /* navy: primary buttons, links */
    --primary-hover: #26395f;
    --on-primary: #ffffff;
    --primary-soft: #e9edf5;
    --primary-ring: rgba(27, 42, 74, .22);
    --link: #1f4fa3;

    /* Calm teal: active and selected states. Muted on purpose (no glare), every pair at least WCAG AA:
       accent 4.6:1 on white, accent-strong 5.8:1 on accent-soft, white on accent 4.6:1. */
    --accent: #3d7f86;
    --accent-strong: #2b6369;
    --accent-soft: #e5f0f0;
    --accent-ink: #ffffff;

    --side-bg: #0f1b2d;
    --side-bg-2: #15233a;
    --side-text: #c3cbd9;
    --side-muted: #7c889e;
    --side-line: rgba(255, 255, 255, .07);

    --success: #1f7a45; --success-soft: #e6f4ec;
    --danger: #b42318;  --danger-hover: #912018; --danger-soft: #fdecea;
    --warning: #a15c07; --warning-soft: #fdf3e1;
    --info: #1f4fa3;    --info-soft: #e9effa;

    --radius-sm: 3px;
    --radius: 4px;
    --radius-lg: 6px;
    --shadow-sm: 0 1px 1px rgba(15, 27, 45, .04);
    --shadow: 0 1px 2px rgba(15, 27, 45, .06);
    --shadow-lg: 0 18px 40px rgba(15, 27, 45, .18), 0 2px 6px rgba(15, 27, 45, .08);
    --shadow-card: 0 1px 0 rgba(15, 27, 45, .03);
    --shadow-hover: 0 4px 14px rgba(15, 27, 45, .10);

    --fs-xs: 12px; --fs-sm: 13px; --fs-base: 14px; --fs-md: 15px; --fs-lg: 17px;
    --gap-tile: 14px;
    --gap-section: 18px;
    --sidebar-width: 248px;
    --topbar-height: 58px;

    --font: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    --mono: "IBM Plex Mono", "Cascadia Mono", Consolas, "SFMono-Regular", Menlo, monospace;
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0b1220;
    --surface: #111a2b;
    --surface-2: #141f33;
    --surface-3: #1a273e;
    --border: #22304a;
    --border-strong: #32435f;
    --text: #e8ecf3;
    --text-2: #c2cada;
    --muted: #8e99ae;
    --muted-2: #7d89a0;           /* 4.9:1 on the dark surface */

    --primary: #5ea9a4;          /* in the dark, primary actions turn soft teal */
    --primary-hover: #74b8b3;
    --on-primary: #0b1a1c;
    --primary-soft: rgba(94, 169, 164, .13);
    --primary-ring: rgba(94, 169, 164, .35);
    --link: #8db4f5;

    --accent: #5ea9a4;           /* 6.4:1 on the dark surface */
    --accent-strong: #86c3be;
    --accent-soft: rgba(94, 169, 164, .14);
    --accent-ink: #0b1a1c;

    --side-bg: #070d18;
    --side-bg-2: #0e1727;

    --success: #4ac07b; --success-soft: rgba(74, 192, 123, .12);
    --danger: #f2685c;  --danger-hover: #ff8478; --danger-soft: rgba(242, 104, 92, .12);
    --warning: #d6aa6a; --warning-soft: rgba(214, 170, 106, .12);
    --info: #8db4f5;    --info-soft: rgba(141, 180, 245, .12);

    --shadow-lg: 0 18px 44px rgba(0, 0, 0, .6);
    --shadow-hover: 0 6px 18px rgba(0, 0, 0, .45);
}

/* ---- Base --------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0; background: var(--bg); color: var(--text);
    font-family: var(--font); font-size: var(--fs-base); line-height: 1.5;
    -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; color: var(--text); font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: 24px; }
h2 { font-size: var(--fs-lg); }
h3 { font-size: var(--fs-md); }
p { margin: 0 0 .75em; }
a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }
img, svg { vertical-align: middle; }
code, .mono { font-family: var(--mono); font-size: .92em; }
/* Mono is for money and price columns; other figures keep the text face with aligned digits. */
.money, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.kpi-value { font-variant-numeric: tabular-nums; }
[hidden] { display: none !important; }
.lucide { width: 18px; height: 18px; stroke-width: 1.9; flex-shrink: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent-soft); }
/* Scrollbars: thin and light everywhere (pale warm grey on the paper, soft slate in
   dark mode, barely visible on the navy sidebar). */
:root { --scroll-thumb: #d9d4c8; --scroll-thumb-hover: #c4bdae; --scroll-track: transparent; }
:root[data-theme="dark"] { --scroll-thumb: #2c3a54; --scroll-thumb-hover: #3b4b69; }
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) var(--scroll-track); }
html { scrollbar-color: var(--scroll-thumb) var(--bg); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: var(--scroll-track); }
::-webkit-scrollbar-thumb { background: var(--scroll-thumb); border-radius: 999px; border: 3px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background: var(--scroll-thumb-hover); background-clip: padding-box; }
::-webkit-scrollbar-corner { background: transparent; }
.sidebar, .sidebar * { --scroll-thumb: rgba(255, 255, 255, .14); --scroll-thumb-hover: rgba(255, 255, 255, .24); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* ---- Shell: sidebar + work area -------------------------------------------- */

.shell { display: flex; min-height: 100vh; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.sidebar {
    position: sticky; top: 0; height: 100vh; z-index: 40;
    width: var(--sidebar-width); flex-shrink: 0;
    display: flex; flex-direction: column;
    background: var(--side-bg); color: var(--side-text);
    border-right: 1px solid var(--side-line);
}
.side-brand {
    display: flex; align-items: center; gap: 11px;
    height: var(--topbar-height); padding: 0 18px;
    border-bottom: 1px solid var(--side-line);
    color: #fff; text-decoration: none !important;
}
.side-brand img { border-radius: 8px; flex-shrink: 0; }
/* The full name may take two lines next to the logo; with the company name it still fits the bar's height. */
.side-brand strong { display: block; font-size: 14px; font-weight: 600; line-height: 1.2; letter-spacing: .01em; }
.side-brand small { display: block; margin-top: 1px; font-size: 11.5px; line-height: 1.3; color: var(--side-muted); }
.side-nav { flex: 1; overflow-y: auto; padding: 10px 10px 16px; }
.side-section {
    margin: 18px 10px 6px;
    font-size: 10.5px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; color: var(--side-muted);
}
.side-section:first-child { margin-top: 8px; }
.side-link {
    position: relative; display: flex; align-items: center; gap: 11px;
    min-height: 38px; padding: 8px 12px; margin-bottom: 2px;
    border-radius: var(--radius);
    color: var(--side-text); font-size: 13.5px; text-decoration: none !important;
    transition: background-color .12s, color .12s;
}
.side-link .lucide { width: 17px; height: 17px; color: var(--side-muted); }
.side-link:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.side-link:hover .lucide { color: var(--side-text); }
/* On the navy sidebar and sign-in panel the teal is lighter, so it reads at 7.5:1. */
.sidebar, .auth-aside { --accent: #6fb8b2; --accent-ink: #0b1a1c; }
.side-link.active { background: rgba(111, 184, 178, .14); color: #fff; font-weight: 600; }
.side-link.active::before { content: ""; position: absolute; left: -10px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.side-link.active .lucide { color: var(--accent); }
.side-link .side-ext { width: 14px; height: 14px; margin-left: auto; }
.side-foot { position: relative; padding: 10px; border-top: 1px solid var(--side-line); }
.side-user {
    display: flex; align-items: center; gap: 10px; width: 100%;
    padding: 8px; border: 0; border-radius: var(--radius);
    background: transparent; color: var(--side-text); font: inherit; text-align: left; cursor: pointer;
}
.side-user:hover { background: rgba(255, 255, 255, .05); }
.side-user .avatar { background: var(--accent); color: var(--accent-ink); }
.side-user-text { flex: 1; min-width: 0; line-height: 1.3; }
.side-user-text strong { display: block; font-size: 13px; color: #fff; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user-text small { display: block; font-size: 11.5px; color: var(--side-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user > .lucide { width: 15px; height: 15px; color: var(--side-muted); }

.topbar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: 12px;
    height: var(--topbar-height); padding: 0 28px;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--border);
}
.topbar .menu-toggle { display: none; }
.topbar-search { position: relative; flex: 1; max-width: 560px; display: flex; align-items: center; }
.topbar-search > .lucide { position: absolute; left: 12px; width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.topbar-search input {
    width: 100%; height: 38px; padding: 0 64px 0 38px;
    border: 1px solid var(--border-strong); border-radius: var(--radius);
    background: var(--surface-2); color: var(--text); font: inherit; font-size: 13.5px;
}
.topbar-search input::placeholder { color: var(--muted); }
.topbar-search input::-webkit-search-cancel-button { display: none; }
.topbar-search input:focus { outline: none; border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.topbar-search kbd {
    position: absolute; right: 8px; padding: 1px 6px;
    border: 1px solid var(--border-strong); border-radius: 3px; background: var(--surface);
    color: var(--muted); font: 500 11px/16px var(--mono); pointer-events: none;
}
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 4px; }

.content { flex: 1; min-width: 0; padding: 0 28px 48px; }
.content > :first-child:not(.page-header) { margin-top: 24px; }
.sidebar-backdrop { display: none; }

/* Page title block: sits on the paper, no bar. */
.page-header {
    display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 20px; flex-wrap: wrap;
    padding: 26px 0 20px;
}
.page-header > div:first-child { flex: 1 1 360px; min-width: 0; }
.page-header h1 { font-size: 26px; font-weight: 600; letter-spacing: -.02em; }
.page-header p { margin: 6px 0 0; color: var(--muted); font-size: 13.5px; }
.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.breadcrumb { display: flex; align-items: center; gap: 6px; margin-bottom: 6px; font-size: 12.5px; color: var(--muted); }
.breadcrumb a { color: var(--muted); }
.breadcrumb a:hover { color: var(--text); }
.breadcrumb .lucide { width: 13px; height: 13px; }

/* ---- Buttons ------------------------------------------------------------------ */

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 36px; padding: 0 15px;
    border: 1px solid transparent; border-radius: var(--radius);
    background: var(--primary); color: var(--on-primary);
    font: inherit; font-size: 13.5px; font-weight: 600; white-space: nowrap;
    cursor: pointer; text-decoration: none !important;
    transition: background-color .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { background: var(--primary-hover); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--primary-ring); }
.btn:disabled, .btn.is-loading { opacity: .6; cursor: not-allowed; }
.btn .lucide { width: 16px; height: 16px; }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); border-color: var(--muted-2); }
.btn-secondary.active { background: var(--accent-soft); border-color: var(--accent); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-3); color: var(--text); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: var(--danger-hover); }
.btn-warning { background: var(--warning); color: #fff; }
.btn-outline-danger { background: var(--surface); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.btn-outline-danger:hover { background: var(--danger-soft); }
.btn-sm { height: 32px; padding: 0 12px; font-size: 13px; }
.btn-xs { height: 28px; padding: 0 10px; font-size: 12.5px; gap: 6px; }
.btn-xs .lucide { width: 14px; height: 14px; }
.btn-lg { height: 46px; padding: 0 22px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-icon { width: 32px; padding: 0; }
.btn.is-loading::after { content: ""; width: 14px; height: 14px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.icon-btn {
    display: inline-grid; place-items: center; width: 36px; height: 36px;
    border: 0; border-radius: var(--radius); background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.theme-toggle .theme-icon-light { display: none; }
[data-theme="dark"] .theme-toggle .theme-icon-light { display: inline; }
[data-theme="dark"] .theme-toggle .theme-icon-dark { display: none; }
.avatar {
    display: inline-grid; place-items: center; width: 32px; height: 32px; flex-shrink: 0;
    border-radius: 50%; background: var(--primary-soft); color: var(--primary);
    font-size: 12px; font-weight: 600;
}

/* ---- Dropdown ------------------------------------------------------------------- */

.dropdown { position: relative; }
.dropdown-menu {
    position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 220px; padding: 6px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
}
.dropdown-menu.dropdown-up { top: auto; bottom: calc(100% - 4px); left: 10px; right: 10px; }
.dropdown-item {
    display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px;
    border: 0; border-radius: var(--radius-sm); background: transparent;
    color: var(--text-2); font: inherit; font-size: 13.5px; text-align: left; cursor: pointer; text-decoration: none !important;
}
.dropdown-item:hover { background: var(--surface-3); color: var(--text); }
.dropdown-item .lucide { width: 16px; height: 16px; color: var(--muted); }
.dropdown-divider { height: 1px; margin: 6px 0; background: var(--border); }
.dropdown-header { padding: 8px 10px 6px; }
.dropdown-header strong { display: block; font-size: 13px; }
.dropdown-header span { display: block; font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }

/* ---- Cards ---------------------------------------------------------------------- */

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-card); }
.card + .card { margin-top: var(--gap-section); }
.card-header {
    display: flex; align-items: center; justify-content: space-between; gap: 6px 12px; flex-wrap: wrap;
    min-height: 52px; padding: 12px 20px; border-bottom: 1px solid var(--border);
}
.card-header h2, .card-header h3 {
    display: flex; align-items: center; gap: 8px;
    font-size: 14.5px; font-weight: 600; letter-spacing: 0; color: var(--text);
}
.card-header h2 .lucide, .card-header h3 .lucide { width: 15px; height: 15px; color: var(--accent-strong); }
.card-header p { margin: 0; color: var(--muted); font-size: var(--fs-sm); }
.card-body { padding: 20px; }
.card-footer { padding: 14px 20px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg); }
.card-flush .card-body { padding: 0; }

.grid { display: grid; gap: var(--gap-section); }
.layout-main-side { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: var(--gap-section); align-items: start; }
.layout-main-side > .card, .layout-main-side > .stack { margin-top: 0 !important; }
.stack > * + * { margin-top: var(--gap-section); }
.content > .alert { margin-bottom: var(--gap-section); }

/* ---- KPI tiles (ledger figures) ------------------------------------------------- */

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--gap-tile); }
.kpi {
    --tone: var(--muted); --tone-soft: var(--surface-3);
    position: relative; display: flex; flex-direction: column; gap: 4px; min-height: 96px;
    padding: 14px 16px 12px; overflow: hidden;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
}
.kpi::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: var(--tone); }
.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.kpi-label { font-size: 12.5px; font-weight: 500; color: var(--muted); }
.kpi-icon { display: grid; place-items: center; width: 26px; height: 26px; border-radius: var(--radius); background: var(--tone-soft); color: var(--tone); }
.kpi-icon .lucide { width: 15px; height: 15px; }
.kpi-value { font-size: 22px; font-weight: 600; line-height: 1.3; letter-spacing: -.02em; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kpi-foot { margin-top: auto; font-size: var(--fs-xs); color: var(--muted); line-height: 1.4; }
/* Compact tiles (Users page): one row each, the icon on the left, the label above its number. */
.kpi-compact { margin-bottom: var(--gap-section); grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kpi-compact .kpi { min-height: 0; flex-direction: row; align-items: center; gap: 12px; padding: 11px 14px; }
.kpi-compact .kpi-icon { flex-shrink: 0; width: 34px; height: 34px; }
.kpi-compact .kpi-icon .lucide { width: 17px; height: 17px; }
.kpi-compact .kpi-body { min-width: 0; line-height: 1.3; }
.kpi-compact .kpi-value { font-size: 20px; line-height: 1.25; }
@media (max-width: 900px) { .kpi-compact { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.tone-blue   { --tone: #1f4fa3; --tone-soft: #e9effa; }
.tone-amber  { --tone: #9a6a12; --tone-soft: #f8efdc; }
.tone-orange { --tone: #c2410c; --tone-soft: #fdeee3; }
.tone-green  { --tone: #1f7a45; --tone-soft: #e6f4ec; }
.tone-red    { --tone: #b42318; --tone-soft: #fdecea; }
.tone-indigo { --tone: #4338ca; --tone-soft: #eceefd; }
.tone-teal   { --tone: #1b2a4a; --tone-soft: #e9edf5; }
.tone-cyan   { --tone: #0e6f8a; --tone-soft: #e0f2f7; }
.tone-gray   { --tone: #6b7385; --tone-soft: #efece4; }
[data-theme="dark"] .tone-blue   { --tone: #8db4f5; --tone-soft: rgba(141, 180, 245, .13); }
[data-theme="dark"] .tone-amber  { --tone: #d6aa6a; --tone-soft: rgba(214, 170, 106, .13); }
[data-theme="dark"] .tone-orange { --tone: #fb923c; --tone-soft: rgba(251, 146, 60, .13); }
[data-theme="dark"] .tone-green  { --tone: #4ac07b; --tone-soft: rgba(74, 192, 123, .13); }
[data-theme="dark"] .tone-red    { --tone: #f2685c; --tone-soft: rgba(242, 104, 92, .13); }
[data-theme="dark"] .tone-indigo { --tone: #a5b4fc; --tone-soft: rgba(165, 180, 252, .13); }
[data-theme="dark"] .tone-teal   { --tone: #c2cada; --tone-soft: rgba(194, 202, 218, .1); }
[data-theme="dark"] .tone-cyan   { --tone: #67c7e0; --tone-soft: rgba(103, 199, 224, .13); }
[data-theme="dark"] .tone-gray   { --tone: #8e99ae; --tone-soft: rgba(142, 153, 174, .12); }

/* ---- Badges --------------------------------------------------------------------- */

.badge {
    display: inline-flex; align-items: center; gap: 4px; padding: 2px 7px;
    border-radius: var(--radius-sm); border: 1px solid transparent;
    font-size: 11.5px; font-weight: 600; line-height: 17px; white-space: nowrap;
}
.badge .lucide { width: 12px; height: 12px; }
.badge-sm { padding: 0 5px; font-size: 10.5px; letter-spacing: .03em; }
.badge-gray   { background: var(--surface-3); color: var(--text-2); }
.badge-amber  { background: var(--warning-soft); color: #8a5c00; }
.badge-green  { background: var(--success-soft); color: var(--success); }
.badge-red    { background: var(--danger-soft); color: var(--danger); }
.badge-blue   { background: var(--info-soft); color: var(--info); }
.badge-indigo { background: #eceefd; color: #4338ca; }
.badge-teal   { background: var(--primary-soft); color: var(--primary); }
[data-theme="dark"] .badge-amber { color: #d6aa6a; }
[data-theme="dark"] .badge-indigo { background: rgba(165, 180, 252, .13); color: #a5b4fc; }
[data-theme="dark"] .badge-teal { background: rgba(194, 202, 218, .1); color: var(--text-2); }

/* ---- Alerts --------------------------------------------------------------------- */

.alert {
    display: flex; gap: 12px; align-items: flex-start; padding: 12px 16px; margin-bottom: 16px;
    border: 1px solid; border-left-width: 4px; border-radius: var(--radius);
    font-size: var(--fs-sm); line-height: 1.55;
}
.alert > .lucide { width: 18px; height: 18px; margin-top: 1px; }
.alert strong { display: block; margin-bottom: 2px; font-size: var(--fs-base); }
.alert a { font-weight: 600; }
.alert p:last-child { margin-bottom: 0; }
.alert-info    { background: var(--info-soft); border-color: color-mix(in srgb, var(--info) 30%, transparent); color: var(--info); }
.alert-success { background: var(--success-soft); border-color: color-mix(in srgb, var(--success) 30%, transparent); color: var(--success); }
.alert-warning { background: var(--warning-soft); border-color: color-mix(in srgb, var(--warning) 30%, transparent); color: var(--warning); }
.alert-danger  { background: var(--danger-soft); border-color: color-mix(in srgb, var(--danger) 30%, transparent); color: var(--danger); }
.alert div { color: var(--text-2); }
.alert strong { color: inherit; }

/* ---- Tables (ledger rows) --------------------------------------------------------- */

/* position: relative keeps absolutely placed children (screen-reader labels) inside the scroll box,
   so a wide table scrolls on its own instead of widening the page. */
.table-wrap { position: relative; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { padding: 11px 16px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th {
    background: var(--surface-2); color: var(--muted);
    font-size: 12px; font-weight: 600; white-space: nowrap;
    border-bottom-color: var(--border-strong);
}
.table td { color: var(--text); font-size: var(--fs-sm); }
.table tbody tr:nth-child(even) td { background: color-mix(in srgb, var(--surface-2) 60%, transparent); }
.table tbody tr:hover td { background: var(--accent-soft); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num, .table th.num { text-align: right; font-family: var(--mono); font-variant-numeric: tabular-nums; }
.table th.num { font-family: var(--font); }
.table .nowrap { white-space: nowrap; }
.table .actions { text-align: right; white-space: nowrap; }
.table .cell-sub { display: block; max-width: 240px; margin-top: 1px; font-family: var(--font); font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---- Empty state -------------------------------------------------------------------- */

.empty-state { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty-state .empty-icon { display: inline-grid; place-items: center; width: 52px; height: 52px; margin-bottom: 12px; border-radius: var(--radius-lg); background: var(--surface-3); color: var(--muted); }
.empty-state .empty-icon .lucide { width: 24px; height: 24px; }
.empty-state h3 { color: var(--text); margin-bottom: 4px; }
.empty-state p { margin-bottom: 16px; }

/* ---- Forms -------------------------------------------------------------------------- */

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.form-grid .span-all { grid-column: 1 / -1; }
.form-group { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.form-label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.form-label .req { color: var(--danger); margin-left: 2px; }
.form-label .optional { font-weight: 400; color: var(--muted); }
.form-hint { font-size: 12px; color: var(--muted); }
.form-control {
    width: 100%; height: 40px; padding: 0 12px;
    border: 1px solid var(--border-strong); border-radius: var(--radius);
    background: var(--surface); color: var(--text); font: inherit; font-size: 14px;
    transition: border-color .12s, box-shadow .12s;
}
.form-control::placeholder { color: var(--muted-2); }
.form-control:hover { border-color: var(--muted-2); }
.form-control:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-control[readonly], .form-control:disabled { background: var(--surface-2); color: var(--text-2); }
textarea.form-control { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
input[type=number].form-control { font-family: var(--mono); }
input[type=date].form-control.is-empty { color: var(--muted-2); }
select.form-control {
    appearance: none; padding-right: 34px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236b7385' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 10px center;
}
.form-control-sm { height: 34px; font-size: 13px; }
.form-control.is-invalid { border-color: var(--danger); }
.form-control.is-invalid:focus { box-shadow: 0 0 0 3px var(--danger-soft); }
.field-error { font-size: 12px; color: var(--danger); }
.field-error:empty { display: none; }
.input-icon { position: relative; }
.input-icon > .lucide { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted-2); pointer-events: none; }
.input-icon .form-control { padding-left: 36px; }
.input-icon .toggle-password { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); padding: 6px; border: 0; background: none; color: var(--muted); cursor: pointer; }
.checkbox { display: flex; align-items: flex-start; gap: 10px; cursor: pointer; font-size: 13.5px; }
.checkbox input { margin-top: 3px; accent-color: var(--accent-strong); }
input[type=checkbox], input[type=radio] { accent-color: var(--accent-strong); }
.radio-cards { display: flex; gap: 10px; flex-wrap: wrap; }

.file-picker {
    position: relative; display: flex; align-items: center; gap: 12px; padding: 12px 14px;
    border: 1.5px dashed var(--border-strong); border-radius: var(--radius-lg); background: var(--surface-2); cursor: pointer;
    transition: border-color .12s, background-color .12s;
}
.file-picker:hover, .file-picker.dragover { border-color: var(--accent); background: var(--accent-soft); }
.file-picker:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.file-picker input[type=file] { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; }
.file-picker-icon { display: grid; place-items: center; flex-shrink: 0; width: 38px; height: 38px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border); color: var(--accent-strong); }
.file-picker-text { flex: 1; min-width: 0; line-height: 1.3; }
.file-picker-text strong { display: block; font-size: 13.5px; font-weight: 600; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-picker-text span { display: block; font-size: 12px; color: var(--muted); }
.file-picker.has-file { border-style: solid; border-color: var(--accent); }
.file-picker.has-file .file-picker-icon { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }

/* ---- Filter bar ---------------------------------------------------------------------- */

/* The fields share the whole row (search twice as wide); the buttons take only their own width. */
.filters {
    display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
    padding: 16px 20px; border-bottom: 1px solid var(--border); background: var(--surface-2);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}
.filters .filter { display: flex; flex-direction: column; gap: 5px; flex: 1 1 150px; min-width: 0; }
.filters .filter-search { flex: 2 1 280px; }
.filters label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.filters .filter-actions { display: flex; flex: 0 0 auto; gap: 8px; align-items: center; }

/* ---- Pagination ------------------------------------------------------------------------ */

.pagination { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 20px; border-top: 1px solid var(--border); font-size: var(--fs-sm); color: var(--muted); }
.pagination strong { color: var(--text); font-family: var(--font); font-variant-numeric: tabular-nums; font-weight: 600; }
.pagination-pages { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.page-link {
    display: inline-flex; align-items: center; justify-content: center; gap: 4px; min-width: 34px; height: 34px; padding: 0 10px;
    border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text-2);
    font-family: var(--font); font-variant-numeric: tabular-nums; font-size: var(--fs-sm); text-decoration: none !important;
}
.page-link:hover { border-color: var(--border-strong); background: var(--surface-2); }
.page-link.active { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.page-link.disabled { opacity: .45; pointer-events: none; }
.page-link .lucide { width: 15px; height: 15px; }
.page-step { font-family: var(--font); padding: 0 12px; }
.page-gap { display: inline-grid; place-items: center; min-width: 20px; color: var(--muted-2); }

/* ---- Toasts ------------------------------------------------------------------------------ */

.toast-stack { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 10px; max-width: calc(100vw - 40px); }
.toast {
    display: flex; align-items: flex-start; gap: 10px; width: 380px; max-width: 100%; padding: 12px 14px;
    background: var(--side-bg); color: #e8ecf3; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg);
    border-left: 4px solid var(--accent); font-size: 13.5px; animation: toast-in .2s ease-out;
}
.toast.leaving { animation: toast-out .2s ease-in forwards; }
.toast-success { border-left-color: #4ac07b; } .toast-success .toast-icon { color: #4ac07b; }
.toast-error { border-left-color: #f2685c; } .toast-error .toast-icon { color: #f2685c; }
.toast-warning .toast-icon, .toast-info .toast-icon { color: var(--accent); }
.toast-body { flex: 1; white-space: pre-line; }
.toast-close { padding: 0; border: 0; background: none; color: #7c889e; cursor: pointer; }
.toast-close .lucide { width: 16px; height: 16px; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(8px); } }

/* ---- Modal --------------------------------------------------------------------------------- */

.modal { position: fixed; inset: 0; z-index: 90; display: grid; place-items: center; padding: 16px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(7, 13, 24, .55); animation: fade-in .15s; }
.modal-dialog {
    position: relative; width: 460px; max-width: 100%; max-height: calc(100vh - 32px); overflow-y: auto;
    background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); animation: modal-in .18s ease-out;
}
.modal-header { display: flex; gap: 14px; align-items: flex-start; padding: 22px 22px 0; }
.modal-icon { display: grid; place-items: center; width: 38px; height: 38px; flex-shrink: 0; border-radius: var(--radius-lg); background: var(--accent-soft); color: var(--accent-strong); }
.modal-icon.tone-success { background: var(--success-soft); color: var(--success); }
.modal-icon.tone-danger { background: var(--danger-soft); color: var(--danger); }
.modal-icon.tone-warning { background: var(--warning-soft); color: var(--warning); }
.modal-header h3 { font-size: 16px; margin-top: 8px; }
.modal-body { padding: 10px 22px 6px 74px; color: var(--text-2); }
.modal-body .form-group { margin-top: 12px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 22px 20px; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.98); } }

/* ---- Small utilities ---------------------------------------------------------------------- */

.text-muted { color: var(--muted); }
.text-small { font-size: 12.5px; }
.fw-600 { font-weight: 600; }
.mt-2 { margin-top: 8px; } .mt-4 { margin-top: 16px; }
.mb-0 { margin-bottom: 0 !important; } .mb-4 { margin-bottom: 16px; }
.flex { display: flex; } .items-center { align-items: center; } .gap-2 { gap: 8px; } .wrap { flex-wrap: wrap; } .ml-auto { margin-left: auto; }

/* ---- Sign-in page --------------------------------------------------------------------------- */

.auth-page { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); background: var(--surface); }
.auth-aside {
    position: relative; overflow: hidden;
    display: flex; flex-direction: column; justify-content: space-between; gap: 40px; padding: 40px 56px;
    background: var(--side-bg); color: var(--side-text);
}
.auth-aside::after {
    content: ""; position: absolute; inset: 0; pointer-events: none;
    background-image: repeating-linear-gradient(0deg, rgba(255, 255, 255, .035) 0 1px, transparent 1px 36px);
}
.auth-brand { position: relative; z-index: 1; display: flex; align-items: center; gap: 12px; }
.auth-brand img { border-radius: 9px; }
.auth-brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.auth-brand-text strong { font-size: 16px; color: #fff; }
.auth-brand-text span { font-size: 12.5px; color: var(--side-muted); }
.auth-pitch { position: relative; z-index: 1; max-width: 480px; }
.auth-pitch h1 { margin-bottom: 14px; color: #fff; font-size: 34px; line-height: 1.15; letter-spacing: -.025em; }
.auth-pitch h1 em { font-style: normal; color: var(--accent); }
.auth-pitch > p { margin-bottom: 28px; color: var(--side-text); font-size: 15px; }
.auth-ledger { position: relative; z-index: 1; width: 100%; max-width: 480px; border-collapse: collapse; font-size: 13px; }
.auth-ledger th { padding: 0 0 8px; color: var(--side-muted); font-size: 10.5px; font-weight: 600; letter-spacing: .12em; text-transform: uppercase; text-align: left; border-bottom: 1px solid var(--side-line); }
.auth-ledger td { padding: 10px 0; border-bottom: 1px solid var(--side-line); color: #e8ecf3; }
.auth-ledger td.num, .auth-ledger th.num { text-align: right; font-family: var(--mono); }
.auth-ledger .best { color: var(--accent); font-weight: 600; }
.auth-aside small { position: relative; z-index: 1; color: var(--side-muted); }
.auth-main { position: relative; display: grid; place-items: center; padding: 40px 24px; background: var(--bg); }
.auth-theme-toggle { position: absolute; top: 20px; right: 24px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h2 { margin-bottom: 6px; font-size: 26px; letter-spacing: -.02em; }
.auth-card > p { margin-bottom: 26px; color: var(--muted); }
.auth-logo-mobile { display: none; margin-bottom: 22px; }
.auth-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.auth-divider { display: flex; align-items: center; gap: 12px; margin: 22px 0 14px; color: var(--muted); font-size: 12.5px; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
/* Sign-up: two short optional fields side by side; a field only form robots fill in, kept off screen. */
.signup-pair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; }
.signup-trap { position: absolute; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
@media (max-width: 420px) { .signup-pair { grid-template-columns: minmax(0, 1fr); } }

/* ---- Error page ------------------------------------------------------------------------------ */

.error-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; text-align: center; }
.error-page .code { font-family: var(--mono); font-size: 13px; font-weight: 600; letter-spacing: .1em; color: var(--accent-strong); text-transform: uppercase; }
.error-page h1 { font-size: 26px; margin: 8px 0 10px; }
.error-page p { max-width: 460px; margin: 0 auto 22px; color: var(--muted); }

/* ---- Responsive -------------------------------------------------------------------------------- */

@media (max-width: 1180px) {
    .layout-main-side { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 960px) {
    .sidebar { position: fixed; left: 0; top: 0; bottom: 0; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-lg); }
    body.sidebar-open .sidebar { transform: none; }
    body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; z-index: 35; background: rgba(7, 13, 24, .5); }
    .topbar { padding: 0 12px; }
    .topbar .menu-toggle { display: inline-grid; }
    .topbar-search kbd { display: none; }
    .topbar-search input { padding-right: 12px; }
    .content { padding: 0 16px 32px; }
    .auth-page { grid-template-columns: 1fr; }
    .auth-aside { display: none; }
    .auth-logo-mobile { display: block; }
}
@media (max-width: 560px) {
    .page-header h1 { font-size: 22px; }
    .page-header-actions { width: 100%; }
    .page-header-actions .btn { flex: 1; }
    .form-grid { grid-template-columns: minmax(0, 1fr); }
    .filters .filter { flex-basis: calc(50% - 6px); }
    .filters .filter-search { flex-basis: 100%; }
    .modal-body { padding-left: 22px; }
    .toast { width: 100%; }
}

/* ---- Live password checklist (app.js initPasswordRules) ------------------------------------ */

.password-rules { list-style: none; margin: -4px 0 18px; padding: 10px 12px; display: grid; gap: 5px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface-2); font-size: 12.5px; color: var(--muted); }
.password-rules li { display: flex; align-items: center; gap: 8px; }
.password-rules li::before { content: ""; flex-shrink: 0; width: 13px; height: 13px; border: 1.5px solid var(--border-strong); border-radius: 50%; }
.password-rules li.is-met { color: var(--success); }
.password-rules li.is-met::before { border-color: var(--success); background: var(--success); box-shadow: inset 0 0 0 2px var(--surface-2); }
.password-rules.is-active li:not(.is-met) { color: var(--text-2); }
