/* ==========================================================================
   DEJAVU Grain Trading System — main stylesheet
   RTL-first (logical properties), light + dark themes, no framework.
   Palette: deep field-green, charcoal, wheat-amber accent.
   ========================================================================== */

/* ---------- Fonts (bundled locally, SIL OFL 1.1 — see assets/fonts/OFL.txt) ---------- */
@font-face { font-family: "Noto Kufi Arabic"; src: url("../fonts/NotoKufiArabic-Regular.woff2") format("woff2"); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: "Noto Kufi Arabic"; src: url("../fonts/NotoKufiArabic-Medium.woff2") format("woff2"); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: "Noto Kufi Arabic"; src: url("../fonts/NotoKufiArabic-Bold.woff2") format("woff2"); font-weight: 700; font-style: normal; font-display: swap; }

/* ---------- Extra fonts, chosen in ڕێکخستن → فۆنتی بەرنامە ----------
   Sarchia Makka is supplied by the company and covers every Kurdish letter.
   The third slot is empty: drop a file into assets/fonts as font-three.woff2
   (ttf / otf also work) and the choice comes alive. While a file is missing the
   browser silently uses the fallback stack, so a page never breaks.
   Each family ships one weight; the browser makes the bold itself. */
@font-face {
    font-family: "Sarchia Makka";
    src: url("../fonts/Sarchia_Makka.woff2") format("woff2");
    font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
    font-family: "DJ Font Three";
    src: url("../fonts/font-three.woff2") format("woff2"), url("../fonts/font-three.ttf") format("truetype"), url("../fonts/font-three.otf") format("opentype");
    font-weight: 400; font-style: normal; font-display: swap;
}

/* ---------- Design tokens: light ---------- */
:root {
    --font: "Noto Kufi Arabic", "Segoe UI", Tahoma, "Arial Unicode MS", sans-serif;
    --font-two: "Sarchia Makka", "Noto Kufi Arabic", Tahoma, sans-serif;
    --font-three: "DJ Font Three", "Traditional Arabic", "Times New Roman", "Noto Kufi Arabic", serif;
    --fs-xs: 11.5px;
    --fs-sm: 12.5px;
    --fs: 13.5px;
    --fs-md: 15px;
    --fs-lg: 18px;
    --fs-xl: 21px;

    --r-sm: 4px;
    --r: 6px;
    --r-lg: 9px;

    --sb-w: 256px;
    --sb-w-collapsed: 68px;
    --tb-h: 58px;
    --ease: cubic-bezier(.2, .7, .2, 1);

    --bg: #f3f1ea;
    --surface: #ffffff;
    --surface-2: #f8f6f0;
    --surface-3: #efebe1;
    --border: #e3ded1;
    --border-strong: #cec7b5;
    --text: #1b231f;
    --text-2: #3b4640;
    --muted: #68736d;
    --faint: #9aa29d;

    --primary: #0e5a4b;
    --primary-hover: #0a4a3d;
    --primary-soft: #e1eee8;
    --primary-ink: #ffffff;
    --primary-text: #0d5a4a;

    --accent: #c1821f;
    --accent-strong: #8f5c0c;
    --accent-soft: #f8ecd4;

    --in: #17774a;
    --in-soft: #e1f1e7;
    --out: #b3362b;
    --out-soft: #f9e4e1;
    --warn: #9a620a;
    --warn-soft: #fbefd6;
    --info: #1f5f86;
    --info-soft: #e2edf5;
    --row-warn: #fdf3f1;

    --focus: 0 0 0 3px rgba(14, 90, 75, .22);
    --shadow-1: 0 1px 2px rgba(27, 35, 31, .05);
    --shadow-2: 0 14px 34px -12px rgba(27, 35, 31, .3);

    /* Sidebar stays dark in both themes */
    --sb-bg: #13201b;
    --sb-bg-2: #1a2b24;
    --sb-text: #c3cfc8;
    --sb-muted: #82938a;
    --sb-hover: rgba(255, 255, 255, .05);
    --sb-active: rgba(224, 165, 58, .13);
    --sb-active-text: #f3d9a4;
    --sb-border: rgba(255, 255, 255, .07);
    --sb-accent: #e0a53a;

    color-scheme: light;
}

/* ---------- Design tokens: dark (re-tuned, not inverted) ---------- */
[data-theme="dark"] {
    --bg: #0d1311;
    --surface: #141c19;
    --surface-2: #19231f;
    --surface-3: #1f2b26;
    --border: #25322c;
    --border-strong: #34443c;
    --text: #e3e9e5;
    --text-2: #c0cac4;
    --muted: #8c9993;
    --faint: #65726b;

    --primary: #38a888;
    --primary-hover: #46b897;
    --primary-soft: rgba(56, 168, 136, .14);
    --primary-ink: #04110c;
    --primary-text: #5cc4a4;

    --accent: #e0a53a;
    --accent-strong: #f0bd5a;
    --accent-soft: rgba(224, 165, 58, .14);

    --in: #4cc48a;
    --in-soft: rgba(76, 196, 138, .13);
    --out: #f07a6d;
    --out-soft: rgba(240, 122, 109, .13);
    --warn: #e6b04f;
    --warn-soft: rgba(230, 176, 79, .13);
    --info: #72b6de;
    --info-soft: rgba(114, 182, 222, .13);
    --row-warn: rgba(240, 122, 109, .06);

    --focus: 0 0 0 3px rgba(56, 168, 136, .35);
    --shadow-1: none;
    --shadow-2: 0 18px 40px -12px rgba(0, 0, 0, .65);

    --sb-bg: #0a100d;
    --sb-bg-2: #111a16;

    color-scheme: dark;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: var(--font);
    font-size: var(--fs);
    line-height: 1.75;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}
