/* 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: 1400px;
  margin: 0 auto;
  padding: 24px;
}

/* 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;
}

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

/* 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: 1;
}

/* 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; }
.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: 10;
  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;
}
.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 */
.filterbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: flex-end;
  padding: 14px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.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;
}

.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 .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; }

/* 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: 10px;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 9px 10px;
  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-grid { display: grid; gap: 12px; }
.trend-grid.grid-4 { grid-template-columns: repeat(4, 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; }

/* 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 — two tables side by side */
.monthly-insights {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 20px;
}
@media (max-width: 900px) { .monthly-insights { grid-template-columns: 1fr; } }

.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);
}

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

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