/* StockPulse — inventory dashboard. Teal brand, slate neutrals. */
:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #e3e8ee;
  --text: #0f1b2a;
  --text-2: #4a5768;
  --muted: #637083;
  --brand: #0f766e;
  --brand-2: #115e59;
  --brand-soft: #ddf3f0;
  --side-bg: #0c1a24;
  --side-text: #c8d3dc;
  --side-active: #16323d;
  --good: #1a7f45; --good-bg: #e2f5ea;
  --warn: #9a5b00; --warn-bg: #fff1d6;
  --crit: #b42318; --crit-bg: #fde6e4;
  --series-in: #2a78d6;
  --series-out: #eb6834;
  --bar: #0f766e;
  --grid: #e9edf2;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 8px 24px -12px rgba(16, 24, 40, .12);
  --r: 14px;
  --side-w: 248px;
  --side-w-collapsed: 76px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, "SF Mono", monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0b1219; --surface: #121c26; --surface-2: #17232f; --border: #243241;
    --text: #e8eef4; --text-2: #b4c0cc; --muted: #93a1b0;
    --brand: #2dd4bf; --brand-2: #5eead4; --brand-soft: #123a3a;
    --side-bg: #070d13; --side-active: #13303a;
    --good: #5fd08f; --good-bg: #123325; --warn: #f5b84a; --warn-bg: #3a2c10; --crit: #ff8a80; --crit-bg: #3d1a18;
    --series-in: #3987e5; --series-out: #d95926; --bar: #2dd4bf; --grid: #223040;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1219; --surface: #121c26; --surface-2: #17232f; --border: #243241;
  --text: #e8eef4; --text-2: #b4c0cc; --muted: #93a1b0;
  --brand: #2dd4bf; --brand-2: #5eead4; --brand-soft: #123a3a;
  --side-bg: #070d13; --side-active: #13303a;
  --good: #5fd08f; --good-bg: #123325; --warn: #f5b84a; --warn-bg: #3a2c10; --crit: #ff8a80; --crit-bg: #3d1a18;
  --series-in: #3987e5; --series-out: #d95926; --bar: #2dd4bf; --grid: #223040;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px -12px rgba(0,0,0,.5);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 400 15px/1.5 var(--font); color: var(--text); background: var(--bg); overflow-x: hidden; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0; }
