/* ═══════════════════════════════════════════════════════════════════
   StockLine · styles
   Colours live in the tokens below; the accent comes from config.js.
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --accent: #6d4aff;
  --accent-2: #c04bff;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f2f1ed;
  --text: #17171c;
  --muted: #6c6b75;
  --border: #e6e4de;
  --critical: #e5484d;
  --warning: #d98a00;
  --ok: #2f9e66;
  --dead: #8a8a96;
  --out: #e5484d;
  --shadow: 0 1px 2px rgb(20 20 30 / 0.04), 0 6px 20px rgb(20 20 30 / 0.05);
  --radius: 16px;
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --accent-2: #d06bff;
    --bg: #0f0f13;
    --surface: #17171d;
    --surface-2: #202028;
    --text: #ececf2;
    --muted: #9d9ca8;
    --border: #2a2a33;
    --critical: #ff6369;
    --warning: #f5b02e;
    --ok: #3dbd7d;
    --dead: #8f8f9c;
    --out: #ff6369;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --accent-2: #d06bff;
  --bg: #0f0f13;
  --surface: #17171d;
  --surface-2: #202028;
  --text: #ececf2;
  --muted: #9d9ca8;
  --border: #2a2a33;
  --critical: #ff6369;
  --warning: #f5b02e;
  --ok: #3dbd7d;
  --dead: #8f8f9c;
  --out: #ff6369;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3);
  color-scheme: dark;
}

/* ── Base ───────────────────────────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
}
html,
body {
  margin: 0;
}
body {
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a {
  color: var(--accent);
}
h1,
h2,
h3,
p {
  margin: 0;
}
button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}
.ic {
  flex: none;
  display: block;
}
.num {
  font-variant-numeric: tabular-nums;
}
.muted {
  color: var(--muted);
}
.small,
small {
  font-size: 12.5px;
}
.center {
  text-align: center;
  justify-content: center;
}
.truncate {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
}
.emoji {
  font-size: 1.15em;
  line-height: 1;
}
.emoji.big {
  font-size: 26px;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  border-radius: 12px;
  flex: none;
}
.spacer {
  flex: 1;
}
.row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.row.wrap {
  flex-wrap: wrap;
}
.stack {
  display: grid;
  gap: 16px;
  align-content: start;
  min-width: 0;
}
.stack-sm {
  display: grid;
  gap: 14px;
}
.grow {
  flex: 1;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── Top bar ────────────────────────────────────────────────────────── */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1200px;
  margin: 0 auto;
  height: 62px;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 20px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: var(--text);
  font-weight: 800;
  font-size: 18px;
  letter-spacing: -0.02em;
}
.tabs {
  display: flex;
  gap: 4px;
  flex: 1;
}
.tabs a {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 10px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.15s, color 0.15s;
}
.tabs a:hover {
  color: var(--text);
  background: var(--surface-2);
}
.tabs a.active {
  color: var(--text);
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--border);
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.ai-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
  display: inline-block;
  flex: none;
}
.ai-badge.demo .dot,
.ai-state.demo .dot {
  background: var(--warning);
}
.ai-badge.live .dot,
.ai-state.live .dot {
  background: var(--ok);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent);
}
.lang-select {
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 0 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}
.icon-btn {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* ── Layout ─────────────────────────────────────────────────────────── */
.container {
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  padding: 28px 20px 48px;
  flex: 1;
}
.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}
.page-head h1 {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.15;
}
.page-head p {
  margin-top: 4px;
}
.page-date {
  color: var(--muted);
  font-weight: 600;
}
.footer {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  padding: 24px 20px 32px;
}

