:root {
  --navy: #15233d;
  --navy-2: #1c2f52;
  --navy-deep: #0f1a30;
  --gold: #c69a3f;
  --gold-soft: #e7cf9b;
  --ink: #26303f;
  --muted: #6a7585;
  --line: #e4e7ec;
  --cream: #f7f5f0;
  --bg: #f4f5f7;
  --card: #ffffff;
  --green: #2e7d55;
  --red: #b23a3a;
  --serif: Georgia, "Times New Roman", "Iowan Old Style", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .05);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
h1, h2, h3, .serif { font-family: var(--serif); }
a { color: var(--navy-2); }

.wrap { max-width: 1120px; margin: 0 auto; padding: 24px 20px 72px; }
.eyebrow {
  font-size: 12px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--gold); font-weight: 700;
}
.muted { color: var(--muted); }
.dash { color: var(--muted); }
.center { text-align: center; }

/* ---------- Login shell ---------- */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(198,154,63,.12), transparent),
    linear-gradient(160deg, var(--navy-deep), var(--navy) 60%, var(--navy-2));
  padding: 24px;
}
.login-card {
  width: 100%; max-width: 420px; background: var(--card); border-radius: 14px;
  box-shadow: var(--shadow); padding: 32px 30px; border: 1px solid rgba(255,255,255,.3);
}
.login-card h1 { font-size: 24px; margin: 6px 0 2px; color: var(--navy); line-height: 1.2; }
.login-card .sub { color: var(--muted); font-size: 14px; margin-bottom: 22px; }
.field { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
input[type=email], input[type=text], input[type=date] {
  font: inherit; padding: 11px 12px; border: 1px solid var(--line); border-radius: 9px;
  background: #fff; color: var(--ink); width: 100%;
}
input:focus { outline: 2px solid var(--gold); outline-offset: 1px; border-color: var(--gold); }
.btn {
  font: inherit; font-weight: 600; cursor: pointer; border: none; border-radius: 9px;
  padding: 11px 16px; background: var(--navy); color: #fff; width: 100%;
}
.btn:hover { background: var(--navy-2); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--navy-2); border: 1px solid var(--line); }
.btn-ghost:hover { background: #f1f2f4; }
.btn-link { background: none; border: none; color: var(--navy-2); cursor: pointer; width: auto; padding: 4px; font: inherit; text-decoration: underline; }
.notice { font-size: 13px; padding: 10px 12px; border-radius: 9px; margin: 6px 0 14px; }
.notice.info { background: #eef4ff; color: #274b8f; }
.notice.warn { background: #fff4e5; color: #8a5a12; }
.notice.error { background: #fdecec; color: var(--red); }
.notice.ok { background: #e9f5ee; color: var(--green); }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 0 16px; flex-wrap: wrap;
}
.topbar .who { font-size: 13px; color: var(--muted); }
.topbar .who strong { color: var(--ink); }
.controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.range-tabs { display: flex; gap: 4px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 4px; flex-wrap: wrap; }
.range-tab {
  font: inherit; font-size: 13px; border: none; background: transparent; color: var(--muted);
  padding: 7px 12px; border-radius: 7px; cursor: pointer; font-weight: 600;
}
.range-tab.active { background: var(--navy); color: #fff; }
.custom-dates { display: none; gap: 6px; align-items: center; }
.custom-dates.show { display: flex; }
.custom-dates input { width: 150px; padding: 7px 8px; }

/* ---------- Hero ---------- */
.hero {
  position: relative; overflow: hidden; border-radius: 16px; color: #fff;
  background: linear-gradient(135deg, var(--navy-deep), var(--navy) 55%, var(--navy-2));
  padding: 34px 36px; box-shadow: var(--shadow);
}
.hero::after {
  content: ""; position: absolute; top: -40%; right: -8%; width: 320px; height: 320px;
  border-radius: 50%; border: 60px solid rgba(255,255,255,.04);
}
.hero .eyebrow { color: var(--gold-soft); }
.hero h1 { font-size: 40px; line-height: 1.08; margin: 10px 0 10px; font-weight: 700; }
.hero .hero-sub { font-size: 14px; color: #c9d3e6; font-weight: 600; }
.hero .hero-sub .sep { opacity: .5; margin: 0 8px; }
.hero .hero-tagline { font-size: 18px; margin-bottom: 12px; color: #e7cf9b; font-weight: 700; }

/* ---------- Freshness strip ---------- */
.freshness {
  display: flex; gap: 22px; flex-wrap: wrap; align-items: center;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 18px; margin: 16px 0 24px; font-size: 12.5px;
}
.freshness .stamp .k { color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-size: 10.5px; }
.freshness .stamp .v { color: var(--ink); font-weight: 600; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-weight: 700; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.pill.partial { background: #fff4e5; color: #9a6612; }
.pill.ok { background: #e9f5ee; color: var(--green); }
.pill.error, .pill.unavailable { background: #fdecec; color: var(--red); }
.pill.stale { background: #f0f1f3; color: #566; }

/* ---------- Section scaffolding ---------- */
section { margin: 30px 0; }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.sec-head h2 { font-size: 22px; color: var(--navy); margin: 0; }
.sec-head .hint { font-size: 12.5px; color: var(--muted); }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); padding: 22px; }

/* ---------- KPI grid ---------- */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: 13px; padding: 16px 18px; box-shadow: var(--shadow); }
.kpi.accent { background: var(--cream); border-color: var(--gold-soft); }
.kpi .k { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.kpi .v { font-family: var(--serif); font-size: 30px; color: var(--navy); margin: 7px 0 3px; line-height: 1; font-weight: 700; }
.kpi .v.dash { color: var(--muted); }
.kpi .cap { font-size: 12px; color: var(--muted); }

/* ---------- Takeaways ---------- */
.takeaways { list-style: none; padding: 0; margin: 0; }
.takeaways li { padding: 13px 0; border-bottom: 1px solid var(--line); display: flex; gap: 12px; font-size: 14.5px; }
.takeaways li:last-child { border-bottom: none; }
.takeaways .bullet { color: var(--gold); font-weight: 800; flex: none; }
.takeaways strong { color: var(--navy); }

/* ---------- Charts ---------- */
.chart-legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); margin-bottom: 10px; }
.chart-legend .key { display: inline-flex; align-items: center; gap: 7px; }
.chart-legend .swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.chart-scroll { overflow-x: auto; }
svg { display: block; max-width: 100%; }
svg text { font-family: var(--sans); }

/* ---------- Tables ---------- */
.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 11px 12px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data th:first-child, table.data td:first-child { text-align: left; }
table.data th.left, table.data td.left { text-align: left; }
table.data thead th {
  font-size: 11px; letter-spacing: .06em; text-transform: uppercase; color: var(--muted);
  font-weight: 700; border-bottom: 2px solid var(--line); cursor: default;
}
table.data thead th.sortable { cursor: pointer; user-select: none; }
table.data thead th.sortable:hover { color: var(--navy); }
table.data thead th .arrow { opacity: .5; font-size: 10px; }
table.data tbody tr:hover { background: #fafbfc; }
table.data tfoot td { font-weight: 700; color: var(--navy); border-top: 2px solid var(--line); border-bottom: none; }
.tag { font-size: 11px; color: var(--muted); font-weight: 600; }
.rank { color: var(--muted); font-variant-numeric: tabular-nums; }
.pos-row td { border-bottom-color: var(--gold-soft); }
.pos-row td:first-child { box-shadow: inset 3px 0 0 var(--gold); }
.good { color: var(--green); font-weight: 600; }
.bad { color: var(--red); font-weight: 600; }
td.num, th.num { font-variant-numeric: tabular-nums; }
.thumb { width: 34px; height: 34px; border-radius: 6px; object-fit: cover; background: #eceef1; vertical-align: middle; border: 1px solid var(--line); }
.ad-cell { display: flex; align-items: center; gap: 10px; }
.ad-cell .nm { font-weight: 600; color: var(--ink); }

/* ---------- Master sales summary ---------- */
.panel.master { border-color: var(--gold-soft); box-shadow: none; }
.ms-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.ms-stat { background: var(--cream); border: 1px solid var(--gold-soft); border-radius: 12px; padding: 16px 18px; }
.ms-k { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.ms-v { font-family: var(--serif); font-size: 40px; line-height: 1; color: var(--navy); font-weight: 700; margin: 8px 0 4px; }
.ms-v .dash { font-size: 24px; }
.ms-cap { font-size: 12.5px; color: var(--muted); }
.ms-chips { display: flex; gap: 10px; flex-wrap: wrap; margin: 16px 0 4px; }
.ms-chip { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 12px; color: var(--muted); }
.ms-chip .n { font-family: var(--serif); font-size: 17px; color: var(--navy); font-weight: 700; margin-right: 6px; }
.ms-notes { margin: 14px 0 0; padding-left: 18px; font-size: 13px; color: #44505f; }
.ms-notes li { margin-bottom: 6px; }
.ms-notes strong { color: var(--navy); }
.banner.coverage { margin-top: 0; }
.ad-cell .ids { font-size: 10.5px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 2px; }

/* ---------- Ad-by-ad detail cards (PDF two-column) ---------- */
.ad-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.ad-card { position: relative; border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 16px; }
.adc-badge { position: absolute; top: 12px; left: 12px; background: var(--navy); color: #fff; font-family: var(--serif); font-weight: 700; font-size: 12px; border-radius: 999px; padding: 3px 9px; }
.adc-grid { display: block; }
.adc-thumb { width: 100%; height: 170px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 8px; background: var(--cream); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.adc-thumb img { width: 100%; height: 100%; object-fit: contain; display: block; }
.adc-thumb.missing { border-style: dashed; }
.adc-noimg { font-size: 11px; color: var(--muted); text-align: center; padding: 6px; }
.adc-body { min-width: 0; }
.adc-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.adc-name { font-size: 19px; color: var(--navy); font-weight: 700; }
.adc-pill { font-size: 10px; letter-spacing: .05em; text-transform: uppercase; font-weight: 700; color: var(--gold); border: 1px solid var(--gold-soft); border-radius: 999px; padding: 2px 8px; white-space: nowrap; }
.adc-ids { font-size: 11px; color: var(--muted); font-variant-numeric: tabular-nums; margin: 3px 0 10px; }
.adc-strip { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 10px 0; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.adc-metric-k { font-size: 10px; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.adc-metric-v { font-family: var(--serif); font-size: 20px; color: var(--navy); font-weight: 700; margin-top: 2px; }
.adc-metric-v .sale-strong { color: var(--gold); }
.adc-detail { margin: 10px 0; }
.adc-row { display: flex; justify-content: space-between; font-size: 13px; padding: 4px 0; border-bottom: 1px solid #f0f1f3; }
.adc-row:last-child { border-bottom: none; }
.adc-row-l { color: var(--muted); }
.adc-row-v { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }
.adc-bars { margin-top: 8px; }
.adc-bar { display: flex; align-items: center; gap: 8px; font-size: 11.5px; margin-top: 5px; }
.adc-bar-l { width: 78px; color: var(--muted); flex: none; }
.adc-bar-track { flex: 1; height: 7px; background: #eef0f3; border-radius: 4px; overflow: hidden; }
.adc-bar-fill { display: block; height: 100%; border-radius: 4px; }
.adc-bar-fill.spend { background: var(--navy); }
.adc-bar-fill.sales { background: var(--gold); }
.adc-bar-v { width: 40px; text-align: right; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; flex: none; }

/* ---------- Methodology ---------- */
.method-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.method-block h3 { font-size: 15px; color: var(--navy); margin: 0 0 8px; }
.method-list { margin: 0; padding-left: 18px; font-size: 13px; color: #44505f; }
.method-list li { margin-bottom: 7px; }
.evidence-chips { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
.chip { background: var(--cream); border: 1px solid var(--gold-soft); border-radius: 10px; padding: 9px 13px; font-size: 12.5px; }
.chip .n { font-family: var(--serif); font-size: 19px; color: var(--navy); font-weight: 700; display: block; }
.chip .l { color: var(--muted); }

.footer-note { margin-top: 40px; padding-top: 16px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); text-align: center; }

/* utility + element-scoped helpers (keeps CSP style-src 'self', no inline styles) */
.stamp-grow { flex: 1; min-width: 180px; }
.prov { font-weight: 400; color: var(--muted); }
.data .nm { font-weight: 600; color: var(--ink); }
.data td.sale-strong { font-weight: 700; color: var(--navy); }
.mt10 { margin-top: 10px; }
.mt16 { margin-top: 16px; }

.banner { border-radius: 12px; padding: 12px 16px; margin-bottom: 18px; font-size: 13.5px; }
.banner.warn { background: #fff4e5; color: #8a5a12; border: 1px solid #f0d9ad; }
.banner.error { background: #fdecec; color: var(--red); border: 1px solid #f3c7c7; }

.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--navy); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 920px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .ad-cards { grid-template-columns: 1fr; }
  .method-grid { grid-template-columns: 1fr; }
  .hero h1 { font-size: 30px; }
  .hero { padding: 26px 22px; }
}
@media (max-width: 560px) {
  .wrap { padding: 16px 14px 56px; }
  .kpis { grid-template-columns: 1fr 1fr; }
  .ad-cards { grid-template-columns: 1fr; }
  .ms-stats { grid-template-columns: 1fr; }
  .adc-grid { grid-template-columns: 1fr; }
  .adc-thumb { width: 100%; height: 170px; }
  .kpi .v { font-size: 25px; }
  .hero h1 { font-size: 25px; }
  .freshness { gap: 14px; }
  .range-tab { padding: 6px 9px; font-size: 12px; }
}
