/* ==========================================================================
   OOT Tracker component styles — consumes ONLY tokens.css variables.
   Both themes (client=light / ops=dark) render from this single file.
   ========================================================================== */

/* ---------- base ---------- */

html { font-size: 15px; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv02", "cv03", "cv04", "tnum" 0;
  min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--accent-soft); color: var(--text); }

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

.num { font-variant-numeric: tabular-nums; }

/* ---------- nav ---------- */

.topnav {
  height: var(--nav-h);
  background: var(--nav-bg);
  border-bottom: 1px solid var(--nav-border);
  display: flex;
  align-items: center;
  gap: var(--space-5);
  padding: 0 var(--space-5);
  position: sticky;
  top: 0;
  z-index: 100;
}

.topnav .brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 800;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
  color: var(--text);
}
.topnav .brand:hover { text-decoration: none; }

.topnav .brand img { height: 28px; width: auto; }

.topnav .links {
  display: flex;
  gap: var(--space-1);
  align-items: center;
  flex: 1;
}

.topnav .links a {
  color: var(--text-2);
  font-weight: 600;
  font-size: 0.9rem;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-s);
}

.topnav .links a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }

.topnav .links a.active {
  color: var(--accent);
  background: var(--accent-soft);
}

.topnav .whoami {
  font-size: 0.82rem;
  color: var(--text-3);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

@media (max-width: 760px) {
  .topnav { gap: var(--space-3); padding: 0 var(--space-3); overflow-x: auto; }
  .topnav .whoami .tenant { display: none; }
}

/* ---------- page scaffold ---------- */

.page { max-width: 1280px; margin: 0 auto; padding: var(--space-5) var(--space-5) var(--space-6); }

@media (max-width: 760px) { .page { padding: var(--space-4) var(--space-3) var(--space-6); } }

.hero {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.hero h1 {
  font-size: 1.7rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 0;
  color: var(--text);
}

.hero .sub { color: var(--text-2); font-size: 0.92rem; margin-top: var(--space-1); }

.hero .actions { display: flex; gap: var(--space-2); flex-wrap: wrap; align-items: center; }

/* ---------- cards ---------- */

.card-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow);
  padding: var(--space-4);
}

.card-panel + .card-panel { margin-top: var(--space-4); }

.card-panel h2 {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--text-3);
  margin: 0 0 var(--space-3);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}
.grid-side { display: grid; grid-template-columns: minmax(280px, 34%) 1fr; gap: var(--space-4); align-items: start; }

@media (max-width: 980px) {
  .grid-2, .grid-side { grid-template-columns: 1fr; }
}

/* ---------- KPI tiles ---------- */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: var(--space-3);
  margin-bottom: var(--space-4);
}

@media (max-width: 980px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 560px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }

.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-m);
  box-shadow: var(--shadow);
  padding: var(--space-3) var(--space-4);
  position: relative;
  overflow: hidden;
}

.kpi::before {
  content: "";
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--kpi-bar, var(--accent));
}

.kpi .k {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--text-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kpi .v {
  font-size: 1.9rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  line-height: 1.15;
  margin-top: var(--space-1);
  font-variant-numeric: tabular-nums;
}

.kpi .d { font-size: 0.76rem; color: var(--text-3); margin-top: var(--space-1); }

/* semantic KPI bar colors — set via inline style --kpi-bar */
.kpi[data-tone="ok"]   { --kpi-bar: var(--ok); }
.kpi[data-tone="warn"] { --kpi-bar: var(--warn); }
.kpi[data-tone="bad"]  { --kpi-bar: var(--bad); }

/* ---------- pills / badges ---------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text-2);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.pill[data-tone="accent"] { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill[data-tone="ok"]     { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill[data-tone="warn"]   { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill[data-tone="bad"]    { background: var(--bad-soft); color: var(--bad); border-color: transparent; }

.pill .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
}
.pill.live .dot { animation: pulse 1.6s ease-in-out infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.45; transform: scale(0.8); }
}

/* numbered link badge — matches heat-map badges 1:1 */
.link-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 26px;
  padding: 0 7px;
  border-radius: 7px;
  font-size: 0.8rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  background: var(--accent);
  color: var(--accent-contrast, #fff);
}

/* ---------- tables ---------- */

.tbl { width: 100%; border-collapse: collapse; font-size: 0.9rem; }

.tbl th {
  text-align: left;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-3);
  font-weight: 700;
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border-strong);
  white-space: nowrap;
}

.tbl td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: middle;
}

