.viz-root, body {
  color-scheme: light;
  --page: #f9f9f9;
  --surface-1: #ffffff;
  --text-primary: #191919;
  --text-secondary: #666666;
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --border: rgba(11,11,11,0.10);
  --series-1: #257de0;   /* blue: sales, COGS */
  --series-2: #f47230;   /* orange: labor */
  --series-3: #00b894;   /* aqua: prime */
  --good: #0aac23; --warning: #fbb315; --serious: #f18a59; --critical: #dc3c3d;
  --good-text: #006c10;
  --seq-0: #f3f7fc; --seq-1: #cce3fd; --seq-2: #9dc8f7; --seq-3: #6aabf1; --seq-4: #338ced; --seq-5: #2370cd; --seq-6: #0f4a96;
}
@media (prefers-color-scheme: dark) {
  .viz-root, body {
    color-scheme: dark;
    --page: #0b0b0b; --surface-1: #191919; --text-primary: #efefef; --text-secondary: #9c9c9c;
    --grid: #303030; --axis: #474747; --border: rgba(255,255,255,0.10);
    --series-1: #338ced; --series-2: #e76624; --series-3: #00a888; --good-text: #53c556;
    --seq-0: #1e2430; --seq-1: #0e3d7e; --seq-2: #1757ac; --seq-3: #2370cd; --seq-4: #338ced; --seq-5: #6aabf1; --seq-6: #b6d5f8;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--text-primary);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
[hidden] { display: none !important; }
h1, h2 { margin: 0; }
h2 { font-size: 1rem; font-weight: 600; }
.muted { color: var(--text-secondary); }
.small { font-size: .8rem; }
.error { color: var(--critical); min-height: 1.2em; margin: .25rem 1rem; }
.note { color: var(--text-secondary); font-size: .8rem; margin: .5rem 0 0; }
button { font: inherit; color: inherit; cursor: pointer; }
.link { background: none; border: 0; color: var(--series-1); padding: .25rem .5rem; min-height: 36px; }
.primary { background: var(--series-1); color: #fff; border: 0; border-radius: 10px; padding: .8rem; font-weight: 600; min-height: 48px; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 1rem; }
.login-card { width: 100%; max-width: 360px; background: var(--surface-1); border: 1px solid var(--border); border-radius: 16px; padding: 1.5rem; text-align: center; }
.login-card h1 { font-size: 1.4rem; margin-top: .5rem; }
.login-card form { display: grid; gap: .8rem; margin-top: 1rem; text-align: left; }
.login-card label { display: grid; gap: .3rem; font-size: .9rem; color: var(--text-secondary); }
.login-card input { font: inherit; padding: .7rem; border-radius: 10px; border: 1px solid var(--axis); background: var(--surface-1); color: var(--text-primary); min-height: 48px; }

/* layout */
#app { max-width: 1100px; margin: 0 auto; padding-bottom: 2rem; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: .75rem 1rem; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.who { display: flex; align-items: center; gap: .25rem; color: var(--text-secondary); font-size: .9rem; }
.filters { display: flex; flex-wrap: wrap; gap: .5rem; padding: 0 1rem; position: sticky; top: 0; z-index: 2; background: var(--page); padding-block: .5rem; }
.seg { display: flex; background: var(--surface-1); border: 1px solid var(--border); border-radius: 12px; padding: 3px; overflow-x: auto; max-width: 100%; }
.seg button { border: 0; background: none; padding: .5rem .8rem; border-radius: 9px; white-space: nowrap; min-height: 40px; color: var(--text-secondary); }
.seg button[aria-checked="true"] { background: var(--series-1); color: #fff; font-weight: 600; }
.range-label { margin: .25rem 1rem 0; font-size: .85rem; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; padding: .5rem 1rem; }
@media (min-width: 700px) { .tiles { grid-template-columns: repeat(6, 1fr); } }
.tile { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: .8rem; }
.tile .label { font-size: .8rem; color: var(--text-secondary); }
.tile .value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: .15rem; }
.tile .sub { font-size: .75rem; color: var(--text-secondary); font-variant-numeric: tabular-nums; }

.card { background: var(--surface-1); border: 1px solid var(--border); border-radius: 14px; padding: 1rem; margin: .6rem 1rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .5rem; }
.grid2 { display: grid; grid-template-columns: 1fr; }
@media (min-width: 900px) { .grid2 { grid-template-columns: 1fr 1fr; } .grid2 .card { margin-right: .3rem; } .grid2 .card + .card { margin-left: .3rem; margin-right: 1rem; } }

.chart { width: 100%; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--text-secondary); font-size: 11px; font-variant-numeric: tabular-nums; }
.legend { display: flex; flex-wrap: wrap; gap: .9rem; font-size: .85rem; color: var(--text-secondary); margin-bottom: .25rem; }
.legend .sw { display: inline-block; width: 12px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: .35rem; }

.tooltip { position: fixed; pointer-events: none; z-index: 10; background: var(--surface-1); color: var(--text-primary); border: 1px solid var(--border); border-radius: 10px; padding: .5rem .7rem; font-size: .85rem; box-shadow: 0 4px 16px rgba(0,0,0,.12); font-variant-numeric: tabular-nums; max-width: 240px; }
.tooltip b { display: block; margin-bottom: .15rem; }

/* tables */
.table-wrap { overflow-x: auto; margin-top: .5rem; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; font-variant-numeric: tabular-nums; }
th, td { text-align: right; padding: .45rem .5rem; border-bottom: 1px solid var(--grid); white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { font-weight: 600; color: var(--text-secondary); font-size: .8rem; }

/* top items */
.bar-row { display: grid; grid-template-columns: minmax(90px, 38%) 1fr auto; align-items: center; gap: .5rem; padding: .3rem 0; font-size: .9rem; }
.bar-row .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-row .track { height: 12px; }
.bar-row .fill { height: 12px; background: var(--series-1); border-radius: 0 4px 4px 0; min-width: 2px; }
.bar-row .num { color: var(--text-secondary); font-variant-numeric: tabular-nums; font-size: .85rem; }

/* inventory */
.inv-group h3 { font-size: .85rem; text-transform: capitalize; color: var(--text-secondary); margin: .8rem 0 .25rem; font-weight: 600; }
.status { display: inline-flex; align-items: center; gap: .3rem; font-size: .8rem; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; }
.status.low .dot { background: var(--critical); } .status.ok .dot { background: var(--good); } .status.none .dot { background: var(--axis); }
footer { padding: 1rem; text-align: center; }

#heatmap svg { max-width: 520px; margin: 0 auto; }
@media (max-width: 500px) { .inv-group th:nth-child(5), .inv-group td:nth-child(5) { display: none; } }
