/* ==========================================================
   EVAM Books — design system and application shell  (v3.2)
   ==========================================================

   HOW TO BUILD A PAGE THAT MATCHES
   --------------------------------
   Tokens (use these, never raw colours):
     Surfaces   --bg (app canvas) · --surface (cards) · --surface-2 (insets, table heads) · --surface-3 (hover)
     Text       --text-strong (headings, figures) · --text (body) · --text-muted (secondary) · --text-faint (hints)
     Lines      --border · --border-soft (row dividers) · --border-strong (hover/inputs)
     Brand      --brand (EVAM navy) · --brand-hover · --brand-soft (tinted bg) · --brand-ink (text on soft)
     Status     --good / --bad / --warn / --info / --neutral   each with -bg and -dot
     Data       --chart-income · --chart-cost · --cat-1 … --cat-6 · --cat-other
     Shape      --r-sm 8 · --r-md 10 · --r-lg 12 · --r-xl 16          Shadow  --shadow-xs/-sm/-md/-lg
     Type       --font (Inter) · body 14px · meta 12–13px · section 15–16px/600 · page title 26px/600

   Building blocks (all exist below):
     .page-head > .ph-text (.ph-eyebrow, h1, .page-sub) + .page-actions    page header
     .card (+ .card-head h2 .card-sub, .card-foot) · .panel                 cards
     .ledger-strip > .ls (.ls-top .ls-label .ls-value .ls-note) · .trend-good|bad|warn|neutral   KPI tiles
     .table-card > table.dtable (th/td, .num for money, .who for names)     tables (sticky head, hover)
     .pill.pill-good|bad|warn|info|neutral|mute                              status pills with a dot
     .btn.btn-primary|btn-ghost|btn-quiet|btn-danger (+ .btn-sm, .btn-icon) · .icon-btn · .link-btn
     .field > label + input/select/textarea + .hint · .grid-2 · .grid-3     forms (40px controls)
     .seg > button.on · .tabs > a.on · .chip                                 segmented controls / filters
     .filters (toolbar: .search + selects)                                   list toolbar
     .empty > .empty-art + h2 + p + .empty-actions                           empty states
     .note-box · .term[data-tip] (any [data-tip] shows a tooltip)            help
   Motion: window.Motion.enter(el) / .stagger(container) / .countUp(el) / .pop(el)  (js/motion.js)
   Dark theme: <html data-theme="dark">; tokens below flip, components follow automatically.
   ========================================================== */

:root {
    /* surfaces */
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f9fafb;
    --surface-3: #f2f4f7;
    --overlay: rgba(15, 23, 42, .44);
    /* text */
    --text-strong: #0f172a;
    --text: #344054;
    --text-muted: #667085;
    --text-faint: #98a2b3;
    /* lines */
    --border: #e4e7ec;
    --border-soft: #eef0f3;
    --border-strong: #d0d5dd;
    /* brand: EVAM navy */
    --brand: #13325b;
    --brand-hover: #0d2647;
    --brand-soft: #edf2f9;
    --brand-soft-2: #dfe8f4;
    --brand-ink: #13325b;
    --on-brand: #ffffff;
    --ring: rgba(19, 50, 91, .16);
    --focus: #2e62a8;
    /* status */
    --good: #067647; --good-bg: #ecfdf3; --good-dot: #17b26a;
    --bad: #b42318;  --bad-bg: #fef3f2;  --bad-dot: #f04438;
    --warn: #b54708; --warn-bg: #fffaeb; --warn-dot: #f79009;
    --info: #1d4f91; --info-bg: #eff5fe; --info-dot: #2e90fa;
    --neutral: #475467; --neutral-bg: #f2f4f7; --neutral-dot: #98a2b3;
    /* data */
    --chart-income: #0e9384;
    --chart-cost: #2c5282;
    --cat-1: #13325b; --cat-2: #0e9384; --cat-3: #5b8def; --cat-4: #f2a93b; --cat-5: #9e77ed; --cat-6: #ee6c8a; --cat-other: #c5cbd4;
    /* shape */
    --r-sm: 8px; --r-md: 10px; --r-lg: 12px; --r-xl: 16px;
    --shadow-xs: 0 1px 2px rgba(16, 24, 40, .04);
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, .04), 0 1px 3px rgba(16, 24, 40, .05);
    --shadow-md: 0 1px 2px rgba(16, 24, 40, .04), 0 6px 16px -4px rgba(16, 24, 40, .08);
    --shadow-lg: 0 24px 48px -12px rgba(16, 24, 40, .22), 0 4px 10px -4px rgba(16, 24, 40, .06);
    /* layout */
    --sidebar-w: 256px;
    --appbar-h: 56px;
    --docbar-h: 64px;
    --control-h: 40px;
    --font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
    --desk: #e3e7ed;

    /* legacy names used across the app (and by the browser edition) */
    --navy: var(--brand); --navy-2: var(--brand-hover); --navy-soft: var(--brand-soft);
    --ink: var(--text-strong); --steel: var(--text-muted); --mute: var(--text-faint);
    --line: var(--border); --line-2: var(--border-soft);
    --app: var(--bg); --panel: var(--surface); --mute-bg: var(--surface-3);
    color-scheme: light;
}

@media screen {
    :root[data-theme="dark"] {
        --bg: #0b0f16;
        --surface: #111722;
        --surface-2: #151c29;
        --surface-3: #1b2331;
        --overlay: rgba(2, 6, 12, .66);
        --text-strong: #f2f5f9;
        --text: #c9d1dd;
        --text-muted: #8f9bad;
        --text-faint: #627083;
        --border: #232c3a;
        --border-soft: #1c2430;
        --border-strong: #303b4c;
        --brand: #3d72c4;
        --brand-hover: #4a80d3;
        --brand-soft: rgba(84, 135, 214, .14);
        --brand-soft-2: rgba(84, 135, 214, .22);
        --brand-ink: #a9c6f2;
        --ring: rgba(96, 148, 226, .28);
        --focus: #6c9be4;
        --good: #47cd89; --good-bg: rgba(23, 178, 106, .13); --good-dot: #47cd89;
        --bad: #f97066;  --bad-bg: rgba(240, 68, 56, .13);  --bad-dot: #f97066;
        --warn: #fdb022; --warn-bg: rgba(247, 144, 9, .13); --warn-dot: #fdb022;
        --info: #84adff; --info-bg: rgba(46, 144, 250, .13); --info-dot: #53b1fd;
        --neutral: #aab4c3; --neutral-bg: rgba(152, 162, 179, .12); --neutral-dot: #7d889a;
        --chart-income: #2ed3b7;
        --chart-cost: #7ea6ea;
        --cat-1: #7ea6ea; --cat-2: #2ed3b7; --cat-3: #a4bcfd; --cat-4: #fdb022; --cat-5: #b692f6; --cat-6: #f58ba6; --cat-other: #3b4657;
        --shadow-xs: 0 1px 2px rgba(0, 0, 0, .3);
        --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3), 0 1px 3px rgba(0, 0, 0, .2);
        --shadow-md: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 20px -6px rgba(0, 0, 0, .45);
        --shadow-lg: 0 24px 56px -12px rgba(0, 0, 0, .7), 0 0 0 1px rgba(255, 255, 255, .04);
        --desk: #0d121a;
        color-scheme: dark;
    }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
    margin: 0;
    font: 14px/1.5 var(--font);
    font-feature-settings: 'cv11';
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
.sheet, #printRoot .sheet { font-feature-settings: normal; -moz-osx-font-smoothing: auto; }
button { cursor: pointer; }
[hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
::selection { background: var(--brand-soft-2); }
a { color: var(--brand-ink); }
.ic { flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--text-faint); }
.small { font-size: 12px; }
.clamp { display: -webkit-box; -webkit-line-clamp: 1; -webkit-box-orient: vertical; overflow: hidden; max-width: 420px; }
.warn-text { color: var(--warn); }
.num, .tnum { font-variant-numeric: tabular-nums; }
code { font-size: 12px; background: var(--surface-3); padding: 1px 5px; border-radius: 5px; }
kbd { font: 500 11px/1 var(--font); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 2px 5px; background: var(--surface); color: var(--text-muted); }
.push { flex: 1; }