/* ── Cards ──────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  min-width: 0;
}
.card.flush {
  padding: 0;
  overflow: hidden;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 6px;
}
.card-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
}
.card-head .card-title {
  margin-bottom: 0;
}
.card-title .ic {
  color: var(--accent);
}
.hint {
  color: var(--muted);
  font-size: 13px;
  margin: 8px 0 14px;
}
.empty {
  color: var(--muted);
  text-align: center;
  padding: 28px 16px;
  display: grid;
  gap: 14px;
}
.notice {
  font-size: 13px;
  background: color-mix(in srgb, var(--warning) 12%, transparent);
  color: color-mix(in srgb, var(--warning) 75%, var(--text));
  padding: 8px 12px;
  border-radius: 10px;
  margin: 10px 0;
}
.demo-note,
.model-note {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  font-size: 13px;
  color: var(--muted);
  background: var(--surface-2);
  padding: 10px 12px;
  border-radius: 10px;
  margin-bottom: 14px;
}
.demo-note .ic,
.model-note .ic {
  margin-top: 2px;
  color: var(--accent);
}
.model-note {
  background: color-mix(in srgb, var(--accent) 9%, transparent);
  color: color-mix(in srgb, var(--accent) 70%, var(--text));
  font-weight: 600;
}

/* ── Buttons & inputs ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 40px;
  padding: 0 16px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  text-decoration: none;
  color: var(--text);
  transition: background 0.15s, transform 0.05s, filter 0.15s;
}
.btn:hover {
  background: var(--surface-2);
}
.btn:active {
  transform: translateY(1px);
}
.btn[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}
.btn-sm {
  height: 32px;
  padding: 0 11px;
  font-size: 13px;
  border-radius: 9px;
  gap: 6px;
}
.btn-primary {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
}
.btn-primary:hover {
  background: var(--accent);
  filter: brightness(1.08);
}
.btn-ai {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 14px color-mix(in srgb, var(--accent) 30%, transparent);
}
.btn-ai:hover {
  background: linear-gradient(120deg, var(--accent), var(--accent-2));
  filter: brightness(1.08);
}
.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost.danger,
.danger {
  color: var(--critical);
}
.btn-danger-solid {
  background: var(--critical);
  color: #fff;
  border-color: transparent;
}
.btn-danger-solid:hover {
  background: var(--critical);
  filter: brightness(1.08);
}
.btn-link {
  background: none;
  border: 0;
  padding: 0;
  height: auto;
  color: var(--accent);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}
.btn.btn-link {
  padding: 0 6px;
  height: 40px;
}
.input {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border-radius: 11px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 14px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
select.input {
  cursor: pointer;
  padding-right: 8px;
}
textarea.input {
  height: auto;
  padding: 10px 12px;
  resize: vertical;
  line-height: 1.45;
}
.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent);
}
.field {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.span-2 {
  grid-column: span 2;
}
.spinner {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  border: 2px solid currentColor;
  border-right-color: transparent;
  animation: spin 0.7s linear infinite;
  display: inline-block;
  flex: none;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Status pills ───────────────────────────────────────────────────── */
.pill {
  --c: var(--ok);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
  color: color-mix(in srgb, var(--c) 85%, var(--text));
  background: color-mix(in srgb, var(--c) 13%, transparent);
}
.pill::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--c);
}
.pill[data-status="out"],
.pill[data-status="critical"] {
  --c: var(--critical);
}
.pill[data-status="warning"] {
  --c: var(--warning);
}
.pill[data-status="dead"] {
  --c: var(--dead);
}
.late {
  color: var(--critical);
}

/* ── Dashboard ──────────────────────────────────────────────────────── */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}
.kpi {
  --c: var(--accent);
  display: grid;
  gap: 2px;
  text-decoration: none;
  color: var(--text);
  transition: transform 0.15s, box-shadow 0.15s;
}
.kpi:hover {
  transform: translateY(-2px);
}
.kpi[data-kind="critical"] {
  --c: var(--critical);
}
.kpi[data-kind="warning"] {
  --c: var(--warning);
}
.kpi[data-kind="dead"] {
  --c: var(--dead);
}
.kpi-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
}
.kpi .dot {
  background: var(--c);
}
.kpi-value {
  font-size: 30px;
  font-weight: 800;
  letter-spacing: -0.03em;
}
.kpi-sub {
  font-size: 12.5px;
  color: var(--muted);
}
.dash-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.quick-form {
  display: grid;
  gap: 12px;
}
.quick-form .hint {
  margin: 0;
}

