/* Surveily dashboard — design system tokens straight from desing-system.md.
 *
 * Poppins: display, headings, big numbers. Inter: all UI/body copy.
 * JetBrains Mono: data only (ids, timestamps, table numbers, eyebrows).
 * Orange is the brand colour AND the "high severity" colour, so it is used for
 * brand surfaces and the primary data mark — never to signal a state.
 * Sentence case everywhere; acronyms (CTR, CPC, CPA, PPE, EHS) stay uppercase.
 */
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@600;700;800&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap");

:root {
  /* Brand orange ramp */
  --orange-50:#FFF3EE;  --orange-100:#FFE1D4; --orange-200:#FFC2A8;
  --orange-300:#FF9B72; --orange-400:#FA6B36; --orange-500:#EF4100;
  --orange-600:#CE3400; --orange-700:#A62A00; --orange-800:#7D2000; --orange-900:#551600;

  /* Slate / ink ramp */
  --gray-0:#FFFFFF;  --gray-50:#F7F8FA;  --gray-100:#EEF0F3; --gray-200:#E2E5EA;
  --gray-300:#CBD1DA; --gray-400:#9AA2AF; --gray-500:#6B7482; --gray-600:#4B535F;
  --gray-700:#323A45; --gray-800:#1E242D; --gray-900:#12161C; --ink:#1A1A1A;

  /* Severity semantics — separate from brand on purpose */
  --sev-critical:#E5342B; --sev-critical-bg:#FDECEB;
  --sev-high:#EF4100;     --sev-high-bg:#FFF3EE;
  --sev-medium:#F5A623;   --sev-medium-bg:#FEF4E1;
  --sev-low:#2D7FF9;      --sev-low-bg:#E9F1FF;
  --sev-ok:#1BA672;       --sev-ok-bg:#E4F6EF;

  /* Semantic aliases — reference these, not the raw ramps */
  --brand:#EF4100; --brand-hover:#CE3400; --brand-active:#A62A00;
  --brand-subtle:#FFF3EE; --brand-on:#FFFFFF;

  --text-strong:#1A1A1A; --text-body:#323A45; --text-muted:#6B7482;
  --text-faint:#9AA2AF;  --text-inverse:#FFFFFF;

  --surface-page:#F7F8FA; --surface-card:#FFFFFF; --surface-sunken:#EEF0F3;
  --surface-inverse:#12161C; --surface-hover:#F7F8FA;
  --line:#E2E5EA; --line-strong:#CBD1DA;

  --radius:10px; --radius-lg:14px; --radius-pill:999px;
  --shadow-sm: 0 1px 2px rgba(18,22,28,0.05);
  --shadow: 0 1px 3px rgba(18,22,28,0.07), 0 1px 2px rgba(18,22,28,0.04);

  --font-display: "Poppins", "Inter", ui-sans-serif, system-ui, sans-serif;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--surface-page); color: var(--text-body);
  font-family: var(--font); font-size: 14px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  /* No element may cause horizontal page scroll; wide tables scroll inside
     their own .table-wrap. */
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }
a:focus-visible, button:focus-visible, input:focus-visible {
  outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 6px;
}
h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.02em; color: var(--text-strong); }

/* ----- Top bar (inverse surface — the logo lockup is the light variant) ----- */
.topbar {
  display: flex; align-items: center; gap: 24px;
  padding: 12px 28px; background: var(--surface-inverse);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand img.wordmark { display: block; height: 26px; width: auto; }
.brand-tag {
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--orange-300);
  padding-left: 12px; border-left: 1px solid rgba(255,255,255,0.16);
}

