:root {
  /* GMA New Media Inc. flame palette — exact stops from the gmanmi.com logo */
  --flame-red: #f74401;
  --flame-orange: #fc8e01;
  --flame-yellow: #feda00;
  --flame-grad: linear-gradient(90deg, #f74401 0%, #fc8e01 55%, #feda00 100%);
  --gma-orange: #fc8e01;   /* GMA */
  --gma-orange-2: #d63a00; /* burnt orange — text on white / hover */
  --brand-gray: #666666;
  --bar: #2a9d8f;          /* teal — competitors / neutral data */
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #3a3a3a;
  --muted: #7a7d85;
  --line: #e6e8ee;
  --good: #157347;   /* positive change only */
  --bad: #b42318;    /* negative change only */
  --radius: 11px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Questrial", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.4;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }
.linkbtn { background: none; border: 0; color: var(--gma-orange-2); font: inherit; font-size: 12px; cursor: pointer; text-decoration: underline; padding: 0; }

/* ---- Gate ---- */
.gate {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(130% 110% at 100% 100%, #fff3e6 0%, #f6f7f9 55%);
  z-index: 50;
}
.gate-card {
  position: relative; overflow: hidden;
  background: var(--card); padding: 36px 32px; border-radius: 16px;
  width: min(380px, 92vw); box-shadow: 0 18px 45px rgba(40, 30, 20, .12); text-align: center;
}
.gate-card::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px; background: var(--flame-grad); }
.gate-brand, .brand { font-weight: 400; letter-spacing: -.2px; color: var(--brand-gray); }
.gate-brand { font-size: 26px; }
.gate-brand span, .brand span { font-weight: 700; color: inherit; }
.gate-card h1 { font-size: 18px; margin: 14px 0 4px; }
.gate-sub { color: var(--muted); margin: 0 0 20px; font-size: 13px; }
.gate-card input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 15px; margin-bottom: 12px;
}
.gate-card button {
  width: 100%; padding: 12px; border: 0; border-radius: 10px; background: var(--flame-grad);
  color: #fff; font-weight: 600; font-size: 15px; cursor: pointer;
}
.gate-card button:hover { filter: brightness(0.94); }
.gate-error { color: var(--bad); font-size: 13px; margin: 12px 0 0; }

/* ---- Topbar ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); padding: 12px 24px;
  position: sticky; top: 0; z-index: 20;
}
.topbar::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: var(--flame-grad); }
.brand { font-size: 18px; white-space: nowrap; }
.brand em { font-style: normal; font-weight: 500; color: var(--muted); font-size: 14px; margin-left: 6px; }
.topbar-actions { display: flex; align-items: center; gap: 12px; flex: none; }
.last-updated { color: var(--muted); font-size: 12px; white-space: nowrap; }
.btn-primary, .btn-ghost, .status-chip { white-space: nowrap; }
@media (max-width: 900px) { .brand em { display: none; } }
@media (max-width: 620px) {
  .topbar { flex-wrap: wrap; gap: 8px; }
  .last-updated { display: none; } /* update times live in the status popover */
}
.btn-primary {
  background: var(--flame-grad); color: #fff; border: 0; padding: 9px 16px; border-radius: 9px;
  font-weight: 600; cursor: pointer; font-size: 14px;
}
.btn-primary:hover { filter: brightness(0.94); }
.btn-primary:disabled { opacity: .6; cursor: progress; }
.btn-ghost {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 8px 12px; border-radius: 9px; cursor: pointer; font-size: 13px;
}
.btn-ghost:hover { border-color: #c9ccd4; color: var(--ink); }

/* Source-status summary + popover */
.status-wrap { position: relative; }
.status-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f1f3f7; border: 1px solid var(--line); color: var(--ink);
  padding: 6px 11px; border-radius: 20px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
}
.status-chip:hover { border-color: #c9ccd4; }
.popover {
  position: absolute; right: 0; top: calc(100% + 8px); width: 300px; z-index: 40;
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: 0 12px 30px rgba(16,24,40,.14); padding: 8px;
}
.popover .prow { display: flex; align-items: center; gap: 9px; padding: 8px; border-radius: 8px; }
.popover .prow + .prow { border-top: 1px solid var(--line); }
.popover .pname { font-weight: 600; font-size: 13px; }
.popover .pmeta { color: var(--muted); font-size: 11px; margin-top: 1px; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.dot.connected { background: var(--good); }
.dot.pending { background: #c99700; }
.dot.error { background: var(--bad); }
.popover .pfoot { border-top: 1px solid var(--line); margin-top: 4px; padding: 9px 8px 5px; font-size: 11px; color: var(--muted); }
.popover .pfoot-title { font-weight: 600; margin-bottom: 5px; color: var(--ink); }
.popover .fam { display: flex; align-items: center; gap: 6px; padding: 2px 0; cursor: pointer; }
.popover .fam input { margin: 0; }
.popover #apply-force { margin-top: 6px; }
.stale-tag { font-size: 10px; font-weight: 600; color: #c99700; background: rgba(201,151,0,.12); border-radius: 4px; padding: 1px 5px; vertical-align: middle; }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 4px; background: var(--card); padding: 0 24px; border-bottom: 1px solid var(--line); }
.tab {
  background: transparent; border: 0; border-bottom: 2px solid transparent; color: var(--muted);
  padding: 11px 16px; font-size: 14px; font-weight: 600; cursor: pointer;
}
.tab.active { color: var(--gma-orange-2); border-bottom-color: var(--flame-red); }

main { padding: 20px 24px; max-width: 1180px; margin: 0 auto; }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
@media (max-width: 780px) { .grid { grid-template-columns: 1fr; } }

/* ---- Cards ---- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; margin-bottom: 13px; box-shadow: var(--shadow);
}
.grid .card { margin-bottom: 0; }
.chead { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.chead-l { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card h2 { font-size: 15px; margin: 0; font-weight: 700; }
.meta { color: var(--muted); font-size: 11.5px; margin: 2px 0 10px; letter-spacing: .1px; }
.card h3 { font-size: 12.5px; margin: 12px 0 6px; color: var(--ink); font-weight: 700; }
.card h3:first-of-type { margin-top: 2px; }
.card h3 .hl { color: var(--gma-orange-2); }
.info {
  border: 0; background: none; color: var(--muted); cursor: help; font-size: 12px; padding: 0;
  width: 16px; height: 16px; line-height: 16px; border-radius: 50%;
}
.info:hover { color: var(--gma-orange-2); }

/* "Hide mature" toggle on the Search Strength keyword list */
.kw-toggle { text-align: right; margin: 6px 0 2px; }
.mature-toggle { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--muted); cursor: pointer; }
.mature-toggle input { accent-color: var(--gma-orange); margin: 0; }
.kw-table.hide-mature tr.mature-row { display: none; }

/* Status chips (exceptional states only) */
.chip { font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 6px; letter-spacing: .3px; text-transform: uppercase; }
.chip-sample { background: #fff4d6; color: #8a6d00; }
.chip-pending { background: #eef1f5; color: #566072; }
.chip-error { background: #fdeceb; color: var(--bad); }
.chip-stale { background: #fdf1dd; color: #8a5a00; }

/* Key takeaways strip */
.takeaways { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 13px; }
.tk {
  flex: 1 1 220px; background: var(--card); border: 1px solid var(--line); border-left: 3px solid #c9ccd4;
  border-radius: 9px; padding: 9px 12px; font-size: 13px; box-shadow: var(--shadow); line-height: 1.35;
}
.tk.positive { border-left-color: var(--good); }
.tk.negative { border-left-color: var(--bad); }
.tk.gma { border-left-color: var(--gma-orange); }
.tk b { color: var(--ink); }

/* State messages (empty / error / loading) — compact, layout-preserving */
.empty {
  background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius);
  padding: 22px; text-align: center; color: var(--muted); font-size: 14px;
}
.state-msg { color: var(--muted); font-size: 13px; padding: 4px 0 2px; }
.state-msg .tech { margin-top: 6px; }
.state-msg summary { cursor: pointer; color: var(--gma-orange-2); font-size: 12px; }
.state-msg code { display: block; margin-top: 5px; background: #f6f7f9; border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; font-size: 11px; color: #6a4a2a; white-space: pre-wrap; word-break: break-word; }

/* KPI */
.kpis { display: flex; gap: 16px; flex-wrap: wrap; }
.kpi { min-width: 104px; }
.kpi .val { font-size: 22px; font-weight: 800; letter-spacing: -.5px; }
.kpi .val .unit { font-size: 14px; font-weight: 600; color: var(--muted); }
.kpi .lbl { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.kpi .sub { font-size: 11px; margin-top: 2px; }

/* Groups within a card (e.g., Audience Scale) */
.group-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); margin: 10px 0 6px; }
.group-label:first-child { margin-top: 2px; }

/* Deltas — the ONLY place green/red is used */
.delta { font-size: 12px; font-weight: 600; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.delta.flat { color: var(--muted); font-weight: 500; }

/* Bars */
.bar-row { display: grid; grid-template-columns: 140px 1fr auto; align-items: center; gap: 10px; margin: 6px 0; font-size: 13px; }
.bar-track { background: #eef1f7; border-radius: 6px; height: 15px; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--bar); border-radius: 6px; }
.bar-fill.self { background: var(--flame-grad); }
.bar-val { font-variant-numeric: tabular-nums; color: var(--muted); min-width: 92px; text-align: right; }
.bar-val .d { margin-left: 6px; }
.bar-row .lbl { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Mini sparkbars */
.spark { display: flex; align-items: flex-end; gap: 4px; height: 38px; margin-top: 6px; }
.spark div { flex: 1; background: var(--bar); border-radius: 3px 3px 0 0; min-height: 3px; }

/* Table */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .3px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.self-row td { background: #fff6ef; font-weight: 700; color: var(--ink); }
td .clamp2 {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  line-height: 1.3; max-height: 2.6em;
}
tr.more-row { display: none; }
table.expanded tr.more-row { display: table-row; }
.show-more { background: none; border: 0; color: var(--gma-orange-2); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; padding: 6px 2px 0; }

/* Traffic-sources peer compare (expandable) */
details.compare { margin-top: 8px; }
details.compare summary { cursor: pointer; color: var(--gma-orange-2); font-size: 12px; font-weight: 600; }
.cmp-row { display: grid; grid-template-columns: 120px 1fr; gap: 8px; align-items: center; font-size: 12px; margin: 5px 0; }
.cmp-bars { display: flex; flex-direction: column; gap: 3px; }
.cmp-bar { height: 9px; border-radius: 4px; }
.cmp-bar.gma { background: var(--gma-orange); }
.cmp-bar.peers { background: var(--bar); opacity: .75; }
.cmp-legend { font-size: 11px; color: var(--muted); margin-top: 4px; }
.cmp-legend .k { display: inline-block; width: 9px; height: 9px; border-radius: 3px; vertical-align: middle; margin: 0 4px 0 10px; }
.cmp-legend .k.gma { background: var(--gma-orange); }
.cmp-legend .k.peers { background: var(--bar); }

/* Device split bar */
.split-bar { display: flex; height: 16px; border-radius: 6px; overflow: hidden; margin-top: 12px; }
.split.mobile { background: var(--bar); }
.split.desktop { background: var(--gma-orange); }
.split-legend { display: flex; gap: 16px; margin-top: 7px; font-size: 12px; color: var(--muted); }

.pill { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 12px; background: #eef1f7; color: var(--muted); }
.pill.aio { background: #fff1e6; color: var(--gma-orange-2); font-weight: 600; }
.gap-flag { background: #fdeceb; color: var(--bad); font-weight: 600; }
.gap-ok { background: #e7f5ec; color: var(--good); font-weight: 600; }

#trends-file { margin: 8px 0 4px; font-size: 13px; }

/* Ranking period picker (placeholder until historical months are wired) */
.rank-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.period-picker { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
.period-picker select { font-family: inherit; font-size: 12px; padding: 5px 26px 5px 9px; border: 1px solid var(--line); border-radius: 8px; background: #f6f7f9; color: var(--muted); cursor: not-allowed; }
.period-note { font-size: 10.5px; color: var(--muted); opacity: .85; }

.foot { text-align: center; color: var(--muted); font-size: 12px; padding: 16px; display: flex; gap: 12px; justify-content: center; align-items: center; }

/* Data notes drawer */
.drawer { position: fixed; inset: 0; z-index: 60; background: rgba(20, 16, 12, .35); display: flex; justify-content: flex-end; }
.drawer-panel { width: min(420px, 92vw); height: 100%; background: var(--card); padding: 22px 22px 32px; overflow-y: auto; box-shadow: -12px 0 40px rgba(0,0,0,.2); }
.drawer-panel h3 { margin: 0 0 12px; font-size: 16px; }
.drawer-panel ul { margin: 0; padding-left: 18px; }
.drawer-panel li { font-size: 13px; color: var(--ink); margin-bottom: 12px; line-height: 1.45; }
.drawer-close { position: absolute; top: 14px; right: 18px; background: none; border: 0; font-size: 24px; color: var(--muted); cursor: pointer; line-height: 1; }