/* ==========================================================
   SHELL — sidebar, top bar
   ========================================================== */
.sidebar {
    position: fixed; z-index: 60; inset: 0 auto 0 0;
    width: var(--sidebar-w);
    display: flex; flex-direction: column;
    background: var(--surface);
    border-right: 1px solid var(--border);
}
.sb-head { height: var(--appbar-h); flex: none; display: flex; align-items: center; justify-content: space-between; padding: 0 14px 0 18px; }
.sidebar .sb-close { display: none; }
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text-strong); min-width: 0; }
.brand-logo { height: 20px; width: auto; }
.brand-name { font-weight: 600; color: var(--text-muted); font-size: 13px; padding: 2px 8px; border-radius: 6px; background: var(--surface-3); letter-spacing: .01em; }
[data-theme="dark"] .brand-logo, [data-theme="dark"] .auth-logo { filter: brightness(0) invert(.94); }
.sb-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 6px 10px 18px; scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
.sb-foot { flex: none; border-top: 1px solid var(--border-soft); padding: 8px 10px 10px; }
.sb-top:not(:empty) { margin-bottom: 6px; }

.sidebar .mainnav, .sidebar .nav-top, .nav-group-items { display: flex; flex-direction: column; gap: 1px; }
.sidebar a[href] {
    position: relative;
    display: flex; align-items: center; gap: 10px;
    min-height: 34px; padding: 6px 10px;
    border-radius: var(--r-sm);
    color: var(--text); text-decoration: none;
    font-size: 13.5px; font-weight: 500; line-height: 1.3;
    transition: background-color .12s, color .12s;
}
.sidebar .brand { min-height: 0; padding: 0; }
.sidebar .brand:hover { background: none; }
.nav-ic { display: grid; place-items: center; width: 20px; color: var(--text-faint); transition: color .12s; flex: none; }
.nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar a[href]:hover { background: var(--surface-3); color: var(--text-strong); }
.sidebar a[href]:hover .nav-ic { color: var(--text-muted); }
.sidebar a.on { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
.sidebar a.on .nav-ic { color: var(--brand-ink); }
.sidebar a.on::before { content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 0 3px 3px 0; background: var(--brand); }
.nav-count:not(:empty) { margin-left: auto; font-size: 11.5px; font-weight: 600; background: var(--surface-3); color: var(--text-muted); border-radius: 10px; padding: 0 7px; line-height: 19px; font-variant-numeric: tabular-nums; }
.sidebar a.on .nav-count { background: var(--surface); color: var(--brand-ink); }

.nav-group { margin-top: 10px; }
.nav-group-h {
    display: flex; align-items: center; width: 100%; gap: 6px;
    border: 0; background: none; padding: 6px 10px 5px;
    font-size: 12px; font-weight: 600; color: var(--text-faint); text-align: left;
    border-radius: 6px;
}
.nav-group-h:hover { color: var(--text-muted); }
.nav-group-h span { flex: 1; }
.nav-chev { display: grid; transition: transform .18s; opacity: 0; }
.nav-group-h:hover .nav-chev, .nav-group-h:focus-visible .nav-chev, .nav-group.collapsed .nav-chev { opacity: 1; }
.nav-group.collapsed .nav-chev { transform: rotate(-90deg); }
.nav-group.collapsed .nav-group-items { display: none; }
.fin-nav, .fin-nav-list { display: contents; }

.sb-scrim { position: fixed; inset: 0; z-index: 55; background: var(--overlay); }

/* Top bar */
.appbar {
    position: sticky; top: 0; z-index: 50;
    height: var(--appbar-h);
    margin-left: var(--sidebar-w);
    display: flex; align-items: center; gap: 14px;
    padding: 0 20px 0 28px;
    background: color-mix(in srgb, var(--surface) 86%, transparent);
    backdrop-filter: saturate(1.4) blur(10px); -webkit-backdrop-filter: saturate(1.4) blur(10px);
    border-bottom: 1px solid var(--border);
}
.appbar .appbar-menu, .appbar .appbar-mark { display: none; }
.appbar-mark img { width: 28px; height: 28px; display: block; border-radius: 7px; }
.crumbs { display: flex; align-items: center; gap: 4px; min-width: 0; font-size: 13.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; }
.crumb-sep { display: grid; color: var(--text-faint); }
.crumb-page { color: var(--text-strong); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.cmdk-trigger {
    margin-left: auto;
    display: flex; align-items: center; gap: 8px;
    width: min(340px, 34vw); height: 36px; padding: 0 6px 0 11px;
    border: 1px solid var(--border); border-radius: var(--r-sm);
    background: var(--surface-2); color: var(--text-faint); font-size: 13.5px; text-align: left;
    transition: border-color .15s, background-color .15s, box-shadow .15s;
}
.cmdk-trigger:hover { border-color: var(--border-strong); background: var(--surface); color: var(--text-muted); }
.cmdk-ic { display: grid; }
.cmdk-ph { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appbar-right { display: flex; align-items: center; gap: 6px; flex: none; }
.appbar-right .btn-ghost { height: 36px; }
#notifyBell:empty { display: none; }
#notifyBell { display: flex; align-items: center; }

/* ==========================================================
   BUTTONS
   ========================================================== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    height: var(--control-h); padding: 0 15px;
    border: 1px solid transparent; border-radius: var(--r-sm);
    font-size: 13.5px; font-weight: 500; line-height: 1;
    background: none; text-decoration: none; white-space: nowrap; color: var(--text);
    transition: background-color .15s, border-color .15s, color .15s, box-shadow .15s, transform .08s;
    -webkit-tap-highlight-color: transparent;
}
.btn:active:not(:disabled) { transform: translateY(.5px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: var(--on-brand); box-shadow: var(--shadow-xs), inset 0 1px 0 rgba(255, 255, 255, .08); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); box-shadow: var(--shadow-xs); }
.btn-ghost:hover { border-color: var(--border-strong); background: var(--surface-2); color: var(--text-strong); }
.btn-ghost .ic { color: var(--text-muted); }
.btn-quiet { background: var(--brand-soft); color: var(--brand-ink); }
.btn-quiet:hover { background: var(--brand-soft-2); }
.btn-danger { background: var(--bad-dot); color: #fff; }
.btn-danger:hover { background: #d92d20; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 12.5px; border-radius: 7px; }
.btn-block { width: 100%; }
.icon-btn {
    display: inline-grid; place-items: center;
    width: 34px; height: 34px; flex: none;
    border: 0; border-radius: var(--r-sm); background: none; color: var(--text-muted);
    transition: background-color .12s, color .12s;
}
.icon-btn:hover { background: var(--surface-3); color: var(--text-strong); }
.link-btn {
    display: inline-flex; align-items: center; gap: 5px;
    border: 0; background: none; padding: 4px 0;
    color: var(--brand-ink); font-size: 13px; font-weight: 500;
}
.link-btn:hover { text-decoration: underline; text-underline-offset: 3px; }
.link-btn.danger { color: var(--bad); }
.link-btn.push { margin-left: auto; }
.link-strong { border: 0; background: none; padding: 0; color: var(--text-strong); font-weight: 600; text-align: left; }
.link-strong:hover { color: var(--brand-ink); text-decoration: underline; text-underline-offset: 3px; }

/* ==========================================================
   DOCUMENT DESK — editor bar and workspace
   ========================================================== */
#app { margin-left: var(--sidebar-w); min-width: 0; }
.docbar {
    position: relative; z-index: 40; flex: none;
    min-height: var(--docbar-h);
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 10px 20px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}
.docbar-left, .docbar-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.docbar-right { flex-wrap: wrap; justify-content: flex-end; }
.btn-icon { width: var(--control-h); padding: 0; }
.docbar-sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }
.type-picker {
    display: grid; grid-template-columns: auto auto; column-gap: 10px; align-items: center;
    text-align: left;
    padding: 5px 10px 5px 12px; min-height: 44px;
    border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface);
    min-width: 172px; box-shadow: var(--shadow-xs);
    transition: border-color .15s;
}
.type-picker:hover { border-color: var(--border-strong); }
.type-picker .tp-kicker { grid-column: 1; font-size: 11.5px; color: var(--text-faint); line-height: 1.2; }
.type-picker .tp-label { grid-column: 1; font-weight: 600; color: var(--text-strong); line-height: 1.3; }
.type-picker .ic { grid-column: 2; grid-row: 1 / span 2; color: var(--text-muted); justify-self: end; }
.docbar-id { display: flex; flex-direction: column; padding: 0 6px; flex: none; }
.docbar-number { font-weight: 600; color: var(--text-strong); font-size: 15px; font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.005em; }
.save-state { font-size: 12px; color: var(--text-faint); white-space: nowrap; }
.save-state[data-state="dirty"] { color: var(--warn); }
.save-state[data-state="saved"] { color: var(--good); }
.status-select {
    width: auto; flex: none;
    height: 28px !important; padding: 0 28px 0 22px !important;
    border: 0 !important; border-radius: 14px !important;
    font-size: 12.5px !important; font-weight: 600;
    appearance: none; -webkit-appearance: none;
    background: var(--neutral-bg) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 10px center !important;
    color: var(--neutral);
    box-shadow: none !important;
    --dot: var(--neutral-dot);
    background-image: radial-gradient(circle, var(--dot) 3px, transparent 3.5px), url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") !important;
    background-position: 10px center, right 10px center !important;
    background-size: 8px 8px, 10px 10px !important;
    background-repeat: no-repeat !important;
}
.status-select[data-tone="good"] { background-color: var(--good-bg) !important; color: var(--good); --dot: var(--good-dot); }
.status-select[data-tone="bad"] { background-color: var(--bad-bg) !important; color: var(--bad); --dot: var(--bad-dot); }
.status-select[data-tone="warn"] { background-color: var(--warn-bg) !important; color: var(--warn); --dot: var(--warn-dot); }
.status-select[data-tone="info"] { background-color: var(--info-bg) !important; color: var(--info); --dot: var(--info-dot); }

#view-create { display: flex; flex-direction: column; height: calc(100vh - var(--appbar-h)); height: calc(100dvh - var(--appbar-h)); }
body[data-view="create"] { overflow: hidden; }
.workspace { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(400px, 540px) 1fr; }
.form-pane { min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 18px 18px 56px; border-right: 1px solid var(--border); scroll-padding-top: 16px; background: var(--bg); }
.desk { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--desk); background-image: radial-gradient(color-mix(in srgb, var(--text-faint) 26%, transparent) 1px, transparent 1px); background-size: 18px 18px; }
.desk-bar {
    flex: none; display: flex; align-items: center; justify-content: space-between; gap: 12px;
    height: 46px; padding: 0 14px 0 20px;
    background: color-mix(in srgb, var(--surface) 80%, transparent); border-bottom: 1px solid var(--border);
    backdrop-filter: blur(6px);
}
.desk-info { font-size: 12.5px; color: var(--text-muted); font-weight: 500; font-variant-numeric: tabular-nums; }
.desk-scroll { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 30px 24px 60px; }
.sheet-holder { width: fit-content; margin: 0 auto; }
.sheet-holder .sheet { box-shadow: 0 1px 2px rgba(15, 35, 60, .08), 0 18px 44px -10px rgba(15, 35, 60, .28); border-radius: 2px; }
.zoombar { display: flex; align-items: center; gap: 2px; padding: 2px; background: var(--surface); border-radius: var(--r-sm); border: 1px solid var(--border); box-shadow: var(--shadow-xs); }
.zoombar button { height: 28px; min-width: 28px; border: 0; background: none; border-radius: 6px; color: var(--text-muted); display: grid; place-items: center; }
.zoombar button:hover { background: var(--surface-3); color: var(--text-strong); }
.zoom-label { font-size: 12.5px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 48px !important; }

