:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #e3e6ea;
  --text: #1a1d23;
  --muted: #6b7280;
  --accent: #4f6df5;
  --accent-soft: #eef1ff;
  --good: #1f9d55;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
  gap: 12px;
}

header.topbar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 650;
}

header.topbar h1 span {
  color: var(--muted);
  font-weight: 400;
  font-size: 13px;
  margin-left: 8px;
}

.filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.data-range-banner {
  background: var(--accent-soft);
  color: var(--text);
  font-size: 12.5px;
  padding: 8px 24px;
  border-bottom: 1px solid var(--border);
  text-align: center;
}

.data-range-banner strong { font-weight: 650; }

.filters label {
  font-size: 12px;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

select, input[type="date"] {
  font-size: 13px;
  padding: 6px 8px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
}

.btn {
  font-size: 13px;
  padding: 7px 12px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  color: var(--text);
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn:hover { filter: brightness(0.97); }

main {
  padding: 20px 24px 48px;
  max-width: 1400px;
  margin: 0 auto;
}

.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

.kpi .label {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 6px;
}

.kpi .value {
  font-size: 22px;
  font-weight: 650;
}

.grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.grid.thirds {
  grid-template-columns: 1fr 1fr;
}

@media (max-width: 900px) {
  .grid, .grid.thirds { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.panel h2 {
  font-size: 14px;
  margin: 0 0 12px;
  font-weight: 650;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel h2 .hint {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted);
}

.chart-wrap { position: relative; height: 280px; }
.chart-wrap.short { height: 220px; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  padding: 7px 6px;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--muted);
  font-weight: 550;
  font-size: 12px;
}

td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

tr:last-child td { border-bottom: none; }

#storeTable tbody tr { cursor: pointer; }
#storeTable tbody tr:hover { background: var(--accent-soft); }

#ordersTable td { white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
#ordersTable td.wrap { white-space: normal; }

.btn:disabled { opacity: 0.4; cursor: not-allowed; }

.bar-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.bar-track {
  flex: 1;
  height: 6px;
  background: var(--accent-soft);
  border-radius: 4px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 4px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}

.badge.good { background: #e7f7ec; color: var(--good); }
.badge.warn { background: #fef3e0; color: var(--warn); }
.badge.bad { background: #fde8e8; color: var(--bad); }

.muted { color: var(--muted); }

.health-list { display: flex; flex-direction: column; gap: 8px; max-height: 280px; overflow-y: auto; }

.health-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.health-row:last-child { border-bottom: none; }

.loading {
  text-align: center;
  padding: 40px;
  color: var(--muted);
}

footer.foot {
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  padding: 20px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --panel: #1c1f26;
    --border: #2b2f38;
    --text: #e7e9ee;
    --muted: #9aa1ad;
    --accent-soft: #23273a;
    --shadow: 0 1px 2px rgba(0,0,0,0.3);
  }
  select, input[type="date"], .btn { background: #22252c; color: var(--text); }
}
