/* Ledger — editorial ledger look: warm paper, ink, one vermilion accent.
   Data marks use the validated chart palette (series blue); UI chrome uses ink + accent. */
:root {
  color-scheme: light;
  --paper: #f4f1ea;
  --surface: #fcfcfb;
  --ink: #16150f;
  --ink-2: #52514e;
  --muted: #898781;
  --rule: #e1ddd2;
  --rule-strong: #c3c2b7;
  --accent: #c2410c;
  --accent-ink: #fff;
  --wash: rgba(22, 21, 15, 0.05);
  --series-1: #2a78d6;
  --series-1-soft: rgba(42, 120, 214, 0.12);
  --reference: #898781;
  --good: #006300;
  --bad: #b42318;
  --grid: #e1e0d9;
  --display: 'Fraunces', Georgia, serif;
  --sans: 'Instrument Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #0f0f0e;
    --surface: #1a1a19;
    --ink: #f4f1ea;
    --ink-2: #c3c2b7;
    --muted: #898781;
    --rule: #2c2c2a;
    --rule-strong: #383835;
    --accent: #f0703a;
    --accent-ink: #16150f;
    --wash: rgba(255, 255, 255, 0.06);
    --series-1: #3987e5;
    --series-1-soft: rgba(57, 135, 229, 0.16);
    --good: #0ca30c;
    --bad: #f97066;
    --grid: #2c2c2a;
  }
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { background: var(--paper); }
body { font: 15px/1.5 var(--sans); color: var(--ink); background: var(--paper); min-height: 100vh; -webkit-font-smoothing: antialiased; }
body::before { /* faint paper grain */
  content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .35;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .05 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}
#app { position: relative; z-index: 1; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
.boot { padding: 40vh 0; text-align: center; color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ── Shell ─────────────────────────────────────────────────────────────── */
.shell { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.side { border-right: 1px solid var(--rule); padding: 28px 18px; display: flex; flex-direction: column; gap: 28px; position: sticky; top: 0; height: 100vh; }
.brand { font-family: var(--display); font-size: 26px; font-weight: 600; letter-spacing: -.02em; display: flex; align-items: baseline; gap: 8px; padding: 0 10px; }
.brand small { font-family: var(--sans); font-size: 11px; font-weight: 500; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 6px; text-decoration: none; color: var(--ink-2); font-weight: 500; }
.nav a svg { width: 18px; height: 18px; stroke-width: 1.75; }
.nav a:hover { background: var(--wash); color: var(--ink); }
.nav a.on { color: var(--ink); background: var(--surface); box-shadow: inset 2px 0 0 var(--accent), 0 0 0 1px var(--rule); }
.side-foot { margin-top: auto; font-size: 13px; padding: 0 10px; display: flex; flex-direction: column; gap: 6px; }
.side-foot b { font-weight: 600; }
.linkish { background: none; border: 0; padding: 0; cursor: pointer; color: var(--ink-2); text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--rule-strong); font-size: 13px; text-align: left; }
.linkish:hover { color: var(--ink); text-decoration-color: currentColor; }

main { padding: 36px 44px 80px; max-width: 1280px; width: 100%; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; margin-bottom: 28px; padding-bottom: 18px; border-bottom: 1px solid var(--ink); }
.head h1 { font-family: var(--display); font-weight: 400; font-size: 40px; line-height: 1.05; letter-spacing: -.025em; }
.head .kicker { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; font-weight: 600; }
.head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Controls ──────────────────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 6px; border: 1px solid var(--rule-strong); background: var(--surface); cursor: pointer; font-weight: 500; font-size: 14px; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--ink-2); }
.btn svg { width: 16px; height: 16px; }
.btn.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.btn.primary:hover { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--wash); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }

