@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500;600;700&display=swap');

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #0f172a;
  --ink-muted: #64748b;
  --ink-faint: #94a3b8;
  --border: #e2e8f0;
  --accent: #2563eb;
  --accent-dim: #dbeafe;
  --good: #16a34a;
  --good-bg: #f0fdf4;
  --warn: #d97706;
  --warn-bg: #fffbeb;
  --bad: #dc2626;
  --bad-bg: #fef2f2;
  --neutral: #64748b;
  --neutral-bg: #f1f5f9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15,23,42,0.06), 0 1px 8px rgba(15,23,42,0.04);
}

* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, Segoe UI, Arial, sans-serif;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

.mono, .kpi-num, .summary-num, .export-num, td.num, .cod-num {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
}

/* ---- Page shell ---- */
.page { max-width: 960px; margin: 0 auto; padding: 0 20px; }

header {
  background: var(--ink);
  color: white;
  padding: 14px 0;
}
header .page { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
header h1 { margin: 0; font-size: 15.5px; font-weight: 600; letter-spacing: -0.01em; }
.subnav { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.subnav span { color: var(--ink-faint); font-size: 12px; font-family: 'IBM Plex Mono', monospace; }
.subnav a { color: #cbd5e1; text-decoration: none; font-size: 12.5px; font-weight: 500; }
.subnav a:hover { color: white; }
.refresh-btn {
  background: var(--accent); color: white !important; padding: 5px 12px;
  border-radius: 6px; font-weight: 600 !important;
}
.refresh-btn:hover { background: #1d4ed8; }

/* ---- App shell: sidebar + main content ---- */
.app-shell { display: flex; align-items: flex-start; min-height: 100vh; }

.sidebar {
  width: 178px; flex-shrink: 0; background: #111827; min-height: 100vh;
  padding: 16px 0; position: sticky; top: 0;
}
.sidebar-brand { color: white; font-size: 13.5px; font-weight: 600; padding: 0 16px 14px 16px; letter-spacing: -0.01em; }
.sidebar-group { margin-bottom: 10px; }
.sidebar-group-label {
  color: #64748b; font-size: 9.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; padding: 0 16px 4px 16px;
}
.sidebar-link {
  display: block; color: #cbd5e1; text-decoration: none; font-size: 12.5px;
  padding: 5px 16px; border-left: 2px solid transparent; line-height: 1.35;
}
.sidebar-link:hover { color: white; background: rgba(255,255,255,0.04); }
.sidebar-link.active { color: white; background: rgba(59,130,246,0.12); border-left: 2px solid var(--accent); font-weight: 500; }

.main-content { flex: 1; min-width: 0; padding-left: 20px; }

.flash {
  background: var(--warn-bg); border-bottom: 1px solid #fde68a; color: #92400e;
  font-size: 12.5px; padding: 8px 0;
}
.flash .page { }

section { padding: 14px 0; }
.page > section { padding: 14px 20px; }
body > section { max-width: 960px; margin: 0 auto; padding: 14px 20px; }

h2 { font-size: 13px; font-weight: 600; color: var(--ink); margin: 0 0 10px 0; letter-spacing: -0.01em; }
.section-title { font-size: 13.5px; font-weight: 600; margin: 20px 0 10px 0; }

/* ---- KPI / summary cards (telemetry readout style) ---- */
.kpis { display: flex; gap: 10px; flex-wrap: wrap; padding: 14px 20px 4px 20px; max-width: 960px; margin: 0 auto; }
.kpi {
  background: var(--surface); border-radius: var(--radius); padding: 12px 16px;
  flex: 0 0 auto; min-width: 150px; box-shadow: var(--shadow); border-left: 3px solid var(--neutral);
}
.kpi-num { font-size: 22px; font-weight: 600; line-height: 1; }
.kpi-label { font-size: 10.5px; color: var(--ink-muted); margin-top: 4px; text-transform: uppercase; letter-spacing: 0.03em; }
.kpi-green { border-left-color: var(--good); }
.kpi-red { border-left-color: var(--bad); }
.kpi-orange { border-left-color: var(--warn); }
.kpi-blue { border-left-color: var(--accent); }
.kpi-gray { border-left-color: var(--neutral); }

.summary-page { max-width: 960px; margin: 0 auto; padding: 20px; }
.summary-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 18px; }
.summary-card {
  background: var(--surface); border-radius: var(--radius); padding: 14px 18px;
  flex: 0 0 auto; min-width: 160px; box-shadow: var(--shadow); border-left: 3px solid var(--neutral);
  text-decoration: none; color: inherit; transition: transform 0.12s, box-shadow 0.12s;
}
.summary-card:hover { transform: translateY(-1px); box-shadow: 0 4px 14px rgba(15,23,42,0.10); }
.summary-num { font-size: 26px; font-weight: 700; line-height: 1; }
.summary-label { font-size: 11px; color: var(--ink-muted); margin-top: 5px; }
.summary-red { border-left-color: var(--bad); }
.summary-orange { border-left-color: var(--warn); }
.summary-blue { border-left-color: var(--accent); }
.summary-green { border-left-color: var(--good); }

.export-row { display: flex; gap: 10px; flex-wrap: wrap; }
.export-card {
  background: var(--surface); border-radius: var(--radius); padding: 12px 18px;
  flex: 0 0 auto; min-width: 150px; box-shadow: var(--shadow); text-align: center;
}
.export-num { font-size: 20px; font-weight: 700; color: var(--ink); }
.export-label { font-size: 11px; color: var(--ink-muted); margin: 4px 0 10px 0; }
.export-btn {
  display: inline-block; background: var(--ink); color: white; text-decoration: none;
  padding: 5px 14px; border-radius: 6px; font-size: 12px; font-weight: 500;
}
.export-btn:hover { background: #334155; }

/* ---- Sync status readout ---- */
.sync-status {
  background: var(--ink); color: #cbd5e1; border-radius: var(--radius);
  padding: 10px 18px; font-family: 'IBM Plex Mono', monospace; font-size: 12px;
  margin: 0 20px 14px 20px; max-width: 920px; margin-left: auto; margin-right: auto;
}
.sync-status .sync-line { display: flex; gap: 10px; align-items: baseline; }
.sync-status .sync-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--good); flex-shrink: 0; }
.sync-status .sync-dot.stale { background: var(--warn); }
.sync-status .sync-dot.error { background: var(--bad); }
.sync-status b { color: white; font-weight: 600; }
.sync-status + .sync-status { margin-top: -8px; }

/* ---- COD banner ---- */
.cod-banner {
  background: var(--warn-bg); border: 1px solid #fde68a; border-radius: var(--radius);
  padding: 9px 16px; margin: 0 20px 14px 20px; max-width: 920px; margin-left: auto; margin-right: auto;
  font-size: 12.5px; font-weight: 500; color: #92400e;
}
.cod-banner .cod-num { font-size: 14px; font-weight: 700; }

/* ---- Tables ---- */
table { width: auto; min-width: 260px; max-width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
th, td { text-align: left; padding: 6px 16px 6px 10px; border-bottom: 1px solid var(--border); font-size: 12px; white-space: nowrap; }
th { background: #f8fafc; color: var(--ink-muted); font-weight: 600; font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.03em; }
tr:last-child td { border-bottom: none; }
.stuck-row { background: var(--bad-bg); }
.sku-alert { background: var(--bad-bg); font-weight: 600; }
.date-header td { background: var(--accent-dim); font-weight: 700; }
.total-row td { background: #f8fafc; font-weight: 600; }

/* Opt-in sticky header — add class="sticky-table" to a <table> to keep
   its header row pinned while the page scrolls (used on long queues).
   Needs overflow:visible (overriding the default clip-for-rounded-
   corners trick above) or the sticky offset has nothing to react to. */
.sticky-table { overflow: visible; }
.sticky-table th { position: sticky; top: 0; z-index: 2; box-shadow: 0 1px 0 var(--border); }

.hint { color: var(--ink-muted); font-size: 11.5px; }
.filter-row { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.filter-row select { padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; font-size: 12px; }
.filter-row a { font-size: 12px; color: var(--accent); text-decoration: none; }
.filter-row a:hover { text-decoration: underline; }

form { margin: 12px 0; }
input[type="file"] { font-size: 12.5px; }
button {
  background: var(--ink); color: white; border: none; padding: 7px 16px;
  border-radius: 6px; font-family: inherit; font-size: 12.5px; font-weight: 500; cursor: pointer;
}
button:hover { background: #334155; }

/* ---- Date range filter (shared component) ---- */
.daterange { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.daterange input[type="date"] { padding: 4px 8px; border: 1px solid var(--border); border-radius: 6px; font-family: inherit; font-size: 12px; }
.daterange button { padding: 5px 14px; font-size: 12px; }
.daterange .quick-link { font-size: 12px; color: var(--accent); text-decoration: none; margin-left: 4px; }
.daterange .quick-link:hover { text-decoration: underline; }
