/* Layout and components. Colors come from tokens.css only. */
* { box-sizing: border-box; }
html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--text-2);
  font: 14px/1.5 var(--font-ui);
}

a { color: var(--text-1); text-decoration: none; }
a:hover { color: var(--amber-hover); }

:focus-visible { outline: 2px solid var(--amber); outline-offset: 2px; }

::placeholder { color: var(--text-4); }
::selection { background: var(--amber-edge); color: var(--text-1); }

/* ---- Layout: sidebar + content ---- */
.layout {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.side {
  border-right: 1px solid var(--line-subtle);
  padding: 22px 12px;
}

.side .brand {
  padding: 0 12px 18px;
  font-size: 22px;
  letter-spacing: .05em;
  color: var(--amber);
}

.side nav a {
  display: block;
  padding: 7px 12px;
  margin-bottom: 2px;
  border-radius: 6px;
  color: var(--text-3);
  font-weight: 500;
}

.side nav a:hover { color: var(--text-1); background: var(--surface-1); }

.side nav a.active {
  color: var(--amber);
  background: var(--surface-2);
}

.main { padding: 26px 32px 32px; min-width: 0; max-width: 1480px; }

.main > header h1 {
  margin: 0 0 20px;
  font-size: 27px;
  font-weight: 700;
  color: var(--text-1);
}

.foot {
  margin-top: 40px;
  padding-top: 14px;
  border-top: 1px solid var(--line-subtle);
  color: var(--text-4);
  font-size: 12.5px;
}

.legend-hatch {
  display: inline-block;
  width: 26px; height: 8px;
  border-radius: 2px;
  background: var(--hatch);
  vertical-align: -1px;
}

@media (max-width: 720px) {
  .layout { grid-template-columns: 1fr; }
  .side {
    border-right: 0;
    border-bottom: 1px solid var(--line-subtle);
    padding: 10px 12px;
  }
  .side .brand { padding: 2px 12px 8px; }
  .side nav { display: flex; overflow-x: auto; gap: 2px; }
  .side nav a { white-space: nowrap; margin-bottom: 0; }
  .main { padding: 16px; }
}

/* ---- Typography ---- */
.display {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: .01em;
}

.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

.meta { color: var(--text-3); font-size: 12.5px; }

/* Small uppercase label: panel headings, table headers, KPI captions */
.panel h2, .eyebrow {
  margin: 0 0 12px;
  font-family: var(--font-ui);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.4;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-3);
}

/* ---- Panels ---- */
.panel {
  background: var(--surface-1);
  border: 1px solid var(--line-subtle);
  border-radius: 10px;
  padding: 18px 20px;
  margin: 0 0 14px;
  overflow-x: auto;
}

.digest-body {
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text-2);
  white-space: pre-wrap;
  word-wrap: break-word;
  margin: 0;
  line-height: 1.55;
}

/* Totals strip / KPI cards */
.totals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin: 0 0 14px;
}
.totals .panel { margin: 0; }
.totals .big {
  font-family: var(--font-display);
  font-size: 42px;
  line-height: 1.05;
  color: var(--text-1);
}
.totals .label {
  margin-top: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-3);
}

/* Clickable KPI tile (e.g. Overview -> Sales) */
a.tile-link { display: block; color: inherit; }
a.tile-link:hover { border-color: var(--line-strong); background: var(--surface-2); }
a.tile-link .big { color: var(--amber); }
.totals .panel .meta { margin-top: 6px; }

/* Delta chip on a KPI card: WoW up/down vs previous window */
.chip {
  display: inline-block;
  margin-top: 8px;
  padding: 1px 7px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--surface-1);
  font-family: var(--font-mono);
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
}
/* For competitor SALES, more is "up" (neutral/amber); we don't moralize it. */
.chip.up { border-color: var(--amber-edge); background: var(--amber-tint); color: var(--amber); }
.chip.down { border-color: var(--line); color: var(--text-3); }

/* Inline share bar inside a table cell (units%/revenue% by kind) */
.sharebar {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 120px;
}
.sharebar .track {
  flex: 1;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}
.sharebar .track i { display: block; height: 100%; background: var(--copper); }
.sharebar .track.censored i { background: var(--hatch); }
.sharebar .pct { font-family: var(--font-mono); font-size: 12px; color: var(--text-3); min-width: 34px; text-align: right; }

/* Two-up grid for side-by-side sales panels */
.grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 14px;
}
.grid-2 .panel { margin: 0; }

/* Callout line (e.g. Pareto headline) */
.callout { font-size: 14px; color: var(--text-2); margin: 0 0 12px; }
.callout b { color: var(--text-1); font-family: var(--font-mono); }

/* Login page */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 340px; display: flex; flex-direction: column; gap: 14px; }
.auth-card .brand { font-size: 24px; letter-spacing: .05em; color: var(--amber); }
.auth-sub { margin: -6px 0 2px; color: var(--text-3); font-size: 13px; }
.auth-field { display: flex; flex-direction: column; gap: 5px; }
.auth-field > span {
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-4);
}
.auth-field input { width: 100%; }
.auth-card button { margin-top: 4px; }

/* Sidebar logout */
.side .logout { margin-top: 16px; padding: 0 12px; }
.side .logout button { width: 100%; }
@media (max-width: 720px) {
  .side .logout { margin-top: 0; padding: 0; align-self: center; }
  .side .logout button { width: auto; }
}