.seg { display: inline-flex; border: 1px solid var(--rule-strong); border-radius: 6px; overflow: hidden; background: var(--surface); }
.seg button { border: 0; background: none; padding: 0 12px; height: 34px; cursor: pointer; font-size: 13px; font-weight: 500; color: var(--ink-2); border-right: 1px solid var(--rule); }
.seg button:last-child { border-right: 0; }
.seg button.on { background: var(--ink); color: var(--paper); }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--ink-2); letter-spacing: .02em; }
.input, select.input, textarea.input { height: 38px; border: 1px solid var(--rule-strong); background: var(--surface); border-radius: 6px; padding: 0 11px; width: 100%; }
textarea.input { height: auto; min-height: 72px; padding: 9px 11px; resize: vertical; }
.input:focus, .btn:focus-visible, .seg button:focus-visible, .nav a:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.input.date { width: auto; height: 34px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .search { width: 260px; }
.toolbar .spacer { flex: 1; }

/* ── Panels, KPIs ──────────────────────────────────────────────────────── */
.panel { background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; padding: 22px 24px; }
.panel h2 { font-family: var(--display); font-weight: 400; font-size: 20px; letter-spacing: -.01em; }
.panel .sub { font-size: 13px; color: var(--muted); }
.panel-head { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }

.kpis { display: grid; grid-template-columns: repeat(4, 1fr); border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); margin-bottom: 28px; }
.kpi { padding: 20px 22px 20px 0; border-right: 1px solid var(--rule); animation: rise .5s both; }
.kpi + .kpi { padding-left: 22px; }
.kpi:last-child { border-right: 0; }
.kpi:nth-child(2) { animation-delay: .05s; } .kpi:nth-child(3) { animation-delay: .1s; } .kpi:nth-child(4) { animation-delay: .15s; }
.kpi .label { font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-2); }
.kpi .value { font-family: var(--display); font-size: 38px; line-height: 1.15; letter-spacing: -.02em; margin: 6px 0 4px; }
.delta { font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.delta svg { width: 14px; height: 14px; stroke-width: 2.25; }
.delta.up { color: var(--good); } .delta.down { color: var(--bad); } .delta.flat { color: var(--muted); }
.delta .vs { color: var(--muted); font-weight: 400; }

.grid-2 { display: grid; grid-template-columns: 1.15fr 1fr; gap: 20px; margin-top: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; margin-top: 20px; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }

/* ── Charts ────────────────────────────────────────────────────────────── */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--rule-strong); stroke-width: 1; }
.chart .tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .line { fill: none; stroke: var(--series-1); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.chart .area { fill: var(--series-1-soft); }
.chart .ref { fill: none; stroke: var(--reference); stroke-width: 1.5; stroke-dasharray: 4 4; }
.chart .cross { stroke: var(--ink-2); stroke-width: 1; }
.chart .dot { fill: var(--series-1); stroke: var(--surface); stroke-width: 2; }
.chart .bar { fill: var(--series-1); }
.legend { display: flex; gap: 18px; font-size: 12px; color: var(--ink-2); }
.legend i { display: inline-block; width: 16px; height: 0; border-top: 2px solid var(--series-1); vertical-align: middle; margin-right: 6px; }
.legend i.ref { border-top: 2px dashed var(--reference); }
.tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--paper); border-radius: 6px; padding: 8px 10px; font-size: 12px; line-height: 1.45; white-space: nowrap; transform: translate(-50%, calc(-100% - 12px)); opacity: 0; transition: opacity .1s; z-index: 5; }
.tip.on { opacity: 1; }
.tip b { font-weight: 600; font-variant-numeric: tabular-nums; }
.tip .k { opacity: .7; }

.hbars { display: flex; flex-direction: column; gap: 12px; }
.hbar { display: grid; grid-template-columns: 92px 1fr auto; gap: 12px; align-items: center; font-size: 13px; }
.hbar .track { height: 10px; position: relative; }
.hbar .fill { position: absolute; inset: 0 auto 0 0; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; transition: width .5s cubic-bezier(.2, .7, .2, 1); }
.hbar .val { color: var(--ink-2); text-align: right; min-width: 92px; }

.rank { list-style: none; counter-reset: r; }
.rank li { counter-increment: r; display: grid; grid-template-columns: 22px 1fr auto; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--rule); font-size: 14px; align-items: baseline; }
.rank li:last-child { border-bottom: 0; }
.rank li::before { content: counter(r); font-family: var(--display); color: var(--muted); }
.rank .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank .name small { display: block; color: var(--muted); font-size: 12px; }
.rank .bar { grid-column: 2 / 4; height: 3px; background: var(--rule); border-radius: 2px; overflow: hidden; margin-top: 6px; }
.rank .bar span { display: block; height: 100%; background: var(--series-1); border-radius: 2px; }

