/* Password gate */
.auth-gate {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, #4f46e5 0%, #8b5cf6 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.auth-gate.hidden { display: none; }
.auth-card {
  background: white;
  border-radius: 14px;
  padding: 32px 32px 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  width: 320px;
  text-align: center;
}
.auth-logo {
  width: 56px; height: 56px;
  background: linear-gradient(135deg, #4f46e5, #8b5cf6);
  color: white;
  font-weight: 700;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 14px;
  font-size: 18px;
}
.auth-card h2 { margin: 0 0 4px; font-size: 20px; }
.auth-card input {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid #e4e8f0;
  border-radius: 8px;
  margin-bottom: 12px;
  font-family: inherit;
  box-sizing: border-box;
}
.auth-card input:focus { outline: none; border-color: #4f46e5; box-shadow: 0 0 0 3px rgba(79,70,229,0.15); }
.auth-card .btn { width: 100%; padding: 10px; font-size: 14px; }
.auth-error { color: #ef4444; font-size: 12px; margin-top: 10px; }

:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --text: #1a2332;
  --muted: #6b7a90;
  --border: #e4e8f0;
  --primary: #4f46e5;
  --primary-light: #eef2ff;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --chart-1: #4f46e5;
  --chart-2: #10b981;
  --chart-3: #f59e0b;
  --chart-4: #ef4444;
  --chart-5: #8b5cf6;
  --chart-6: #06b6d4;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 8px 24px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

.app {
  max-width: 1720px;
  margin: 0 auto;
  padding: 20px 24px;
}
@media (max-width: 1200px) { .app { padding: 16px; } }

/* Topbar */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.logo {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: white;
  font-weight: 700;
  font-size: 14px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: -0.5px;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
}

.muted {
  color: var(--muted);
  font-size: 12px;
}
.muted-inline {
  color: var(--muted);
  font-weight: 400;
  font-size: 0.85em;
}

.topbar p { margin: 2px 0 0; }

/* Report toggle (top-most: D2C Web & App | Store Offline) */
.report-mode-bar {
  display: inline-flex;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
  border-radius: 12px;
  padding: 5px;
  margin-bottom: 14px;
  gap: 4px;
}
.rm-btn {
  background: transparent;
  border: none;
  padding: 9px 22px;
  font-size: 14px;
  font-weight: 600;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  border-radius: 8px;
  font-family: inherit;
  letter-spacing: 0.2px;
}
.rm-btn:hover { color: white; }
.rm-btn.active {
  background: white;
  color: var(--primary);
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}

/* GG sub-report tabs (Campaign / Keyword / Geo) — only on Store Offline → GG Ads */
.gg-subtab-bar {
  display: inline-flex;
  align-items: center;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px 6px 4px 12px;
  margin-bottom: 14px;
  gap: 4px;
}
.gg-subtab-bar .tab-group-label { padding: 0 8px 0 0; }

/* Top-level view mode (Objective vs Ads system) */
.view-mode-bar {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 16px;
  gap: 4px;
}
.vm-btn {
  background: transparent;
  border: none;
  padding: 8px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-radius: 7px;
  font-family: inherit;
}
.vm-btn:hover { color: var(--text); }
.vm-btn.active {
  background: white;
  color: var(--primary);
  box-shadow: 0 1px 3px rgba(16,24,40,0.08);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  align-items: center;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tabs.tabs-channel { margin-bottom: 0; }
.tabs.tabs-objective {
  background: #fafbfd;
  border-radius: 8px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  flex: 0 1 auto;
}
/* Ads system dropdown sits at the left of nav-row when in Ads mode */

/* Nav row: channel dropdown + objective tabs */
.nav-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

/* Channel dropdown menu */
.channel-menu { position: relative; display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.channel-source-note {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted);
  background: var(--bg);
  padding: 4px 10px;
  border-radius: 12px;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.channel-source-note.ads-only {
  color: var(--warning);
  background: #fffbeb;
  border-color: #fde68a;
}
.channel-trigger {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 14px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  transition: all 0.15s;
  min-width: 220px;
}
.channel-trigger:hover { border-color: var(--primary); }
.channel-trigger.open { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.channel-trigger .trigger-label-prefix { color: var(--muted); font-size: 11px; text-transform: uppercase; font-weight: 600; letter-spacing: 0.5px; }
.channel-trigger strong { font-weight: 600; flex: 1; text-align: left; }
.channel-trigger .chevron { transition: transform 0.2s; color: var(--muted); }
.channel-trigger.open .chevron { transform: rotate(180deg); }

.channel-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 240px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(16,24,40,0.12);
  padding: 6px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.channel-dropdown[hidden] { display: none; }
.channel-option {
  background: transparent;
  border: none;
  padding: 9px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  border-radius: 6px;
  color: var(--text);
}
.channel-option:hover { background: var(--bg); }
.channel-option.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}
.channel-option[data-channel="none"] {
  color: var(--muted);
  font-style: italic;
  border-bottom: 1px dashed var(--border);
  margin-bottom: 4px;
  padding-bottom: 8px;
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 80px 24px;
  background: var(--surface);
  border-radius: 14px;
  border: 2px dashed var(--border);
  margin: 20px 0;
}
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.7; }
.empty-state h2 { margin: 0 0 10px; font-size: 18px; }
.empty-state p { margin: 0; line-height: 1.7; }
.tab-group-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 0 8px 0 4px;
  white-space: nowrap;
}
.obj-tab {
  font-size: 12px !important;
  padding: 6px 12px !important;
}
.obj-tab.active {
  color: var(--success) !important;
  border-bottom-color: var(--success) !important;
  background: #ecfdf5 !important;
}
.obj-tab[data-objective="Performance"].active {
  color: var(--primary) !important;
  border-bottom-color: var(--primary) !important;
  background: var(--primary-light) !important;
}
.obj-tab[data-objective="Install"].active {
  color: var(--success) !important;
  border-bottom-color: var(--success) !important;
  background: #ecfdf5 !important;
}
.obj-tab[data-objective="Branding"].active {
  color: var(--warning) !important;
  border-bottom-color: var(--warning) !important;
  background: #fffbeb !important;
}

.tab {
  background: transparent;
  border: none;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all 0.15s;
}

.tab:hover { color: var(--text); background: var(--primary-light); }

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
  background: var(--primary-light);
}

/* Filter bar — sticky to viewport when scrolling */
.filterbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  padding: 12px 14px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
  position: sticky;
  top: 8px;
  z-index: 40;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--border);
}

.filter {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 130px;
}

.filter.grow { flex: 1; min-width: 200px; }

.filter label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* Multi-select dropdown (Month filter — supports multiple selections) */
.ms-wrap { position: relative; }
.ms-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  min-width: 130px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  gap: 6px;
}
.ms-trigger:hover { border-color: var(--primary); }
.ms-trigger.open { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.ms-trigger svg { color: var(--muted); flex-shrink: 0; }
.ms-trigger span {
  flex: 1;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ms-panel {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  min-width: 100%;
  max-height: 260px;
  overflow-y: auto;
  background: white;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 6px 18px rgba(16,24,40,0.12);
  z-index: 90;
  padding: 4px;
}
.ms-panel[hidden] { display: none; }
.ms-opt {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 4px;
  font-size: 12.5px;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.ms-opt:hover { background: var(--bg); }
.ms-opt input { margin: 0; cursor: pointer; }
.ms-opt.divider {
  border-top: 1px dashed var(--border);
  margin-top: 4px;
  padding-top: 8px;
  font-weight: 600;
  color: var(--muted);
  font-size: 11px;
  cursor: default;
}

.filter input,
.filter select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: white;
  color: var(--text);
  font-family: inherit;
}

.filter input:focus, .filter select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Buttons */
.btn {
  padding: 9px 16px;
  border: 1px solid var(--primary);
  background: var(--primary);
  color: white;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.btn:hover { background: #4338ca; }

.btn.ghost {
  background: white;
  color: var(--text);
  border-color: var(--border);
}

.btn.ghost:hover { background: var(--bg); border-color: var(--muted); }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn .icon { vertical-align: -2px; margin-right: 5px; }
.btn { display: inline-flex; align-items: center; gap: 4px; }

/* Objective breakdown (Performance / Install / Branding) */
.obj-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}
@media (max-width: 800px) { .obj-grid { grid-template-columns: 1fr; } }

.obj-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
  border-top: 3px solid var(--primary);
}
.obj-card.performance { border-top-color: var(--primary); }
.obj-card.install { border-top-color: var(--success); }
.obj-card.branding { border-top-color: var(--warning); }

.obj-card .obj-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
}
.obj-card .obj-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text);
}
.obj-card .obj-share {
  font-size: 11px;
  color: var(--muted);
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 10px;
}
.obj-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}
.obj-metric .obj-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
}
.obj-metric .obj-value {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.obj-card .obj-campaigns {
  font-size: 11px;
  color: var(--muted);
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
}

/* Hero mode: 3 large scorecards for Performance/Install objective tabs */
.obj-grid.hero-mode {
  grid-template-columns: repeat(3, 1fr);
}
.hero-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
  border-left: 5px solid var(--primary);
  position: relative;
}
.hero-card.performance { border-left-color: var(--primary); background: linear-gradient(135deg, #eef2ff 0%, #ffffff 50%); }
.hero-card.install     { border-left-color: var(--success); background: linear-gradient(135deg, #ecfdf5 0%, #ffffff 50%); }
.hero-card.green       { border-left-color: var(--success); }
.hero-card.orange      { border-left-color: var(--warning); }
.hero-card.blue        { border-left-color: #2563eb; background: linear-gradient(135deg, #eff6ff 0%, #ffffff 50%); }

.hero-card .hero-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 8px;
}
.hero-card .hero-value {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1.1;
  color: var(--text);
}
.hero-card .hero-sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 6px;
}
@media (max-width: 800px) { .obj-grid.hero-mode { grid-template-columns: 1fr; } }

/* KPI Grid */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi {
  background: var(--surface);
  padding: 16px 18px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border-left: 3px solid var(--primary);
}

.kpi .label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}

.kpi .value {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.kpi .sub {
  font-size: 11px;
  color: var(--muted);
  margin-top: 4px;
}

.kpi.green { border-left-color: var(--success); }
.kpi.orange { border-left-color: var(--warning); }
.kpi.red { border-left-color: var(--danger); }
.kpi.purple { border-left-color: #8b5cf6; }
.kpi.cyan { border-left-color: #06b6d4; }
.kpi.blue { border-left-color: #2563eb; }

/* FB Ad visual code (compact identifier for long ad names) */
td.ad-code {
  font-family: ui-monospace, "SF Mono", Consolas, monospace;
  font-size: 11px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-light);
  padding: 4px 8px !important;
  border-radius: 4px;
  letter-spacing: 0.5px;
  white-space: nowrap;
  cursor: help;
}
td.ad-name-short {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11.5px;
  cursor: help;
}

/* Sortable table headers */
.table-wrap table th {
  cursor: pointer;
  user-select: none;
  position: relative;
}
.table-wrap table th:hover { background: var(--primary-light); }
.table-wrap table th.sort-asc::after,
.table-wrap table th.sort-desc::after {
  content: '';
  display: inline-block;
  margin-left: 4px;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  vertical-align: middle;
}
.table-wrap table th.sort-asc::after  { border-bottom: 5px solid var(--primary); }
.table-wrap table th.sort-desc::after { border-top: 5px solid var(--primary); }
.table-wrap table.no-sort th { cursor: default; }
.table-wrap table.no-sort th:hover { background: inherit; }

/* ===================== RP (Report) view ===================== */
#rpView {
  background: #fff;
  min-height: 100vh;
  font-family: inherit;
  color: #1f2937;
}
.rp-toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.rp-toolbar-left { display: flex; align-items: center; gap: 12px; }
.rp-toolbar-left .rp-logo {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, #4f46e5, #8b5cf6);
  color: #fff; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px;
}
.rp-toolbar-left strong { display: block; font-size: 14px; }
.rp-toolbar-left .muted { font-size: 12px; }
.rp-toolbar-right { display: flex; align-items: center; gap: 10px; }
.rp-toolbar-right select { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; }

.rp-report {
  max-width: 1180px;
  margin: 0 auto;
  padding: 32px 24px;
  background: #fff;
}

.rp-cover {
  text-align: center;
  padding: 60px 20px 40px;
  border-bottom: 3px solid var(--primary);
  margin-bottom: 32px;
}
.rp-cover-logo {
  display: inline-block;
  padding: 10px 18px;
  background: linear-gradient(135deg, #4f46e5, #8b5cf6);
  color: #fff; border-radius: 10px;
  font-weight: 700; font-size: 16px;
  margin-bottom: 16px;
}
.rp-cover h1 { font-size: 32px; margin: 8px 0; color: #111827; }
.rp-cover h2 { font-size: 22px; margin: 4px 0; color: var(--primary); font-weight: 600; }

.rp-section {
  margin: 32px 0;
  page-break-inside: avoid;
}
.rp-section h2 {
  font-size: 18px;
  border-left: 4px solid var(--primary);
  padding-left: 10px;
  margin-bottom: 16px;
  color: #111827;
}

/* Slide-style page sections (each prints as own A4 landscape page) */
.rp-slide {
  margin: 24px 0;
  padding: 24px 36px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  page-break-after: always;
  page-break-inside: avoid;
  /* Landscape ratio (16:10 approximated A4 landscape) */
  aspect-ratio: 297 / 210;
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
.rp-slide.rp-cover {
  aspect-ratio: 297 / 210;
  align-items: center;
  justify-content: center;
  text-align: center;
}
@media (max-width: 900px) {
  .rp-slide { aspect-ratio: auto; min-height: 500px; }
}
.rp-slide-head {
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 2px solid var(--primary);
  padding-bottom: 10px;
  margin-bottom: 14px;
}
.rp-slide-head h2 {
  margin: 0;
  border: 0;
  padding: 0;
  font-size: 20px;
  flex: 1;
  color: #111827;
}
.rp-slide-no {
  background: var(--primary);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 4px;
  letter-spacing: 0.5px;
}
.rp-slide-tag {
  font-size: 11px;
  color: var(--muted);
  background: var(--primary-light);
  padding: 3px 10px;
  border-radius: 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}
.rp-lede {
  font-size: 12.5px;
  color: var(--muted);
  margin: 0 0 16px;
  line-height: 1.5;
}
.rp-cover-foot {
  position: absolute;
  bottom: 30px;
  left: 0; right: 0;
  text-align: center;
  font-size: 11px;
}

/* Per-section insight footer */
.rp-section-insight {
  margin-top: 18px;
  border-top: 2px dashed var(--border);
  padding-top: 12px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
}
.rp-insight-col {
  background: #f9fafb;
  border-radius: 6px;
  padding: 9px 12px;
  border-left: 3px solid var(--border);
  font-size: 11.5px;
  line-height: 1.45;
}
.rp-insight-col h4 {
  font-size: 11px;
  margin: 0 0 5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.rp-insight-col ul { margin: 0; padding-left: 16px; }
.rp-insight-col li { margin-bottom: 3px; }
.rp-insight-col.good   { border-left-color: #047857; }
.rp-insight-col.good h4   { color: #047857; }
.rp-insight-col.bad    { border-left-color: #b91c1c; }
.rp-insight-col.bad h4    { color: #b91c1c; }
.rp-insight-col.action { border-left-color: #1d4ed8; }
.rp-insight-col.action h4 { color: #1d4ed8; }
.rp-insight-col .muted { font-style: italic; font-size: 10.5px; }
.rp-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
  flex: 1;
  min-height: 0;
}
.rp-chart { height: 240px; position: relative; }

.rp-kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
@media (min-width: 1100px) {
  .rp-slide .rp-kpis { grid-template-columns: repeat(4, 1fr); }
}
.rp-kpi {
  background: #f9fafb;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  border-left: 4px solid var(--primary);
}
.rp-kpi .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.3px; font-weight: 600; }
.rp-kpi .value { font-size: 22px; font-weight: 700; margin-top: 4px; color: #111827; }
.rp-kpi .delta { font-size: 11px; margin-top: 4px; display: block; }

#rpInsights ul { padding-left: 20px; line-height: 1.7; }
#rpInsights li { margin-bottom: 6px; }
#rpInsights .insight-good { color: #047857; }
#rpInsights .insight-bad  { color: #b91c1c; }
#rpInsights .insight-flat { color: #6b7280; }

/* Eval grid (Good / Bad / Recommendations) */
.rp-eval-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}
.rp-eval-card {
  border-radius: 8px;
  padding: 14px 16px 14px 14px;
  border: 1px solid var(--border);
  border-left-width: 4px;
  font-size: 12.5px;
  line-height: 1.55;
}
.rp-eval-card h3 {
  font-size: 13px;
  margin: 0 0 10px;
  font-weight: 700;
}
.rp-eval-card ul { padding-left: 18px; margin: 0; }
.rp-eval-card li { margin-bottom: 6px; }
.rp-eval-card li b { font-weight: 700; }
.rp-eval-good   { border-left-color: #047857; background: #ecfdf5; }
.rp-eval-good h3 { color: #047857; }
.rp-eval-bad    { border-left-color: #b91c1c; background: #fef2f2; }
.rp-eval-bad h3  { color: #b91c1c; }
.rp-eval-action { border-left-color: #1d4ed8; background: #eff6ff; }
.rp-eval-action h3 { color: #1d4ed8; }
@media (max-width: 768px) {
  .rp-eval-grid { grid-template-columns: 1fr; }
}
@media print {
  .rp-eval-grid { grid-template-columns: 1fr 1fr 1fr; gap: 10px; }
  .rp-eval-card { page-break-inside: avoid; }
}

.rp-footer {
  margin-top: 60px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 11px;
}

#rpView .table-wrap { overflow: visible; max-height: none; }
#rpView table { font-size: 12px; border-collapse: collapse; width: 100%; }
#rpView table th, #rpView table td { padding: 8px 10px; border-bottom: 1px solid #e5e7eb; text-align: left; }
#rpView table th { background: var(--primary-light); color: var(--primary); font-weight: 600; font-size: 11px; }
#rpView table td.num { text-align: right; font-variant-numeric: tabular-nums; }
#rpView table tr.total td { font-weight: 700; background: #f3f4f6; border-top: 2px solid var(--primary); }

/* Print styles — PDF export via window.print() */
@media print {
  body { background: #fff; }
  .no-print, #appRoot, #authGate, #rpGate { display: none !important; }
  #rpView { display: block !important; }
  .rp-toolbar { display: none !important; }
  .rp-report { max-width: none; padding: 0; }
  .rp-slide {
    page-break-after: always;
    page-break-inside: avoid;
    border: none;
    border-radius: 0;
    padding: 8px 4px;
    margin: 0;
    aspect-ratio: auto;
    min-height: 0;
    overflow: visible;
    display: block;
  }
  .rp-slide:last-child { page-break-after: auto; }
  .rp-slide.rp-cover { padding: 60px 0; text-align: center; }
  .rp-section { page-break-inside: avoid; }
  .rp-2col { grid-template-columns: 1fr 1fr; }
  @page { size: A4 landscape; margin: 10mm 14mm; }
  canvas { max-height: 200px !important; }
  .rp-slide-head { margin-bottom: 8px; padding-bottom: 6px; }
  .rp-slide-head h2 { font-size: 18px; }
  .rp-lede { margin-bottom: 8px; font-size: 11.5px; }
  .rp-kpis { gap: 8px; }
  .rp-kpi { padding: 8px 10px; }
  .rp-kpi .value { font-size: 18px; }
  .rp-section-insight { margin-top: 10px; padding-top: 8px; gap: 8px; }
  .rp-insight-col { padding: 6px 9px; font-size: 10.5px; }
  #rpView table { font-size: 10.5px; }
  #rpView table th, #rpView table td { padding: 5px 7px; }
}

/* Funnel chart wrapper */
.funnel-wrap {
  position: relative;
  width: 100%;
  height: 280px;
  padding: 8px 0;
}
#objectiveFunnel { margin-bottom: 16px; }
#perfFunnelSection .funnel-wrap { height: 320px; }

/* Pyramid funnel — HTML/CSS trapezoids stacked, narrowing downward */
.pyramid-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 20px 10px;
  width: 100%;
}
.pyramid-stage {
  position: relative;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 14px;
  text-shadow: 0 1px 2px rgba(0,0,0,.25);
  transition: transform .2s;
  cursor: default;
}
.pyramid-stage:hover { transform: scale(1.02); }
.pyramid-stage .stage-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.3;
  text-align: center;
  z-index: 2;
  padding: 0 12px;
}
.pyramid-stage .stage-label .stage-name { font-size: 12px; opacity: 0.95; font-weight: 500; }
.pyramid-stage .stage-label .stage-value { font-size: 18px; font-weight: 700; }
.pyramid-stage .stage-label .stage-sub { font-size: 10.5px; opacity: 0.85; font-weight: 500; margin-top: 2px; }
.pyramid-stage .stage-cr {
  position: absolute;
  right: -120px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 11px;
  color: var(--muted);
  font-weight: 600;
  text-shadow: none;
  background: var(--bg);
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}
@media (max-width: 768px) {
  .pyramid-stage .stage-cr { position: static; transform: none; margin-top: 4px; }
  .pyramid-wrap { padding: 12px 4px; }
}

/* Charts */
.chart-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}

.chart-grid .card:nth-child(1) { grid-row: span 2; }
.chart-grid .card:nth-child(2) { }
.chart-grid .card:nth-child(3) { }

@media (max-width: 900px) {
  .chart-grid { grid-template-columns: 1fr; }
  .chart-grid .card:nth-child(1) { grid-row: auto; }
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.card-head h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}

.chart-wrap {
  position: relative;
  height: 260px;
}

.chart-grid .card:nth-child(1) .chart-wrap { height: 300px; }

/* Table */
.table-wrap {
  overflow-x: auto;
  max-height: 500px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

thead {
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}

th {
  text-align: left;
  padding: 8px 8px;
  font-weight: 600;
  font-size: 10.5px;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 7px 8px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
}

tbody tr:hover { background: var(--primary-light); }

td.num { text-align: right; font-variant-numeric: tabular-nums; }

.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 12px;
}

/* Loader */
.loader {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 40px;
  color: var(--muted);
}

.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.foot {
  text-align: center;
  padding: 20px;
  margin-top: 20px;
}

/* Metric trends (Overview) — sections of mini charts */
.metric-trends { margin-bottom: 20px; }
.trend-section { margin-bottom: 18px; }
.trend-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin: 0 0 10px;
  padding: 4px 12px;
  color: var(--primary);
  background: var(--primary-light);
  border-radius: 6px;
  display: inline-block;
}
.trend-title.install-title { color: var(--success); background: #ecfdf5; }
.trend-title.branding-title { color: var(--warning); background: #fffbeb; }
.trend-grid { display: grid; gap: 12px; }
.trend-grid.grid-4 { grid-template-columns: repeat(4, 1fr); }
.trend-grid.distro-grid {
  grid-template-columns: 1fr 1fr 1fr 2fr;
}
.trend-grid.distro-grid .card.mini.wide .chart-wrap { height: 240px; }
.trend-grid.distro-grid .card.mini .chart-wrap { height: 240px; }
@media (max-width: 1400px) { .trend-grid.distro-grid { grid-template-columns: 1fr 1fr 1fr; } }
@media (max-width: 1100px) { .trend-grid.distro-grid { grid-template-columns: 1fr 1fr; } }
@media (max-width: 700px)  { .trend-grid.distro-grid { grid-template-columns: 1fr; } }
.trend-grid.grid-3 { grid-template-columns: repeat(3, 1fr); }
.trend-grid.grid-5 { grid-template-columns: repeat(5, 1fr); }
@media (max-width: 1300px) { .trend-grid.grid-5 { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 1100px) { .trend-grid.grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 800px)  { .trend-grid.grid-5 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 700px) { .trend-grid { grid-template-columns: 1fr !important; } }

.card.mini { padding: 12px 14px; }
.card.mini h4 {
  margin: 0 0 8px;
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.card.mini .chart-wrap { height: 150px; }

/* Per-objective campaign breakdown */
.obj-campaigns-section { margin-bottom: 20px; }
.obj-campaigns-section .obj-group { margin-bottom: 16px; }
.obj-campaigns-section .obj-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 14px;
  background: var(--primary-light);
  color: var(--primary);
  border-radius: 8px 8px 0 0;
  border: 1px solid var(--border);
  border-bottom: none;
}
.obj-campaigns-section .obj-group.install .obj-group-header { background: #ecfdf5; color: var(--success); }
.obj-campaigns-section .obj-group.branding .obj-group-header { background: #fffbeb; color: var(--warning); }
.obj-campaigns-section .obj-group-header h3 { margin: 0; font-size: 14px; font-weight: 700; }
.obj-campaigns-section .obj-group-header .obj-group-stats { font-size: 12px; opacity: 0.85; }
.obj-campaigns-section .obj-group .table-wrap {
  border: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
  background: var(--surface);
  max-height: 360px;
}
.obj-campaigns-section table { font-size: 11.5px; }
.obj-campaigns-section thead th { background: #fafbfd; font-size: 10.5px; padding: 8px; }
.obj-campaigns-section td { padding: 6px 8px; max-width: 280px; }
.obj-campaigns-section tr.total td { font-weight: 700; background: #fafbfd; border-top: 2px solid currentColor; }

/* Dimension insights — grid of breakdown tables for GG/FB tabs */
.dim-insights {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
@media (max-width: 1000px) { .dim-insights { grid-template-columns: 1fr; } }

.dim-insights .card .card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}
.dim-insights table { font-size: 11.5px; }
.dim-insights thead th {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 10.5px;
  padding: 8px 8px;
}
.dim-insights td {
  padding: 6px 8px;
  max-width: 180px;
}
.dim-insights td.num { font-variant-numeric: tabular-nums; }
.dim-insights tr.total td {
  font-weight: 700;
  background: #fafbfd;
  border-top: 2px solid var(--primary);
}
.dim-insights .table-wrap { max-height: 380px; }
.dim-insights .wide-card {
  grid-column: 1 / -1;
}
.dim-insights .wide-card .table-wrap { max-height: 600px; overflow-x: auto; }
.dim-insights .wide-card thead th { font-size: 10.5px; padding: 7px 5px; white-space: nowrap; }
.dim-insights .wide-card td { padding: 5px 5px; font-size: 11px; white-space: nowrap; }
/* Stack delta below value in dim-insights tables to keep cols narrow */
.dim-insights td .delta {
  display: block;
  margin-left: 0;
  margin-top: 2px;
  font-size: 9.5px;
  padding: 0 4px;
  width: fit-content;
  margin-left: auto;
}
.dim-insights td.num { line-height: 1.25; }

/* Daily insight tables — stacked, scrollable */
.daily-insights { margin-bottom: 20px; }
.daily-insights .card { margin-bottom: 16px; }
.daily-insights table { font-size: 11.5px; }
.daily-insights thead th {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 10.5px;
  padding: 8px;
  position: sticky;
  top: 0;
  z-index: 1;
}
.daily-insights .table-wrap { max-height: 460px; }
.daily-insights tr.total td { font-weight: 700; background: #fafbfd; border-top: 2px solid var(--primary); position: sticky; bottom: 0; }

/* Monthly insights — single full-width card now (Install removed) */
.monthly-insights {
  margin-bottom: 20px;
}

.monthly-insights table { font-size: 12px; }
.monthly-insights thead th { background: var(--primary-light); color: var(--primary); }
.monthly-insights td.kpi-val { font-weight: 600; }
.monthly-insights tr.total td { font-weight: 700; background: #fafbfd; border-top: 2px solid var(--primary); }

/* Branding view — pivot tables (Campaign Type / name × Month) */
.branding-view { margin-bottom: 20px; }
.branding-view .card { margin-bottom: 16px; }
.branding-view table { font-size: 11.5px; border-collapse: separate; border-spacing: 0; }
.branding-view thead th {
  background: #fffbeb;
  color: var(--warning);
  font-size: 10.5px;
  padding: 8px;
  position: sticky;
  top: 0;
  z-index: 1;
}
.branding-view thead th:first-child { z-index: 2; left: 0; }
.branding-view tbody td:first-child {
  position: sticky;
  left: 0;
  background: var(--surface);
  font-weight: 500;
  max-width: 280px;
  z-index: 1;
}
.branding-view tbody tr:hover td:first-child { background: var(--primary-light); }
.branding-view td { padding: 6px 8px; }
.branding-view td.heat-0 { background: #fef3c7; }
.branding-view td.heat-1 { background: #fde68a; }
.branding-view td.heat-2 { background: #fcd34d; }
.branding-view td.heat-3 { background: #fbbf24; color: #78350f; font-weight: 600; }
.branding-view tr.total td {
  font-weight: 700;
  background: #fafbfd !important;
  border-top: 2px solid var(--warning);
}
.branding-view tr.total td:first-child { background: #fafbfd !important; }

/* Card menu: 3-dot button + dropdown for Download Excel */
.card-actions { position: relative; }
.card-menu-btn {
  background: transparent;
  border: none;
  font-size: 18px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  font-family: inherit;
}
.card-menu-btn:hover { background: var(--bg); color: var(--text); }
.card-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(16,24,40,0.12);
  padding: 4px;
  z-index: 20;
  min-width: 180px;
}
.card-menu[hidden] { display: none; }
.card-menu-item {
  display: block;
  width: 100%;
  background: transparent;
  border: none;
  padding: 8px 12px;
  font-size: 13px;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: 6px;
  color: var(--text);
}
.card-menu-item:hover { background: var(--bg); }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.card-head h3 { flex: 1; }

/* Objective Budget pivot (All objective only) */
.obj-budget {
  margin-bottom: 20px;
}
.obj-budget thead th {
  background: var(--primary-light);
  color: var(--primary);
  font-size: 10.5px;
  padding: 8px;
}
.obj-budget tbody td:first-child {
  font-weight: 600;
}
.obj-budget tr.row-performance td:first-child { color: var(--primary); }
.obj-budget tr.row-install td:first-child { color: var(--success); }
.obj-budget tr.row-branding td:first-child { color: var(--warning); }
.obj-budget tr.total td {
  font-weight: 700;
  background: #fafbfd;
  border-top: 2px solid var(--primary);
}

/* TOC sidebar */
.body-layout {
  display: flex;
  gap: 18px;
  align-items: flex-start;
}
.app-main {
  flex: 1;
  min-width: 0; /* allow children to shrink/scroll */
}
.toc {
  width: 200px;
  flex-shrink: 0;
  position: sticky;
  top: 96px; /* clears the sticky filter bar above */
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 10px;
  box-shadow: var(--shadow);
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  font-size: 13px;
  transition: width 0.2s;
}
.toc.collapsed { width: 38px; padding: 8px 6px; }
.toc.collapsed ul,
.toc.collapsed .toc-head span { display: none; }
.toc.collapsed .toc-head { justify-content: center; }
.toc.collapsed .toc-toggle { transform: rotate(180deg); }

.toc-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 4px 8px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.7px;
  color: var(--muted);
}
.toc-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 22px; height: 22px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  font-family: inherit;
}
.toc-toggle:hover { background: var(--bg); color: var(--text); }

.toc ul { list-style: none; margin: 0; padding: 0; }
.toc li { margin: 2px 0; }
.toc a {
  display: block;
  padding: 7px 10px;
  color: var(--text);
  text-decoration: none;
  border-radius: 6px;
  font-size: 12.5px;
  border-left: 2px solid transparent;
}
.toc a:hover { background: var(--primary-light); color: var(--primary); border-left-color: var(--primary); }
.toc a.active { background: var(--primary-light); color: var(--primary); border-left-color: var(--primary); font-weight: 600; }

@media (max-width: 1100px) {
  .body-layout { display: block; }
  .toc { position: static; max-height: none; margin-bottom: 16px; width: 100%; }
}

html { scroll-behavior: smooth; scroll-padding-top: 16px; }

/* Period-over-period delta badges */
.delta {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 4px;
  vertical-align: middle;
  white-space: nowrap;
  letter-spacing: 0.2px;
}
.delta.up    { color: #047857; background: #d1fae5; }
.delta.down  { color: #b91c1c; background: #fee2e2; }
.delta.flat  { color: var(--muted); background: var(--bg); }
/* In KPI/table cells, delta sits inline with value */
.kpi .sub .delta,
td .delta {
  font-size: 10px;
  padding: 0 5px;
}
.hero-value .delta {
  font-size: 13px;
  vertical-align: 0.25em;
}

/* FB Ad preview modal */
.preview-modal {
  position: fixed; inset: 0;
  z-index: 1000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.preview-modal[hidden] { display: none; }
.preview-backdrop {
  position: absolute; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
}
.preview-card {
  position: relative;
  background: white;
  width: 100%;
  max-width: 540px;
  height: min(85vh, 800px);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.preview-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
}
.preview-title {
  font-size: 13px;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preview-actions { display: flex; gap: 6px; flex-shrink: 0; }
.preview-body { flex: 1; position: relative; overflow: hidden; background: #f8fafc; }
.preview-body iframe { width: 100%; height: 100%; border: 0; display: block; background: white; }
.preview-fallback {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 30px; text-align: center;
  background: white;
  color: var(--muted);
  font-size: 14px; line-height: 1.6;
}
.link-btn {
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid transparent;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.link-btn:hover { background: var(--primary); color: white; }

/* Hidden tabs */
.hidden { display: none !important; }

/* Global: HTML hidden attribute should always win over display rules */
[hidden] { display: none !important; }
