/* ==========================================================================
   Northwind demo — design system + responsive shell
   Dark by default, light via [data-theme="light"]; all colour comes from
   custom properties so charts can read them too.
   ========================================================================== */

:root {
  --font-ui: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  --radius: 12px;
  --radius-sm: 8px;
  --gap: 16px;
  --shadow-1: 0 1px 2px rgb(15 23 42 / .08), 0 8px 24px -12px rgb(15 23 42 / .18);
  --shadow-2: 0 18px 48px -18px rgb(15 23 42 / .35);
  --sidebar-w: 236px;
  --rail-w: 66px;
}

html[data-theme="dark"] {
  --bg: #0a1020;
  --bg-grad: radial-gradient(1200px 700px at 8% -10%, #14263d 0%, transparent 55%),
             radial-gradient(900px 600px at 100% 0%, #16232f 0%, transparent 50%);
  --surface: #101a2c;
  --surface-2: #14233a;
  --surface-3: #1b2c46;
  --border: #22334e;
  --border-strong: #2f4667;
  --text-strong: #eef4ff;
  --text: #cbd8ea;
  --text-soft: #9fb2cc;
  --text-muted: #7c8fa9;
  --brand: #2dd4bf;
  --brand-ink: #052e2b;
  --accent: #60a5fa;
  --pos: #34d399;
  --neg: #f87171;
  --warn: #fbbf24;
  --chart-grid: #1e304b;
  --chart-hover: #38506f;
  --chart-band: rgb(45 212 191 / .07);
  --c1: #2dd4bf; --c2: #60a5fa; --c3: #f59e0b; --c4: #f472b6;
  --c5: #a78bfa; --c6: #4ade80; --c7: #fb7185; --c8: #38bdf8;
  --skeleton: linear-gradient(90deg, #17253c 25%, #1e304b 37%, #17253c 63%);
}

html[data-theme="light"] {
  --bg: #f4f7fb;
  --bg-grad: radial-gradient(900px 600px at 100% -10%, #dce9f7 0%, transparent 55%);
  --surface: #ffffff;
  --surface-2: #f7fafc;
  --surface-3: #eef3f9;
  --border: #dde5ee;
  --border-strong: #c6d3e2;
  --text-strong: #0f172a;
  --text: #24344b;
  --text-soft: #46586f;
  --text-muted: #6b7d94;
  --brand: #0f766e;
  --brand-ink: #ecfeff;
  --accent: #2563eb;
  --pos: #15803d;
  --neg: #b91c1c;
  --warn: #b45309;
  --chart-grid: #e6ecf4;
  --chart-hover: #b9c7d9;
  --chart-band: rgb(15 118 110 / .06);
  --c1: #0f766e; --c2: #2563eb; --c3: #d97706; --c4: #db2777;
  --c5: #7c3aed; --c6: #16a34a; --c7: #dc2626; --c8: #0ea5e9;
  --skeleton: linear-gradient(90deg, #eef2f7 25%, #e2e9f2 37%, #eef2f7 63%);
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }

/* The `hidden` attribute must beat any display rule below (.modal, .palette,
   .grid__bulk, .columns-menu, .chart-empty all set display explicitly). */
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  font-family: var(--font-ui);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
body.is-locked { overflow: hidden; }

h1, h2, h3, h4 { color: var(--text-strong); line-height: 1.22; font-weight: 650; letter-spacing: -.01em; }
h1 { font-size: clamp(1.35rem, 2.6vw, 1.85rem); }
h2 { font-size: 1.12rem; }
h3 { font-size: 1rem; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, kbd, pre { font-family: var(--font-mono); font-size: .86em; }
kbd {
  border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 5px;
  padding: 1px 5px; background: var(--surface-2); color: var(--text-soft); font-size: .78em;
}
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 1.05em; height: 1.05em; fill: none; stroke: currentColor; stroke-width: 1.7;
  stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--text-muted); font-size: .86rem; }
.strong { font-weight: 650; color: var(--text-strong); }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--brand); color: var(--brand-ink);
  padding: 8px 14px; z-index: 200; border-radius: 0 0 8px 0; }
.skip-link:focus { left: 0; }

/* ------------------------------------------------------------------ shell */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  grid-template-areas: "side top" "side main" "side foot";
  min-height: 100vh;
}
.sidebar {
  grid-area: side; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column;
  gap: 14px; padding: 18px 14px; background: color-mix(in srgb, var(--surface) 82%, transparent);
  border-right: 1px solid var(--border); backdrop-filter: blur(8px); z-index: 60;
}
.brand { display: flex; gap: 10px; align-items: center; color: var(--text-strong); }
.brand:hover { text-decoration: none; }
.brand__mark { color: var(--brand); display: grid; place-items: center; }
.brand__mark svg { width: 34px; height: 34px; }
.brand__text { display: flex; flex-direction: column; line-height: 1.15; }
.brand__text small { color: var(--text-muted); font-size: .72rem; letter-spacing: .04em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; overflow-y: auto; }
.nav__link {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--text-soft); font-weight: 520; font-size: .93rem;
}
.nav__link:hover { background: var(--surface-2); color: var(--text-strong); text-decoration: none; }
.nav__link.is-active { background: color-mix(in srgb, var(--brand) 16%, transparent);
  color: var(--text-strong); box-shadow: inset 2px 0 0 var(--brand); }