/* Form sections (editor) */
.fsec { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); margin-bottom: 12px; box-shadow: var(--shadow-xs); }
.fsec > summary {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 18px;
    list-style: none; cursor: pointer; user-select: none;
    border-radius: var(--r-lg);
}
.fsec > summary:hover { background: var(--surface-2); }
.fsec[open] > summary { border-radius: var(--r-lg) var(--r-lg) 0 0; }
.fsec > summary::-webkit-details-marker { display: none; }
.fsec-title { font-weight: 600; color: var(--text-strong); font-size: 14.5px; }
.fsec-aside { margin-left: auto; color: var(--text-muted); font-size: 13px; font-variant-numeric: tabular-nums; }
.fsec-chev { color: var(--text-faint); display: grid; transition: transform .18s; }
.fsec-aside + .fsec-chev { margin-left: 0; }
.fsec-title + .fsec-chev { margin-left: auto; }
.fsec:not([open]) .fsec-chev { transform: rotate(-90deg); }
.fsec-body { padding: 4px 18px 18px; }

/* ==========================================================
   FORMS
   ========================================================== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 16px; }
.span-2 { grid-column: 1 / -1; }
.field { min-width: 0; }
.field > label, .label-row > label { display: block; font-size: 13px; font-weight: 500; color: var(--text-strong); margin-bottom: 6px; }
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.label-actions { display: flex; gap: 12px; }
.label-actions .link-btn { font-size: 12px; padding: 0; }
.req { color: var(--bad-dot); margin-left: 3px; }
.opt { margin-left: 6px; font-weight: 400; color: var(--text-faint); font-size: 12px; }
.hint { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; line-height: 1.45; }
.hint.warn-text { color: var(--warn); }
.fsec-body > * + *, .sub-block > * + *, .dialog-body > * + *, .panel .grid-2 + *, .panel .field + .field, .panel .field + .grid-2, .panel .check + .grid-2 { margin-top: 16px; }
.grid-2 > * { margin-top: 0 !important; }
.grid-2 > .check { align-self: end; }

input[type=text], input[type=tel], input[type=email], input[type=number], input[type=date], input[type=month], input[type=time], input[type=password], input[type=url], input[type=search], input:not([type]), select, textarea {
    width: 100%;
    height: var(--control-h);
    padding: 0 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--r-sm);
    background: var(--surface);
    color: var(--text-strong);
    font-size: 14px;
    box-shadow: var(--shadow-xs);
    transition: border-color .15s, box-shadow .15s, background-color .15s;
}
[data-theme="dark"] input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]), [data-theme="dark"] select, [data-theme="dark"] textarea { background-color: var(--surface-2); }
textarea { height: auto; padding: 9px 12px; resize: vertical; line-height: 1.5; }
select { padding-right: 32px; appearance: none; -webkit-appearance: none;
    background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23667085' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m7 15 5 5 5-5M7 9l5-5 5 5'/%3E%3C/svg%3E") no-repeat right 10px center; }
input:hover, select:hover, textarea:hover { border-color: color-mix(in srgb, var(--border-strong) 60%, var(--text-faint)); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 4px var(--ring); }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
input[type=number] { font-variant-numeric: tabular-nums; }
input[type=date] { font-variant-numeric: tabular-nums; }
[data-theme="dark"] input[type=date]::-webkit-calendar-picker-indicator, [data-theme="dark"] input[type=month]::-webkit-calendar-picker-indicator { filter: invert(1) opacity(.65); }
input:disabled, select:disabled, textarea:disabled { background-color: var(--surface-3); color: var(--text-muted); cursor: not-allowed; }
.field.invalid input, .field.invalid textarea { border-color: var(--bad-dot); box-shadow: 0 0 0 4px var(--bad-bg); }
.field.invalid > label { color: var(--bad); }
.line.invalid { border-color: var(--bad-dot); box-shadow: 0 0 0 4px var(--bad-bg); }
.line.invalid .line-name { border-color: var(--bad-dot); }

.addon-wrap { display: flex; min-width: 0; }
.addon-wrap > input { border-top-right-radius: 0; border-bottom-right-radius: 0; min-width: 0; }
.addon-toggle, .addon-btn, .addon-text {
    flex: none; display: inline-flex; align-items: center; gap: 4px;
    height: var(--control-h); padding: 0 11px;
    border: 1px solid var(--border-strong); border-left: 0; border-radius: 0 var(--r-sm) var(--r-sm) 0;
    background: var(--surface-2); color: var(--text-muted);
    font-size: 12.5px; font-weight: 500; white-space: nowrap;
}
button.addon-toggle:hover, button.addon-btn:hover { background: var(--brand-soft); color: var(--brand-ink); }
.addon-toggle { min-width: 46px; justify-content: center; }

/* Checkboxes */
.check { position: relative; display: flex; align-items: flex-start; gap: 10px; cursor: pointer; padding: 2px 0; }
.check input { position: absolute; left: 0; top: 0; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
.check-box {
    flex: none; width: 18px; height: 18px; margin-top: 1px;
    display: grid; place-items: center;
    border: 1.5px solid var(--border-strong); border-radius: 5px; background: var(--surface); color: transparent;
    transition: background-color .12s, border-color .12s, box-shadow .12s;
}
.check:hover .check-box { border-color: var(--text-faint); }
.check input:checked + .check-box { background: var(--brand); border-color: var(--brand); color: #fff; }
.check input:focus-visible + .check-box { box-shadow: 0 0 0 4px var(--ring); border-color: var(--focus); }
.check-text { font-size: 13.5px; color: var(--text-strong); font-weight: 500; }
.check-text small { display: block; font-weight: 400; color: var(--text-muted); font-size: 12.5px; margin-top: 2px; }
input[type=checkbox] { accent-color: var(--brand); width: 16px; height: 16px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip {
    display: inline-flex; align-items: center; gap: 5px;
    height: 26px; padding: 0 10px;
    border: 1px solid var(--border); border-radius: 13px; background: var(--surface);
    font-size: 12px; font-weight: 500; color: var(--text-muted);
    transition: border-color .12s, color .12s, background-color .12s;
}
button.chip:hover, a.chip:hover { border-color: var(--border-strong); color: var(--text-strong); background: var(--surface-2); }
.chip.on { background: var(--brand-soft); border-color: transparent; color: var(--brand-ink); }
.hint .chips { margin-top: 4px; }
.chips-tight { gap: 4px; }
.chips-tight .chip { height: 24px; padding: 0 9px; font-size: 11.5px; }
.fsec-body > .sub-block:first-child { border-top: 0; padding-top: 0; margin-top: 0; }
.sub-block { border-top: 1px solid var(--border-soft); margin-top: 18px; padding-top: 16px; }
.sub-title { font-size: 13.5px; font-weight: 600; color: var(--text-strong); }
.sub-title + * { margin-top: 10px !important; }

/* Segmented control */
.seg { display: inline-flex; border-radius: var(--r-sm); padding: 3px; background: var(--surface-3); gap: 2px; }
.seg button { border: 0; background: none; padding: 5px 12px; border-radius: 6px; font-size: 13px; font-weight: 500; color: var(--text-muted); transition: background-color .15s, color .15s, box-shadow .15s; }
.seg button:hover { color: var(--text-strong); }
.seg button.on { background: var(--surface); color: var(--text-strong); box-shadow: var(--shadow-sm); }
[data-theme="dark"] .seg button.on { background: var(--border-strong); }
.seg-wide { display: flex; }
.seg-wide button { flex: 1; }
.mobile-only { display: none; }

/* Line items */
.items-list { display: flex; flex-direction: column; gap: 8px; }
.line { border: 1px solid var(--border-soft); border-radius: var(--r-md); padding: 9px 9px 11px; background: var(--surface-2); transition: border-color .15s, background-color .15s, box-shadow .15s; }
.line:focus-within { border-color: var(--border-strong); background: var(--surface); box-shadow: var(--shadow-sm); }
.line-top { display: grid; grid-template-columns: 24px 1fr auto 30px; align-items: center; gap: 6px; }
.line-no { width: 22px; height: 22px; border-radius: 50%; background: var(--surface-3); color: var(--text-muted); font-size: 11.5px; font-weight: 600; display: grid; place-items: center; }
.line .line-name { border-color: transparent; background: transparent; font-weight: 500; padding: 0 6px; box-shadow: none; height: 36px; }
.line .line-name:hover { border-color: var(--border); background: var(--surface); }
.line .line-name:focus { background: var(--surface); border-color: var(--focus); }
.line-amt { font-weight: 600; color: var(--text-strong); font-variant-numeric: tabular-nums; white-space: nowrap; font-size: 13.5px; }
.line .line-desc {
    display: block; width: calc(100% - 30px); margin: 2px 0 6px 30px;
    min-height: 30px; padding: 5px 6px; resize: none; overflow: hidden;
    border-color: transparent; background: transparent; color: var(--text-muted); font-size: 13px; box-shadow: none;
}
.line .line-desc:hover { border-color: var(--border); background: var(--surface); }
.line .line-desc:focus { background: var(--surface); color: var(--text); }
.line-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-left: 30px; }
.line-grid label { display: block; min-width: 0; flex: 1 1 62px; }
.line-grid label.w-rate { flex: 1.3 1 72px; }
.line-grid label.w-disc { flex: 1.8 1 100px; }
.line-grid label > span:first-child { display: block; font-size: 11.5px; color: var(--text-muted); margin-bottom: 4px; }
.line-grid input { height: 34px; padding: 0 9px; font-size: 13.5px; }
.line-grid .addon-toggle { height: 34px; padding: 0 7px; min-width: 40px; font-size: 11.5px; }
.items-actions { display: flex; align-items: center; gap: 12px; margin-top: 12px; }
.kbd-hint { font-size: 12px; color: var(--text-faint); }
.empty-mini { color: var(--text-faint); font-size: 13px; padding: 8px 0; }

.charges { margin-top: 14px; }
.charge { display: grid; grid-template-columns: 1fr 150px 118px 30px; gap: 8px; align-items: center; margin-bottom: 8px; }
.charge input { height: 36px; }
.charge .addon-text { height: 36px; }
.sum-box { margin-top: 14px; background: var(--surface-2); border: 1px solid var(--border-soft); border-radius: var(--r-md); padding: 12px 14px; font-variant-numeric: tabular-nums; }
.sum-row { display: flex; justify-content: space-between; gap: 16px; padding: 3px 0; font-size: 13px; color: var(--text-muted); font-variant-numeric: tabular-nums; }
.sum-row span:last-child { color: var(--text); font-weight: 500; }
.sum-total { border-top: 1px solid var(--border); margin-top: 6px; padding-top: 9px; font-size: 14.5px; font-weight: 600; color: var(--text-strong); }
.sum-total span:last-child { color: var(--text-strong); font-weight: 700; }
.sum-due span:last-child { color: var(--bad); font-weight: 600; }
.sum-good span:last-child { color: var(--good); font-weight: 600; }
.sum-fx { font-size: 12.5px; }

/* Rich text editor */
.rte { border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface); box-shadow: var(--shadow-xs); }
.rte:focus-within { border-color: var(--focus); box-shadow: 0 0 0 4px var(--ring); }
.rte-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 4px; border-bottom: 1px solid var(--border-soft); background: var(--surface-2); border-radius: var(--r-sm) var(--r-sm) 0 0; }
.rte-btn { position: relative; width: 30px; height: 30px; display: inline-grid; place-items: center; border: 0; border-radius: 6px; background: none; color: var(--text); font-size: 14px; }
.rte-btn:hover { background: var(--surface-3); }
.rte-btn.on { background: var(--brand-soft); color: var(--brand-ink); }
.rte-bar select { width: auto; height: 30px; font-size: 12.5px; padding: 0 26px 0 8px; border-color: transparent; background-color: transparent; box-shadow: none; }
.rte-bar select:hover { border-color: var(--border); }
.rte-sep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; }
.rte-color input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.rte-color span { font-weight: 700; border-bottom: 3px solid var(--brand); line-height: 1.1; }
.rte-hl span { border-bottom-color: #f2d45c; }
.rte-area { position: relative; padding: 10px 12px; outline: none; font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; color: var(--text-strong); }
.rte-area.is-empty::before { content: attr(data-placeholder); position: absolute; left: 12px; top: 10px; color: var(--text-faint); pointer-events: none; }
.rte-area ol, .rte-area ul { padding-left: 22px; margin: 4px 0; }
.rte-area p { margin: 0 0 8px; }

/* ==========================================================
   PAGES — header, KPI tiles, toolbar, tables, pills, empty states
   ========================================================== */
.page-view { max-width: 1280px; margin: 0 auto; padding: 30px 36px 72px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px 24px; flex-wrap: wrap; }
.page-head > div:first-child { min-width: 0; }
.page-head h1 { margin: 0; font-size: 26px; line-height: 1.2; font-weight: 600; color: var(--text-strong); letter-spacing: -.022em; }
.ph-eyebrow { font-size: 13px; font-weight: 500; color: var(--text-muted); margin-bottom: 4px; }
.page-sub { margin: 6px 0 0; color: var(--text-muted); max-width: 680px; font-size: 14px; line-height: 1.5; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.ledger-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-top: 24px; }
.ls {
    position: relative;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
    padding: 16px 18px 15px; min-width: 0;
    box-shadow: var(--shadow-sm);
    display: flex; flex-direction: column;
}
a.ls { text-decoration: none; color: inherit; transition: border-color .15s, box-shadow .15s, transform .15s; }
a.ls:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); }
.ls-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 22px; }
.ls-label { font-size: 13px; color: var(--text-muted); font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.ls-value { font-size: 24px; line-height: 1.25; font-weight: 600; color: var(--text-strong); font-variant-numeric: tabular-nums; margin-top: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: -.02em; }
.ls-cur { font-size: 12.5px; color: var(--text-faint); font-weight: 500; margin-right: 6px; letter-spacing: 0; }
.ls-more { font-size: 12px; color: var(--text-muted); font-variant-numeric: tabular-nums; margin-top: 2px; }
.ls-note { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; line-height: 1.4; }
.ls-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; min-width: 0; }
.ls-foot { align-items: flex-start; }
.ls-foot .trend { margin-top: -1px; }
.ls-foot .ls-note { margin-top: 1px; min-width: 0; }
.trend:empty { display: none; }
.trend .ic:only-child { margin: 0 -3px; }
.ls-bad .ls-value { color: var(--bad); }
.trend { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 600; white-space: nowrap; flex: none; font-variant-numeric: tabular-nums; }
.trend-good { background: var(--good-bg); color: var(--good); }
.trend-bad { background: var(--bad-bg); color: var(--bad); }
.trend-warn { background: var(--warn-bg); color: var(--warn); }
.trend-neutral { background: var(--neutral-bg); color: var(--neutral); }