/* Death line chart */
.dl-axis,
.dl-row {
  display: grid;
  grid-template-columns: minmax(110px, 190px) minmax(0, 1fr) 104px;
  gap: 14px;
  align-items: center;
}
.dl-ticks {
  position: relative;
  height: 18px;
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
}
.dl-ticks span {
  position: absolute;
  transform: translateX(-50%);
  white-space: nowrap;
}
.dl-ticks span:first-child {
  transform: none;
}
.dl-ticks span:last-child {
  transform: translateX(-100%);
}
.dl-row {
  width: 100%;
  padding: 9px 8px;
  margin: 0 -8px;
  width: calc(100% + 16px);
  border: 0;
  background: none;
  border-radius: 10px;
  text-align: left;
  cursor: pointer;
}
.dl-row:hover {
  background: var(--surface-2);
}
.dl-name {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
  min-width: 0;
}
.dl-track {
  position: relative;
  height: 12px;
  border-radius: 999px;
  background: var(--surface-2);
  box-shadow: inset 0 0 0 1px var(--border);
}
.dl-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 999px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--c) 55%, transparent), var(--c));
}
.dl-skull {
  position: absolute;
  top: 50%;
  width: 24px;
  height: 24px;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--surface);
  color: var(--c);
  box-shadow: 0 0 0 2px var(--c), 0 2px 6px rgb(0 0 0 / 0.15);
}
.dl-skull.overdue {
  background: var(--critical);
  color: #fff;
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--critical);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  50% {
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 7px color-mix(in srgb, var(--critical) 35%, transparent);
  }
}
.dl-when {
  display: grid;
  font-size: 13px;
  line-height: 1.25;
  text-align: right;
}
.dl-when small {
  color: var(--muted);
}
.dl-when.late strong {
  color: var(--critical);
}
.dl-legend {
  display: flex;
  gap: 18px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--border);
  font-size: 12.5px;
  color: var(--muted);
}
.dl-legend span {
  display: flex;
  align-items: center;
  gap: 6px;
}
.legend-bar {
  width: 22px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, color-mix(in srgb, var(--warning) 55%, transparent), var(--warning));
}
.legend-skull .ic {
  color: var(--critical);
}

/* AI analysis */
.analysis {
  position: relative;
  overflow: hidden;
}
.analysis::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
.analysis .card-head {
  margin-bottom: 14px;
}
.thinking {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--accent);
  font-weight: 600;
  margin: 6px 0 16px;
}
.skeleton {
  height: 14px;
  border-radius: 7px;
  margin: 10px 0;
  background: linear-gradient(90deg, var(--surface-2) 25%, color-mix(in srgb, var(--accent) 12%, var(--surface-2)) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer {
  to {
    background-position: -200% 0;
  }
}
.an-headline {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.3;
}
.an-summary {
  color: var(--muted);
  margin: 6px 0 14px;
}
.an-actions {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}
.an-action {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: grid;
  gap: 4px;
}
.an-top {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.an-text {
  font-weight: 600;
}
.an-reason {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}
.prio {
  --c: var(--dead);
  flex: none;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  border-radius: 6px;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 13%, transparent);
}
.prio[data-p="urgent"] {
  --c: var(--critical);
}
.prio[data-p="soon"] {
  --c: var(--warning);
}
.an-insights {
  margin-top: 16px;
  padding: 12px 14px;
  border-radius: 12px;
  background: color-mix(in srgb, var(--accent) 7%, transparent);
}
.an-insights h3 {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 6px;
}
.an-insights ul {
  margin: 0;
  padding-left: 18px;
  display: grid;
  gap: 4px;
  font-size: 14px;
}

/* ── Toolbar ────────────────────────────────────────────────────────── */
.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}
.toolbar > select {
  width: auto;
  min-width: 150px;
}
.search {
  position: relative;
  flex: 1 1 260px;
  display: block;
}
.search .ic {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}
.search .input {
  padding-left: 36px;
}
.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 11px;
  padding: 3px;
  gap: 2px;
}
.segmented button,
.segmented label span {
  border: 0;
  background: none;
  padding: 0 12px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.segmented button.active,
.segmented input:checked + span {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.1);
}
.segmented.big {
  display: grid;
  grid-template-columns: 1fr 1fr;
}
.segmented label {
  display: grid;
}
.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.toggle input {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

/* ── Inventory list ─────────────────────────────────────────────────── */
.inv-head,
.inv-row {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) 160px 110px 140px 118px;
  gap: 14px;
  align-items: center;
  padding: 12px 18px;
}
.inv-head {
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.inv-row {
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}
.inv-row:last-child {
  border-bottom: 0;
}
.inv-row:hover {
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
}
.inv-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}
.inv-item > div {
  display: grid;
}
.inv-stock {
  display: flex;
  align-items: center;
  gap: 8px;
}
.inv-stock .num {
  min-width: 64px;
  text-align: center;
}
.step {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--muted);
  flex: none;
}
.step:hover:not([disabled]) {
  color: var(--text);
  border-color: var(--accent);
}
.step[disabled] {
  opacity: 0.4;
  cursor: not-allowed;
}
.inv-rate {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}
.trend.up {
  color: var(--critical);
}
.trend.down {
  color: var(--ok);
}
.inv-dl {
  display: grid;
  font-size: 14px;
  line-height: 1.3;
}
.inv-dl small {
  color: var(--muted);
}