.tabs { display: flex; gap: 2px; margin-left: 8px; }
.tab {
  padding: 7px 14px; border-radius: var(--radius-pill); color: rgba(255,255,255,0.68);
  font-weight: 500; font-size: 13.5px; letter-spacing: -0.005em;
  transition: background 120ms ease, color 120ms ease;
}
.tab:hover { background: rgba(255,255,255,0.08); color: #fff; }
.tab.is-active { background: var(--brand); color: var(--brand-on); font-weight: 600; }
.tab-signout { display: none; }   /* only inside the mobile hamburger menu */

.user { margin-left: auto; display: flex; align-items: center; gap: 12px; color: rgba(255,255,255,0.7); }
.freshness-badge {
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  padding: 4px 10px; border-radius: var(--radius-pill);
  letter-spacing: 0.04em; text-transform: uppercase;
  background: rgba(255,255,255,0.08); color: rgba(255,255,255,0.75);
  border: 1px solid rgba(255,255,255,0.14);
  cursor: help; white-space: nowrap;
}
.freshness-badge.fresh  { background: var(--sev-ok-bg); color: #0F6B4A; border-color: transparent; }
.freshness-badge.stale  { background: var(--sev-medium-bg); color: #8A5A05; border-color: transparent; }
.freshness-badge.broken { background: var(--sev-critical-bg); color: #A81E17; border-color: transparent; }
.avatar { width: 26px; height: 26px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.2); }
.email { font-size: 13px; color: rgba(255,255,255,0.7); }
.logout {
  color: rgba(255,255,255,0.7); font-size: 12.5px; padding: 6px 12px;
  border: 1px solid rgba(255,255,255,0.2); border-radius: var(--radius-pill);
  transition: background 120ms ease, color 120ms ease, border-color 120ms ease;
}
.logout:hover { color: #fff; background: rgba(255,255,255,0.1); border-color: rgba(255,255,255,0.34); }

.hamburger {
  display: none;
  background: transparent; border: 1px solid rgba(255,255,255,0.2); border-radius: 8px;
  padding: 0; cursor: pointer;
  flex-direction: column; gap: 4px; align-items: center; justify-content: center;
  width: 38px; height: 38px;
}
.hamburger span { display: block; width: 18px; height: 2px; background: #fff; border-radius: 1px; transition: transform 200ms ease, opacity 200ms ease; }
.hamburger[aria-expanded="true"] span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.hamburger[aria-expanded="true"] span:nth-child(2) { opacity: 0; }
.hamburger[aria-expanded="true"] span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

/* ----- Range bar ----- */
.range {
  display: flex; align-items: center; gap: 14px; padding: 18px 28px 6px;
  flex-wrap: wrap; max-width: 1480px; margin: 0 auto;
}
.range label {
  font-family: var(--mono); color: var(--text-muted); font-size: 10.5px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.08em;
  display: flex; align-items: center; gap: 8px;
}
.range input[type="date"] {
  padding: 7px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface-card); font-family: var(--font); font-size: 13.5px; color: var(--text-strong);
}
.range input[type="date"]:hover { border-color: var(--line-strong); }
.btn-primary {
  background: var(--brand); color: var(--brand-on); border: 0; padding: 8px 18px;
  border-radius: var(--radius-pill); font-family: var(--font);
  font-weight: 600; font-size: 13.5px; letter-spacing: -0.005em; cursor: pointer;
  transition: background 120ms ease, transform 80ms ease;
}
.btn-primary:hover { background: var(--brand-hover); }
.btn-primary:active { background: var(--brand-active); transform: translateY(1px); }
.range-sep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }

main { padding: 8px 28px 64px; max-width: 1480px; margin: 0 auto; }

/* ----- Page intro ----- */
.intro { margin: 14px 0 20px; }
.eyebrow {
  font-family: var(--mono); font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--brand);
  margin-bottom: 6px;
}
.intro h1 { margin: 0; font-size: 26px; font-weight: 800; letter-spacing: -0.03em; }
.intro p { margin: 6px 0 0; color: var(--text-muted); font-size: 13.5px; max-width: 70ch; }

/* ----- KPI tiles ----- */
.kpis {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr));
  gap: 10px; margin-bottom: 20px;
}
.kpi {
  background: var(--surface-card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm);
}
.kpi.accent { border-color: var(--orange-200); background: linear-gradient(180deg, var(--brand-subtle), var(--surface-card) 60%); }
.kpi .label {
  font-family: var(--mono); color: var(--text-muted); font-size: 10px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.08em;
}
.kpi .value {
  font-family: var(--font-display); font-size: 24px; font-weight: 700;
  letter-spacing: -0.03em; color: var(--text-strong); margin-top: 8px;
  font-variant-numeric: tabular-nums;
}
.kpi .sub { color: var(--text-faint); font-size: 11.5px; margin-top: 6px; }
.delta {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 8px;
  font-family: var(--mono); font-size: 11px; font-weight: 500;
  padding: 2px 8px; border-radius: var(--radius-pill);
  background: var(--surface-sunken); color: var(--text-muted);
}
.delta.up   { background: var(--sev-ok-bg); color: #0F6B4A; }
.delta.down { background: var(--sev-critical-bg); color: #A81E17; }
.delta .arrow { font-size: 10px; }

/* ----- Cards ----- */
.card {
  background: var(--surface-card); border: 1px solid var(--line);
  border-radius: var(--radius-lg); padding: 18px 20px; box-shadow: var(--shadow-sm);
  margin-bottom: 18px;
}
.card.no-pad { padding: 0; }
.card.no-pad > h2, .card.no-pad > .card-head { padding: 18px 20px 12px; margin: 0; }
.card h2 { margin: 0 0 4px; font-size: 15px; font-weight: 700; letter-spacing: -0.02em; }
.card .card-sub { color: var(--text-muted); font-size: 12px; margin: 0 0 14px; }
.card-head h2 { margin-bottom: 4px; }
.card-head .card-sub { margin: 0; }

.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 18px; margin-bottom: 18px; }
.two-col > .card { margin-bottom: 0; }
/* Three single-measure charts side by side; they stack below ~1100px. */
.chart-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; margin-bottom: 18px; }
.chart-grid > .card { margin-bottom: 0; }

