:root {
  --bg: #f5f6fb; --card: #ffffff; --ink: #0f172a; --muted: #64748b; --faint: #94a3b8;
  --line: #e8eaf2; --line2: #eef0f6;
  --indigo: #6366f1; --violet: #8b5cf6; --green: #16a34a; --red: #dc2626; --amber: #d97706;
  --green-bg: #ecfdf3; --red-bg: #fef2f2; --amber-bg: #fffbeb; --grey-bg: #f1f5f9;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 4px 16px rgba(16,24,40,.06);
  --radius: 14px;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink);
  font: 14px/1.55 'Inter', -apple-system, Segoe UI, Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
canvas { max-width: 100%; }

/* ---------- HERO ---------- */
.hero { background: radial-gradient(120% 140% at 0% 0%, #7c3aed 0%, #6366f1 45%, #4f46e5 100%); color: #fff; padding: 30px 32px 80px; }
.hero-inner { display: flex; justify-content: space-between; align-items: flex-start; max-width: 1180px; margin: 0 auto; gap: 16px; flex-wrap: wrap; }
.logo { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }
.tagline { opacity: .85; font-size: 14px; margin-top: 2px; }
.hero-meta { text-align: right; font-size: 13px; opacity: .9; display: flex; gap: 14px; align-items: center; }
.hero-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; max-width: 1180px; margin: 26px auto -64px; }
@media (max-width: 880px) { .hero-stats { grid-template-columns: repeat(2, 1fr); } }
.hstat { background: var(--card); color: var(--ink); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.hstat .k { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.hstat .v { font-size: 30px; font-weight: 800; margin: 4px 0 2px; letter-spacing: -.02em; }
.hstat .d { font-size: 12.5px; color: var(--muted); }

/* ---------- LAYOUT ---------- */
main { max-width: 1180px; margin: 0 auto; padding: 0 32px 48px; }
section { margin-top: 40px; }
.section-head { margin-bottom: 16px; }
.section-head h2 { font-size: 19px; font-weight: 700; }
.section-sub { color: var(--muted); font-size: 13.5px; margin: 4px 0 0; max-width: 760px; }
.hint { color: var(--faint); font-weight: 500; font-size: 12px; }

.chart-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 880px) { .chart-grid { grid-template-columns: 1fr; } }
.chart-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.chart-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 12px; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
/* fixed-height canvas wrapper — prevents Chart.js infinite-resize growth */
.cv { position: relative; height: 240px; width: 100%; }
.cv-sm { height: 180px; }
.cv > canvas { position: absolute; inset: 0; max-height: 100% !important; max-width: 100% !important; }
.cv-spark { position: relative; height: 46px; width: 100%; margin-top: 10px; }
.cv-spark > canvas { position: absolute; inset: 0; max-height: 100% !important; max-width: 100% !important; }

/* segmented granularity toggle */
.seg { display: inline-flex; background: var(--grey-bg); border: 1px solid var(--line); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button { background: transparent; color: var(--muted); border: 0; padding: 5px 14px; border-radius: 7px; font-weight: 600; font-size: 12.5px; cursor: pointer; }
.seg button.active { background: #fff; color: var(--indigo); box-shadow: var(--shadow); }
.head-row { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; }

/* objective card footer (latest-period + delta) */
.obj-foot { margin-top: 6px; padding-left: 8px; font-size: 11.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }

/* all-KPIs tile grid */
.kpi-group { margin-top: 18px; }
.kpi-group > h4 { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); margin: 0 0 10px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 11px 13px; box-shadow: var(--shadow); }
.tile .tk { font-size: 11.5px; color: var(--muted); font-weight: 500; }
.tile .tv { font-size: 19px; font-weight: 700; margin-top: 2px; letter-spacing: -.01em; }
.tile .tile-sub { font-size: 10.5px; color: var(--faint); margin-top: 3px; }
.tile .tile-stale { font-size: 10.5px; color: var(--amber); font-weight: 700; margin-top: 3px; }
.kpi-group > .group-note { font-size: 11.5px; color: var(--muted); margin: -4px 0 10px; max-width: 760px; line-height: 1.45; }

/* ---------- OBJECTIVE CARDS ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 16px; box-shadow: var(--shadow); position: relative; }
.card::before { content: ''; position: absolute; left: 0; top: 14px; bottom: 14px; width: 4px; border-radius: 4px; }
.card.on_track::before { background: var(--green); }
.card.off_track::before { background: var(--red); }
.card.no_data::before { background: var(--faint); }
.card .label { color: var(--muted); font-size: 12.5px; font-weight: 600; padding-left: 8px; }
.card .value { font-size: 27px; font-weight: 800; margin: 3px 0; padding-left: 8px; letter-spacing: -.02em; }
.card .target { font-size: 12px; color: var(--faint); padding-left: 8px; }
.card .help { font-size: 11.5px; color: var(--faint); margin-top: 8px; padding-left: 8px; line-height: 1.45; }
.card .pill { position: absolute; top: 14px; right: 14px; }

/* ---------- BADGES / PILLS ---------- */
.badge { display: inline-flex; align-items: center; gap: 3px; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; }
.badge.up { color: var(--green); background: var(--green-bg); }
.badge.down { color: var(--red); background: var(--red-bg); }
.badge.flat { color: var(--muted); background: var(--grey-bg); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 4px 11px; border-radius: 999px; font-size: 13px; font-weight: 600; }
.chip.g { background: var(--green-bg); color: var(--green); }
.chip.r { background: var(--red-bg); color: var(--red); }
.chip.n { background: var(--grey-bg); color: var(--muted); }

/* ---------- STAT ROW (user value) ---------- */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
@media (max-width: 880px) { .stat-row { grid-template-columns: repeat(2, 1fr); } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.stat .k { font-size: 12px; color: var(--muted); font-weight: 600; }
.stat .v { font-size: 24px; font-weight: 800; margin-top: 3px; letter-spacing: -.02em; }
.stat .s { font-size: 11.5px; color: var(--faint); margin-top: 3px; }

/* ---------- CALLOUT ---------- */
.callout { background: linear-gradient(90deg, #fff7ed, #fffbeb); border: 1px solid #fde9c8; border-left: 4px solid var(--amber);
  border-radius: var(--radius); padding: 14px 18px; margin-bottom: 16px; font-size: 14px; color: #7c2d12; }
.callout b { color: #9a3412; }

/* ---------- BUTTON ---------- */
button { background: rgba(255,255,255,.18); color: #fff; border: 1px solid rgba(255,255,255,.35); padding: 8px 15px;
  border-radius: 9px; font: inherit; font-weight: 600; font-size: 13px; cursor: pointer; transition: background .15s; }
button:hover { background: rgba(255,255,255,.3); }
button:disabled { opacity: .55; cursor: default; }

/* ---------- REPORT ---------- */
.report { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 22px 18px; box-shadow: var(--shadow); }
.report h2 { font-size: 16px; margin-top: 20px; }
.report table { border-collapse: collapse; width: 100%; margin: 10px 0; }
.report th, .report td { border: 1px solid var(--line); padding: 7px 11px; text-align: left; font-size: 13px; }
.report th { background: var(--grey-bg); font-weight: 600; }
.report code { background: var(--grey-bg); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }

footer { max-width: 1180px; margin: 0 auto; padding: 28px 32px 40px; color: var(--faint); font-size: 12px; border-top: 1px solid var(--line); margin-top: 40px; }

/* acquisition & experiments */
.sub-h { margin: 18px 0 10px; font-size: 15px; }
.card.exp .value { font-size: 20px; }
.badge.warn { color: #b45309; background: #fef3c7; }
.exp-checks { margin-top: 8px; padding-left: 8px; display: flex; flex-direction: column; gap: 3px; }
.exp-check { font-size: 11.5px; display: flex; gap: 6px; align-items: baseline; }
.exp-check .ok { color: var(--green); font-weight: 700; }
.exp-check .ko { color: var(--red); font-weight: 700; }
.exp-check .na { color: var(--faint); font-weight: 700; }
.exp-meta { font-size: 11px; color: var(--faint); padding-left: 8px; margin-top: 6px; }

/* ---------- DATA INTEGRITY ---------- */
.seg-static { display: inline-flex; gap: 6px; align-items: center; }
.card.no_data::before { background: var(--amber, #f59e0b); }
#integrity .card .help { margin-top: 6px; line-height: 1.5; }
#composition .callout { margin-top: 14px; }

/* ---------- PLATFORM COMPONENT TABLE ---------- */
.ptable { display: flex; flex-direction: column; gap: 2px; height: 100%; overflow-y: auto; }
.prow { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 2px; border-bottom: 1px solid var(--line); }
.prow:last-child { border-bottom: 0; }
.prow .pl { display: flex; flex-direction: column; min-width: 0; }
.prow .pl b { font-size: 12.5px; font-weight: 600; }
.prow .pv { display: flex; flex-direction: column; align-items: flex-end; white-space: nowrap; }
.prow .pv b { font-size: 15px; font-weight: 800; letter-spacing: -.01em; }
.prow .s { font-size: 10.5px; color: var(--faint); margin-top: 2px; }

/* chart reconciliation note */
.chart-note { font-size: 11px; color: var(--faint); margin-top: 8px; line-height: 1.4; }
.chart-note.bad { color: var(--red); font-weight: 700; }