/* ── Item detail ────────────────────────────────────────────────────── */
.detail-top {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}
.stat {
  background: var(--surface-2);
  border-radius: 12px;
  padding: 10px 12px;
  display: grid;
  gap: 2px;
}
.stat small {
  color: var(--muted);
  font-weight: 600;
}
.stat strong {
  font-size: 17px;
}
.stat strong small {
  font-size: 12px;
  font-weight: 500;
}
.stat.late strong {
  color: var(--critical);
}
.section-title {
  font-size: 14px;
  font-weight: 700;
  margin: 20px 0 10px;
}
.chart-box {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 6px 2px;
}
.chart {
  width: 100%;
  height: auto;
  display: block;
  overflow: visible;
}
.c-grid {
  stroke: var(--border);
  stroke-width: 1;
}
.c-label {
  fill: var(--muted);
  font-size: 11px;
  font-family: var(--font);
}
.c-area {
  fill: color-mix(in srgb, var(--accent) 12%, transparent);
}
.c-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.2;
  stroke-linejoin: round;
}
.c-forecast {
  stroke-width: 2.2;
  stroke-dasharray: 6 5;
  stroke-linecap: round;
}
.c-today {
  stroke: var(--muted);
  stroke-dasharray: 2 4;
}
.c-now {
  fill: var(--accent);
  stroke: var(--surface);
  stroke-width: 2;
}
.c-deathline {
  stroke: var(--critical);
  stroke-width: 1.6;
  stroke-dasharray: 4 4;
}
.c-deathline-label {
  fill: var(--critical);
  font-weight: 700;
}
.c-stockout {
  fill: var(--critical);
  stroke: var(--surface);
  stroke-width: 2;
}
.mini-moves {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
}
.mini-moves li {
  display: grid;
  grid-template-columns: 130px 64px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.mini-moves li:last-child {
  border-bottom: 0;
}
.qty.in {
  color: var(--ok);
}
.qty.out {
  color: var(--critical);
}
.src {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  background: var(--surface-2);
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
  justify-self: end;
}
.src[data-src^="ai-"] {
  color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

/* ── Movements ──────────────────────────────────────────────────────── */
#mov-list {
  display: grid;
  gap: 16px;
}
.mov-day {
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  padding: 12px 18px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.mov-row {
  width: 100%;
  display: grid;
  grid-template-columns: 56px minmax(0, 1.4fr) 110px minmax(0, 1.4fr) auto;
  gap: 14px;
  align-items: center;
  padding: 11px 18px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: none;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
}
.mov-row:last-child {
  border-bottom: 0;
}
.mov-row:hover {
  background: color-mix(in srgb, var(--surface-2) 70%, transparent);
}
.mov-item {
  font-weight: 600;
}

/* ── Chat ───────────────────────────────────────────────────────────── */
.chat {
  display: flex;
  flex-direction: column;
  gap: 12px;
  height: calc(100vh - 250px);
  min-height: 460px;
}
.chat-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 4px 2px 8px;
}
.msg {
  max-width: min(78%, 680px);
  padding: 11px 15px;
  border-radius: 16px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}
.msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 5px;
  white-space: pre-wrap;
}
.msg.assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border-bottom-left-radius: 5px;
}
.msg.error {
  background: color-mix(in srgb, var(--critical) 12%, transparent);
  color: color-mix(in srgb, var(--critical) 80%, var(--text));
}
.msg p + p,
.msg p + ul,
.msg ul + p,
.msg p + ol,
.msg ol + p {
  margin-top: 8px;
}
.msg ul,
.msg ol {
  margin: 4px 0;
  padding-left: 20px;
}
.msg code {
  font-size: 0.92em;
  background: color-mix(in srgb, var(--text) 8%, transparent);
  padding: 1px 5px;
  border-radius: 5px;
}
.typing {
  display: inline-flex;
  gap: 4px;
  padding: 4px 0;
}
.typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--muted);
  animation: blink 1.2s infinite;
}
.typing i:nth-child(2) {
  animation-delay: 0.2s;
}
.typing i:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes blink {
  0%,
  80%,
  100% {
    opacity: 0.25;
  }
  40% {
    opacity: 1;
  }
}
.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.chip:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.chat-input {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
.chat-input textarea {
  min-height: 44px;
  max-height: 160px;
  resize: none;
}
.chat-input .btn {
  height: 44px;
  width: 48px;
  padding: 0;
}

/* ── Modals ─────────────────────────────────────────────────────────── */
dialog.modal {
  width: min(640px, calc(100vw - 24px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 70px rgb(0 0 0 / 0.28);
  overflow: hidden;
  display: none;
  flex-direction: column;
}
dialog.modal[open] {
  display: flex;
  animation: pop 0.18s ease-out;
}
dialog.modal.wide {
  width: min(860px, calc(100vw - 24px));
}
dialog.modal.small {
  width: min(440px, calc(100vw - 24px));
}
dialog.modal::backdrop {
  background: rgb(12 12 20 / 0.5);
  backdrop-filter: blur(3px);
}
@keyframes pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px 14px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-head h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
  font-weight: 700;
  min-width: 0;
}
.modal-head h2 .ic {
  color: var(--accent);
}
.modal-body {
  padding: 20px;
  overflow-y: auto;
}
.modal-foot {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  flex-wrap: wrap;
}
.confirm-text {
  font-size: 15px;
}

/* Review of AI proposals */
.review-split {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}
.review-image {
  margin: 0;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  position: sticky;
  top: 0;
}
.review-image img {
  width: 100%;
  display: block;
}
.review-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 22px;
  margin-bottom: 12px;
}
.review-meta span {
  display: grid;
  font-weight: 600;
}
.review-meta small {
  color: var(--muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.04em;
}
.review-rows {
  display: grid;
  gap: 10px;
  margin-top: 10px;
}
.review-row {
  display: grid;
  grid-template-columns: 22px 118px 76px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 12px;
  transition: opacity 0.15s;
}
.review-row.off {
  opacity: 0.5;
}
.review-row .note {
  grid-column: 2 / -1;
}
.review-row .check {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}
.review-warn {
  grid-column: 2 / -1;
  color: var(--critical);
  font-size: 12.5px;
  font-weight: 600;
}
.review-warn:empty {
  display: none;
}

/* Photo scanning */
.scan {
  position: relative;
  max-width: 420px;
  margin: 0 auto 16px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.scan img {
  width: 100%;
  display: block;
}
.scan.scanning::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 28%;
  top: -28%;
  background: linear-gradient(to bottom, transparent, color-mix(in srgb, var(--accent) 38%, transparent), transparent);
  animation: scan 1.5s linear infinite;
}
@keyframes scan {
  to {
    top: 100%;
  }
}
.modal-body > .thinking {
  justify-content: center;
}

/* Settings */
.settings-section {
  display: grid;
  gap: 12px;
  padding-bottom: 20px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.settings-section:last-child {
  border-bottom: 0;
  margin-bottom: 0;
  padding-bottom: 0;
}
.settings-section h3 {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 700;
}
.settings-section .hint {
  margin: 0;
}
.ai-state {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 14px;
}
.key-row {
  display: flex;
  gap: 8px;
}
.provider-switch {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}
.provider-switch button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.key-dot {
  width: 6px;
  height: 6px;
  background: var(--ok);
}

/* ── Toasts ─────────────────────────────────────────────────────────── */
.toasts {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  display: grid;
  gap: 8px;
  justify-items: end;
  pointer-events: none;
}
.toast {
  max-width: min(420px, calc(100vw - 32px));
  background: var(--text);
  color: var(--bg);
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 10px 30px rgb(0 0 0 / 0.2);
  animation: pop 0.2s ease-out;
  transition: opacity 0.3s, transform 0.3s;
}
.toast.success {
  border-left: 4px solid var(--ok);
}
.toast.error {
  border-left: 4px solid var(--critical);
}
.toast.leaving {
  opacity: 0;
  transform: translateY(6px);
}

/* ── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 980px) {
  .dash-grid {
    grid-template-columns: 1fr;
  }
  .kpis {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .inv-head {
    display: none;
  }
  .inv-row {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "item status"
      "stock dl"
      "rate dl";
    row-gap: 8px;
  }
  .inv-item {
    grid-area: item;
  }
  .inv-status {
    grid-area: status;
    justify-self: end;
  }
  .inv-stock {
    grid-area: stock;
  }
  .inv-rate {
    grid-area: rate;
  }
  .inv-dl {
    grid-area: dl;
    text-align: right;
  }
}

@media (max-width: 760px) {
  body {
    font-size: 14.5px;
    padding-bottom: calc(66px + env(safe-area-inset-bottom));
  }
  /* backdrop-filter would trap the fixed bottom nav inside the header */
  .topbar {
    backdrop-filter: none;
    background: var(--bg);
  }
  .topbar-inner {
    padding: 0 16px;
    gap: 10px;
  }
  .brand span {
    display: none;
  }
  .topbar-actions {
    margin-left: auto;
  }
  .tabs {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    justify-content: space-around;
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    gap: 0;
  }
  .tabs a {
    flex: 1;
    flex-direction: column;
    gap: 3px;
    font-size: 11px;
    padding: 6px 4px;
  }
  .tabs a.active {
    box-shadow: none;
    color: var(--accent);
    background: color-mix(in srgb, var(--accent) 10%, transparent);
  }
  .container {
    padding: 20px 16px 32px;
  }
  .page-head h1 {
    font-size: 24px;
  }
  .kpis {
    gap: 10px;
  }
  .card {
    padding: 16px;
  }
  .kpi-value {
    font-size: 24px;
  }
  .dl-axis,
  .dl-row {
    grid-template-columns: minmax(0, 1fr) 84px;
    row-gap: 6px;
    column-gap: 10px;
  }
  .dl-axis {
    display: none;
  }
  .dl-name {
    grid-column: 1;
  }
  .dl-when {
    grid-column: 2;
    grid-row: 1 / span 2;
  }
  .dl-track {
    grid-column: 1;
  }
  .toolbar > select {
    flex: 1 1 140px;
    min-width: 0;
  }
  .mov-row {
    grid-template-columns: 44px minmax(0, 1fr) auto;
    row-gap: 2px;
  }
  .mov-note {
    grid-column: 2;
  }
  .mov-row .src {
    grid-column: 3;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
  .span-2 {
    grid-column: auto;
  }
  .review-split {
    grid-template-columns: 1fr;
  }
  .review-image {
    position: static;
    max-height: 180px;
  }
  .review-row {
    grid-template-columns: 22px 1fr 70px;
  }
  .review-row .item {
    grid-column: 2 / -1;
  }
  .mini-moves li {
    grid-template-columns: 1fr auto;
  }
  .mini-moves li .truncate {
    grid-column: 1 / -1;
  }
  .msg {
    max-width: 88%;
  }
  .chat {
    height: calc(100dvh - 290px);
    min-height: 380px;
  }
  .toasts {
    left: 16px;
    right: 16px;
    bottom: calc(80px + env(safe-area-inset-bottom));
    justify-items: center;
  }
  .ai-badge {
    padding: 0 10px;
  }
}

@media (max-width: 420px) {
  .ai-badge {
    font-size: 0;
    gap: 0;
    width: 32px;
    padding: 0;
    justify-content: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