img { max-width: 100%; display: block; }
a { color: var(--primary-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; font-weight: 700; line-height: 1.5; }
p { margin: 0 0 .75em; }
p:last-child { margin-bottom: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
::selection { background: var(--accent-soft); }
kbd { font-family: var(--font); }

.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.icon { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.muted { color: var(--muted); }
.text-in { color: var(--in); }
.text-out { color: var(--out); }
.money, .qty { white-space: nowrap; }
.money .cur, .qty .unit { font-size: .86em; color: var(--muted); }
.money.is-neg, .money.is-neg .cur { color: var(--out); }
.money.is-owed, .money.is-owed .cur { color: var(--out); }
.money.is-credit, .money.is-credit .cur { color: var(--in); }
.text-in .money, .text-in .money .cur { color: var(--in); }
/* payment rows / cells get a light green field so they stand apart from sales */
.cell-in { background: var(--in-soft); }
.table tbody tr.row-in td { background: var(--in-soft); }
.table tbody tr.row-in:hover td { background: var(--in-soft); filter: brightness(.98); }
.text-out .money, .text-out .money .cur { color: var(--out); }
.qty.is-neg, .qty.is-neg .unit { color: var(--out); }
.qty.text-in .unit { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; inset-inline-start: 12px; top: -60px; z-index: 200; padding: 8px 14px; background: var(--primary); color: var(--primary-ink); border-radius: var(--r); }
.skip-link:focus { top: 12px; }
[data-theme="dark"] .only-light,
:root:not([data-theme="dark"]) .only-dark { display: none; }
.mb { margin-bottom: 18px; }
.mb-sm { margin-bottom: 10px; }
.print-only { display: none; }

/* ==========================================================================
   Layout: sidebar (right, RTL) + shell
   ========================================================================== */
html.sb-collapsed { --sb-w: var(--sb-w-collapsed); }

.sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: 40;
    width: var(--sb-w);
    display: flex;
    flex-direction: column;
    background: var(--sb-bg);
    color: var(--sb-text);
    border-inline-end: 1px solid var(--sb-border);
    transition: width .2s var(--ease), transform .25s var(--ease);
}
.shell {
    margin-inline-start: var(--sb-w);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: margin .2s var(--ease);
}

.sb-brand { height: var(--tb-h); display: flex; align-items: center; padding: 0 14px; border-bottom: 1px solid var(--sb-border); flex: none; }
.sb-brand-link { display: flex; align-items: center; gap: 11px; min-width: 0; color: #fff; text-decoration: none !important; }
.sb-logo {
    width: 36px; height: 36px; flex: none;
    display: grid; place-items: center;
    border-radius: 8px;
    background: linear-gradient(145deg, #e8b24c, #b87919);
    color: #1d1405;
}
.sb-logo .icon { width: 22px; height: 22px; stroke-width: 1.7; }
.sb-logo.has-img { background: #fff; padding: 3px; }
.sb-logo img { width: 100%; height: 100%; object-fit: contain; border-radius: 5px; }
.sb-brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.sb-brand-text strong { font-size: var(--fs); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-brand-text small { font-size: 10.5px; color: var(--sb-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.sb-nav { flex: 1; overflow-y: auto; padding: 12px 10px 18px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.12) transparent; }
.sb-link {
    position: relative;
    display: flex; align-items: center; gap: 12px;
    width: 100%;
    margin-bottom: 2px;
    padding: 9px 12px;
    border: 0; border-radius: var(--r);
    background: none;
    color: var(--sb-text);
    font-size: var(--fs);
    text-align: start;
    text-decoration: none !important;
    cursor: pointer;
}
.sb-link:hover { background: var(--sb-hover); color: #fff; }
.sb-link .icon { width: 19px; height: 19px; opacity: .9; }
.sb-link.is-active { background: var(--sb-active); color: var(--sb-active-text); }
.sb-link.is-active::before {
    content: ""; position: absolute;
    inset-block: 9px; inset-inline-start: -10px;
    width: 3px; border-radius: 3px;
    background: var(--sb-accent);
}
.sb-label { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-caret { width: 14px !important; height: 14px !important; opacity: .6; transition: transform .2s var(--ease); }
.sb-group.is-open > .sb-group-toggle .sb-caret { transform: rotate(180deg); }
.sb-group.has-active > .sb-group-toggle { color: #fff; }
.sb-sub { display: none; margin: 0 0 6px; margin-inline-start: 21px; padding: 2px 0; border-inline-start: 1px solid var(--sb-border); }
.sb-group.is-open > .sb-sub { display: block; }
.sb-sub-title { display: none; }
.sb-sublink {
    position: relative; display: block;
    padding: 6px 18px;
    border-radius: var(--r);
    color: var(--sb-muted);
    font-size: var(--fs-sm);
    text-decoration: none !important;
}
.sb-sublink:hover { color: #fff; background: rgba(255,255,255,.035); }
.sb-sublink.is-active { color: var(--sb-active-text); font-weight: 500; }
.sb-sublink.is-active::before {
    content: ""; position: absolute;
    inset-inline-start: -4px; top: 50%;
    width: 7px; height: 7px; margin-top: -3.5px;
    border-radius: 50%; background: var(--sb-accent);
}
.sb-foot { flex: none; padding: 10px 18px; border-top: 1px solid var(--sb-border); font-size: var(--fs-xs); color: var(--sb-muted); }
.sb-overlay { display: none; }

/* Collapsed icon-only sidebar (desktop) with flyout groups */
@media (min-width: 769px) {
    html.sb-collapsed .sb-label,
    html.sb-collapsed .sb-caret,
    html.sb-collapsed .sb-brand-text { display: none; }
    html.sb-collapsed .sb-brand { padding: 0; justify-content: center; }
    html.sb-collapsed .sb-link { justify-content: center; padding: 10px; }
    html.sb-collapsed .sb-nav { overflow: visible; }
    html.sb-collapsed .sb-group { position: relative; }
    html.sb-collapsed .sb-group > .sb-sub {
        display: none !important;
        position: absolute; top: 0; inset-inline-start: 100%;
        z-index: 60; min-width: 220px;
        margin: 0; padding: 6px;
        background: var(--sb-bg-2);
        border: 1px solid var(--sb-border);
        border-radius: var(--r-lg);
        box-shadow: var(--shadow-2);
    }
    html.sb-collapsed .sb-group:hover > .sb-sub,
    html.sb-collapsed .sb-group:focus-within > .sb-sub { display: block !important; }
    html.sb-collapsed .sb-sub-title { display: block; padding: 5px 12px 7px; color: #fff; font-weight: 700; font-size: var(--fs-sm); }
    html.sb-collapsed .sb-sublink.is-active::before { display: none; }
    html.sb-collapsed .sb-link[data-tip]:hover::after {
        content: attr(data-tip);
        position: absolute; inset-inline-start: calc(100% + 10px); top: 50%;
        transform: translateY(-50%);
        z-index: 60; padding: 5px 10px;
        background: var(--sb-bg-2); color: #fff;
        border: 1px solid var(--sb-border); border-radius: var(--r);
        font-size: var(--fs-sm); white-space: nowrap;
        box-shadow: var(--shadow-2);
    }
}

/* ---------- Topbar ---------- */
.topbar {
    position: sticky; top: 0; z-index: 30;
    height: var(--tb-h);
    display: flex; align-items: center; gap: 14px;
    padding: 0 22px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.tb-icon {
    width: 38px; height: 38px; flex: none;
    display: inline-grid; place-items: center;
    border: 1px solid transparent; border-radius: var(--r);
    background: none; color: var(--text-2);
    cursor: pointer;
}
.tb-icon:hover { background: var(--surface-2); border-color: var(--border); }
.tb-crumb { display: flex; align-items: center; gap: 6px; min-width: 0; font-size: var(--fs-sm); color: var(--muted); }
.tb-crumb strong { color: var(--text); font-weight: 500; white-space: nowrap; }
.tb-company { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.tb-sep { width: 14px; height: 14px; opacity: .55; }
.tb-search { position: relative; margin-inline-start: auto; width: min(380px, 38vw); }
.tb-search > .icon { position: absolute; inset-inline-start: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.tb-search input {
    width: 100%; height: 38px;
    padding-inline: 36px 40px;
    border: 1px solid var(--border); border-radius: var(--r);
    background: var(--surface-2);
    font-size: var(--fs-sm);
}
.tb-search input:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); background: var(--surface); }
.tb-search kbd {
    position: absolute; inset-inline-end: 8px; top: 50%; transform: translateY(-50%);
    min-width: 22px; height: 22px; display: grid; place-items: center;
    border: 1px solid var(--border-strong); border-radius: 4px;
    font-size: 11px; color: var(--muted); background: var(--surface);
}
.tb-actions { display: flex; align-items: center; gap: 6px; }
.tb-user {
    display: flex; align-items: center; gap: 10px;
    padding: 4px 6px 4px 10px;
    border: 1px solid transparent; border-radius: var(--r);
    background: none; cursor: pointer;
}
.tb-user:hover, .dropdown.is-open .tb-user { background: var(--surface-2); border-color: var(--border); }
.avatar {
    width: 32px; height: 32px; flex: none;
    display: grid; place-items: center;
    border-radius: 50%;
    background: var(--primary); color: var(--primary-ink);
    font-size: var(--fs-sm); font-weight: 700;
}
.tb-user-text { display: flex; flex-direction: column; line-height: 1.35; text-align: start; }
.tb-user-text strong { font-size: var(--fs-sm); font-weight: 500; white-space: nowrap; }
.tb-user-text small { font-size: var(--fs-xs); color: var(--muted); white-space: nowrap; }
.tb-caret { width: 14px; height: 14px; color: var(--muted); }

/* ---------- Dropdown ---------- */
.dropdown { position: relative; }
.dropdown-menu {
    position: absolute; top: calc(100% + 6px); inset-inline-end: 0; z-index: 50;
    display: none; min-width: 210px; padding: 6px;
    background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--r-lg);
    box-shadow: var(--shadow-2);
}
.dropdown.is-open .dropdown-menu { display: block; }
.dropdown-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%; padding: 8px 10px;
    border: 0; border-radius: var(--r);
    background: none; color: var(--text);
    font-size: var(--fs-sm); text-align: start;
    text-decoration: none !important; cursor: pointer;
}
.dropdown-item:hover { background: var(--surface-2); }
.dropdown-item .icon { width: 16px; height: 16px; color: var(--muted); }
.dropdown-item.is-danger, .dropdown-item.is-danger .icon { color: var(--out); }
.dropdown-sep { height: 1px; margin: 5px 4px; background: var(--border); }

/* ---------- Content & footer ---------- */
.content { flex: 1; width: 100%; max-width: 1640px; padding: 24px 28px 32px; }
.content:focus { outline: none; }
.app-footer {
    display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 16px;
    padding: 14px 28px;
    border-top: 1px solid var(--border);
    font-size: var(--fs-xs); color: var(--muted);
}
.dejavu-credit { font-family: "Segoe UI", Tahoma, Arial, sans-serif; letter-spacing: .02em; }
.dejavu-credit a { font-weight: 700; color: var(--text-2); letter-spacing: .08em; }
.dejavu-credit a:hover { color: var(--accent-strong); text-decoration: none; }

/* ==========================================================================
   Page elements
   ========================================================================== */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 20px; margin-bottom: 20px; }
.page-title { font-size: var(--fs-xl); letter-spacing: -.005em; }
.page-sub { margin: 2px 0 0; font-size: var(--fs-sm); color: var(--muted); }
.page-actions, .btn-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-1); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 50px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.panel-title { font-size: var(--fs-md); }
.panel-body { padding: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }

/* Stat tiles (ledger strip) */
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stats-tight { margin-bottom: 14px; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.stat {
    --tone: var(--primary);
    position: relative; overflow: hidden;
    padding: 13px 16px;
    background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--r-lg);
}
.stat::before { content: ""; position: absolute; inset-block: 0; inset-inline-start: 0; width: 3px; background: var(--tone); }
.stat-label { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--muted); }
.stat-label .icon { width: 16px; height: 16px; color: var(--tone); }
.stat-value { margin-top: 4px; font-size: 20px; font-weight: 700; line-height: 1.5; }
.stat-value .cur, .stat-value .unit { font-size: 12px; font-weight: 500; }
.stat-sub { font-size: var(--fs-xs); color: var(--muted); }
.tone-in { --tone: var(--in); }
.tone-out { --tone: var(--out); }
.tone-accent { --tone: var(--accent); }
.tone-info { --tone: var(--info); }

/* Key/value list */
.kv { margin: 0; padding: 6px 16px 10px; }
.kv > div { display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.kv > div:last-child { border-bottom: 0; }
.kv dt { color: var(--muted); font-size: var(--fs-sm); }
.kv dd { margin: 0; font-weight: 500; text-align: end; }

/* Dashboard (foundation) */
.dash-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.quick-tile {
    display: flex; align-items: center; gap: 10px;
    padding: 12px;
    border: 1px solid var(--border); border-radius: var(--r);
    background: var(--surface-2);
    color: var(--text); font-weight: 500; font-size: var(--fs-sm);
    text-decoration: none !important;
    transition: border-color .15s, background .15s;
}
.quick-tile:hover { border-color: var(--primary); background: var(--primary-soft); }
.quick-icon { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: var(--r); background: var(--surface); color: var(--primary-text); border: 1px solid var(--border); }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    height: 38px; padding: 0 16px;
    border: 1px solid var(--border-strong); border-radius: var(--r);
    background: var(--surface); color: var(--text);
    font-size: var(--fs-sm); font-weight: 500; white-space: nowrap;
    text-decoration: none !important;
    cursor: pointer;
    transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:focus-visible { outline: none; box-shadow: var(--focus); }
.btn .icon { width: 16px; height: 16px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #1d1405; }
.btn-accent:hover { filter: brightness(1.05); background: var(--accent); }
.btn-danger { background: var(--out); border-color: var(--out); color: #fff; }
.btn-danger:hover { filter: brightness(1.07); background: var(--out); }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn-sm { height: 32px; padding: 0 11px; font-size: var(--fs-xs); }
.btn-lg { height: 46px; font-size: var(--fs); }
.btn-block { width: 100%; }
.btn-icon { width: 38px; padding: 0; }
.btn-sm.btn-icon { width: 32px; }
.btn.is-loading { pointer-events: none; opacity: .75; }
.btn.is-loading::after {
    content: ""; width: 14px; height: 14px;
    border: 2px solid currentColor; border-inline-end-color: transparent; border-radius: 50%;
    animation: dj-spin .7s linear infinite;
}
@keyframes dj-spin { to { transform: rotate(360deg); } }

/* ==========================================================================
   Forms
   ========================================================================== */
.form-grid { display: grid; grid-template-columns: repeat(var(--cols, 2), minmax(0, 1fr)); gap: 14px 18px; }
.form-grid .span-all { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: var(--fs-sm); font-weight: 500; color: var(--text-2); }
.req { color: var(--out); margin-inline-start: 3px; }
.field-hint { font-size: var(--fs-xs); color: var(--muted); }
.field-error { display: flex; gap: 4px; font-size: var(--fs-xs); color: var(--out); }

.input, .select, .textarea {
    width: 100%; height: 40px; padding: 0 12px;
    border: 1px solid var(--border-strong); border-radius: var(--r);
    background: var(--surface); color: var(--text);
    font-size: var(--fs);
    transition: border-color .15s, box-shadow .15s, background .15s;
}
.input[dir="ltr"] { text-align: right; }
.textarea { height: auto; min-height: 88px; padding: 9px 12px; line-height: 1.7; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--primary); box-shadow: var(--focus); }
.input::placeholder, .textarea::placeholder { color: var(--faint); }
.input[readonly] { background: var(--surface-2); }
.field.is-invalid .input, .field.is-invalid .select, .field.is-invalid .textarea, .input.is-invalid { border-color: var(--out); }
.field.is-invalid .input:focus { box-shadow: 0 0 0 3px var(--out-soft); }
.select {
    appearance: none; -webkit-appearance: none;
    padding-inline-end: 34px; cursor: pointer;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%237a847e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-size: 16px; background-position: left 11px center;
}
.select-sm { height: 32px; font-size: var(--fs-sm); padding-inline-start: 10px; }
input[type="date"].input { direction: ltr; text-align: right; }

.input-group { display: flex; align-items: stretch; }
.input-group > .input { border-start-end-radius: 0; border-end-end-radius: 0; min-width: 0; }
.input-addon {
    display: grid; place-items: center; padding: 0 12px;
    border: 1px solid var(--border-strong); border-inline-start: 0;
    border-start-end-radius: var(--r); border-end-end-radius: var(--r);
    background: var(--surface-2); color: var(--muted);
    font-size: var(--fs-sm); white-space: nowrap;
}
.input-computed {
    display: flex; align-items: center;
    background: var(--primary-soft); border-style: dashed; border-color: var(--primary);
    color: var(--primary-text); font-weight: 700;
    font-variant-numeric: tabular-nums;
}
.input-icon { position: relative; }
.input-icon > .icon { position: absolute; inset-inline-start: 12px; top: 50%; transform: translateY(-50%); width: 17px; height: 17px; color: var(--muted); pointer-events: none; }
.input-icon .input { padding-inline: 40px; }
.input-reveal {
    position: absolute; inset-inline-end: 5px; top: 50%; transform: translateY(-50%);
    width: 32px; height: 32px; display: grid; place-items: center;
    border: 0; border-radius: var(--r); background: none; color: var(--muted); cursor: pointer;
}
.input-reveal:hover { background: var(--surface-2); color: var(--text); }

.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); width: 16px; height: 16px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; min-height: 40px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch-track { position: relative; width: 40px; height: 22px; flex: none; border-radius: 999px; background: var(--border-strong); transition: background .2s; }
.switch-track::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.2); transition: inset-inline-start .2s var(--ease); }
.switch input:checked + .switch-track { background: var(--primary); }
.switch input:checked + .switch-track::after { inset-inline-start: 21px; }
.switch input:focus-visible + .switch-track { box-shadow: var(--focus); }

/* ==========================================================================
   Badges & alerts
   ========================================================================== */
.badge {
    display: inline-flex; align-items: center; gap: 5px;
    height: 22px; padding: 0 9px;
    border-radius: 999px;
    background: var(--surface-3); color: var(--text-2);
    font-size: var(--fs-xs); font-weight: 500; white-space: nowrap;
}
.badge-in { background: var(--in-soft); color: var(--in); }
.badge-out { background: var(--out-soft); color: var(--out); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-accent { background: var(--accent-soft); color: var(--accent-strong); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.alert {
    --tone: var(--info); --tone-soft: var(--info-soft);
    display: flex; align-items: flex-start; gap: 10px;
    margin-bottom: 14px; padding: 11px 14px;
    background: var(--tone-soft);
    border-inline-start: 3px solid var(--tone); border-radius: var(--r);
    color: var(--text); font-size: var(--fs-sm);
}
.alert > .icon { color: var(--tone); margin-top: 3px; }
.alert-success { --tone: var(--in); --tone-soft: var(--in-soft); }
.alert-warning { --tone: var(--warn); --tone-soft: var(--warn-soft); }
.alert-error { --tone: var(--out); --tone-soft: var(--out-soft); }

/* ==========================================================================
   Tables (ledger style) + mobile cards
   ========================================================================== */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
.toolbar .grow { flex: 1; }
.search-inline { position: relative; min-width: 220px; }
.search-inline .icon { position: absolute; inset-inline-start: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.search-inline .input { padding-inline-start: 36px; height: 38px; }
.toolbar .select { width: auto; height: 38px; }

.table-wrap {
    overflow: auto;
    background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--r-lg);
    box-shadow: var(--shadow-1);
}
.table-wrap.flat { border: 0; border-radius: 0; box-shadow: none; }
.table-wrap.sticky { max-height: calc(100vh - 250px); }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-sm); }
.table th {
    position: sticky; top: 0; z-index: 1;
    padding: 10px 12px;
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    color: var(--muted); font-weight: 500; text-align: start; white-space: nowrap;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }
.table .n { text-align: end; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table tfoot td {
    position: sticky; bottom: 0;
    background: var(--surface-3);
    border-top: 2px solid var(--border-strong); border-bottom: 0;
    font-weight: 700;
}
.table .w-check { width: 40px; }
.cell-main { font-weight: 500; }
.cell-sub { font-size: var(--fs-xs); color: var(--muted); }
.cell-actions { width: 1%; white-space: nowrap; text-align: end; }
.row-warn td { background: var(--row-warn); }
.row-warn td:first-child { box-shadow: inset -3px 0 0 var(--out); }

/* Pagination */
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 12px 4px; font-size: var(--fs-sm); color: var(--muted); }
.pager-size label { display: flex; align-items: center; gap: 8px; }
.pager-size .select { width: auto; }
.pager-links { display: flex; flex-wrap: wrap; gap: 4px; }
.pager-links a, .pager-links span {
    min-width: 32px; height: 32px; padding: 0 8px;
    display: inline-grid; place-items: center;
    border: 1px solid var(--border); border-radius: var(--r);
    background: var(--surface); color: var(--text);
    text-decoration: none !important;
}
.pager-links a:hover { border-color: var(--primary); }
.pager-links .is-current { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); font-weight: 700; }
.pager-links .gap { border-color: transparent; background: none; }
.pager-links .icon { width: 15px; height: 15px; }

/* Empty state */
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty-icon { width: 58px; height: 58px; margin: 0 auto 14px; display: grid; place-items: center; border-radius: 50%; background: var(--surface-2); color: var(--faint); border: 1px solid var(--border); }
.empty-icon .icon { width: 26px; height: 26px; }
.empty h3 { margin-bottom: 4px; font-size: var(--fs-md); color: var(--text); }

/* ==========================================================================
   Toasts & modals
   ========================================================================== */
.toasts {
    position: fixed; z-index: 120;
    inset-block-start: calc(var(--tb-h) + 12px); inset-inline-end: 20px;
    display: flex; flex-direction: column; gap: 8px;
    width: min(380px, calc(100vw - 32px));
    pointer-events: none;
}
.toast {
    --tone: var(--info);
    display: flex; align-items: flex-start; gap: 10px;
    padding: 12px 12px 12px 14px;
    background: var(--surface);
    border: 1px solid var(--border); border-inline-start: 3px solid var(--tone); border-radius: var(--r);
    box-shadow: var(--shadow-2);
    font-size: var(--fs-sm);
    pointer-events: auto;
    animation: dj-toast-in .25s var(--ease);
}
.toast > .icon { color: var(--tone); margin-top: 3px; }
.toast-msg { flex: 1; }
.toast-close { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 2px; border-radius: var(--r-sm); }
.toast-close:hover { color: var(--text); }
.toast-success { --tone: var(--in); }
.toast-error { --tone: var(--out); }
.toast-warning { --tone: var(--warn); }
.toast.is-leaving { animation: dj-toast-out .2s var(--ease) forwards; }
@keyframes dj-toast-in { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: none; } }
@keyframes dj-toast-out { to { opacity: 0; transform: translateY(-6px); } }

.modal-backdrop {
    position: fixed; inset: 0; z-index: 100;
    display: none; align-items: center; justify-content: center;
    padding: 20px;
    background: rgba(8, 12, 10, .55);
}
.modal-backdrop.is-open { display: flex; }
.modal {
    width: min(580px, 100%); max-height: calc(100vh - 40px); overflow: auto;
    background: var(--surface);
    border: 1px solid var(--border); border-radius: var(--r-lg);
    box-shadow: var(--shadow-2);
    animation: dj-modal-in .2s var(--ease);
}
.modal-sm { width: min(420px, 100%); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 18px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: var(--fs-md); }
.modal-body { padding: 18px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); }
.modal-confirm { text-align: center; padding-top: 24px; }
.modal-confirm-icon { width: 46px; height: 46px; margin: 0 auto 12px; display: grid; place-items: center; border-radius: 50%; background: var(--out-soft); color: var(--out); }
.modal-confirm p { margin-top: 6px; color: var(--text-2); }
@keyframes dj-modal-in { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }

/* ==========================================================================
   Login
   ========================================================================== */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.1fr); }
.auth-panel { display: flex; flex-direction: column; align-items: center; padding: 32px 24px 20px; background: var(--surface); }
.auth-form { width: min(380px, 100%); margin-block: auto; display: flex; flex-direction: column; gap: 16px; }
.auth-form h1 { font-size: 24px; }
.auth-form > .muted { margin: -10px 0 4px; font-size: var(--fs-sm); }
.auth-form .alert { margin: 0; }
.auth-foot { width: min(380px, 100%); display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 24px; font-size: var(--fs-xs); color: var(--muted); }
.auth-mobile-brand { display: none; align-items: center; gap: 10px; align-self: stretch; font-weight: 700; }
.auth-brand {
    position: relative; overflow: hidden;
    display: flex; align-items: flex-end;
    padding: 56px;
    color: #e6eee9;
    background:
        radial-gradient(900px 500px at 15% 0%, rgba(224, 165, 58, .22), transparent 60%),
        repeating-linear-gradient(118deg, rgba(255, 255, 255, .03) 0 2px, transparent 2px 26px),
        linear-gradient(160deg, #0f4438 0%, #0c2e27 55%, #0a211c 100%);
}
.auth-stalk { position: absolute; top: -40px; inset-inline-end: -60px; width: 460px; height: 460px; stroke: #e0a53a; fill: none; stroke-width: .7; stroke-linecap: round; stroke-linejoin: round; opacity: .16; transform: rotate(-12deg); }
.auth-brand-inner { position: relative; max-width: 460px; }
.auth-mark { width: 54px; height: 54px; display: grid; place-items: center; margin-bottom: 20px; border-radius: 12px; background: linear-gradient(145deg, #e8b24c, #b87919); color: #1d1405; }
.auth-mark .icon { width: 30px; height: 30px; }
.auth-mark.has-img { background: #fff; padding: 5px; }
.auth-mark img { width: 100%; height: 100%; object-fit: contain; }
.auth-brand h2 { font-size: 28px; color: #fff; margin-bottom: 8px; }
.auth-brand p { color: #b7c8bf; font-size: var(--fs); }
.auth-points { list-style: none; margin: 22px 0 0; padding: 0; display: grid; gap: 10px; }
.auth-points li { display: flex; align-items: center; gap: 10px; color: #dbe6df; font-size: var(--fs-sm); }
.auth-points li::before { content: ""; width: 7px; height: 7px; flex: none; border-radius: 2px; background: #e0a53a; transform: rotate(45deg); }

/* ==========================================================================
   Error page
   ========================================================================== */
.error-page { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 24px; padding: 24px; }
.error-card { width: min(560px, 100%); padding: 32px; text-align: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-1); }
.error-code { font-size: 58px; font-weight: 700; line-height: 1.2; color: var(--primary-text); }
.error-card h1 { font-size: var(--fs-lg); margin: 8px 0 6px; }
.error-card p { color: var(--text-2); }
.error-actions { margin-top: 18px; display: flex; justify-content: center; gap: 8px; }
.error-details { margin-top: 20px; text-align: start; }
.error-details summary { cursor: pointer; color: var(--muted); font-size: var(--fs-sm); }
.error-details pre { margin-top: 8px; padding: 12px; max-height: 320px; overflow: auto; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); font-family: Consolas, "Courier New", monospace; font-size: 12px; text-align: left; white-space: pre-wrap; }
.error-foot { font-size: var(--fs-xs); color: var(--muted); }

/* Style guide */
.letters { display: flex; flex-wrap: wrap; gap: 12px 36px; font-size: 34px; line-height: 1.8; margin-bottom: 8px; }
.sample-text { font-size: var(--fs-md); }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1100px) {
    .dash-grid { grid-template-columns: 1fr; }
    .tb-company, .tb-crumb .tb-sep { display: none; }
}

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

@media (max-width: 768px) {
    .sidebar { width: 284px; transform: translateX(100%); box-shadow: var(--shadow-2); }
    html.sb-open .sidebar { transform: none; }
    .shell { margin-inline-start: 0; }
    .sb-overlay {
        display: block; position: fixed; inset: 0; z-index: 35;
        background: rgba(8, 12, 10, .5);
        opacity: 0; pointer-events: none; transition: opacity .2s;
    }
    html.sb-open .sb-overlay { opacity: 1; pointer-events: auto; }
    html.sb-open { overflow: hidden; }

    .topbar { gap: 8px; padding: 0 10px; }
    .tb-crumb { display: none; }
    .tb-search { width: auto; flex: 1; }
    .tb-search kbd { display: none; }
    .tb-search input { padding-inline-end: 12px; }
    .tb-user-text, .tb-caret { display: none; }
    .tb-user { padding: 3px; }

    .content { padding: 16px 14px 24px; }
    .app-footer { padding: 12px 14px; justify-content: center; text-align: center; }
    .page-title { font-size: var(--fs-lg); }
    .page-actions { width: 100%; }

    .form-grid { grid-template-columns: 1fr !important; }
    .btn { height: 42px; }
    .btn-sm { height: 36px; }
    .btn-icon { width: 42px; }
    .btn-sm.btn-icon { width: 36px; }
    .input, .select { height: 44px; font-size: 16px; }  /* 16px stops iOS zoom */
    .textarea { font-size: 16px; }
    .toolbar > * { flex: 1 1 auto; }
    .search-inline { min-width: 0; flex-basis: 100%; }

    .toasts { inset-inline: 12px; inset-block-start: auto; bottom: 12px; width: auto; }
    .modal-backdrop { align-items: flex-end; padding: 0; }
    .modal { width: 100%; max-height: 92vh; border-radius: 14px 14px 0 0; }
    .modal-foot { border-radius: 0; }
    .modal-foot .btn { flex: 1; }
    .grid-2 { grid-template-columns: 1fr; }
}

/* Tables become stacked cards on phones (screen only — print keeps real tables) */
@media screen and (max-width: 768px) {
    .table-cards thead { display: none; }
    .table-cards, .table-cards tbody, .table-cards tfoot, .table-cards tr, .table-cards td { display: block; width: 100%; }
    .table-wrap:has(.table-cards) { overflow: visible; background: transparent; border: 0; box-shadow: none; }
    .table-cards tr { margin-bottom: 10px; padding: 6px 2px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); }
    .table-cards tbody tr:hover td { background: transparent; }
    .table-cards td { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 12px; border: 0; text-align: start; }
    .table-cards td.n { text-align: end; }
    .table-cards td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: var(--fs-xs); font-weight: 400; }
    .table-cards td:empty, .table-cards td.w-check { display: none; }
    .table-cards td.cell-actions { justify-content: flex-end; width: 100%; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 8px; }
    .table-cards tfoot td { position: static; background: transparent; border: 0; }
    .table-cards tfoot tr { background: var(--surface-3); border-color: var(--border-strong); }
    .table-cards .row-warn { border-inline-start: 3px solid var(--out); }
    .table-cards .row-warn td { background: transparent; box-shadow: none; }
}

/* ==========================================================================
   Lists, row actions, filters, autocomplete
   ========================================================================== */
.row-actions { display: flex; justify-content: flex-end; gap: 2px; }
.row-actions form { margin: 0; }
.btn.is-danger { color: var(--out); }
.btn.is-danger:hover { background: var(--out-soft); border-color: transparent; }
.btn-danger-outline { color: var(--out); border-color: var(--out); background: var(--surface); }
.btn-danger-outline:hover { background: var(--out-soft); }
.btn-danger-outline:disabled { opacity: .45; cursor: not-allowed; }
.filter-inline { display: flex; align-items: center; gap: 6px; font-size: var(--fs-sm); color: var(--muted); }
.filter-inline .input { width: auto; height: 38px; }
.filter-flag { height: 38px; padding: 0 10px; border: 1px solid var(--border-strong); border-radius: var(--r); background: var(--surface); font-size: var(--fs-sm); }
.table a.sort { display: inline-flex; align-items: center; gap: 3px; color: inherit; text-decoration: none; }
.table a.sort:hover, .table a.sort.is-active { color: var(--text); }
.sort-arrow { width: 13px !important; height: 13px !important; }
.table tbody tr.is-selected td { background: var(--primary-soft); }
[data-list-body].is-loading { opacity: .5; pointer-events: none; transition: opacity .15s; }
.lookup-box {
    position: absolute; inset-inline: 0; top: 100%; z-index: 45;
    margin-top: 4px; max-height: 264px; overflow: auto;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
    box-shadow: var(--shadow-2);
}
.lookup-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; width: 100%; padding: 8px 12px; border: 0; background: none; text-align: start; font-size: var(--fs-sm); cursor: pointer; }
.lookup-item:hover, .lookup-item.is-active { background: var(--primary-soft); }
.lookup-item bdi { font-size: var(--fs-xs); }
.page-note { font-size: var(--fs-xs); color: var(--muted); margin: -8px 0 16px; }
.form-section { margin: 4px 0 2px; padding-top: 12px; border-top: 1px dashed var(--border); font-size: var(--fs-sm); font-weight: 700; color: var(--primary-text); grid-column: 1 / -1; }
.form-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 0; }
.detail-grid > div { padding: 10px 16px; border-bottom: 1px dashed var(--border); }
.detail-grid dt { font-size: var(--fs-xs); color: var(--muted); }
.detail-grid dd { margin: 2px 0 0; font-weight: 500; }
.warn-box { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: var(--r); background: var(--warn-soft); border-inline-start: 3px solid var(--warn); font-size: var(--fs-sm); }
.warn-box .icon { color: var(--warn); margin-top: 3px; }
.credit-box { padding: 12px 14px; border-radius: var(--r); background: var(--in-soft); border-inline-start: 3px solid var(--in); }
/* Dashboard chart & movements */
/* Chart series — validated with the dataviz palette checks (light surface #fff, dark surface #141c19) */
:root { --series-purchases: #c1821f; --series-sales: #12876a; }
[data-theme="dark"] { --series-purchases: #b8801f; --series-sales: #38a888; }
.chart-box { position: relative; padding: 10px 12px 4px; }
.chart-svg { width: 100%; height: auto; display: block; overflow: visible; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-base { stroke: var(--border-strong); stroke-width: 1; }
.chart-axis { fill: var(--muted); font-size: 11px; font-family: var(--font); }
.chart-label { fill: var(--text-2); font-size: 11px; font-weight: 700; font-family: var(--font); }
.chart-bar { stroke: var(--surface); stroke-width: 1; }
.chart-bar.s-purchases, .swatch.s-purchases { fill: var(--series-purchases); background: var(--series-purchases); }
.chart-bar.s-sales, .swatch.s-sales { fill: var(--series-sales); background: var(--series-sales); }
.chart-hit { fill: transparent; }
.chart-group:hover .chart-hit, .chart-group.is-hover .chart-hit, .chart-group:focus .chart-hit { fill: var(--surface-2); }
.chart-group:focus { outline: none; }
.dash-period { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.dash-period .period-label { color: var(--muted); font-size: var(--fs-sm); }
.chart-head-side { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.chart-ranges .tab { padding: 5px 10px; font-size: var(--fs-xs); }
.panel-head-wrap { flex-wrap: wrap; row-gap: 8px; }
.chart-legend { display: flex; gap: 14px; font-size: var(--fs-sm); color: var(--text-2); }
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.chart-tip { position: absolute; z-index: 5; pointer-events: none; min-width: 170px; padding: 8px 10px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow-2); font-size: var(--fs-xs); color: var(--text); }
.chart-tip strong { display: block; margin-bottom: 2px; font-size: var(--fs-sm); }
.chart-table { padding: 0 16px 12px; }
.chart-table summary { cursor: pointer; color: var(--muted); font-size: var(--fs-sm); padding: 6px 0; }
.moves { list-style: none; margin: 0; padding: 4px 8px; }
.moves li { display: flex; align-items: center; gap: 10px; padding: 9px 8px; border-bottom: 1px dashed var(--border); }
.moves li:last-child { border-bottom: 0; }
.move-icon { width: 32px; height: 32px; flex: none; display: grid; place-items: center; border-radius: 50%; }
.move-icon.is-in { background: var(--in-soft); color: var(--in); }
.move-icon.is-out { background: var(--out-soft); color: var(--out); }
.move-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.move-text strong { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.move-text small { color: var(--muted); font-size: var(--fs-xs); }
.stat-link { color: inherit; text-decoration: none !important; transition: border-color .15s; }
.stat-link:hover { border-color: var(--tone); }
.alert-link { color: var(--text); text-decoration: none !important; }
.alert-link > .icon:last-child { margin-inline-start: auto; opacity: .5; }
.alert-link:hover { filter: brightness(.98); }
.changelog { margin: 0 0 12px; padding-inline-start: 20px; }
.changelog li { margin-bottom: 4px; }
.file-list { max-height: 240px; overflow: auto; padding: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r); font-family: Consolas, monospace; font-size: 12px; text-align: left; }
.report-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.report-card { display: flex; gap: 12px; align-items: flex-start; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); color: var(--text); text-decoration: none !important; transition: border-color .15s, box-shadow .15s; }
.report-card:hover { border-color: var(--primary); box-shadow: var(--shadow-1); }
.report-card span:last-child { display: flex; flex-direction: column; gap: 2px; }
.report-card small { color: var(--muted); font-size: var(--fs-sm); }
/* Column chooser (list toolbar) */
.colpick { position: relative; }
.colpick > summary { list-style: none; cursor: pointer; }
.colpick > summary::-webkit-details-marker { display: none; }
.colpick[open] > summary { background: var(--surface-3); }
.colpick-panel {
    position: absolute; z-index: 20; inset-inline-start: 0; top: calc(100% + 6px);
    display: grid; grid-template-columns: repeat(2, minmax(140px, 1fr)); gap: 2px 14px;
    min-width: 320px; max-height: 60vh; overflow: auto; padding: 12px 14px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-2);
}
.colpick-panel .check { padding: 3px 0; font-size: var(--fs-sm); white-space: nowrap; }
@media (max-width: 640px) {
    .colpick-panel { grid-template-columns: 1fr; min-width: min(280px, 80vw); }
}
.tabs { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-3); border-radius: var(--r); }
.tab { padding: 6px 14px; border-radius: 5px; color: var(--muted); font-size: var(--fs-sm); text-decoration: none !important; }
.tab.is-active { background: var(--surface); color: var(--text); font-weight: 500; box-shadow: var(--shadow-1); }
.pl-table td { padding: 9px 16px; }
.pl-table tr.pl-strong td { background: var(--surface-2); }
.settings-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 16px; align-items: start; }
.logo-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.logo-row .input-file { flex: 1; min-width: 220px; }
.perm-extra { margin-top: 18px; border: 1px solid var(--border); border-radius: var(--r-lg); padding: 10px 14px; }
.perm-extra summary { cursor: pointer; display: flex; align-items: center; gap: 8px; font-weight: 500; }
.perm-matrix { margin-top: 10px; }
.perm-matrix td, .perm-matrix th { padding: 7px 10px; }
.perm-special { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 22px; margin-top: 12px; padding: 10px 12px; background: var(--surface-2); border-radius: var(--r); font-size: var(--fs-sm); }
.audit-diff summary { cursor: pointer; color: var(--primary-text); font-size: var(--fs-xs); }
.audit-diff table { margin-top: 6px; border-collapse: collapse; font-size: 11.5px; }
.audit-diff th, .audit-diff td { padding: 2px 6px; border: 1px solid var(--border); text-align: start; max-width: 260px; word-break: break-word; }
.search-results { list-style: none; margin: 0; padding: 6px; }
.search-results a { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 9px 10px; border-radius: var(--r); color: var(--text); text-decoration: none !important; }
.search-results a:hover { background: var(--surface-2); }
.search-results span { display: flex; flex-direction: column; min-width: 0; }
.search-results small { font-size: var(--fs-xs); }
@media (max-width: 1000px) { .settings-grid { grid-template-columns: 1fr; } }
.customer-pick { display: flex; gap: 8px; align-items: stretch; }
.customer-pick .btn { height: 40px; }
.salary-table td, .salary-table th { white-space: nowrap; }
.month-picker { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.month-picker .field { min-width: 180px; }
@media (max-width: 768px) { .customer-pick { flex-direction: column; } .customer-pick .btn { height: 44px; } }
@media screen and (max-width: 768px) {
    .filter-inline { flex: 1 1 45%; }
    .filter-inline .input { width: 100%; }
    .table-cards td.cell-actions .row-actions { width: 100%; justify-content: flex-end; }
}

/* ==========================================================================
   Installer
   ========================================================================== */
.install { width: min(780px, 100%); margin: 0 auto; padding: 28px 16px 24px; }
.install-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.install-brand .sb-logo { width: 42px; height: 42px; }
.install-brand h1 { font-size: var(--fs-lg); }
.install-brand small { display: block; font-size: var(--fs-xs); }
.install-brand .tb-icon { margin-inline-start: auto; }
.stepper { display: flex; gap: 6px; margin: 0 0 16px; padding: 0; list-style: none; }
.stepper li {
    flex: 1; min-width: 0;
    display: flex; align-items: center; gap: 8px;
    padding: 9px 10px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r);
    font-size: var(--fs-xs); color: var(--muted);
}
.stepper .dot { width: 24px; height: 24px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--surface-3); font-size: 12px; font-weight: 700; }
.stepper .dot .icon { width: 14px; height: 14px; stroke-width: 2.4; }
.stepper .step-label { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stepper li.is-current { border-color: var(--primary); color: var(--text); font-weight: 500; }
.stepper li.is-current .dot { background: var(--primary); color: var(--primary-ink); }
.stepper li.is-done .dot { background: var(--in-soft); color: var(--in); }
.install-card .panel-body { padding: 20px 22px; }
.install-card .panel-body > p { color: var(--text-2); }
.install-actions { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 8px; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.install-foot { margin-top: 18px; text-align: center; font-size: var(--fs-xs); color: var(--muted); }
.req-list, .check-list { list-style: none; margin: 0; padding: 0; }
.req-list li, .check-list li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px dashed var(--border); }
.req-list li:last-child, .check-list li:last-child { border-bottom: 0; }
.req-icon { width: 24px; height: 24px; flex: none; display: grid; place-items: center; border-radius: 50%; }
.req-icon .icon { width: 14px; height: 14px; stroke-width: 2.4; }
.is-ok .req-icon { background: var(--in-soft); color: var(--in); }
.is-fail .req-icon { background: var(--out-soft); color: var(--out); }
.is-warn .req-icon { background: var(--warn-soft); color: var(--warn); }
.req-label { flex: 1; min-width: 0; }
.req-label small { display: block; color: var(--muted); font-size: var(--fs-xs); }
.req-value { color: var(--muted); font-size: var(--fs-xs); }
.check-list .req-count { margin-inline-start: auto; font-weight: 700; }
.pw-meter { height: 6px; margin-top: 2px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.pw-meter span { display: block; width: 0; height: 100%; border-radius: 999px; transition: width .2s var(--ease), background .2s; }
.pw-meter[data-level="1"] span { width: 33%; background: var(--out); }
.pw-meter[data-level="2"] span { width: 66%; background: var(--warn); }
.pw-meter[data-level="3"] span { width: 100%; background: var(--in); }
.input-file { height: auto; padding: 8px; cursor: pointer; }
@media (max-width: 768px) {
    .stepper li { justify-content: center; padding: 8px 4px; }
    .stepper .step-label { display: none; }
    .stepper li.is-current .step-label { display: block; }
    .install-actions .btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ---------- Program font (ڕێکخستن → فۆنتی بەرنامە) ----------
   Set on <html> as data-font; it drives the whole interface AND every printed
   document, because both read var(--font). `kufi` is the bundled default. */
:root[data-font="two"] { --font: var(--font-two); }
:root[data-font="three"] { --font: var(--font-three); }
