/* Next Gen Marketing Dashboard - styles.css
   Palette: Okabe-Ito colour-blind-safe hues for data, dark-on-light text for AA contrast. */

:root {
  --bg: #f3f6fa;
  --surface: #ffffff;
  --text: #1b2733;
  --text-muted: #46556a;
  --border: #cbd5e1;
  --primary: #0b4f8a;
  --primary-dark: #083b68;
  --focus: #b45309;

  --ok-bg: #e3f4ea;      --ok-text: #0a5c34;      --ok-border: #8fcfa9;
  --err-bg: #fdeaea;     --err-text: #8f1a1a;     --err-border: #eba0a0;
  --warn-bg: #fff3d1;    --warn-text: #6b4200;    --warn-border: #e6c56a;
  --info-bg: #e6f0fb;    --info-text: #0b4f8a;    --info-border: #9fc3ea;

  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 30, 50, 0.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
}

.wrap { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px; }

h1, h2, h3 { line-height: 1.25; margin: 0; }
h2 { font-size: 1.35rem; margin: 32px 0 12px; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 12px; }
code { background: #eef2f7; padding: 1px 5px; border-radius: 4px; font-size: 0.9em; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  background: #fff; color: var(--primary); padding: 10px 14px; border-radius: 6px;
  border: 2px solid var(--primary); font-weight: 600;
}
.skip-link:focus { top: 8px; }

:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Header */
.site-header { background: var(--primary); color: #fff; padding: 20px 0; }
.header-inner { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; justify-content: space-between; }
.eyebrow { margin: 0 0 4px; font-size: 0.85rem; letter-spacing: 0.04em; text-transform: uppercase; opacity: 0.92; }
.site-header h1 { font-size: clamp(1.5rem, 4vw, 2.1rem); }
.refresh-panel { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
.refresh-line { margin: 0; font-size: 0.95rem; }
.refresh-sub { font-size: 0.85rem; opacity: 0.92; }

/* Buttons */
.btn {
  font: inherit; font-weight: 600; min-height: 44px; padding: 8px 20px;
  border-radius: 8px; border: 2px solid transparent; cursor: pointer;
}
.btn-primary { background: #fff; color: var(--primary); border-color: #fff; }
.btn-primary:hover:not(:disabled) { background: #e6f0fb; }
.btn-primary:disabled { opacity: 0.75; cursor: progress; }
.btn-secondary { background: var(--surface); color: var(--primary); border-color: var(--primary); }
.btn-secondary:hover { background: #e6f0fb; }
.site-header .btn:focus-visible { outline-color: #ffd58a; }

/* Panels */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px;
}
.status-panel { margin-top: 24px; }
.status-panel h2, .panel > h2 { margin-top: 0; }
.hint { color: var(--text-muted); font-size: 0.95rem; }

/* Badges: colour is always paired with an icon and text */
.badge {
  display: inline-flex; align-items: center; gap: 8px; margin: 0 0 12px;
  padding: 6px 14px; border-radius: 999px; font-weight: 600; border: 1px solid;
}
.badge-small { margin: 0; padding: 2px 10px; font-size: 0.9rem; }
.badge[data-state="ok"]      { background: var(--ok-bg);   color: var(--ok-text);   border-color: var(--ok-border); }
.badge[data-state="error"]   { background: var(--err-bg);  color: var(--err-text);  border-color: var(--err-border); }
.badge[data-state="warn"]    { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }
.badge[data-state="loading"] { background: var(--info-bg); color: var(--info-text); border-color: var(--info-border); }

.source-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.source-list li { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.src-name { font-weight: 600; min-width: 120px; }
.src-detail { color: var(--text-muted); font-size: 0.92rem; overflow-wrap: anywhere; flex: 1 1 240px; }

.notice {
  margin: 12px 0; padding: 12px 14px; border-radius: 8px; border: 1px solid;
  background: var(--info-bg); color: var(--info-text); border-color: var(--info-border);
}
.notice-error { background: var(--err-bg); color: var(--err-text); border-color: var(--err-border); }
.notice-warn  { background: var(--warn-bg); color: var(--warn-text); border-color: var(--warn-border); }
.notice[hidden] { display: none; }
.notice ul { margin: 6px 0 0; padding-left: 20px; }
.notice p { margin: 0 0 6px; }

/* Filters */
.filters { display: grid; gap: 12px 16px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); align-items: end; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-weight: 600; font-size: 0.92rem; }
.field select, .field input {
  font: inherit; min-height: 44px; padding: 8px 10px; width: 100%;
  border: 1px solid #64748b; border-radius: 8px; background: #fff; color: var(--text);
}
.field-action .btn { width: 100%; }
.filter-summary { margin: 12px 0 0; color: var(--text-muted); font-size: 0.95rem; }

/* KPI cards */
.kpi-grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.kpi {
  background: var(--surface); border: 1px solid var(--border); border-left: 6px solid var(--primary);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; min-width: 0;
}
.kpi:nth-child(n+6) { border-left-color: #b34700; }
.kpi h3 { font-size: 0.92rem; color: var(--text-muted); font-weight: 600; }
.kpi-value { margin: 6px 0 4px; font-size: clamp(1.3rem, 2.6vw, 1.7rem); font-weight: 700; overflow-wrap: anywhere; }
.kpi-value.is-empty { color: var(--text-muted); }
.kpi-note { margin: 0; font-size: 0.8rem; color: var(--text-muted); }

/* Charts */
.chart-grid { display: grid; gap: 16px; grid-template-columns: 1fr; }
@media (min-width: 900px) {
  .chart-grid { grid-template-columns: 1fr 1fr; }
  .chart-wide { grid-column: 1 / -1; }
}
.chart-card { margin: 0; min-width: 0; }
.chart-card figcaption p { margin: 2px 0 12px; font-size: 0.9rem; color: var(--text-muted); }
.chart-box { position: relative; height: 320px; }
.chart-msg {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 16px; color: var(--text-muted); background: #f8fafc;
  border: 1px dashed var(--border); border-radius: 8px; overflow: auto; font-weight: 600;
}
.chart-msg[hidden] { display: none; }
.chart-msg ul { list-style: none; margin: 8px 0 0; padding: 0; font-weight: 400; font-size: 0.92rem; }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; min-width: 900px; }
.data-table th, .data-table td { padding: 10px 12px; text-align: left; border-bottom: 1px solid #e2e8f0; white-space: nowrap; }
.data-table th.num, .data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table thead th { background: #e9eef5; position: sticky; top: 0; }
.data-table tbody tr:nth-child(even) { background: #f8fafc; }
.data-table tfoot th, .data-table tfoot td { background: #e9eef5; font-weight: 700; border-top: 2px solid #94a3b8; border-bottom: 0; }
.sort-btn {
  font: inherit; font-weight: 700; color: var(--text); background: none; border: 0; padding: 4px 2px; cursor: pointer;
  display: inline-flex; gap: 6px; align-items: center; min-height: 32px;
}
.sort-btn .arrow { font-size: 0.8em; color: var(--primary); min-width: 1ch; }
.table-empty td { text-align: center; padding: 24px; color: var(--text-muted); font-weight: 600; white-space: normal; }

/* Answers */
.answers { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); }
.answer-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; min-width: 0; }
.answer-card.q-wide { grid-column: 1 / -1; }
.answer-title { display: flex; gap: 10px; align-items: baseline; margin-bottom: 10px; }
.q-id { background: var(--primary); color: #fff; padding: 2px 10px; border-radius: 6px; font-size: 0.9rem; }
.answer-headline { font-weight: 700; font-size: 1.05rem; }
.facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 8px; margin: 0 0 8px; }
.facts div { background: #f1f5f9; border-radius: 8px; padding: 8px 10px; }
.facts dt { font-size: 0.8rem; color: var(--text-muted); }
.facts dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.rank-list { margin: 0 0 8px; padding-left: 24px; }
.rank-list li { margin-bottom: 8px; }
.rank-list .rank-detail { display: block; color: var(--text-muted); font-size: 0.92rem; }
.answer-note { font-size: 0.9rem; color: var(--text-muted); margin: 8px 0 0; }
.answer-caveat { font-size: 0.92rem; margin: 12px 0 0; padding: 10px 12px; background: var(--warn-bg); color: var(--warn-text); border-radius: 8px; border: 1px solid var(--warn-border); }
.answer-card .table-wrap { margin: 8px 0; }
.answer-card .data-table { min-width: 640px; }
.answer-empty { margin: 0; padding: 12px; background: #f1f5f9; border-radius: 8px; font-weight: 700; color: var(--text-muted); }

/* Method */
.method h3 { margin: 16px 0 6px; }
.formulas { margin: 0 0 12px; padding-left: 22px; }

.site-footer { margin-top: 40px; padding: 20px 0 32px; color: var(--text-muted); font-size: 0.9rem; border-top: 1px solid var(--border); }

@media (max-width: 600px) {
  h2 { font-size: 1.2rem; }
  .refresh-panel { width: 100%; }
  .refresh-panel .btn { width: 100%; }
  .chart-box { height: 280px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