/* ----- Charts (canvas always inside a fixed-height box) ----- */
.chart-box { position: relative; width: 100%; }
.chart-box > canvas { width: 100% !important; height: 100% !important; display: block; }

/* ----- Tables ----- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table-wrap > table { min-width: 860px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td {
  padding: 10px 14px; text-align: right; border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
th:first-child, td:first-child { text-align: left; }
thead th {
  font-family: var(--mono); background: var(--surface-sunken); color: var(--text-muted);
  font-weight: 500; font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em;
}
tbody tr:hover { background: var(--surface-hover); }
tbody tr:last-child td { border-bottom: 0; }
tr.total td { font-weight: 600; background: var(--surface-sunken); border-top: 1px solid var(--line-strong); color: var(--text-strong); }
td.num { font-family: var(--mono); font-size: 12.5px; color: var(--text-strong); font-variant-numeric: tabular-nums; }
td.num.dim { color: var(--text-faint); }
td.name { font-weight: 500; color: var(--text-strong); max-width: 340px; overflow: hidden; text-overflow: ellipsis; }
td.meta { font-family: var(--mono); font-size: 11.5px; color: var(--text-muted); text-align: left; }

/* Two-level table: campaign header row with its ad groups nested beneath. */
tbody.grp { border-bottom: 1px solid var(--line); }
tbody.grp:last-of-type { border-bottom: 0; }
tr.grp-head > td { font-weight: 600; color: var(--text-strong); border-bottom: 0; padding-top: 12px; }
tr.grp-head > td.num { font-weight: 600; }
tr.grp-child > td { border-bottom: 0; padding-top: 6px; padding-bottom: 6px; }
tr.grp-child > td.num { color: var(--text-muted); font-size: 12px; }
tr.grp-child:last-child > td { padding-bottom: 14px; }
/* The nested block is marked by a hairline rule down the left of the name
   column, not by dashes or glyphs in front of every row. */
td.name.sub {
  padding-left: 28px; font-weight: 400; font-size: 12.5px;
  color: var(--text-muted); position: relative;
}
td.name.sub::before {
  content: ""; position: absolute; left: 15px; top: -6px; bottom: -6px;
  width: 1px; background: var(--line);
}
tr.grp-child:first-of-type > td.name.sub::before { top: 0; }
tr.grp-child:last-child > td.name.sub::before { bottom: 14px; }