.tbl tbody tr:last-child td { border-bottom: none; }
.tbl tbody tr.rowlink { cursor: pointer; }
.tbl tbody tr.rowlink:hover td { background: var(--surface-2); }

.tbl td.strong, .tbl td .strong { color: var(--text); font-weight: 600; }
.tbl .num, .tbl td.num { font-variant-numeric: tabular-nums; text-align: right; }
.tbl th.num { text-align: right; }

/* detail table — the client-report summary style (label/value rows) */
.detail-tbl { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.detail-tbl td { padding: var(--space-2) var(--space-3); border: 1px solid var(--border); }
.detail-tbl td:first-child {
  width: 42%;
  background: var(--surface-2);
  color: var(--text-2);
  font-weight: 600;
  font-size: 0.86rem;
}
.detail-tbl td:last-child { color: var(--text); font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- bars (share-of-total inline bars) ---------- */

.bar-row { display: grid; grid-template-columns: minmax(90px, 1fr) 2fr 72px; gap: var(--space-3); align-items: center; padding: var(--space-1) 0; }

.bar-row .lbl { font-size: 0.88rem; color: var(--text-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.bar-row .track { height: 8px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }

.bar-row .fill { height: 100%; border-radius: 999px; background: linear-gradient(90deg, var(--chart-1), var(--chart-2)); }

.bar-row .val { font-size: 0.86rem; color: var(--text); text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- buttons ---------- */

.btn-t {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-s);
  font-size: 0.86rem;
  font-weight: 700;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: box-shadow 0.12s ease, transform 0.12s ease, background 0.12s ease;
}
.btn-t:hover { box-shadow: var(--shadow-lift); text-decoration: none; }
.btn-t:active { transform: translateY(1px); }

.btn-t.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-contrast, #fff);
}

.btn-t.ghost { background: transparent; border-color: var(--border); color: var(--text-2); }

/* ---------- range picker ---------- */

.range-picker { display: inline-flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

.range-picker .rp-pills { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-s); overflow: hidden; }

.range-picker .rp-pills button,
.range-picker .rp-pills a {
  border: none;
  background: var(--surface);
  color: var(--text-2);
  font-size: 0.82rem;
  font-weight: 700;
  padding: 6px 12px;
  cursor: pointer;
}
.range-picker .rp-pills button:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.range-picker .rp-pills button.on { background: var(--accent); color: var(--accent-contrast, #fff); }

.range-picker input[type="date"] {
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-s);
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  padding: 5px 8px;
  font-family: var(--font-sans);
}

.range-picker .rp-label { font-size: 0.82rem; color: var(--text-3); font-weight: 600; }

/* ---------- chart containers (unified heights via tokens) ---------- */

.chart-box-trend { height: var(--chart-h-trend); position: relative; }
.chart-box-cat { height: var(--chart-h-category); position: relative; }
.chart-box-trend canvas, .chart-box-cat canvas { position: absolute; inset: 0; }

/* ---------- sparkline (CSS bars, campaign list) ---------- */

.spark { display: inline-flex; align-items: flex-end; gap: 2px; height: 22px; }
.spark i {
  display: block;
  width: 5px;
  border-radius: 2px 2px 0 0;
  background: var(--chart-1);
  opacity: 0.85;
  min-height: 2px;
}
.spark i:last-child { background: var(--accent); opacity: 1; }

/* ---------- legend ---------- */

.legend { display: flex; gap: var(--space-3); flex-wrap: wrap; font-size: 0.8rem; color: var(--text-2); }
.legend .li { display: inline-flex; align-items: center; gap: 6px; }
.legend .sw { width: 12px; height: 12px; border-radius: 4px; border: 1px solid rgba(255, 255, 255, 0.25); }

/* heat ramp legend bar */
.ramp {
  height: 10px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--heat-1), var(--heat-2), var(--heat-3), var(--heat-4), var(--heat-5));
}

/* ---------- heat map host (parent page side) ---------- */

.heat-host { border: 1px solid var(--border); border-radius: var(--radius-m); overflow: hidden; background: var(--surface-2); }

.heat-toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-wrap: wrap;
}

.heat-toolbar .seg { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-s); overflow: hidden; }
.heat-toolbar .seg button {
  border: none; background: var(--surface); color: var(--text-2);
  font-size: 0.78rem; font-weight: 700; padding: 5px 10px; cursor: pointer;
}
.heat-toolbar .seg button.on { background: var(--accent); color: var(--accent-contrast, #fff); }

.heat-toolbar .spacer { flex: 1; }

.heat-frame-wrap { position: relative; }
.heat-frame-wrap iframe { display: block; width: 100%; border: none; background: #fff; }

/* print-captured heat image replaces the iframe */
img.print-heatmap { display: none; }

/* heat map card: keep heading + captured image on the SAME page in print
   (prevents the "Creative Click Heat Map" heading orphaned alone on a page) */
@media print {
  .card-panel:has(.heat-host) { break-inside: avoid; }
  .card-panel:has(.heat-host) img.print-heatmap { max-height: 78vh; object-fit: contain; }
}

/* ---------- footer ---------- */

footer.site {
  margin-top: var(--space-6);
  padding: var(--space-4) 0;
  border-top: 1px solid var(--border);
  color: var(--text-3);
  text-align: center;
  font-size: 0.8rem;
}

/* ---------- misc ---------- */

.empty-note {
  padding: var(--space-4);
  text-align: center;
  color: var(--text-3);
  font-size: 0.9rem;
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-m);
}

.text-ok { color: var(--ok); }
.text-warn { color: var(--warn); }
.text-bad { color: var(--bad); }
.muted { color: var(--text-3); }

/* report header (client-facing, white-label ready) */
.report-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: var(--space-4);
  flex-wrap: wrap;
  padding-bottom: var(--space-4);
  border-bottom: 2px solid var(--text);
  margin-bottom: var(--space-5);
}
.report-head .rh-left { display: flex; align-items: center; gap: var(--space-4); }
.report-head .rh-logo { height: 44px; width: auto; max-width: 220px; object-fit: contain; }
.report-head h1 { font-size: 1.55rem; font-weight: 800; letter-spacing: -0.02em; margin: 0; }
.report-head .rh-sub { color: var(--text-2); font-size: 0.88rem; margin-top: 4px; }
.report-head .rh-right { text-align: right; font-size: 0.8rem; color: var(--text-3); display: flex; flex-direction: column; gap: var(--space-2); align-items: flex-end; }

/* ==========================================================================
   PRINT — pinned to light values regardless of screen theme, so ops users
   printing the dark dashboard still get a clean light PDF.
   ========================================================================== */

@media print {
  :root, html[data-theme="ops"], html[data-theme="client"] {
    --bg: #fff;
    --surface: #fff;
    --surface-2: #f4f5f7;
    --border: #d5d8de;
    --border-strong: #b9bec7;
    --text: #000;
    --text-2: #333;
    --text-3: #666;
    --accent: #1a6fe8;
    --accent-soft: #eef2ff;
    --shadow: none;
    --shadow-lift: none;
    --grid: rgba(0, 0, 0, 0.1);
    --nav-bg: #fff;
  }

  .topnav, .range-picker, .heat-toolbar, .pdf-bar, footer.site .noprint { display: none !important; }

  body { background: #fff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  .page { max-width: none; padding: 0; }

  .card-panel { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }

  .kpi-grid { grid-template-columns: repeat(6, 1fr); gap: 6px; }
  .kpi .v { font-size: 1.3rem; }

  /* Charts in print: the canvas is a RENDERED BITMAP (laid out at screen
     size). Shrinking its box or forcing a small height clips the artwork
     (donut bottom + legend cut off). Instead: neutralize the absolute
     positioning, size the box TO the canvas (height:auto, no fixed height),
     and let the bitmap scale by width — like an <img>. Atomic via
     break-inside so it never splits across pages. */
  .chart-box-trend, .chart-box-trend { height: auto !important; }
  .chart-box-cat { height: auto !important; }
  .chart-box-trend, .chart-box-cat { break-inside: avoid; overflow: visible; }
  .chart-box-trend canvas, .chart-box-cat canvas {
    position: static !important;
    inset: auto !important;
    display: block;
    width: 100% !important;
    height: auto !important;
    max-height: none;
    break-inside: avoid;
  }

  /* tables + bars rows never split either */
  .tbl, .detail-tbl, .bar-row { break-inside: avoid; }
  .tbl tr, .detail-tbl tr { break-inside: avoid; }

  /* heat map: hide interactive iframe, show captured image */
  .heat-frame-wrap iframe { display: none !important; }
  img.print-heatmap { display: block !important; width: 100%; break-inside: avoid; }

  .report-foot {
    margin-top: 12px; padding-top: 8px; border-top: 1px solid #ccc;
    font-size: 10px; color: #555; display: block !important;
  }
}

.report-foot { display: none; }
