/* ─── Tokens ─────────────────────────────────────────────────────────────── */
:root {
  --bg:       #0f1117;
  --surface:  #181c27;
  --border:   #252936;
  --border2:  #2e3347;
  --text:     #dde1f0;
  --sub:      #7c83a0;
  --faint:    #454b63;
  --accent:       #4f8ef7;
  --chart-closed: #34d399;
  --green:    #4ade80;
  --amber:    #f8b84e;
  --red:      #f87171;
  --radius:   8px;
}
:root[data-theme="light"] {
  --bg:      #f4f5f8;
  --surface: #ffffff;
  --border:  #e0e3ec;
  --border2: #c8cdde;
  --text:    #1a1e2e;
  --sub:     #5a6080;
  --faint:   #a0a8c0;
  --accent:  #2563eb;
  --chart-closed: #059669;
  --green:   #16a34a;
  --amber:   #d97706;
  --red:     #dc2626;
}

/* ─── Reset & base ───────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { cursor: pointer; font: inherit; }
table { border-collapse: collapse; width: 100%; }

/* ─── Layout ─────────────────────────────────────────────────────────────── */
.app { display: flex; flex-direction: column; min-height: 100vh; }
.content { flex: 1; padding: 24px; max-width: 1280px; margin: 0 auto; width: 100%; }

/* ─── Top nav ────────────────────────────────────────────────────────────── */
.topnav {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0 20px;
  height: 46px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.nav-brand {
  display: flex;
  align-items: baseline;
  gap: 4px;
  margin-right: 24px;
  flex-shrink: 0;
}
.brand-label {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--text);
}
.brand-sub {
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.nav-tabs {
  display: flex;
  gap: 2px;
  flex: 1;
}
.tab-btn {
  background: none;
  border: none;
  color: var(--sub);
  padding: 0 14px;
  height: 46px;
  font-size: 12.5px;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--text); border-bottom-color: var(--accent); }

.nav-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.sync-status { font-size: 11px; color: var(--sub); }
.sync-status.syncing { color: var(--amber); }
.sync-status.ok { color: var(--green); }

/* ─── Sync banner ────────────────────────────────────────────────────────── */
.sync-banner {
  background: #1e2038;
  border-bottom: 1px solid var(--border);
  color: var(--amber);
  font-size: 11.5px;
  padding: 7px 24px;
  text-align: center;
}

/* ─── Buttons ────────────────────────────────────────────────────────────── */
.btn-sm {
  background: var(--border);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 11.5px;
  font-weight: 500;
  transition: background 0.12s;
}
.btn-sm:hover { background: var(--border2); }

/* ─── Loading ────────────────────────────────────────────────────────────── */
.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  gap: 16px;
  color: var(--sub);
}
.loading-spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Section headings ───────────────────────────────────────────────────── */
.section-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--sub);
  margin-bottom: 12px;
}

/* ─── KPI tiles ──────────────────────────────────────────────────────────── */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.kpi-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.kpi-label {
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sub);
  margin-bottom: 6px;
}
.kpi-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.kpi-value.green { color: var(--green); }
.kpi-value.amber { color: var(--amber); }
.kpi-value.red   { color: var(--red); }
.kpi-sub {
  font-size: 10.5px;
  color: var(--sub);
  margin-top: 4px;
}
.kpi-sub-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.kpi-sub-row span {
  font-variant-numeric: tabular-nums;
}

/* ─── Cards ──────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--sub);
  margin-bottom: 14px;
}

/* ─── Two-column grid ────────────────────────────────────────────────────── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}
@media (max-width: 760px) { .two-col { grid-template-columns: 1fr; } }

/* ─── Tables ─────────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  font-size: 12.5px;
}
.data-table th {
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--sub);
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th.r, .data-table td.r { text-align: right; }
.data-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-variant-numeric: tabular-nums;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(79,142,247,0.04); }
.data-table .muted { color: var(--sub); }

/* ─── Inline badges / pills ──────────────────────────────────────────────── */
.pill {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 100px;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.6;
}
.pill-blue   { background: rgba(79,142,247,.15); color: #7fb3ff; }
.pill-green  { background: rgba(74,222,128,.12); color: var(--green); }
.pill-amber  { background: rgba(248,184,78,.12); color: var(--amber); }
.pill-red    { background: rgba(248,113,113,.12); color: var(--red); }
.pill-gray   { background: rgba(100,110,140,.15); color: var(--sub); }

/* Category colours */
.cat-refund    { color: var(--red); }
.cat-shipping  { color: var(--amber); }
.cat-exchange  { color: #a78bfa; }
.cat-order     { color: var(--accent); }
.cat-product   { color: #34d399; }
.cat-damage    { color: #fb923c; }
.cat-retention { color: #f472b6; }
.cat-other     { color: var(--sub); }

/* ─── Bar fill ───────────────────────────────────────────────────────────── */
.bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}
.bar-track {
  flex: 1;
  height: 5px;
  background: var(--border2);
  border-radius: 3px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.4s ease;
}
.bar-fill.green { background: var(--green); }
.bar-fill.amber { background: var(--amber); }
.bar-fill.red   { background: var(--red); }

/* ─── Volume chart ───────────────────────────────────────────────────────── */
.chart-wrap {
  width: 100%;
  overflow-x: auto;
}
.vol-chart {
  width: 100%;
  height: 150px;
  display: block;
  cursor: crosshair;
}
.chart-hit { cursor: crosshair; }
.chart-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  color: var(--sub);
  margin-bottom: 8px;
}
.cl-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.chart-tooltip {
  position: absolute;
  top: 10px;
  left: 14px;
  background: var(--surface);
  border: 1px solid var(--border2);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 11.5px;
  color: var(--text);
  pointer-events: none;
  display: none;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
  min-width: 150px;
  z-index: 10;
}
.tt-day { font-size: 10.5px; color: var(--sub); margin-bottom: 2px; }
.tt-row { display: flex; align-items: center; gap: 6px; }
.tt-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }

/* ─── Collapsible stores card ────────────────────────────────────────────── */
.stores-card > summary { list-style: none; cursor: pointer; }
.stores-card > summary::-webkit-details-marker { display: none; }
.stores-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.stores-chevron {
  font-size: 14px;
  color: var(--sub);
  transition: transform 0.18s ease;
  flex-shrink: 0;
}
.stores-card[open] .stores-chevron { transform: rotate(180deg); }

/* ─── Funnel ─────────────────────────────────────────────────────────────── */
.funnel-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
}
.funnel-row:last-child { border-bottom: none; }
.funnel-label { width: 160px; font-size: 12px; color: var(--text); flex-shrink: 0; }
.funnel-count { width: 40px; text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--sub); flex-shrink: 0; }
.funnel-bar-wrap { flex: 1; height: 16px; background: var(--border); border-radius: 3px; overflow: hidden; }
.funnel-bar { height: 100%; background: var(--red); border-radius: 3px; }

/* ─── Agent expand ───────────────────────────────────────────────────────── */
.agent-row { cursor: pointer; }
.agent-macros-row { background: rgba(79,142,247,0.03); }
.agent-macros-row td { padding: 8px 12px 12px 32px; }
.agent-macros-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ─── Empty / pending states ─────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  color: var(--sub);
  padding: 48px 24px;
  font-size: 13px;
}
.pending-banner {
  background: rgba(248,184,78,.08);
  border: 1px solid rgba(248,184,78,.2);
  color: var(--amber);
  border-radius: 6px;
  padding: 12px 16px;
  font-size: 12.5px;
  margin-bottom: 20px;
}
