/* ==========================================================================
   FWM × TRAFFIK - Apple design layer
   Self-contained: defines the Apple-kit tokens locally (FWM's base styles.css
   does not ship them), then re-points the dashboard onto the TRAFFIK palette -
   black / white / red, Apple structure, single-row frosted header.
   Loaded LAST so it overrides the base stylesheets.
   ========================================================================== */

:root {
  /* ---- Apple-kit tokens (mapped onto FWM's base where one exists) -------- */
  --font-text:     var(--font);
  --font-display:  var(--font);
  --material-backdrop: saturate(180%) blur(20px);
  --shadow-1: var(--shadow-xs);
  --shadow-2: var(--shadow-sm);
  --shadow-3: var(--shadow-md);
  --shadow-card: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --radius-md:   10px;
  --radius-pill: 980px;
  --radius-card: 16px;
  --fw-medium:   500;
  --fw-semibold: 600;
  --dur-fast: var(--duration-fast);
  --dur-base: var(--duration-base);
  --ease-standard: var(--ease-out);
  --separator-non-opaque: rgba(0,0,0,.08);
  --bg-primary: #ffffff;
  --fill-tertiary:   #EFEFF0;
  --fill-quaternary: #E6E6E8;
  --transition-color: color var(--duration-fast) var(--ease-out), background var(--duration-fast) var(--ease-out);

  /* ---- TRAFFIK palette - chrome is black per client (was red #D91F1F) --- */
  --tfk-red:        #1A1A1A;
  --tfk-red-dark:   #000000;
  --fwm-primary:     #00b1ca;   /* FWM brand primary (teal) - stats/graphics */
  --fwm-secondary:   #5e2e85;   /* FWM brand secondary (purple) */
  --csun-red:       var(--tfk-red);       /* alias kept so ported rules resolve */
  --csun-red-dark:  var(--tfk-red-dark);
  --tfk-yellow:     #5e2e85;
  --tfk-yellow-dark:#42205d;
  --tfk-yellow-dim: rgba(94, 46, 133, 0.18);
  --tint:           var(--tfk-red);
  --ac-blue:        var(--tfk-red);
  --ac-blue-hover:  var(--tfk-red-dark);
  --ac-link:        var(--tfk-red);
  --gold:           var(--tfk-yellow);
  --gold-dark:      var(--tfk-yellow-dark);
  --gold-dim:       var(--tfk-yellow-dim);

  /* ---- Full TRAFFIK neutral palette ------------------------------------- */
  --tfk-paper:      #FFFFFF;
  --tfk-paper-alt:  #FAFAFA;
  --tfk-ink:        #313131;
  --tfk-ink-2:      #464646;
  --tfk-gray:       #A2A2A2;
  --tfk-gray-light: #DCDDDF;

  --bg:            var(--tfk-paper-alt);
  --surface:       var(--tfk-paper);
  --surface-2:     #F2F2F3;
  --surface-3:     #ECECEE;
  --surface-4:     var(--tfk-gray-light);
  --border:        var(--tfk-gray-light);
  --border-subtle: #E9E9EB;
  --border-strong: #C7C8CB;
  --text:           var(--tfk-ink);
  --text-secondary: var(--tfk-ink-2);
  --text-muted:     var(--tfk-gray);
  --text-disabled:  #C7C8CB;

  /* Brand accents (Meta channel, stats, graphics) use the FWM primary. */
  --mavroon:        var(--fwm-primary);
  --mavroon-dark:   #008598;
  --mavroon-dim:    color-mix(in srgb, var(--fwm-primary) 8%, transparent);
  --mavroon-mid:    color-mix(in srgb, var(--fwm-primary) 15%, transparent);
  --mavroon-border: color-mix(in srgb, var(--fwm-primary) 25%, transparent);
  --brand:          var(--fwm-primary);
  --brand-dark:     #008598;

  /* Channel identity colours (kept distinct for legibility). */
  --google-dark:   #155481;
  --dsp-dark:      #c45e00;
}