/* ── Tables ────────────────────────────────────────────────────────────── */
.table-wrap { background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-2); font-weight: 600; padding: 12px 16px; border-bottom: 1px solid var(--ink); white-space: nowrap; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th .arrow { opacity: .7; }
td { padding: 11px 16px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr.click:hover td { background: var(--wash); }
td.r, th.r { text-align: right; }
td.mono { font-family: var(--mono); font-size: 13px; }
.empty { padding: 48px 20px; text-align: center; color: var(--muted); }
.empty h3 { font-family: var(--display); font-weight: 400; font-size: 22px; color: var(--ink); margin-bottom: 6px; }
.empty .btn { margin-top: 16px; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; font-size: 13px; color: var(--ink-2); }
.pager div { display: flex; gap: 6px; }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; }
.status svg { width: 14px; height: 14px; stroke-width: 2; }
.status.pending { color: #8a5a00; } .status.paid { color: var(--good); } .status.shipped { color: var(--ink-2); } .status.cancelled { color: var(--bad); }
@media (prefers-color-scheme: dark) { .status.pending { color: #fab219; } }
.pill { display: inline-block; font-size: 11px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; padding: 2px 8px; border-radius: 99px; border: 1px solid var(--rule-strong); color: var(--ink-2); }
.pill.admin { border-color: var(--accent); color: var(--accent); }

/* ── Modal, toast ──────────────────────────────────────────────────────── */
dialog { margin: auto; border: 1px solid var(--rule-strong); border-radius: 12px; background: var(--surface); color: var(--ink); width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; box-shadow: 0 30px 80px rgba(0, 0, 0, .25); }
dialog.wide { width: min(860px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(22, 21, 15, .45); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 24px 14px; border-bottom: 1px solid var(--rule); }
.modal-head h2 { font-family: var(--display); font-weight: 400; font-size: 24px; }
.modal-body { padding: 20px 24px; display: grid; gap: 14px; }
.modal-foot { display: flex; justify-content: space-between; gap: 8px; padding: 14px 24px 20px; }
.modal-foot .right { display: flex; gap: 8px; margin-left: auto; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.lines { display: grid; gap: 8px; }
.line-row { display: grid; grid-template-columns: 1.4fr 1.6fr 80px 110px 90px 32px; gap: 8px; align-items: center; }
.line-row .sum { text-align: right; font-size: 14px; }
.lines-head { font-size: 11px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.order-total { display: flex; justify-content: flex-end; gap: 16px; align-items: baseline; padding-top: 10px; border-top: 1px solid var(--rule); }
.order-total b { font-family: var(--display); font-size: 26px; font-weight: 400; }
.err { color: var(--bad); font-size: 13px; min-height: 1em; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 8px; font-size: 14px; opacity: 0; transition: .2s; pointer-events: none; z-index: 100; }
#toast.on { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--bad); color: #fff; }

/* ── Auth ──────────────────────────────────────────────────────────────── */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-art { background: var(--ink); color: var(--paper); padding: 56px; display: flex; flex-direction: column; justify-content: space-between; position: relative; overflow: hidden; }
.auth-art .brand { padding: 0; color: var(--paper); }
.auth-art h2 { font-family: var(--display); font-weight: 400; font-size: clamp(36px, 4.5vw, 60px); line-height: 1.02; letter-spacing: -.03em; max-width: 12ch; }
.auth-art h2 em { color: var(--accent); font-style: italic; }
.auth-art .ledger-lines { position: absolute; inset: 0; background: repeating-linear-gradient(to bottom, transparent 0 39px, rgba(244, 241, 234, .07) 39px 40px); pointer-events: none; }
.auth-art .ledger-lines::after { content: ''; position: absolute; top: 0; bottom: 0; left: 40px; border-left: 1px solid rgba(194, 65, 12, .5); }
.auth-art p { color: rgba(244, 241, 234, .65); max-width: 40ch; font-size: 14px; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 40px; }
.auth-form form { width: 100%; max-width: 360px; display: grid; gap: 16px; }
.auth-form h1 { font-family: var(--display); font-weight: 400; font-size: 32px; letter-spacing: -.02em; }
.auth-form .btn { height: 42px; justify-content: center; }

/* ── Import ────────────────────────────────────────────────────────────── */
.drop { border: 1.5px dashed var(--rule-strong); border-radius: 10px; padding: 32px; text-align: center; background: var(--surface); cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--wash); }
.drop svg { width: 28px; height: 28px; color: var(--muted); margin-bottom: 8px; }
.report { display: grid; grid-template-columns: repeat(4, auto) 1fr; gap: 24px; align-items: baseline; padding: 14px 0; }
.report b { font-family: var(--display); font-size: 28px; font-weight: 400; display: block; }
.report span { font-size: 12px; color: var(--ink-2); text-transform: uppercase; letter-spacing: .08em; }
.cols { font-family: var(--mono); font-size: 12px; color: var(--ink-2); }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.steps code { font-family: var(--mono); font-size: 12px; background: var(--wash); padding: 1px 5px; border-radius: 4px; }

@media (max-width: 1100px) {
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .kpi:nth-child(2) { border-right: 0; }
  .kpi:nth-child(3) { padding-left: 0; border-top: 1px solid var(--rule); }
  .kpi:nth-child(4) { border-top: 1px solid var(--rule); }
  .steps { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; padding: 14px 16px; gap: 12px; border-right: 0; border-bottom: 1px solid var(--rule); }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav a span { display: none; }
  .side-foot { margin: 0 0 0 auto; }
  main { padding: 24px 16px 60px; }
  .head h1 { font-size: 30px; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { min-height: 260px; padding: 32px; }
  .row-2, .row-3 { grid-template-columns: 1fr; }
  .line-row { grid-template-columns: 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