/* Run status / banner */
.runline { color: var(--text-3); font-size: 12.5px; margin: -8px 0 16px; }
.banner {
  background: var(--brick-tint);
  border: 1px solid var(--brick-edge);
  color: var(--text-1);
  border-radius: 8px;
  padding: 10px 14px;
  margin: 0 0 16px;
  font-size: 13px;
}

/* ---- Data tables ---- */
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td {
  padding: 8px 10px;
  text-align: left;
  border-bottom: 1px solid var(--line-subtle);
}
table.data th {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-3);
  white-space: nowrap;
}
table.data td { color: var(--text-2); vertical-align: baseline; }
table.data th:first-child, table.data td:first-child { min-width: 240px; }
table.data .c-style { min-width: 150px; }
table.data td.n, table.data th.n { text-align: right; }
table.data td.n, table.data .num { font-family: var(--font-mono); font-size: 12.5px; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--surface-1); }
table.data a { color: var(--text-1); }
table.data a:hover { color: var(--amber-hover); }

/* Sortable headers: server-side (links) and client-side (plain th) */
table.data th a { color: var(--text-3); }
table.data th a:hover { color: var(--text-1); }
table.data th.sortable { cursor: pointer; user-select: none; }
table.data th.sortable:hover { color: var(--text-1); }
table.data th.sorted, table.data th.sorted a { color: var(--amber); }
table.data th.sorted::after { content: " \25B4"; }
table.data th.sorted.desc::after { content: " \25BE"; }

/* Deltas: competitor raised price = attention (brick), lowered = good (hop) */
.delta-up { color: var(--brick); }
.delta-down { color: var(--hop); }

/* ---- Stock cell: qty text + bar; hatched fill = censored lower bound ---- */
.stock {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  white-space: nowrap;
}
.stock .qty { font-family: var(--font-mono); font-size: 12px; color: var(--text-3); }
.stock .qty b { color: var(--text-2); font-weight: 400; }
.stockbar {
  flex: none;
  width: 56px;
  height: 6px;
  border-radius: 3px;
  background: var(--surface-2);
  overflow: hidden;
}
.stockbar i { display: block; height: 100%; background: var(--copper); }
.stockbar--censored i { background: var(--hatch); }

/* ---- Badges: one construction — tinted bg, hue border, colored caps text ---- */
.badge {
  display: inline-block;
  margin-left: 4px;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: var(--surface-1);
  color: var(--text-4);
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .05em;
  vertical-align: 1px;
  white-space: nowrap;
}
.badge--new { border-color: var(--amber-edge); background: var(--amber-tint); color: var(--amber); }
.badge--discount { border-color: var(--brick-edge); background: var(--brick-tint); color: var(--brick); }

/* Event lists */
.events {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 12px;
  align-items: start;
}
.events .panel { margin: 0; }
.events ul { list-style: none; margin: 0; padding: 0; }
.events li { padding: 4px 0; border-bottom: 1px solid var(--line-subtle); }
.events li:last-child { border-bottom: 0; }
.events .meta { font-family: var(--font-mono); font-size: 12px; }

details.more > summary {
  cursor: pointer;
  padding: 6px 0 2px;
  color: var(--text-3);
  font-size: 12.5px;
  list-style: none;
}
details.more > summary::before { content: "+ "; color: var(--amber); }
details.more[open] > summary::before { content: "\2212 "; }
details.more > summary:hover { color: var(--text-1); }

/* ---- Forms ---- */
input[type="text"], input[type="search"], input[type="number"], select {
  background: var(--surface-1);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text-1);
  font: inherit;
  font-size: 13px;
  padding: 5px 10px;
  min-height: 32px;
}
select option { background: var(--bg-solid-raised); }
input:hover, select:hover { border-color: var(--line-strong); }
input:focus, select:focus { outline: none; border-color: var(--amber); }
input[type="checkbox"] { accent-color: var(--amber); width: 14px; height: 14px; }

button, .btn {
  background: var(--amber);
  border: 1px solid transparent;
  border-radius: 6px;
  color: #241a08;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  padding: 5px 14px;
  min-height: 32px;
  cursor: pointer;
}
button:hover, .btn:hover { background: var(--amber-hover); color: #241a08; }

.btn-ghost {
  display: inline-block;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--text-2);
  font-size: 13px;
  font-weight: 500;
  padding: 5px 12px;
}
.btn-ghost:hover { background: var(--surface-3); color: var(--text-1); }

/* Filter bar */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  align-items: flex-end;
}
.filters .field { display: flex; flex-direction: column; gap: 4px; }
.filters .field > span {
  font-size: 10.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-4);
}
.filters .pair { display: flex; gap: 6px; }
.filters .pair input { width: 74px; }
.filters .checks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
  align-items: center;
  min-height: 32px;
}
.filters .checks label {
  display: flex;
  gap: 6px;
  align-items: center;
  font-size: 13px;
  color: var(--text-2);
  cursor: pointer;
}
.filters .reset { align-self: flex-end; }

@media (max-width: 720px) {
  .filters { display: grid; grid-template-columns: 1fr 1fr; }
  .filters .field { min-width: 0; }
  .filters .field select, .filters .field input { width: 100%; min-width: 0; }
  .filters .checks { grid-column: 1 / -1; }
  .filters button, .filters .reset { width: max-content; }
}

/* Pagination */
.pager {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--text-3);
}
.count { margin: 0 0 10px; }