.sidebar__foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; }
.sidebar__meta { color: var(--text-muted); font-size: .74rem; padding-left: 4px; }

.topbar {
  grid-area: top; position: sticky; top: 0; z-index: 55; display: flex; align-items: center; gap: 12px;
  padding: 10px clamp(12px, 2vw, 22px); border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: blur(10px);
}
.topbar__menu { display: none; }
.crumbs { display: flex; align-items: center; gap: 8px; color: var(--text-muted); font-size: .88rem; min-width: 0; }
.crumbs a { color: var(--text-soft); display: inline-flex; }
.crumbs__sep { opacity: .55; }
.crumbs__current { color: var(--text-strong); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar__right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.search-pill {
  display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-muted);
  font: inherit; font-size: .85rem; cursor: pointer; min-width: 0;
}
.search-pill span { max-width: 34ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-pill:hover { border-color: var(--border-strong); color: var(--text-soft); }

.main { grid-area: main; padding: clamp(14px, 2.4vw, 26px); display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.foot { grid-area: foot; display: flex; flex-wrap: wrap; gap: 8px; justify-content: space-between;
  padding: 14px clamp(12px, 2vw, 26px) 22px; color: var(--text-muted); font-size: .8rem; border-top: 1px solid var(--border); }
.foot__links { display: flex; gap: 14px; align-items: center; }
.foot__links button { background: none; border: 0; color: inherit; font: inherit; cursor: pointer; text-decoration: underline; }

.nav-scrim { position: fixed; inset: 0; background: rgb(3 8 18 / .55); z-index: 59; }

/* ------------------------------------------------------------ page pieces */
.page-head { display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end; justify-content: space-between; }
.page-head__sub { color: var(--text-muted); max-width: 70ch; margin-top: 4px; font-size: .9rem; }
.page-head__actions { display: flex; flex-wrap: wrap; gap: 8px; }
.eyebrow { text-transform: uppercase; letter-spacing: .09em; font-size: .72rem; color: var(--text-muted); font-weight: 600; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-1); }

.range-chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.range-form { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-soft);
  font-size: .78rem; white-space: nowrap;
}
a.chip:hover { border-color: var(--border-strong); text-decoration: none; color: var(--text-strong); }
.chip.is-active { background: color-mix(in srgb, var(--brand) 18%, transparent); border-color: var(--brand); color: var(--text-strong); }
.chip b { color: var(--text-strong); font-weight: 650; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface-2); color: var(--text);
  font: inherit; font-size: .87rem; font-weight: 550; cursor: pointer; white-space: nowrap;
  transition: transform .12s ease, border-color .12s ease, background .12s ease;
}
.btn:hover { border-color: var(--brand); color: var(--text-strong); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: progress; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 650; }
.btn--primary:hover { filter: brightness(1.08); color: var(--brand-ink); }
.btn--danger { background: color-mix(in srgb, var(--neg) 14%, transparent); border-color: color-mix(in srgb, var(--neg) 55%, transparent); color: var(--neg); }
.btn--ghost { background: transparent; border-color: var(--border); color: var(--text-muted); }
.btn--sm { padding: 5px 9px; font-size: .8rem; }
.btn--block { width: 100%; justify-content: center; }
.icon-btn { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text-soft); cursor: pointer; }
.icon-btn:hover { color: var(--text-strong); border-color: var(--border-strong); }
.icon-btn--danger { color: var(--neg); border-color: color-mix(in srgb, var(--neg) 40%, transparent); background: transparent; }