/* ============================ Typography ================================= */
body, button, input, select, textarea,
.preset, .view-nav-btn, .ghost-btn, .channel-tab {
  font-family: var(--font-text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
h1, h2, h3,
.header-descriptor, .chart-card-title,
.card-value, .totals .value, .exec-metric-value {
  font-family: var(--font-display);
  letter-spacing: -0.012em;
}

/* ============================ Header - light Apple bar ================== */
/* White frosted bar, single row: logo · nav · status. */
.header {
  position: sticky; top: 0; z-index: 200;
  background: color-mix(in srgb, var(--surface) 82%, transparent);
  -webkit-backdrop-filter: var(--material-backdrop);
  backdrop-filter: var(--material-backdrop);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow-1);
  color: var(--text);
  min-height: 62px; padding-top: 0; padding-bottom: 0;
}
.header-inner { min-height: 62px; gap: 22px; justify-content: flex-start; }
.header-left { gap: 13px; }
.header-right { margin-left: auto; }

/* FWM logo is a full-colour SVG - show it as-is on the light bar (the base
   inverts it to white for the old dark header; undo that). */
.header-logo {
  filter: none;
  height: 30px; width: auto;
}
.header-descriptor { font-weight: var(--fw-semibold); letter-spacing: -0.01em; color: var(--text); }
.header-poweredby { opacity: 1; color: var(--text-muted); letter-spacing: 0.01em; }
.traffik-wordmark { color: var(--text); }

/* Tab nav inline with the logo (Apple toolbar layout). */
.header .view-nav {
  width: auto; max-width: none; margin: 0; align-self: center;
  background: transparent; border-radius: 0; padding: 0; gap: 2px;
  box-shadow: none;
}
.header .view-nav-btn {
  color: var(--text-secondary);
  border-radius: 8px; background: transparent;
  padding: 7px 14px; min-height: 34px; font-weight: var(--fw-medium);
}
.header .view-nav-btn:hover { color: var(--text); background: var(--fill-tertiary); }
.header .view-nav-btn.active {
  background: var(--tfk-red); color: #fff; box-shadow: var(--shadow-1);
}

/* Status text on the light bar. */
.header .freshness-text, .header .freshness-text.subtle, .header .subtle,
.header #last-updated { color: var(--text-muted); }
/* The footer copy of the "Updated ..." label sits on a light background too (gate R12: it was white-on-white). */
.updated-footer #last-updated, .updated-footer .freshness-text { color: var(--text-secondary); }

/* ============================ Date controls - segmented ================== */
.controls { background: transparent; border: 0; }
.preset-group {
  display: inline-flex; gap: 2px; padding: 2px;
  background: var(--fill-tertiary);
  border-radius: 10px; border: 0;
}
.preset {
  border: 0; background: transparent; cursor: pointer;
  min-height: 32px; padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px; font-weight: var(--fw-medium);
  color: var(--text-secondary);
  transition: background var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
}
.preset:hover { background: var(--fill-quaternary); color: var(--text); }
.preset.active, .preset.active:hover {
  background: var(--surface); color: var(--tfk-red);
  box-shadow: var(--shadow-1);
}
.custom-range input, input[type="date"], select { border-radius: 10px; border: 0.5px solid var(--border-strong); }
#apply-custom, .ghost-btn {
  border-radius: 10px;
  border: 0.5px solid var(--border-strong);
  transition: var(--transition-color), transform var(--dur-fast) var(--ease-standard);
}
#apply-custom:active, .ghost-btn:active { transform: scale(0.97); }

/* ============================ Tab nav - segmented (when not in header) === */
.view-nav {
  display: inline-flex; gap: 2px; padding: 2px;
  background: var(--fill-tertiary);
  border-radius: 10px;
  border: 0; box-shadow: none;
}
.view-nav-btn {
  border: 0; background: transparent; cursor: pointer;
  padding: 7px 16px; min-height: 34px;
  border-radius: 8px;
  font-size: 14px; font-weight: var(--fw-medium);
  color: var(--text-secondary);
  transition: background var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
}
.view-nav-btn:hover { color: var(--text); }
.view-nav-btn.active {
  background: var(--bg-primary); color: var(--tfk-red);
  box-shadow: var(--shadow-1);
}

/* ============================ Tab transition - Apple fade =============== */
@keyframes fwm-fade-in  { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes fwm-fade-out { from { opacity: 1; } to { opacity: 0; } }
.view-exit  { animation: fwm-fade-out 150ms var(--ease-standard) forwards !important; }
.view-enter { animation: fwm-fade-in 300ms var(--ease-standard) forwards !important; }

/* ============================ Cards - Apple material ===================== */
.card, .chart-card, .totals .card, .exec-overview .card,
.table-section, .exec-channel-card, .ab-panel {
  background: var(--surface);
  border: 0.5px solid var(--border-subtle);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow-card);
}
.card-interactive:hover { transform: translateY(-2px); box-shadow: var(--shadow-3); }
.card { transition: transform var(--dur-base) var(--ease-standard), box-shadow var(--dur-base) var(--ease-standard); }

