:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --border: #e3e6ec;
  --text: #12141a;
  --muted: #6b7280;
  --accent: #1f6feb;
  --green: #17864a;
  --green-bg: #e7f6ed;
  --amber: #a86a12;
  --amber-bg: #fdf3e0;
  --red: #b4232b;
  --red-bg: #fdecec;
  --grey-bg: #eef0f4;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .04);
}

:root[data-theme="dark"] {
  --bg: #0e1015;
  --surface: #171a21;
  --border: #262b36;
  --text: #e7eaf0;
  --muted: #8b93a3;
  --accent: #5c9dff;
  --green: #4ecb7d;
  --green-bg: #12301f;
  --amber: #e0a33f;
  --amber-bg: #322612;
  --red: #f2777f;
  --red-bg: #331a1c;
  --grey-bg: #1e222b;
  --shadow: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px 64px;
}

.muted { color: var(--muted); font-weight: 400; }

/* ---- top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  max-width: 1080px;
  margin: 0 auto;
  padding: 18px 20px;
}

.brand { display: flex; align-items: center; gap: 9px; font-size: 15px; }

.dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.dot.live { background: var(--green); box-shadow: 0 0 0 3px var(--green-bg); }
.dot.stale { background: var(--red); box-shadow: 0 0 0 3px var(--red-bg); }

.ghost {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 11px;
  font: inherit;
  font-size: 14px;
  cursor: pointer;
}
.ghost:hover { border-color: var(--accent); color: var(--accent); }

/* ---- hero ---- */
.hero { padding: 12px 0 24px; }
h1 { font-size: clamp(26px, 4vw, 34px); margin: 0 0 8px; letter-spacing: -.02em; }
.lede { margin: 0; color: var(--muted); max-width: 62ch; }

/* ---- stats ---- */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.stat-value {
  font-size: 26px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.stat-value.zero { color: var(--red); }
.stat-value.good { color: var(--green); }
.stat-label { font-size: 12.5px; color: var(--muted); }

/* ---- stale warning ---- */
.stale-banner {
  margin: 0 0 16px;
  padding: 11px 14px;
  border-radius: var(--radius);
  background: var(--amber-bg);
  color: var(--amber);
  border: 1px solid currentColor;
  font-size: 14px;
  font-weight: 500;
}
.stale-banner[hidden] { display: none; }

/* ---- source health ---- */
.sources { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 22px; }
.source {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 13px;
}
.source .bullet { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.source.ok .bullet { background: var(--green); }
.source.bad .bullet { background: var(--red); }
.source.idle .bullet { background: var(--muted); }
.source.bad { border-color: var(--red); color: var(--red); }

/* ---- controls ---- */
.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 22px;
}
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }
.field input, .field select {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  min-width: 130px;
}
.field input:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.check { display: flex; align-items: center; gap: 7px; font-size: 14px; padding-bottom: 8px; }
#geoBtn { align-self: flex-end; margin-bottom: 1px; }

/* ---- panels ---- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px 6px;
  margin-bottom: 22px;
}
.panel h2 { font-size: 15px; margin: 0 0 12px; letter-spacing: -.01em; }

.restocks { list-style: none; margin: 0 0 12px; padding: 0; }
.restocks li {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.restocks li:last-child { border-bottom: none; }
.restocks .empty { color: var(--muted); }
.restocks .when { color: var(--muted); font-size: 13px; margin-left: auto; }

/* ---- table ---- */
.table-wrap { overflow-x: auto; margin: 0 -18px; padding: 0 18px; }
table.stores { width: 100%; border-collapse: collapse; font-size: 14px; }
table.stores th {
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 0 12px 8px 0;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
table.stores td {
  padding: 10px 12px 10px 0;
  border-bottom: 1px solid var(--border);
  vertical-align: baseline;
}
table.stores tr:last-child td { border-bottom: none; }
table.stores .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.stores tr.avail td { background: var(--green-bg); }
table.stores a { color: inherit; text-decoration: none; border-bottom: 1px solid var(--border); }
table.stores a:hover { color: var(--accent); border-color: var(--accent); }
.qty { font-weight: 650; }

.pill {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
}
.pill.in_stock { background: var(--green-bg); color: var(--green); }
.pill.low { background: var(--amber-bg); color: var(--amber); }
.pill.out { background: var(--red-bg); color: var(--red); }
.pill.unlisted, .pill.unknown { background: var(--grey-bg); color: var(--muted); }

.disclaimer { color: var(--muted); font-size: 12.5px; max-width: 70ch; }

@media (max-width: 600px) {
  .controls { gap: 10px; }
  .field input, .field select { min-width: 0; width: 100%; }
  .field { flex: 1 1 140px; }
  table.stores th:nth-child(2), table.stores td:nth-child(2) { display: none; }
}