/* Status pills — campaign state, never brand orange (that would read as severity) */
.pill {
  display: inline-block; padding: 2px 9px; border-radius: var(--radius-pill);
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.06em;
  background: var(--surface-sunken); color: var(--text-muted);
}
.pill.enabled { background: var(--sev-ok-bg); color: #0F6B4A; }
.pill.paused  { background: var(--sev-medium-bg); color: #8A5A05; }
.pill.removed { background: var(--sev-critical-bg); color: #A81E17; }

/* ----- Empty / notice states ----- */
.empty {
  padding: 40px 28px; text-align: center; color: var(--text-muted); font-size: 13px;
}
.empty .empty-mark {
  width: 44px; height: 44px; margin: 0 auto 14px; display: block;
  border-radius: 50%; background: var(--brand-subtle);
  display: flex; align-items: center; justify-content: center; color: var(--brand);
}
.empty strong {
  display: block; font-family: var(--font-display); font-size: 16px; font-weight: 700;
  letter-spacing: -0.02em; color: var(--text-strong); margin-bottom: 6px;
}
.empty p { margin: 0 auto; max-width: 46ch; }

.note {
  display: flex; gap: 10px; align-items: flex-start;
  background: var(--brand-subtle); border: 1px solid var(--orange-100);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 18px;
  color: var(--text-body); font-size: 13px;
}
.note .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); margin-top: 6px; flex: 0 0 auto; }
.note strong { font-weight: 600; color: var(--text-strong); }

/* ===== Mobile / narrow viewport ===== */
@media (max-width: 900px) {
  .topbar { flex-wrap: wrap; gap: 10px 8px; padding: 10px 16px; position: relative; }
  .brand { order: 0; flex: 1 1 auto; }
  .brand img.wordmark { height: 22px; }
  .brand-tag { display: none; }
  .user { order: 1; gap: 8px; margin-left: auto; }
  .user .email, .user .logout { display: none; }
  .hamburger { display: inline-flex; order: 2; }

  .tabs {
    order: 99; width: 100%; margin: 8px -16px -10px; padding: 8px 16px 12px;
    flex-direction: column; gap: 2px;
    background: var(--surface-inverse); border-top: 1px solid rgba(255,255,255,0.12);
    display: none;
  }
  .tabs.is-open { display: flex; }
  .tab { padding: 12px 14px; font-size: 14px; border-radius: 8px; }
  .tab-signout {
    display: block; margin-top: 8px; padding-top: 14px;
    border-top: 1px solid rgba(255,255,255,0.12); color: var(--orange-300); font-weight: 600;
  }

  .range {
    padding: 12px 16px 6px; gap: 8px;
    display: grid; grid-template-columns: 1fr 1fr;
    grid-template-areas: "from to" "quick quick" "apply apply";
    align-items: center;
  }
  .range > label:nth-of-type(1) { grid-area: from; }
  .range > label:nth-of-type(2) { grid-area: to; }
  .range > #applyRange { grid-area: apply; width: 100%; }
  .range > #quickRange { grid-area: quick; }
  .range-sep { display: none; }
  .range label { flex-direction: column; align-items: stretch; gap: 4px; }
  .range input[type="date"] { width: 100%; padding: 9px 10px; font-size: 14px; }
  #quickRange {
    /* Columns follow the number of buttons. A hard-coded count leaves a dead
       column the moment a preset is added or removed. */
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    gap: 4px; width: 100%;
    background: var(--surface-sunken); border: 1px solid var(--line);
    border-radius: 8px; padding: 3px;
  }
  #quickRange .seg-btn { padding: 8px 4px; font-size: 12px; }

  main { padding: 4px 16px 48px; }
  .intro h1 { font-size: 21px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi { padding: 11px 13px; }
  .kpi .value { font-size: 19px; }
  .two-col, .chart-grid { grid-template-columns: 1fr; gap: 12px; }
  .card { padding: 14px; }
  .card.no-pad > h2, .card.no-pad > .card-head { padding: 14px 14px 10px; }
}

@media (max-width: 480px) {
  .freshness-badge { display: none; }
  main { padding: 4px 12px 40px; }
  .range { padding: 10px 12px 4px; }
  .kpi .value { font-size: 18px; }
}

/* ----- Segmented control (quick ranges) ----- */
.seg { display: inline-flex; background: var(--surface-sunken); border-radius: var(--radius-pill); padding: 3px; border: 1px solid var(--line); }
.seg-btn {
  background: transparent; border: 0; padding: 6px 13px; border-radius: var(--radius-pill);
  font-family: var(--font); font-size: 12.5px; font-weight: 500; color: var(--text-muted);
  cursor: pointer; letter-spacing: -0.005em;
  transition: background 120ms ease, color 120ms ease;
}
.seg-btn:hover:not(.is-active) { color: var(--text-strong); }
.seg-btn.is-active { background: var(--surface-card); color: var(--text-strong); font-weight: 600; box-shadow: var(--shadow-sm); }

/* ----- Login page (its own surface: the ink ground the light logo needs) ----- */
.login-page { background: var(--surface-inverse); }
.login-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 24px 16px; max-width: none;
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface-card);
  border-radius: var(--radius-lg); padding: 28px 28px 22px;
  box-shadow: 0 18px 48px rgba(0,0,0,0.34);
}
.login-brand {
  background: var(--surface-inverse); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 22px; display: flex; justify-content: center;
}
.login-brand img { height: 30px; width: auto; display: block; }
.login-card h1 { margin: 0 0 6px; font-size: 22px; font-weight: 800; letter-spacing: -0.03em; }
.login-sub { margin: 0 0 20px; color: var(--text-muted); font-size: 13px; }
.login-error {
  background: var(--sev-critical-bg); color: #A81E17;
  border-radius: var(--radius); padding: 10px 12px; margin-bottom: 16px;
  font-size: 13px; font-weight: 500;
}
.field { display: block; margin-bottom: 14px; }
.field > span {
  display: block; margin-bottom: 6px;
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted);
}
.field input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 8px; background: var(--surface-card);
  font-family: var(--font); font-size: 14px; color: var(--text-strong);
}
.field input:hover { border-color: var(--line-strong); }
.field input:focus { border-color: var(--brand); outline: 2px solid var(--brand-subtle); outline-offset: 0; }
.btn-block { width: 100%; margin-top: 6px; padding: 11px 18px; font-size: 14px; }
.login-foot { margin: 18px 0 0; color: var(--text-faint); font-size: 11.5px; line-height: 1.5; }