/* ============================ Channel filter → segmented ================= */
.channel-tabs {
  display: inline-flex; gap: 2px; padding: 2px;
  background: var(--fill-tertiary); border-radius: 10px; border: 0; box-shadow: none;
}
.channel-tab {
  border: 0; background: transparent; cursor: pointer;
  padding: 7px 16px; min-height: 34px; border-radius: 8px;
  font-size: 14px; font-weight: var(--fw-medium); color: var(--text-secondary);
  transition: background var(--dur-fast) var(--ease-standard), color var(--dur-fast) var(--ease-standard);
}
.channel-tab:hover { color: var(--text); background: transparent; }
.channel-tab.active, .channel-tab.active:hover {
  background: var(--bg-primary); box-shadow: var(--shadow-1); color: var(--tfk-red);
}
.channel-tab[data-channel="google_ads"].active, .channel-tab[data-channel="google_ads"].active:hover { color: var(--google-dark); background: var(--bg-primary); }
.channel-tab[data-channel="meta_ads"].active, .channel-tab[data-channel="meta_ads"].active:hover { color: var(--fwm-primary); background: var(--bg-primary); }
.channel-tab[data-channel="dsp"].active, .channel-tab[data-channel="dsp"].active:hover { color: var(--dsp-dark); background: var(--bg-primary); }

/* ====================== Crispness pass - Apple alignment ================= */
.card-value, .exec-metric-value, .totals .value, .stat-value,
.exec-hero .card-value, .exec-kpi-grid .card-value, .card-overall .card-value {
  font-family: var(--font-display);
  font-weight: var(--fw-semibold);
  letter-spacing: -0.022em;
}
.exec-hero .card-value { letter-spacing: -0.028em; color: var(--fwm-primary); }
.exec-hero .card { padding: 26px 32px; border-top: 0; }

.card-label, .exec-hero .card-label, .exec-kpi-grid .card-label,
.totals .label {
  font-weight: var(--fw-semibold);
  letter-spacing: 0.055em;
  color: var(--text-muted);
}
.exec-kpi-grid { gap: 12px; }

/* Channel breakdown fills the row evenly however many channels run -
   e.g. no DSP → the two cards split the width 50/50 instead of leaving a gap. */