/* inputs */
input[type="search"], input[type="text"], input[type="number"], input[type="date"],
input[type="datetime-local"], input[type="tel"], input[type="url"], select, textarea {
  font: inherit; font-size: .88rem; color: var(--text-strong); background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 7px 9px; width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible, .btn:focus-visible,
.icon-btn:focus-visible, .nav__link:focus-visible, .chip:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 1px;
}
::placeholder { color: var(--text-muted); }

/* ------------------------------------------------------------------- KPIs */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr)); }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 15px; position: relative; overflow: hidden; box-shadow: var(--shadow-1); }
.kpi__label { color: var(--text-muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .07em; font-weight: 600; }
.kpi__value { color: var(--text-strong); font-size: clamp(1.35rem, 2.4vw, 1.85rem); font-weight: 680; margin-top: 6px; letter-spacing: -.02em; }
.kpi__delta { display: inline-flex; align-items: center; gap: 3px; font-size: .78rem; font-weight: 600; margin-top: 4px; }
.kpi__delta.is-up { color: var(--pos); } .kpi__delta.is-down { color: var(--neg); }
.kpi__delta .icon { width: .9em; height: .9em; stroke-width: 2.4; }
.kpi__hint { color: var(--text-muted); font-size: .76rem; margin-top: 4px; }
.kpi__spark { position: absolute; right: 0; bottom: 0; left: 0; height: 38px; opacity: .85; pointer-events: none; }

.ops-strip { display: grid; gap: 1px; background: var(--border); border-radius: var(--radius);
  overflow: hidden; grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr)); }
.stat { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; background: var(--surface); color: var(--text-soft); }
a.stat:hover { background: var(--surface-2); text-decoration: none; }
.stat b { color: var(--text-strong); font-size: 1.16rem; font-weight: 660; }
.stat span { color: var(--text-muted); font-size: .76rem; }
.stat.is-warn b { color: var(--warn); }

/* ----------------------------------------------------------------- charts */
.charts-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 330px), 1fr)); }
.charts-grid--two { grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.chart-card { display: flex; flex-direction: column; padding: 12px 14px 8px; }
.chart-card__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.chart-card__head h3 { font-size: .95rem; }
.chart-card__legend { display: flex; flex-wrap: wrap; gap: 10px; }
.legend__item { display: inline-flex; align-items: center; gap: 5px; color: var(--text-muted); font-size: .76rem; }
.legend__dot { width: 9px; height: 9px; border-radius: 3px; display: inline-block; flex: none; }
.chart-card__body { position: relative; margin-top: 8px; height: clamp(180px, 24vh, 280px); }
.chart-card--wide .chart-card__body { height: clamp(210px, 30vh, 330px); }
.chart-card__body canvas { width: 100%; height: 100%; display: block; }
.chart-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--text-muted); font-size: .85rem; }
.chart-tip { position: absolute; z-index: 5; pointer-events: none; background: var(--surface-3);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 7px 9px; min-width: 130px;
  box-shadow: var(--shadow-2); font-size: .78rem; }
.chart-tip__head { color: var(--text-strong); font-weight: 650; margin-bottom: 4px; }
.chart-tip__row { display: flex; align-items: center; gap: 6px; color: var(--text-soft); }
.chart-tip__row b { font-weight: 550; } .chart-tip__row em { margin-left: auto; font-style: normal; color: var(--text-strong); font-variant-numeric: tabular-nums; }

.split-3 { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.panel { padding: 14px; }
.panel__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 10px; }

.feed { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 320px; overflow: auto; }
.feed__item { display: flex; gap: 9px; align-items: baseline; font-size: .85rem; border-bottom: 1px dashed var(--border); padding-bottom: 7px; }
.feed__item:last-child { border-bottom: 0; }
.feed__text a { color: var(--text-strong); font-weight: 550; }
.feed__text em { display: block; color: var(--text-muted); font-style: normal; font-size: .76rem; }