ul { margin: 0; padding: 0; list-style: none; }
a { color: var(--brand); }
svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
:focus-visible { outline: 2.5px solid var(--brand); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
code { font-family: var(--mono); font-size: .85em; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; border: 1px solid var(--border); }
.skip-link { position: absolute; top: -50px; left: 10px; background: var(--brand); color: #fff; padding: 8px 14px; border-radius: 8px; z-index: 300; }
.skip-link:focus { top: 10px; }
.back-link {
  position: fixed; right: 14px; bottom: 14px; z-index: 60; text-decoration: none;
  background: var(--text); color: var(--surface); font: 600 12px/1 var(--font); padding: 9px 13px; border-radius: 999px; box-shadow: var(--shadow); opacity: .9;
}
.back-link:hover { opacity: 1; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 42px; padding: 0 16px; border-radius: 10px; border: 1px solid transparent; font-weight: 600; font-size: 14px; white-space: nowrap; text-decoration: none; transition: background .15s, border-color .15s; }
.btn svg { width: 18px; height: 18px; stroke-width: 2.2; }
.btn-primary { background: var(--brand); color: #fff; }
:root[data-theme="dark"] .btn-primary { color: #04201d; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn-primary { color: #04201d; } }
.btn-primary:hover { background: var(--brand-2); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--crit); color: #fff; }
:root[data-theme="dark"] .btn-danger { color: #2a0906; }
.icon-btn { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text-2); position: relative; font-size: 22px; line-height: 1; }
.icon-btn:hover { color: var(--text); background: var(--surface-2); }

/* Layout */
.app { display: grid; grid-template-columns: var(--side-w) 1fr; min-height: 100vh; transition: grid-template-columns .25s; }
.app.collapsed { grid-template-columns: var(--side-w-collapsed) 1fr; }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--side-bg); color: var(--side-text); display: flex; flex-direction: column; padding: 18px 14px; overflow: hidden; z-index: 50; }
.side-brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px 22px; }
.logo { width: 38px; height: 38px; border-radius: 11px; background: linear-gradient(135deg, #14b8a6, #0f766e); display: grid; place-items: center; color: #fff; flex: none; }
.logo svg { stroke-width: 2.4; }
.brand-name { font-weight: 800; font-size: 18px; color: #fff; letter-spacing: -.01em; }
.side-nav { display: flex; flex-direction: column; gap: 4px; }
.side-nav a { display: flex; align-items: center; gap: 12px; min-height: 44px; padding: 0 12px; border-radius: 10px; color: var(--side-text); text-decoration: none; font-weight: 500; white-space: nowrap; position: relative; }
.side-nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.side-nav a[aria-current="page"] { background: var(--side-active); color: #fff; }
.side-nav a[aria-current="page"]::before { content: ""; position: absolute; left: -14px; top: 10px; bottom: 10px; width: 3px; border-radius: 0 3px 3px 0; background: #2dd4bf; }
.side-badge { margin-left: auto; background: #f59e0b; color: #1f1300; font-size: 11px; font-weight: 700; border-radius: 999px; padding: 1px 7px; }
.side-foot { margin-top: auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; border-top: 1px solid rgba(255,255,255,.08); padding-top: 14px; }
.side-user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.side-user strong { display: block; color: #fff; font-size: 13px; white-space: nowrap; }
.side-user small { font-size: 12px; opacity: .7; white-space: nowrap; }
.avatar { width: 36px; height: 36px; border-radius: 50%; background: #334155; color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; flex: none; }
.collapse-btn { width: 36px; height: 36px; border-radius: 9px; border: 1px solid rgba(255,255,255,.12); background: transparent; color: var(--side-text); display: grid; place-items: center; flex: none; }
.collapse-btn svg { transition: transform .25s; }
.app.collapsed .collapse-btn svg { transform: rotate(180deg); }
.app.collapsed .side-label, .app.collapsed .side-badge { display: none; }
.app.collapsed .side-nav a { justify-content: center; padding: 0; }
.app.collapsed .side-foot { flex-direction: column; }
.app.collapsed .side-brand { justify-content: center; padding-inline: 0; }
.app.collapsed .side-nav a[aria-current="page"]::before { left: -14px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 14px; padding: 14px 28px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); }
.menu-btn { display: none; }
.page-title { font-size: 22px; font-weight: 750; letter-spacing: -.02em; min-width: 0; }
.top-search { margin-left: auto; position: relative; width: min(360px, 32vw); }
.top-search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 18px; height: 18px; }
.top-search input { width: 100%; height: 42px; padding: 0 36px 0 38px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); }
.top-search input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
.top-search kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); font: 600 11px var(--mono); color: var(--muted); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.i-sun { display: none; }
:root[data-theme="dark"] .i-sun { display: block; } :root[data-theme="dark"] .i-moon { display: none; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .i-sun { display: block; } :root:not([data-theme="light"]) .i-moon { display: none; } }
.dot-count { position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px; background: var(--crit); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; border: 2px solid var(--bg); }
.alerts { position: relative; }
.alert-panel { position: absolute; right: 0; top: calc(100% + 10px); width: 320px; max-width: calc(100vw - 24px); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: 0 20px 40px -12px rgba(0,0,0,.25); padding: 8px; z-index: 70; }
.panel-title { font-weight: 700; padding: 8px 10px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.alert-panel li button { width: 100%; display: flex; align-items: center; gap: 10px; text-align: left; border: 0; background: transparent; padding: 8px 10px; border-radius: 8px; }
.alert-panel li button:hover { background: var(--surface-2); }
.alert-panel li small { display: block; color: var(--muted); }

.content { padding: 24px 28px 64px; outline: none; flex: 1; }
.app-foot { margin-top: 36px; color: var(--muted); font-size: 12.5px; }
.app-foot a { color: inherit; }

/* Panels & KPIs */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); box-shadow: var(--shadow); padding: 20px; min-width: 0; }
.panel h2 { font-size: 16px; font-weight: 700; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 14px; }
.panel-head .muted { font-size: 13px; }
.link { font-size: 13px; font-weight: 600; text-decoration: none; white-space: nowrap; padding: 6px 0; }
.link:hover { text-decoration: underline; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 16px; }
.kpi { position: relative; overflow: hidden; }
.kpi-label { font-size: 13px; color: var(--muted); font-weight: 600; display: flex; align-items: center; gap: 8px; }
.kpi-icon { width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; background: var(--brand-soft); color: var(--brand); }
.kpi-icon svg { width: 17px; height: 17px; }
.kpi-value { font-size: 30px; font-weight: 750; letter-spacing: -.02em; margin: 10px 0 4px; font-variant-numeric: tabular-nums; }
.kpi-foot { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.delta { font-weight: 700; border-radius: 6px; padding: 1px 6px; }
.delta.up { color: var(--good); background: var(--good-bg); }
.delta.down { color: var(--crit); background: var(--crit-bg); }
.kpi.alert .kpi-icon { background: var(--warn-bg); color: var(--warn); }
.kpi.danger .kpi-icon { background: var(--crit-bg); color: var(--crit); }
.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; margin-bottom: 16px; }
.grid-2 + .grid-2 { grid-template-columns: 1fr 1fr; }

/* Charts */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 0 10px; height: 32px; border-radius: 7px; font-size: 13px; font-weight: 600; color: var(--muted); min-width: 40px; }
.seg button[aria-pressed="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); margin-bottom: 6px; }
.legend li { display: flex; align-items: center; gap: 6px; }
.sw { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sw-in { background: var(--series-in); } .sw-out { background: var(--series-out); }
.chart { position: relative; width: 100%; }
.chart svg { width: 100%; height: auto; display: block; overflow: visible; stroke: none; }
.chart text { fill: var(--muted); font: 500 11px var(--font); }
.chart .val { fill: var(--text-2); font-weight: 600; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .baseline { stroke: var(--border); stroke-width: 1; }
.chart .hit { fill: transparent; cursor: crosshair; }
.chart .hit:hover, .chart .hit:focus { fill: color-mix(in srgb, var(--text) 5%, transparent); outline: none; }
.chart .b-in { fill: var(--series-in); } .chart .b-out { fill: var(--series-out); } .chart .b-cat { fill: var(--bar); }
.tooltip { position: fixed; z-index: 90; pointer-events: none; background: var(--text); color: var(--surface); border-radius: 8px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 8px 20px rgba(0,0,0,.2); min-width: 120px; }
.tooltip strong { display: block; margin-bottom: 2px; }
.tooltip .row { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.tooltip .row span { display: flex; align-items: center; gap: 6px; }
.data-table { margin-top: 10px; font-size: 13px; }
.data-table summary { cursor: pointer; color: var(--muted); font-weight: 600; padding: 4px 0; }
.table-scroll { overflow-x: auto; max-height: 240px; }
.data-table table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.data-table th, .data-table td { text-align: left; padding: 5px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table td:not(:first-child), .data-table th:not(:first-child) { text-align: right; font-variant-numeric: tabular-nums; }

/* Lists */
.low-list li, .activity li { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.low-list li:last-child, .activity li:last-child { border: 0; }
.thumb { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; flex: none; background: var(--surface-2); border: 1px solid var(--border); }
.thumb.ph { display: grid; place-items: center; font-weight: 700; font-size: 13px; color: var(--brand); background: var(--brand-soft); }
.li-main { min-width: 0; flex: 1; }
.li-main strong { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-main small { color: var(--muted); font-size: 12.5px; }
.meter { height: 6px; border-radius: 3px; background: var(--surface-2); border: 1px solid var(--border); margin-top: 6px; overflow: hidden; max-width: 220px; }
.meter i { display: block; height: 100%; background: var(--warn); border-radius: 3px; }
.meter.crit i { background: var(--crit); }
.btn-sm { min-height: 36px; padding: 0 12px; font-size: 13px; border-radius: 8px; }
.mv-ico { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none; font-weight: 800; font-size: 15px; }
.mv-in { background: color-mix(in srgb, var(--series-in) 16%, transparent); color: var(--series-in); }
.mv-out { background: color-mix(in srgb, var(--series-out) 16%, transparent); color: var(--series-out); }
.mv-adjust { background: var(--surface-2); color: var(--text-2); }
.when { font-size: 12px; color: var(--muted); white-space: nowrap; }
.empty-note { color: var(--muted); padding: 18px 0; text-align: center; font-size: 14px; }

/* Toolbar */
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.toolbar-right { display: flex; gap: 10px; flex-wrap: wrap; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { min-height: 38px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); font-size: 13.5px; font-weight: 600; color: var(--text-2); }
.chip[aria-pressed="true"] { background: var(--text); color: var(--surface); border-color: var(--text); }
.chip .n { opacity: .6; margin-left: 4px; font-weight: 500; }
.sel select { height: 40px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); padding: 0 10px; min-width: 0; }
.result-count { font-size: 13px; color: var(--muted); margin-bottom: 10px; }

/* Tables */
.table-panel { padding: 0; overflow: hidden; }
.ptable, .mtable { width: 100%; border-collapse: collapse; font-size: 14px; }
.ptable th, .mtable th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; padding: 12px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.ptable td, .mtable td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.ptable tbody tr:hover, .mtable tbody tr:hover { background: var(--surface-2); }
.ptable tbody tr:last-child td, .mtable tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right !important; font-variant-numeric: tabular-nums; }
.th-sort { border: 0; background: none; padding: 4px 0; font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; display: inline-flex; align-items: center; gap: 4px; }
.th-sort::after { content: "↕"; opacity: .35; font-size: 12px; }
.th-sort[data-dir="asc"]::after { content: "↑"; opacity: 1; }
.th-sort[data-dir="desc"]::after { content: "↓"; opacity: 1; }
.prod { display: flex; align-items: center; gap: 12px; min-width: 0; }
.prod strong { display: block; font-weight: 600; }
.prod small { color: var(--muted); font-family: var(--mono); font-size: 12px; }
.qty-cell strong { font-variant-numeric: tabular-nums; }
.qty-cell small { display: block; color: var(--muted); font-size: 12px; }
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 999px; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { color: var(--good); background: var(--good-bg); }
.badge.low { color: var(--warn); background: var(--warn-bg); }
.badge.out { color: var(--crit); background: var(--crit-bg); }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.row-actions .icon-btn { width: 36px; height: 36px; }
.row-actions svg { width: 17px; height: 17px; }
.type-tag { font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 6px; }
.type-in { color: var(--series-in); background: color-mix(in srgb, var(--series-in) 13%, transparent); }
.type-out { color: var(--series-out); background: color-mix(in srgb, var(--series-out) 13%, transparent); }
.type-adjust { color: var(--text-2); background: var(--surface-2); }
.pos { color: var(--good); } .neg { color: var(--crit); }
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty svg { width: 40px; height: 40px; margin: 0 auto 10px; }
.empty p { margin-bottom: 14px; }
.pager { display: flex; justify-content: center; align-items: center; gap: 8px; padding: 12px; font-size: 13px; color: var(--muted); }
.pager:empty { display: none; }

/* Settings */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.settings-grid .panel > p { margin: 6px 0 14px; font-size: 14px; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }
.drop { display: flex; flex-direction: column; align-items: center; gap: 8px; border: 2px dashed var(--border); border-radius: 12px; padding: 22px; text-align: center; color: var(--text-2); cursor: pointer; font-size: 14px; }
.drop:hover, .drop.over { border-color: var(--brand); background: var(--brand-soft); }
.drop:focus-within { outline: 2.5px solid var(--brand); outline-offset: 2px; }
.drop input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.drop svg { width: 28px; height: 28px; color: var(--brand); }
.import-result { margin-top: 10px; font-size: 13.5px; }
.import-result.bad { color: var(--crit); } .import-result.good { color: var(--good); }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.setting-row:last-child { border: 0; }
.setting-row small { display: block; font-size: 12.5px; }
.switch { width: 48px; height: 28px; border-radius: 14px; border: 0; background: var(--border); position: relative; flex: none; transition: background .2s; }
.switch span { position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch[aria-checked="true"] { background: var(--brand); }
.switch[aria-checked="true"] span { transform: translateX(20px); }
.danger-zone { border-color: color-mix(in srgb, var(--crit) 35%, var(--border)); }

/* Dialogs */
.dlg { border: 0; padding: 0; border-radius: 16px; background: var(--surface); color: var(--text); width: min(560px, calc(100vw - 24px)); box-shadow: 0 30px 60px -12px rgba(0,0,0,.4); }
.dlg::backdrop { background: rgba(6, 12, 18, .55); backdrop-filter: blur(2px); }
.dlg[open] { animation: pop .2s ease; }
.dlg-sm { width: min(420px, calc(100vw - 24px)); }
.dlg-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px 6px; }
.dlg-head h2, .dlg-sm h2 { font-size: 18px; }
.dlg-body { padding: 14px 20px; }
.dlg-sm .dlg-body p { margin-top: 8px; }
.dlg-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px 18px; border-top: 1px solid var(--border); }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px; }
.f { display: flex; flex-direction: column; min-width: 0; }
.f.full { grid-column: 1 / -1; }
.f label, .f legend { font-size: 13px; font-weight: 600; margin-bottom: 5px; }
.f input, .f select { height: 42px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); padding: 0 12px; width: 100%; }
.f input:focus, .f select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 22%, transparent); }
.f.invalid input, .f.invalid select { border-color: var(--crit); }
.ferr { color: var(--crit); font-size: 12px; min-height: 18px; margin-top: 2px; }
.type-pick { border: 0; padding: 0; margin: 0 0 14px; display: flex; flex-direction: row; flex-wrap: wrap; gap: 8px; }
.type-pick legend { width: 100%; padding: 0; }
.type-pick label { flex: 1; margin: 0; }
.type-pick input { position: absolute; opacity: 0; }
.type-pick span { display: flex; align-items: center; justify-content: center; min-height: 42px; border: 1px solid var(--border); border-radius: 9px; font-weight: 600; font-size: 14px; cursor: pointer; padding: 0 8px; text-align: center; }
.type-pick input:checked + span { border-color: var(--brand); background: var(--brand-soft); color: var(--brand); }
.type-pick input:focus-visible + span { outline: 2.5px solid var(--brand); outline-offset: 2px; }
.after { height: 42px; display: flex; align-items: center; font-size: 20px; font-weight: 750; font-variant-numeric: tabular-nums; }

/* Toasts */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; width: max-content; max-width: calc(100vw - 24px); }
.toast { background: var(--text); color: var(--surface); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 10px 30px rgba(0,0,0,.25); display: flex; gap: 12px; align-items: center; animation: pop .2s ease; }
.toast button { border: 0; background: transparent; color: inherit; font-weight: 700; text-decoration: underline; padding: 4px; }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ============ Responsive ============ */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-2 + .grid-2 { grid-template-columns: 1fr; }
  .top-search { width: min(300px, 30vw); }
}
@media (max-width: 900px) {
  .app, .app.collapsed { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 272px; transform: translateX(-100%); transition: transform .25s ease, visibility .25s; visibility: hidden; }
  .sidebar.open { transform: none; visibility: visible; box-shadow: 20px 0 40px rgba(0,0,0,.3); }
  .app.collapsed .side-label { display: inline; } .app.collapsed .side-nav a { justify-content: flex-start; padding: 0 12px; }
  .collapse-btn { display: none; }
  .scrim { position: fixed; inset: 0; background: rgba(6,12,18,.55); z-index: 45; }
  .menu-btn { display: grid; }
  .topbar { flex-wrap: wrap; padding: 12px 16px; gap: 10px; }
  .top-actions { margin-left: auto; }
  .top-search { order: 5; width: 100%; margin: 0; }
  .top-search kbd { display: none; }
  .content { padding: 16px 16px 72px; }
  .settings-grid { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .page-title { font-size: 19px; }
  #addBtn span { display: none; }
  #addBtn { width: 42px; padding: 0; }
  .kpis { gap: 10px; }
  .kpi { padding: 14px; }
  .kpi-value { font-size: 22px; margin: 8px 0 2px; }
  .kpi-foot { font-size: 11.5px; }
  .kpi-label { font-size: 12px; }
  .kpi-icon { width: 26px; height: 26px; }
  .panel { padding: 16px; }
  .toolbar { flex-direction: column; align-items: stretch; flex-wrap: nowrap; }
  .toolbar-right { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr); }
  .sel { min-width: 0; }
  .toolbar-right .btn { grid-column: 1 / -1; }
  .chips { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 4px; scrollbar-width: none; }
  .chips::-webkit-scrollbar { display: none; }
  .chip { flex: none; }
  .sel select { width: 100%; }

  /* table -> cards */
  .table-panel { background: transparent; border: 0; box-shadow: none; overflow: visible; padding: 0; }
  .ptable thead, .mtable thead { display: none; }
  .ptable, .ptable tbody, .mtable, .mtable tbody { display: block; }
  .ptable tr { display: grid; grid-template-columns: 1fr auto; gap: 10px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r); padding: 14px; margin-bottom: 10px; box-shadow: var(--shadow); }
  .ptable td { display: block; padding: 0; border: 0; }
  .ptable td.c-prod { grid-column: 1 / -1; }
  .ptable td.c-cat { display: none; }
  .ptable td[data-label]::before { content: attr(data-label); display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; margin-bottom: 2px; }
  .ptable td.num { text-align: left !important; }
  .ptable td.c-status { grid-column: 2; grid-row: 1; align-self: start; }
  .ptable td.c-prod { grid-column: 1; grid-row: 1; }
  .ptable tr > td.c-qty, .ptable tr > td.c-price, .ptable tr > td.c-value { grid-column: auto; }
  .ptable tr { grid-template-columns: repeat(3, 1fr); }
  .ptable td.c-prod { grid-column: 1 / 3; }
  .ptable td.c-status { grid-column: 3; justify-self: end; }
  .ptable td.c-actions { grid-column: 1 / -1; border-top: 1px solid var(--border); padding-top: 10px; }
  .row-actions { justify-content: stretch; }
  .row-actions .icon-btn { flex: 1; width: auto; height: 40px; }
  .ptable tbody tr:hover { background: var(--surface); }

  .mtable tr { display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; }
  .mtable td { padding: 0; border: 0; }
  .mtable td.c-date { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
  .mtable td.c-prod { font-weight: 600; }
  .mtable td.c-type { grid-column: 2; grid-row: 2; justify-self: end; }
  .mtable td.c-qty { text-align: left !important; }
  .mtable td.c-after { text-align: right !important; color: var(--muted); font-size: 13px; }
  .mtable td.c-after::before { content: "Stock after: "; }
  .mtable td.c-note { grid-column: 1 / -1; font-size: 13px; color: var(--muted); }
  .mtable td.c-note:empty { display: none; }
  .mtable tbody tr:hover { background: var(--surface); }
  .pager { padding: 8px 0; }

  .form-grid { grid-template-columns: 1fr 1fr; }
  .dlg { margin: auto auto 0; width: 100vw; max-width: 100vw; border-radius: 18px 18px 0 0; max-height: 92vh; }
  .back-link { bottom: 12px; right: 12px; }
  .toasts { bottom: 60px; }
}
@media (max-width: 420px) {
  .top-actions { gap: 6px; }
  .page-title { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
@media print {
  .sidebar, .topbar, .back-link, .toolbar, .row-actions, .app-foot { display: none !important; }
  .app { display: block; }
}

/* "All projects" link: on phones it moves into the page footer (see app.js) so it never covers content;
   without JS it falls back to a small round button */
@media (max-width: 640px) {
  .back-link { width: 40px; height: 40px; min-height: 0; padding: 0 !important; display: inline-grid; place-items: center; overflow: hidden; font-size: 0 !important; letter-spacing: 0; }
  .back-link::before { content: "\2190"; font-size: 1.1rem; line-height: 1; }
}
.back-foot { display: flex; justify-content: center; width: 100%; flex-basis: 100%; grid-column: 1 / -1; padding: 16px 16px 24px; }
.back-link.in-footer { position: static; inset: auto; width: auto; height: auto; min-height: 42px; padding: 0 18px !important; display: inline-flex; align-items: center; font-size: .82rem !important; letter-spacing: .02em; opacity: 1; transform: none; box-shadow: none; }
.back-link.in-footer::before { content: none; }