.exec-channels { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

/* TRAFFIK agency logo, top-right of the header (black wordmark on the light bar). */
.header-right { display: inline-flex; align-items: center; gap: 14px; }
.header-traffik-logo { height: 22px; width: auto; display: block; }
/* "Updated …" timestamp relocated from the header to the foot of the page. */
.updated-footer {
  display: flex; align-items: center; justify-content: center; gap: 7px;
  padding: 16px 0 28px;
}
.updated-footer .freshness-text { font-size: 12px; }

/* Filter dropdown focus ring sits INSIDE the control - the view-panel uses
   overflow:hidden for the wipe animation, which was clipping an outset ring at the top. */
select:focus, select:focus-visible {
  outline: none;
  border-color: var(--tfk-red);
  box-shadow: inset 0 0 0 2px var(--tfk-red);
}

/* ── Mobile: burger nav + tap targets (ported from the JenaValve dashboard) ── */
.nav-burger {
  display: none; align-items: center;
  border: 0.5px solid var(--border-strong); background: var(--surface); color: var(--text);
  min-height: 40px; padding: 8px 12px; border-radius: 999px; cursor: pointer;
  margin-left: 8px; flex: none;
}
.burger-lines { display: inline-flex; flex-direction: column; justify-content: center; gap: 3.5px; width: 16px; height: 12px; }
.burger-lines span { display: block; height: 1.8px; width: 100%; background: currentColor; border-radius: 2px;
  transition: transform .25s ease, opacity .2s ease; }
.header.menu-open .burger-lines span:nth-child(1) { transform: translateY(5.3px) rotate(45deg); }
.header.menu-open .burger-lines span:nth-child(2) { opacity: 0; }
.header.menu-open .burger-lines span:nth-child(3) { transform: translateY(-5.3px) rotate(-45deg); }
.nav-scrim {
  position: fixed; inset: 0; z-index: 150; background: rgba(0,0,0,0.16);
  opacity: 0; visibility: hidden; transition: opacity .2s ease, visibility .2s ease;
}
.nav-scrim.open { opacity: 1; visibility: visible; }

@media (max-width: 768px) {
  /* Compact single header row (overrides the stacked base) */
  .header { flex-direction: row; align-items: center; padding: 10px 16px; }
  .header-inner { display: flex; align-items: center; gap: 10px; width: 100%; }
  .header-titleblock { display: none; }
  .header-right { display: none; }         /* TRAFFIK logo yields the row on phones */
  .nav-burger { display: inline-flex; margin-left: auto; }

  /* The tab strip becomes a dropdown card anchored under the sticky header */
  .header .view-nav {
    position: absolute; top: calc(100% + 6px); left: 12px; right: 12px; z-index: 210;
    display: flex; flex-direction: column; align-items: stretch; gap: 2px;
    width: auto; padding: 8px; margin: 0; overflow-y: auto; max-height: calc(100vh - 90px);
    background: color-mix(in srgb, var(--surface) 96%, transparent);
    -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
    border: 0.5px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-2);
    opacity: 0; visibility: hidden; transform: translateY(-8px);
    transition: opacity .2s ease, transform .2s ease, visibility .2s ease;
  }
  .header.menu-open .view-nav { opacity: 1; visibility: visible; transform: translateY(0); }
  .header .view-nav-btn {
    width: 100%; flex-shrink: 1; text-align: left;
    min-height: 44px; padding: 10px 14px; border-radius: 10px; font-size: 15px;
  }

  /* Every tappable control meets the 44px HIG minimum */
  .preset, .channel-tab, select, .custom-range input, #apply-custom { min-height: 44px; }
  .preset { padding: 10px 8px; }

  /* Hero number sized for a phone */
  .exec-hero .card-value { font-size: 38px; }

  /* Campaign drill-down modal: chart pairs stack full-width - nothing pokes
     off-screen (cm-grid-2 was still 1fr 1fr on phones). */
  .campaign-modal-panel { width: 100vw; }
  .cm-grid-2 { grid-template-columns: 1fr; }
  .cm-grid-2 > *, .cm-section-body { min-width: 0; }
  .cm-chart, .cm-section-body svg, .cm-section-body canvas { max-width: 100%; }
  .cm-kpi-strip { grid-template-columns: repeat(2, 1fr); }

  /* Full-width charts earn a little more height on a phone */
  .chart-wrap { height: 260px; }

  /* Channel tab strip swipes sideways instead of clipping */
  .channel-tabs { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  .channel-tabs::-webkit-scrollbar { display: none; }
  .channel-tab { flex: 0 0 auto; }

  /* Table headers (title + FILTER + count) wrap instead of clipping */
  .table-header { flex-wrap: wrap; row-gap: 8px; }
}

/* Big stat numbers use the system display font (matches CSUN) - its digits are
   wider/larger-reading than DM Sans at the same size, so the hero looks bigger. */
.exec-hero .card-value, .exec-kpi-grid .card-value, .card-overall .card-value,
.card-metric-value, .totals .value {
  font-family: "SF Pro Display", "SF Pro", -apple-system, "system-ui", "Helvetica Neue", Helvetica, Arial, sans-serif;
}

.table-section table th, .table-section table td { border-color: var(--separator-non-opaque); }

@media (prefers-reduced-motion: reduce) {
  .card-interactive:hover { transform: none; }
}

/* On tighter windows, drop the descriptor block so the nav never clips. */
@media (max-width: 1120px) {
  .header-titleblock { display: none; }
}
@media (max-width: 720px) {
  .header-inner { flex-wrap: wrap; gap: 10px; }
  /* .header .view-nav { order: 3; width: 100%; } - REMOVED: leftover from
     before the burger-dropdown redesign at the 768px breakpoint below.
     .view-nav is now position:absolute (so flex `order` is inert on it
     anyway) with an explicit `width: auto` so left:12px/right:12px both
     apply. This rule has identical specificity and loads later in this
     same file, so at any width <720px it was winning and forcing width
     back to 100% of the containing block while left:12px still applied -
     pushing the (invisible when closed - opacity:0/visibility:hidden, but
     still laid out) dropdown's right edge 12px past the viewport, which
     document.documentElement.scrollWidth still counts, causing a
     permanent 12px of dead horizontal page scroll on every phone-width
     view. Removing it lets the 768px block's width:auto apply cleanly. */
}

/* ====================== Exec Overview - per-campaign scope =============== */
.exec-scope {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 14px;
}
.exec-scope-label {
  font-size: 12px; font-weight: var(--fw-semibold);
  letter-spacing: 0.055em; text-transform: uppercase; color: var(--text-muted);
}
.exec-scope-select {
  appearance: none; -webkit-appearance: none;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23A2A2A2' stroke-width='3'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center;
  border: 0.5px solid var(--border-strong); border-radius: 10px;
  padding: 8px 34px 8px 13px; min-height: 36px;
  font-family: var(--font-text); font-size: 14px; font-weight: var(--fw-medium);
  color: var(--text); cursor: pointer; max-width: 420px;
}
.exec-scope-select:focus, .exec-scope-select:focus-visible { outline: none; border-color: var(--tfk-red); box-shadow: inset 0 0 0 2px var(--tfk-red); }

/* ====================== A/B campaign test =============================== */
.ab-panel { padding: 22px 24px; margin-top: 16px; }
.ab-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.ab-title { font-size: 15px; font-weight: var(--fw-semibold); color: var(--text); margin: 0; }
.ab-sub { font-size: 13px; color: var(--text-muted); margin: 2px 0 0; }
.ab-toggle { cursor: pointer; padding: 8px 16px; min-height: 36px; font-size: 13px; font-weight: var(--fw-medium); color: var(--text); background: var(--surface); }

.ab-body { margin-top: 18px; display: flex; flex-direction: column; gap: 18px; }
.ab-picker { display: flex; align-items: center; gap: 8px; }
.ab-vs { font-size: 13px; font-weight: var(--fw-semibold); color: var(--text-muted); }
.ab-badge {
  flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 6px; color: #fff;
  font-size: 12px; font-weight: 700;
}
.ab-badge-a { background: #00b1ca; }
.ab-badge-b { background: #1A6099; }

.ab-compare {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); gap: 12px;
}
.ab-metric-card {
  background: var(--surface-2); border: 0.5px solid var(--border-subtle);
  border-radius: 12px; padding: 12px 14px;
}
.ab-metric-label {
  font-size: 11px; font-weight: var(--fw-semibold); letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--text-muted); margin-bottom: 8px;
}
.ab-metric-vals { display: flex; flex-direction: column; gap: 5px; }
.ab-side {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 7px; border-radius: 8px; border: 1.5px solid transparent;
}
.ab-side.win { border-color: var(--fwm-primary); }
.ab-side .ab-badge { width: 18px; height: 18px; border-radius: 5px; font-size: 11px; }
.ab-side-val { font-family: var(--font-display); font-weight: var(--fw-semibold); font-size: 15px; letter-spacing: -0.01em; color: var(--text); }
.ab-side.win .ab-side-val { color: var(--fwm-primary); }
.ab-metric-delta { margin-top: 8px; font-size: 11px; color: var(--text-muted); min-height: 13px; }
.ab-trend-note { font-size: 12px; color: var(--text-muted); min-height: 14px; }

/* A/B ad test - campaign + ad pickers, ad thumbnails */
.ab-campaign-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ab-picker-label { font-size: 12px; font-weight: var(--fw-semibold); letter-spacing: 0.055em; text-transform: uppercase; color: var(--text-muted); }
.ab-ad-pickers { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ab-ad-pickers .exec-scope-select { max-width: 300px; }
.ab-ad-heads { display: flex; align-items: stretch; gap: 12px; }
.ab-ad-head { flex: 1 1 0; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface-2); border: 0.5px solid var(--border-subtle); border-radius: 12px; }
.ab-ad-thumb { width: 48px; height: 48px; flex: 0 0 auto; border-radius: 8px; object-fit: cover; background: var(--surface-3); }
.ab-ad-thumb--ph { display: flex; align-items: center; justify-content: center; color: var(--text-muted); font-size: 18px; }
.ab-ad-name { font-size: 13px; font-weight: var(--fw-medium); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ab-vs-mid { flex: 0 0 auto; align-self: center; }

/* A/B empty state - no tests run yet */
.ab-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 30px 20px 26px; gap: 4px; }
.ab-empty-icon { color: var(--text-disabled); margin-bottom: 6px; }
.ab-empty-title { font-size: 15px; font-weight: var(--fw-semibold); color: var(--text-secondary); margin: 0; }
.ab-empty-sub { font-size: 13px; color: var(--text-muted); margin: 0; }


/* Meta DMA: intentional empty state (Meta reports no market-level data for this account) */
.table-section.dma-empty #meta-dma-thead,
.table-section.dma-empty #meta-dma-campaign-select,
.table-section.dma-empty .location-filter { display: none; }
.table-section.dma-empty .table-wrap-fixed { max-height: none; height: auto; }
.dma-empty-note { padding: 28px 16px; text-align: center; color: var(--text-muted); font-size: 14px; }