/* Toolbar with search and filters */
.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 22px 0 12px; }
.filters select { width: auto; min-width: 150px; height: 36px; border-radius: 18px; padding-left: 14px; font-size: 13px; font-weight: 500; color: var(--text); }
.search { position: relative; flex: 1; min-width: 220px; max-width: 420px; }
.search-ic { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--text-faint); display: grid; pointer-events: none; }
.search input { padding-left: 36px; height: 36px; border-radius: 18px; }

/* Tables */
.measure { position: fixed; left: -10000px; top: 0; visibility: hidden; pointer-events: none; }
.table-card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: auto; max-height: none; box-shadow: var(--shadow-sm); }
.dtable { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
.dtable th {
    position: sticky; top: 0; z-index: 2;
    text-align: left; font-size: 12px; color: var(--text-muted); font-weight: 500;
    padding: 10px 16px; border-bottom: 1px solid var(--border);
    background: var(--surface-2); white-space: nowrap;
}
.dtable th.has-tip { cursor: help; text-decoration: underline dotted var(--text-faint); text-underline-offset: 3px; }
.dtable td { padding: 12px 16px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; white-space: nowrap; color: var(--text); }
.dtable td b { color: var(--text-strong); font-weight: 600; }
.dtable tbody tr:last-child td { border-bottom: 0; }
.dtable tbody tr { transition: background-color .1s; }
.dtable tbody tr:hover td { background: var(--surface-2); }
.dtable tr[data-row], .dtable tr[data-doc] { cursor: pointer; }
.dtable tr[data-row]:focus-visible, .dtable tr[data-doc]:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.dtable .num { text-align: right; font-variant-numeric: tabular-nums; }
.dtable td.num { color: var(--text-strong); }
.dtable .cur { font-size: 11px; color: var(--text-faint); margin-right: 5px; font-weight: 500; }
.dtable .who { max-width: 280px; overflow: hidden; text-overflow: ellipsis; }
.dtable .act { width: 44px; text-align: right; }
.dtable .icon-btn { width: 30px; height: 30px; margin: -4px 0; vertical-align: middle; }
.dtable td .small { white-space: normal; }
.dtable td a { color: var(--brand-ink); text-decoration: none; font-weight: 500; }
.dtable td a:hover { text-decoration: underline; text-underline-offset: 3px; }
.dtable td a.btn { color: var(--text); font-weight: 500; }
.dtable td .btn-sm { height: 28px; padding: 0 10px; margin: -4px 0; }
.dtable td a.btn:hover { text-decoration: none; }

/* Status pills: soft tint with a dot */
.pill { display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px 0 8px; border-radius: 11px; font-size: 12px; font-weight: 500; white-space: nowrap; line-height: 1; --dot: var(--neutral-dot); }
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--dot); flex: none; }
.pill-neutral { background: var(--neutral-bg); color: var(--neutral); }
.pill-info { background: var(--info-bg); color: var(--info); --dot: var(--info-dot); }
.pill-good { background: var(--good-bg); color: var(--good); --dot: var(--good-dot); }
.pill-bad { background: var(--bad-bg); color: var(--bad); --dot: var(--bad-dot); }
.pill-warn { background: var(--warn-bg); color: var(--warn); --dot: var(--warn-dot); }
.pill-mute { background: var(--neutral-bg); color: var(--text-faint); --dot: var(--text-faint); }