/* ------------------------------------------------------------------ grids */
.grid { padding: 0; overflow: hidden; }
.grid__head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--border); }
.grid__titles h2 { font-size: 1.05rem; }
.grid__blurb { color: var(--text-muted); font-size: .82rem; }
.grid__summary { display: flex; flex-wrap: wrap; gap: 6px; }
.grid__actions { display: flex; flex-wrap: wrap; gap: 8px; margin-left: auto; }

.grid__tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; padding: 12px 16px;
  border-bottom: 1px solid var(--border); background: var(--surface-2); position: relative; }
.tool { display: flex; flex-direction: column; gap: 4px; min-width: 150px; flex: 1 1 170px; }
.tool > span { color: var(--text-muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.tool--search { position: relative; flex: 1 1 240px; }
.tool--search .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.tool--search input { padding-left: 30px; }
.tool--range { flex-direction: row; align-items: center; gap: 6px; flex-wrap: wrap; flex: 1 1 240px; }
.tool--range > span { flex: 1 1 100%; }
.tool--pager-size { flex: 0 0 auto; min-width: 110px; max-width: 130px; }

.columns-menu { position: absolute; right: 16px; top: calc(100% - 6px); z-index: 20; display: grid;
  gap: 4px; padding: 10px 12px; background: var(--surface-3); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); box-shadow: var(--shadow-2); max-height: 320px; overflow: auto; min-width: 190px; }
.columns-menu label { display: flex; gap: 8px; align-items: center; font-size: .84rem; color: var(--text-soft); cursor: pointer; }

.grid__bulk { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 9px 16px;
  background: color-mix(in srgb, var(--brand) 12%, transparent); border-bottom: 1px solid var(--border); }
.grid__bulk b { color: var(--text-strong); }
[data-bulk-actions] { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-left: auto; }
.bulk__select { width: auto; min-width: 150px; }

.grid__scroll { overflow-x: auto; overflow-y: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: .87rem; }
.table th, .table td { padding: 9px 12px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: middle; }
.table thead th { position: sticky; top: 0; z-index: 4; background: var(--surface-2); color: var(--text-muted);
  font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 650; white-space: nowrap; }
.table thead th::after { content: ""; }
.table thead tr { box-shadow: inset 0 -1px 0 var(--border); }
.table th a[data-sort] { display: inline-flex; gap: 4px; align-items: center; color: inherit; text-decoration: none; }
.table th a[data-sort]:hover { color: var(--text-strong); text-decoration: none; }
.table th.is-sorted-asc a[data-sort], .table th.is-sorted-desc a[data-sort] { color: var(--brand); }
.sortmark { font-size: .9em; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr.is-selected { background: color-mix(in srgb, var(--brand) 12%, transparent); }
.table tbody tr.is-loading td { padding: 11px 12px; }
.skeleton { display: block; height: 10px; border-radius: 5px; background: var(--skeleton);
  background-size: 300% 100%; animation: shimmer 1.2s infinite linear; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.empty-row td { color: var(--text-muted); padding: 22px 12px; text-align: center; }
.rowlink { color: var(--text-strong); font-weight: 600; }
.rowlink:hover { color: var(--brand); }
.is-hidden { display: none !important; }
.align-right { text-align: right; font-variant-numeric: tabular-nums; }
.align-center { text-align: center; }
.cell--money, .cell--int, .cell--num, .cell--pct1 { font-variant-numeric: tabular-nums; }
.col-check { width: 34px; padding-left: 14px; }
.col-check input { accent-color: var(--brand); width: 15px; height: 15px; cursor: pointer; }
.table--mini { font-size: .82rem; }
.table--mini th, .table--mini td { padding: 7px 9px; }

.grid__foot { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
  padding: 11px 16px; border-top: 1px solid var(--border); background: var(--surface-2); }
.grid__count { color: var(--text-muted); font-size: .8rem; }
.pager { display: flex; gap: 4px; align-items: center; }
.pager__btn, .pager__num { display: inline-grid; place-items: center; min-width: 32px; height: 30px; padding: 0 8px;
  border-radius: var(--radius-sm); border: 1px solid var(--border); color: var(--text-soft); font-size: .82rem; background: var(--surface); }
.pager__num:hover, .pager__btn:hover { text-decoration: none; border-color: var(--border-strong); color: var(--text-strong); }
.pager__num.is-active { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 650; }
.pager__btn.is-off { opacity: .35; pointer-events: none; }
.pager__gap { color: var(--text-muted); padding: 0 4px; }

/* badges */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px;
  font-size: .74rem; font-weight: 600; text-transform: capitalize; white-space: nowrap;
  border: 1px solid transparent; background: var(--surface-3); color: var(--text-soft); }
.badge--delivered, .badge--in-stock, .badge--ok, .badge--create { background: color-mix(in srgb, var(--pos) 16%, transparent); color: var(--pos); border-color: color-mix(in srgb, var(--pos) 35%, transparent); }
.badge--shipped, .badge--neutral, .badge--update, .badge--undo-delete { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.badge--processing, .badge--low-stock, .badge--warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); }
.badge--picked { background: color-mix(in srgb, var(--c5) 18%, transparent); color: var(--c5); border-color: color-mix(in srgb, var(--c5) 40%, transparent); }
.badge--cancelled, .badge--out-of-stock, .badge--danger, .badge--delete { background: color-mix(in srgb, var(--neg) 16%, transparent); color: var(--neg); border-color: color-mix(in srgb, var(--neg) 38%, transparent); }
.badge--draft, .badge--chip { background: var(--surface-3); color: var(--text-muted); border-color: var(--border); }
.badge--discontinued { background: var(--surface-3); color: var(--text-muted); border-color: var(--border-strong); }
.badge--stock-adjust, .badge--lines-replaced, .badge--seed { background: color-mix(in srgb, var(--brand) 16%, transparent); color: var(--brand); border-color: color-mix(in srgb, var(--brand) 35%, transparent); }

/* --------------------------------------------------------------- detail */
.detail-layout { display: grid; gap: 12px; grid-template-columns: minmax(280px, 330px) minmax(0, 1fr); align-items: start; }
.facts { padding: 14px; }
.facts__list { display: flex; flex-direction: column; gap: 9px; }
.facts__list > div { display: grid; grid-template-columns: 96px 1fr; gap: 8px; border-bottom: 1px dashed var(--border); padding-bottom: 7px; }
.facts__list dt { color: var(--text-muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; }
.facts__list dd { color: var(--text); font-size: .88rem; }
.facts__notes { margin-top: 12px; color: var(--text-soft); font-size: .86rem; border-left: 2px solid var(--brand); padding-left: 10px; }
.detail-main { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.grid-block { display: flex; }
.grid-block > .grid { flex: 1; }

.status-flow { display: flex; flex-wrap: wrap; gap: 6px; padding: 10px 12px; align-items: center; }
.status-step { position: relative; flex: 1 1 120px; text-align: center; padding: 8px 10px; border-radius: var(--radius-sm);
  border: 1px dashed var(--border-strong); background: transparent; color: var(--text-muted); font: inherit;
  font-size: .8rem; text-transform: capitalize; cursor: pointer; }
.status-step:hover { color: var(--text-strong); border-color: var(--brand); }
.status-step.is-done { color: var(--text-soft); border-style: solid; border-color: var(--border-strong); background: var(--surface-2); }
.status-step.is-active { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 650; }

.editor { padding: 14px; }
.editor__head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.editor__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.editor__scroll { overflow-x: auto; }
.editor__table { min-width: 640px; }
.editor__table td { padding: 6px 8px; }
.editor__table tfoot th { color: var(--text-muted); font-weight: 550; font-size: .82rem; }
.editor__table tfoot td { font-variant-numeric: tabular-nums; color: var(--text-strong); }
.editor__table tr.is-total td, .editor__table tr.is-total th { border-top: 1px solid var(--border-strong); padding-top: 8px; font-weight: 700; }
.cell-input { width: 100%; padding: 6px 7px; text-align: right; }
.w-qty { max-width: 74px; } .w-price { max-width: 104px; } .w-disc { max-width: 68px; }
.editor__table select { min-width: 220px; }

.stock-adjust { margin-top: 16px; border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.stock-adjust h4 { font-size: .84rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); }
.stock-adjust__btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* -------------------------------------------------------------- reports */
.report-layout { display: grid; gap: 12px; grid-template-columns: minmax(240px, 290px) minmax(0, 1fr); align-items: start; }
.report-nav { padding: 8px; display: flex; flex-direction: column; gap: 2px; position: sticky; top: 72px; }
.report-nav__item { display: flex; gap: 10px; padding: 9px 10px; border-radius: var(--radius-sm); color: var(--text-soft); align-items: flex-start; }
.report-nav__item:hover { background: var(--surface-2); text-decoration: none; color: var(--text-strong); }
.report-nav__item.is-active { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--text-strong); box-shadow: inset 2px 0 0 var(--brand); }
.report-nav__item span { display: flex; flex-direction: column; }
.report-nav__item small { color: var(--text-muted); font-size: .76rem; line-height: 1.35; }
.report-body { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.table-shell { overflow-x: auto; }
.th-sort { background: none; border: 0; color: inherit; font: inherit; font-size: .74rem; text-transform: uppercase;
  letter-spacing: .06em; cursor: pointer; padding: 0; }
.th-sort:hover { color: var(--text-strong); }
.th-sort.is-sorted { color: var(--brand); }

.cell-diff { max-width: 380px; }
.diff { list-style: none; padding: 0; display: flex; flex-direction: column; gap: 3px; font-size: .78rem; }
.diff b { color: var(--text-soft); }
.diff s { color: var(--text-muted); }
.diff i { font-style: normal; color: var(--brand); }

/* ----------------------------------------------------------- api + error */
.api-layout { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.api-card { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.api-card h2 { font-size: 1.02rem; } .api-card h3 { margin-top: 8px; font-size: .9rem; }
.api-table { width: 100%; border-collapse: collapse; font-size: .85rem; }
.api-table td { padding: 7px 6px; border-bottom: 1px dashed var(--border); vertical-align: top; }
.param-list { padding-left: 18px; display: flex; flex-direction: column; gap: 5px; font-size: .85rem; }
.try { display: flex; gap: 8px; }
.try input { flex: 1; font-family: var(--font-mono); }
.try__out { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px; overflow: auto; max-height: 460px; font-size: .78rem; white-space: pre-wrap; color: var(--text-soft); }
.try__out.is-error { color: var(--neg); }

.error-page { padding: 40px 24px; text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.error-page__code { font-size: 3.6rem; font-weight: 700; color: var(--brand); letter-spacing: -.03em; }
.error-page__actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 10px; }

/* ---------------------------------------------------------- overlays */
.toasts { position: fixed; right: 14px; bottom: 14px; z-index: 120; display: flex; flex-direction: column; gap: 8px; max-width: min(94vw, 400px); }
.toast { display: flex; align-items: center; gap: 10px; background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius); padding: 11px 12px; box-shadow: var(--shadow-2);
  opacity: 0; transform: translateY(8px); transition: opacity .2s ease, transform .2s ease; }
.toast.is-in { opacity: 1; transform: none; }
.toast--ok { border-left: 3px solid var(--pos); }
.toast--error { border-left: 3px solid var(--neg); }
.toast__msg { font-size: .86rem; font-weight: 550; color: var(--text-strong); }
.toast__detail { font-size: .78rem; color: var(--text-muted); }
.toast__action { background: var(--brand); color: var(--brand-ink); border: 0; border-radius: var(--radius-sm);
  padding: 6px 10px; font: inherit; font-size: .8rem; font-weight: 650; cursor: pointer; }
.toast__close { background: none; border: 0; color: var(--text-muted); font-size: 1.1rem; cursor: pointer; line-height: 1; }

.modal { position: fixed; inset: 0; z-index: 130; display: grid; place-items: center; padding: 16px; }
.modal__backdrop { position: absolute; inset: 0; background: rgb(4 9 18 / .62); backdrop-filter: blur(3px); }
.modal__panel { position: relative; width: min(100%, 560px); max-height: 88vh; overflow: auto; background: var(--surface);
  border: 1px solid var(--border-strong); border-radius: 14px; box-shadow: var(--shadow-2); display: flex; flex-direction: column; }
.modal[data-size="lg"] .modal__panel { width: min(100%, 760px); }
.modal[data-size="sm"] .modal__panel { width: min(100%, 430px); }
.modal__head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.modal__body { padding: 16px; overflow: auto; }
.modal__foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface-2); }

.form-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field--textarea, .field--checkbox { grid-column: 1 / -1; }
.field label { color: var(--text-muted); font-size: .76rem; text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.field__help { color: var(--text-muted); font-size: .76rem; }
.field__error { color: var(--neg); font-size: .78rem; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--neg); background: color-mix(in srgb, var(--neg) 8%, var(--surface-2)); }
.field--checkbox { flex-direction: row; align-items: center; gap: 8px; }
.field--checkbox label { text-transform: none; letter-spacing: 0; font-size: .86rem; color: var(--text); }
.field--checkbox input { width: 16px; height: 16px; accent-color: var(--brand); }
.confirm__warn { color: var(--text-muted); font-size: .82rem; margin-top: 8px; }
.shortcut-table { width: 100%; border-collapse: collapse; font-size: .86rem; }
.shortcut-table td { padding: 6px 4px; border-bottom: 1px dashed var(--border); }

.palette { position: fixed; inset: 0; z-index: 140; display: grid; place-items: start center; padding: 12vh 16px 16px;
  background: rgb(4 9 18 / .55); backdrop-filter: blur(3px); }
.palette__panel { width: min(100%, 640px); background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: 14px; box-shadow: var(--shadow-2); overflow: hidden; display: flex; flex-direction: column; }
.palette__input { border: 0; border-bottom: 1px solid var(--border); border-radius: 0; padding: 14px 16px; font-size: 1rem; background: transparent; }
.palette__results { max-height: 52vh; overflow: auto; padding: 6px; }
.palette__item { display: grid; grid-template-columns: 76px 1fr auto; gap: 10px; align-items: center; padding: 9px 11px;
  border-radius: var(--radius-sm); color: var(--text); }
.palette__item:hover, .palette__item.is-active { background: var(--surface-2); text-decoration: none; }
.palette__item.is-active { outline: 1px solid var(--border-strong); }
.palette__kind { color: var(--text-muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; }
.palette__label { font-weight: 550; color: var(--text-strong); }
.palette__sub { color: var(--text-muted); font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.palette__foot { display: flex; justify-content: space-between; gap: 10px; padding: 9px 14px; border-top: 1px solid var(--border);
  background: var(--surface-2); color: var(--text-muted); font-size: .78rem; }

/* --------------------------------------------------------- print styles */
@media print {
  .sidebar, .topbar, .foot, .toasts, .grid__actions, .grid__tools, .pager, .editor__actions,
  .status-flow, .page-head__actions, .range-chips { display: none !important; }
  body { background: #fff; color: #111; }
  .shell { grid-template-columns: 1fr; }
  .card { box-shadow: none; border-color: #ccc; }
}

/* -------------------------------------------------------- breakpoints */
@media (max-width: 1240px) {
  .shell { grid-template-columns: var(--rail-w) minmax(0, 1fr); }
  .sidebar { padding: 16px 8px; align-items: center; }
  .brand__text, .nav__link span, .sidebar__foot span, .sidebar__meta { display: none; }
  .nav__link { justify-content: center; padding: 10px; }
  .sidebar__foot .btn { padding: 8px; }
  .sidebar__foot kbd { display: none; }
}

@media (max-width: 1020px) {
  .detail-layout, .report-layout { grid-template-columns: minmax(0, 1fr); }
  .report-nav { position: static; flex-direction: row; overflow-x: auto; }
  .report-nav__item { min-width: 210px; }
}

@media (max-width: 860px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "main" "foot"; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: min(84vw, 290px); padding: 18px 14px;
    transform: translateX(-105%); transition: transform .22s ease; box-shadow: var(--shadow-2); }
  .sidebar .brand__text, .sidebar .nav__link span, .sidebar .sidebar__meta, .sidebar .sidebar__foot span { display: initial; }
  .sidebar .nav__link { justify-content: flex-start; padding: 10px 12px; }
  body.nav-open .sidebar { transform: none; }
  .topbar__menu { display: inline-grid; }
  .search-pill span, .search-pill kbd { display: none; }
  .grid__actions { margin-left: 0; width: 100%; }
  .table thead th { position: static; }
  .charts-grid, .charts-grid--two { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 620px) {
  body { font-size: 14.5px; }
  .grid__tools { gap: 8px; }
  .tool { flex: 1 1 100%; }
  .columns-menu { right: 8px; left: 8px; }
  .btn span { display: none; }
  .btn { padding: 8px 10px; }
  .grid__head, .grid__foot { padding: 12px; }
  .kpi__value { font-size: 1.4rem; }
  .facts__list > div { grid-template-columns: 1fr; }
  .editor__table select { min-width: 160px; }
}

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