/* Empty states */
.empty { text-align: center; padding: 56px 24px; }
.empty-art { color: var(--text-muted); display: grid; place-items: center; margin: 0 auto 14px; width: 52px; height: 52px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--border); box-shadow: var(--shadow-xs); }
.empty h2 { margin: 0 0 6px; font-size: 16px; color: var(--text-strong); font-weight: 600; }
.empty p { margin: 0 auto 16px; max-width: 460px; color: var(--text-muted); line-height: 1.55; }
.empty-sm { padding: 40px 20px 36px; }
.empty-sm p { margin-bottom: 0; }
.empty-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-top: 16px; }

/* Cards */
.panel, .card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.panel { padding: 24px 28px 28px; max-width: 840px; }
.panel h2 { margin: 0; font-size: 17px; color: var(--text-strong); font-weight: 600; letter-spacing: -.01em; }
.panel-sub { margin: 4px 0 20px; color: var(--text-muted); }
.panel-h3 { font-size: 15px; color: var(--text-strong); margin: 28px 0 10px; font-weight: 600; }
.panel .check { margin-top: 12px; }

/* Help: tooltip on terms */
.term { text-decoration: underline dotted var(--text-faint); text-underline-offset: 3px; cursor: help; }
.ls-label.has-tip, .ls-label .term { text-decoration: underline dotted color-mix(in srgb, var(--text-faint) 70%, transparent); text-underline-offset: 4px; cursor: help; }
.tooltip {
    position: fixed; z-index: 3000; max-width: 280px;
    padding: 8px 11px; border-radius: var(--r-sm);
    background: #0f172a; color: #f1f5f9; font-size: 12.5px; line-height: 1.45; font-weight: 400;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .25);
    pointer-events: none; opacity: 0; transform: translateY(2px); transition: opacity .12s, transform .12s;
}
[data-theme="dark"] .tooltip { background: #e6ebf2; color: #0f172a; }
.tooltip.in { opacity: 1; transform: none; }

/* ==========================================================
   SETTINGS (document desk)
   ========================================================== */
.settings { display: grid; grid-template-columns: 210px minmax(0, 1fr); gap: 28px; margin-top: 24px; align-items: start; }
.settings-nav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: calc(var(--appbar-h) + 20px); }
.settings-nav button { text-align: left; border: 0; background: none; padding: 8px 12px; border-radius: var(--r-sm); color: var(--text-muted); font-weight: 500; font-size: 13.5px; }
.settings-nav button:hover { background: var(--surface-3); color: var(--text-strong); }
.settings-nav button.on { background: var(--surface); color: var(--text-strong); font-weight: 600; box-shadow: var(--shadow-sm), 0 0 0 1px var(--border); }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.swatch { position: relative; width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--surface); background: var(--sw); box-shadow: 0 0 0 1px var(--border); padding: 0; }
.swatch.on { box-shadow: 0 0 0 2px var(--text-strong); }
.swatch-custom { background: conic-gradient(#c0392b, #e6a23c, #3f9d5a, #2f6db5, #7d4cc2, #c0392b); cursor: pointer; }
.swatch-custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }

.layout-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.layout-card { display: flex; flex-direction: column; gap: 4px; text-align: left; padding: 10px; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); transition: border-color .15s, box-shadow .15s; }
.layout-card:hover { border-color: var(--border-strong); }
.layout-card.on { border-color: var(--brand); box-shadow: 0 0 0 3px var(--ring); }
.lc-name { font-weight: 600; color: var(--text-strong); font-size: 13.5px; margin-top: 4px; }
.lc-desc { font-size: 12px; color: var(--text-muted); line-height: 1.35; }
.lc-art { position: relative; display: block; height: 74px; border-radius: 6px; background: #f3f5f8; overflow: hidden; }
.lc-art i { position: absolute; display: block; }
.lc-classic i:nth-child(1) { left: 10%; top: 14%; width: 30%; height: 7px; background: #9aa8b8; border-radius: 2px; }
.lc-classic i:nth-child(2) { right: 0; top: 12%; width: 34%; height: 12px; background: #14395e; border-radius: 8px 0 0 8px; }
.lc-classic i:nth-child(3) { left: 0; right: 0; bottom: 0; height: 9px; background: #14395e; }
.lc-letterhead i:nth-child(1) { left: 0; right: 0; top: 0; height: 17px; background: linear-gradient(90deg, #14395e 18%, #c9d1da 18%); }
.lc-letterhead i:nth-child(2) { left: 36%; right: 36%; top: 26px; height: 5px; background: #14395e; border-radius: 2px; }
.lc-letterhead i:nth-child(3) { left: 0; right: 0; bottom: 0; height: 9px; background: linear-gradient(#c9d1da 55%, #14395e 55%); }
.lc-minimal i:nth-child(1) { left: 10%; top: 14%; width: 38%; height: 9px; background: none; border-bottom: 2px solid #6b7b8c; }
.lc-minimal i:nth-child(2) { right: 10%; top: 14%; width: 22%; height: 14px; background: #c9d1da; border-radius: 2px; }
.lc-minimal i:nth-child(3) { left: 10%; right: 10%; top: 40px; height: 1px; background: #8c9aa9; }

.assets { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.asset { display: flex; gap: 12px; align-items: center; border: 1px solid var(--border); border-radius: var(--r-md); padding: 10px; min-width: 0; }
.asset-thumb { flex: none; width: 76px; height: 56px; border-radius: 6px; background: #f3f5f8; display: grid; place-items: center; overflow: hidden; padding: 4px; }
.asset-thumb.wide { width: 128px; }
.asset-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.asset-info { min-width: 0; }
.asset-label { font-weight: 600; font-size: 13.5px; color: var(--text-strong); }
.asset-info .hint { margin-top: 0; }
.asset-actions { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.asset-actions label { cursor: pointer; }

.panel .bank-card, .settings-body .bank-card { border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px 16px; margin-bottom: 12px; background: var(--surface-2); }
.bank-card .link-btn { margin-top: 8px; }
.bank-card textarea { font-variant-numeric: tabular-nums; }

.num-table, .col-table { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.num-row { display: grid; grid-template-columns: 170px 1fr 84px 1fr; gap: 10px; align-items: center; }
.num-head, .col-head { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.num-type { font-weight: 500; color: var(--text-strong); }
.num-ex { color: var(--text-muted); font-variant-numeric: tabular-nums; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.col-row { display: grid; grid-template-columns: 110px 1fr 140px; gap: 10px; align-items: center; }
.col-name { font-size: 13px; color: var(--text-muted); }
.backup-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* ==========================================================
   MENUS, DIALOGS, COMMAND PALETTE, TOASTS
   ========================================================== */
.menu {
    position: fixed; z-index: 1000;
    min-width: 252px; max-width: 340px; max-height: 70vh; overflow: auto;
    padding: 6px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
    box-shadow: var(--shadow-lg);
}
.menu-item {
    display: flex; align-items: flex-start; gap: 10px; width: 100%;
    padding: 8px 10px; border: 0; border-radius: 7px; background: none;
    text-align: left; font-size: 13.5px; color: var(--text);
}
.menu-item .ic { margin-top: 2px; color: var(--text-muted); }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-3); outline: none; color: var(--text-strong); }
.menu-item.active { background: var(--brand-soft); color: var(--brand-ink); font-weight: 600; }
.menu-item.danger, .menu-item.danger .ic { color: var(--bad); }
.menu-item:disabled { opacity: .45; cursor: default; background: none; }
.menu-label small { display: block; font-size: 12px; color: var(--text-muted); font-weight: 400; margin-top: 1px; }
.menu-heading { font-size: 12px; color: var(--text-faint); padding: 8px 10px 6px; font-weight: 500; }
.menu-sep { height: 1px; background: var(--border-soft); margin: 6px 4px; }

.dialog { border: 1px solid var(--border); padding: 0; border-radius: var(--r-xl); width: min(480px, calc(100vw - 32px)); color: var(--text); background: var(--surface); box-shadow: var(--shadow-lg); }
.dialog.dialog-wide { width: min(680px, calc(100vw - 32px)); }
.dialog::backdrop, .cmdk::backdrop { background: var(--overlay); backdrop-filter: blur(2px); }
.dialog-inner { margin: 0; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 20px 22px 6px; }
.dialog-head h2 { margin: 0; font-size: 17px; color: var(--text-strong); font-weight: 600; letter-spacing: -.01em; }
.dialog-body { padding: 8px 22px 10px; max-height: 66vh; overflow: auto; }
.dialog-text { margin: 0 0 12px; color: var(--text); line-height: 1.55; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 14px 22px 18px; flex-wrap: wrap; border-top: 1px solid var(--border-soft); margin-top: 10px; background: var(--surface-2); border-radius: 0 0 var(--r-xl) var(--r-xl); }
.dialog-fx { width: min(420px, calc(100vw - 32px)); }
.dialog-fx .dialog-inner { padding-bottom: 0; }
.dialog-fx iframe { display: block; width: calc(100% - 40px); height: 440px; margin: 6px 20px 0; border: 1px solid var(--border); border-radius: var(--r-sm); }
.dialog-fx .hint { padding: 0 22px; }
.form-grid { display: grid; gap: 14px; }

/* Command palette */
.cmdk { border: 0; padding: 0; background: transparent; width: min(640px, calc(100vw - 24px)); max-height: none; margin: 12vh auto auto; overflow: visible; }
.cmdk-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-xl); box-shadow: var(--shadow-lg); overflow: hidden; display: flex; flex-direction: column; max-height: min(560px, 74vh); }
.cmdk-input { display: flex; align-items: center; gap: 10px; padding: 0 16px; border-bottom: 1px solid var(--border-soft); color: var(--text-faint); }
.cmdk-input input { flex: 1; height: 54px; border: 0 !important; box-shadow: none !important; background: transparent !important; padding: 0; font-size: 15.5px; color: var(--text-strong); }
.cmdk-list { overflow-y: auto; padding: 6px 8px 8px; flex: 1; min-height: 0; }
.cmdk-group { font-size: 12px; font-weight: 500; color: var(--text-faint); padding: 10px 10px 5px; }
.cmdk-item { display: flex; align-items: center; gap: 11px; padding: 0 10px; height: 42px; border-radius: var(--r-sm); cursor: pointer; color: var(--text); }
.cmdk-item .cmdk-ic { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 7px; background: var(--surface-2); border: 1px solid var(--border-soft); color: var(--text-muted); flex: none; }
.cmdk-label { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.cmdk-hint { color: var(--text-faint); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; flex: 1; }
.cmdk-go { margin-left: auto; color: var(--text-faint); display: grid; opacity: 0; }
.cmdk-item.on { background: var(--brand-soft); color: var(--text-strong); }
.cmdk-item.on .cmdk-ic { background: var(--surface); color: var(--brand-ink); border-color: transparent; }
.cmdk-item.on .cmdk-go { opacity: 1; }
.cmdk-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 40px 20px; color: var(--text-muted); text-align: center; }
.cmdk-empty b { color: var(--text-strong); }
.cmdk-foot { display: flex; align-items: center; gap: 14px; padding: 9px 14px; border-top: 1px solid var(--border-soft); background: var(--surface-2); font-size: 12px; color: var(--text-faint); }
.cmdk-foot kbd { margin-right: 3px; }

/* Toasts */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 2000; display: flex; flex-direction: column; align-items: flex-end; gap: 8px; pointer-events: none; width: max-content; max-width: calc(100vw - 32px); }
.toast {
    display: flex; align-items: center; gap: 10px;
    padding: 11px 14px; border-radius: var(--r-md);
    background: var(--surface); color: var(--text-strong); font-size: 13.5px; font-weight: 500;
    border: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
    opacity: 0; transform: translateY(8px);
    transition: opacity .2s, transform .2s;
    pointer-events: auto; max-width: 440px;
}
.toast.in { opacity: 1; transform: none; }
.toast-ic { display: grid; color: var(--info-dot); flex: none; }
.toast-good .toast-ic { color: var(--good-dot); }
.toast-bad .toast-ic { color: var(--bad-dot); }
.toast-warn .toast-ic { color: var(--warn-dot); }
.toast-bad { border-color: color-mix(in srgb, var(--bad-dot) 35%, var(--border)); }
.toast button { border: 0; background: none; color: var(--brand-ink); font-weight: 600; padding: 0 0 0 4px; }

/* ---------- Print: only the document ---------- */
#printRoot { display: none; }
@media print {
    body, body[data-view="create"] { background: #fff; margin: 0; overflow: visible !important; height: auto !important; }
    body > *:not(#printRoot) { display: none !important; }
    #printRoot { display: block; }
}

/* ==========================================================
   RESPONSIVE
   ========================================================== */
@media (max-width: 1280px) {
    .docbar-right .btn span { display: none; }
    .docbar-right .btn { padding: 0 11px; }
    .docbar-right .btn-primary span { display: inline; }
}
@media (max-width: 1024px) {
    /* sidebar becomes a drawer */
    .sidebar { width: min(300px, 86vw); transform: translateX(-102%); transition: transform .28s cubic-bezier(.16, 1, .3, 1); box-shadow: none; z-index: 70; }
    body.sb-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
    body.sb-open .sb-scrim { display: block; }
    .sidebar .sb-close { display: inline-grid; }
    .sidebar a[href] { min-height: 40px; }
    .appbar, #app { margin-left: 0; }
    .appbar { padding: 0 12px; gap: 8px; }
    .appbar .appbar-menu { display: inline-grid; }
    .appbar .appbar-mark { display: block; flex: none; }
    .cmdk-trigger { width: 40px; padding: 0; justify-content: center; margin-left: auto; flex: none; height: 38px; }
    .cmdk-ph, .cmdk-kbd { display: none; }
    .workspace { grid-template-columns: 1fr; }
    .workspace[data-pane="form"] .desk { display: none; }
    .workspace[data-pane="preview"] .form-pane { display: none; }
    .form-pane { border-right: 0; padding-left: max(12px, calc((100% - 720px) / 2)); padding-right: max(12px, calc((100% - 720px) / 2)); }
    .mobile-only { display: inline-flex; }
    .docbar { flex-wrap: wrap; }
    .ledger-strip { grid-template-columns: 1fr 1fr; }
    .settings { grid-template-columns: 1fr; gap: 16px; }
    .settings-nav { flex-direction: row; overflow-x: auto; position: static; background: var(--surface-3); padding: 3px; border-radius: var(--r-md); scrollbar-width: none; }
    .settings-nav button { white-space: nowrap; flex: none; }
    .page-view { padding: 24px 20px 64px; }
}
@media (max-width: 640px) {
    .crumbs { font-size: 13px; }
    .crumb-group, .crumb-sep { display: none; }
    .appbar-right { gap: 2px; }
    .appbar-right .btn span { display: none; }
    .appbar-right .btn { padding: 0 10px; width: 38px; height: 38px; }
    .page-view { padding: 20px 16px 56px; }
    .page-head h1 { font-size: 23px; }
    .docbar { padding: 10px 12px; }
    .docbar-left { width: 100%; flex-wrap: wrap; }
    .docbar-id { flex: 1; min-width: 110px; }
    .type-picker { min-width: 0; }
    .docbar-right { width: 100%; justify-content: flex-start; flex-wrap: nowrap; }
    .docbar-right .seg { margin-right: auto; }
    .docbar-sep { display: none; }
    .docbar-right .btn-primary span { display: none; }
    .docbar-right .btn-primary { padding: 0 12px; }
    .grid-2 { grid-template-columns: 1fr; }
    .form-pane { padding: 12px 12px 40px; }
    .charge { grid-template-columns: 1fr 1fr 30px; }
    .charge input[data-cf=label] { grid-column: 1 / -1; }
    .ledger-strip { grid-template-columns: 1fr; gap: 10px; }
    .layout-cards, .assets { grid-template-columns: 1fr; }
    .num-row { grid-template-columns: 1fr 1fr; }
    .num-row .num-type { grid-column: 1 / -1; }
    .num-head { display: none; }
    .col-row { grid-template-columns: 1fr 1fr; }
    .col-row .col-name { grid-column: 1 / -1; }
    .panel { padding: 18px 16px 20px; }
    .kbd-hint { display: none; }
    .search { min-width: 0; max-width: none; flex: 1 1 100%; }
    .filters select { flex: 1 1 140px; min-width: 0; }
    .toasts { left: 16px; right: 16px; align-items: stretch; width: auto; }
    .toast { max-width: none; }
    .cmdk { margin-top: 8vh; }
    .cmdk-hint { display: none; }
    .cmdk-foot { display: none; }
    .dialog-actions { justify-content: stretch; }
    .dialog-actions .btn { flex: 1 1 auto; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition: none !important; animation: none !important; scroll-behavior: auto !important; }
}

/* ---------- Editable lists (directors, background, resolutions) ---------- */
.rlist { display: flex; flex-direction: column; gap: 8px; }
.rrow { display: grid; align-items: center; gap: 8px; }
.rrow-dir { grid-template-columns: 1.3fr 1fr auto 30px; }
.rrow-text { grid-template-columns: 24px 1fr auto; align-items: start; }
.rrow-text .line-no { margin-top: 9px; }
.rrow-text textarea { min-height: 78px; resize: none; overflow: hidden; }
.rrow-tools { display: flex; flex-direction: column; gap: 2px; }
.rrow-tools .icon-btn { width: 28px; height: 24px; }
.rrow-tools .icon-btn:disabled { opacity: .3; cursor: default; background: none; }
.check-inline { padding: 0; align-items: center; white-space: nowrap; }
.sub-block > .btn-sm { margin-top: 10px; }
@media (max-width: 640px) {
    .rrow-dir { grid-template-columns: 1fr 1fr 30px; }
    .rrow-dir .check-inline { grid-column: 1 / 2; }
}

/* ---------- Import (document desk) ---------- */
.import-grid { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 20px; margin-top: 24px; align-items: start; }
.dropzone {
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
    min-height: 240px; padding: 28px;
    border: 1.5px dashed var(--border-strong); border-radius: var(--r-xl); background: var(--surface);
    text-align: center; cursor: pointer; transition: border-color .15s, background-color .15s, box-shadow .15s;
}
.dropzone:hover, .dropzone.over { border-color: var(--brand); background: var(--brand-soft); }
.dropzone:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.dz-art { color: var(--brand-ink); display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--brand-soft); margin-bottom: 8px; box-shadow: inset 0 0 0 1px var(--brand-soft-2); }
.dz-title { font-size: 16px; font-weight: 600; color: var(--text-strong); }
.dz-title u { color: var(--brand-ink); text-underline-offset: 3px; }
.dz-sub { color: var(--text-muted); font-size: 13px; }
.import-side { padding: 20px 22px 22px; }
.import-side h2 { font-size: 15px; margin-bottom: 14px; }
.import-side .check { margin-top: 12px; }
.import-notes { margin: 0; padding-left: 18px; color: var(--text-muted); font-size: 13px; display: flex; flex-direction: column; gap: 7px; line-height: 1.5; }
.import-queue { margin-top: 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
.iq-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface-2); flex-wrap: wrap; }
.iq-head-actions { display: flex; gap: 8px; }
.iq-row { display: grid; grid-template-columns: 22px minmax(140px, 1fr) minmax(0, 1.6fr); gap: 12px; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border-soft); }
.iq-row:last-child { border-bottom: 0; }
.iq-file { color: var(--text-muted); display: grid; }
.iq-name { min-width: 0; }
.iq-name b { display: block; font-weight: 500; color: var(--text-strong); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iq-name small { color: var(--text-faint); font-size: 12px; }
.iq-right { min-width: 0; }
.iq-msg { font-size: 12.5px; color: var(--text-muted); margin-bottom: 5px; }
.iq-bar { height: 6px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.iq-bar i { display: block; height: 100%; background: var(--brand); border-radius: 3px; transition: width .25s; }
.iq-result { display: flex; align-items: center; gap: 10px; min-width: 0; }
.iq-doc { flex: 1; min-width: 0; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.iq-err { flex: 1; min-width: 0; font-size: 12.5px; color: var(--bad); }

.import-banner { border: 1px solid color-mix(in srgb, var(--info-dot) 30%, var(--border)); background: var(--info-bg); border-radius: var(--r-md); padding: 12px 14px; margin-bottom: 12px; }
.import-banner.has-issues { border-color: color-mix(in srgb, var(--warn-dot) 35%, var(--border)); background: var(--warn-bg); }
.ib-head { display: flex; gap: 10px; align-items: flex-start; }
.ib-icon { color: var(--info); display: grid; margin-top: 1px; }
.has-issues .ib-icon { color: var(--warn); }
.ib-title { font-weight: 600; color: var(--text-strong); font-size: 13.5px; }
.ib-title small { display: block; font-weight: 400; color: var(--text-muted); font-size: 12px; margin-top: 2px; }
.ib-list { margin: 8px 0 0 26px; padding-left: 16px; font-size: 13px; color: var(--text); display: flex; flex-direction: column; gap: 3px; }
.ib-actions { display: flex; gap: 8px; margin: 10px 0 0 26px; flex-wrap: wrap; }
.ib-actions .push { margin-left: auto; }
.ocr-text { white-space: pre-wrap; font: 12px/1.5 ui-monospace, Menlo, Consolas, monospace; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 12px; max-height: 50vh; overflow: auto; margin: 0; }
@media (max-width: 1100px) { .import-grid { grid-template-columns: 1fr; } }
@media (max-width: 640px) {
    .iq-row { grid-template-columns: 22px 1fr; }
    .iq-right { grid-column: 1 / -1; }
    .iq-result { flex-wrap: wrap; }
}

/* ---------- Signature & stamp placement ---------- */
.marks-box { border: 1px solid var(--border-soft); border-radius: var(--r-md); padding: 10px 12px; background: var(--surface-2); display: grid; gap: 8px; }
.marks-head { display: grid; gap: 2px; }
.marks-head .hint { margin: 0; }
.mark-item { display: grid; gap: 4px; padding-top: 6px; border-top: 1px solid var(--border-soft); }
.mark-item[hidden] { display: none; }
.mark-row { display: grid; grid-template-columns: 44px 1fr 46px; align-items: center; gap: 10px; color: var(--text-muted); font-size: 13px; }
.mark-name { justify-self: start; background: none; border: 0; padding: 0; font: inherit; font-weight: 600; color: var(--brand-ink); cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
.marks-mode { display: flex; flex-wrap: wrap; }
.marks-mode button:disabled { opacity: .45; cursor: not-allowed; }
.mark-rot-stem { position: absolute; left: 50%; top: -22px; width: 1.5px; height: 22px; background: #14395e; transform: translateX(-50%); }
.mark-rot { position: absolute; left: 50%; top: -30px; width: 14px; height: 14px; margin-left: -7px; border-radius: 50%; background: #fff; border: 1.5px solid #14395e; cursor: grab; }
.mark-rot:active { cursor: grabbing; }
@media (pointer: coarse) { .mark-rot { width: 22px; height: 22px; margin-left: -11px; top: -36px; } }
.mark-row input[type=range] { width: 100%; accent-color: var(--brand); padding: 0; border: 0; box-shadow: none; height: 22px; }
.mark-row output { font-variant-numeric: tabular-nums; text-align: right; color: var(--text-muted); }
.marks-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.desk-scroll { position: relative; }
#sheetHolder [data-mark] { cursor: move; touch-action: none; user-select: none; -webkit-user-drag: none; }
#sheetHolder [data-mark]:hover { outline: 1px dashed rgba(20, 57, 94, .55); outline-offset: 2px; }
.mark-box { position: absolute; z-index: 20; border: 1.5px solid #14395e; border-radius: 2px; cursor: move; touch-action: none; box-shadow: 0 0 0 9999px rgba(0,0,0,0); }
.mark-box[hidden] { display: none; }
.mark-label { position: absolute; left: -1.5px; top: 100%; margin-top: 6px; white-space: nowrap; background: #14395e; color: #fff; font-size: 11px; padding: 2px 7px; border-radius: 4px; pointer-events: none; }
.mark-h { position: absolute; width: 11px; height: 11px; background: #fff; border: 1.5px solid #14395e; border-radius: 2px; }
.mark-nw { left: -6px; top: -6px; cursor: nwse-resize; }
.mark-ne { right: -6px; top: -6px; cursor: nesw-resize; }
.mark-sw { left: -6px; bottom: -6px; cursor: nesw-resize; }
.mark-se { right: -6px; bottom: -6px; cursor: nwse-resize; }
body.mark-dragging, body.mark-dragging * { user-select: none !important; }
@media (pointer: coarse) { .mark-h { width: 18px; height: 18px; } .mark-nw, .mark-sw { left: -10px; } .mark-ne, .mark-se { right: -10px; } .mark-nw, .mark-ne { top: -10px; } .mark-sw, .mark-se { bottom: -10px; } }
@media print { .mark-box { display: none !important; } }
