:root {
  --bg: #f8f9fa;
  --card-bg: #ffffff;
  --border: #e2e5e9;
  --text: #1a1d21;
  --text-muted: #6b7280;
  --accent: #2563eb;
  --accent-light: #eff6ff;
  --green: #16a34a;
  --green-light: #f0fdf4;
  --red: #dc2626;
  --red-light: #fef2f2;
  --orange: #ea580c;
  --orange-light: #fff7ed;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

h1 { font-size: 1.25rem; font-weight: 600; }

.updated {
  font-size: 0.8rem;
  color: var(--text-muted);
}

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
}

.loading {
  text-align: center;
  padding: 4rem 0;
  color: var(--text-muted);
}

.error {
  background: var(--red-light);
  color: var(--red);
  padding: 1rem;
  border-radius: 8px;
  text-align: center;
}

.hidden { display: none; }

/* Sections */
.section {
  margin-bottom: 2rem;
}

.section-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.75rem;
  color: var(--text);
}

.section-subtitle {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

/* KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 2rem;
}

.kpi-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.25rem;
}

.kpi-card h3 {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-bottom: 0.75rem;
}

.kpi-row {
  display: flex;
  justify-content: space-between;
  padding: 0.3rem 0;
  font-size: 0.875rem;
}

.kpi-row .label { color: var(--text-muted); }
.kpi-row .value { font-weight: 600; font-variant-numeric: tabular-nums; }

.kpi-big {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  font-variant-numeric: tabular-nums;
}

.kpi-big.accent { color: var(--accent); }
.kpi-big.green { color: var(--green); }

/* Tables */
.table-wrap {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 1rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.825rem;
}

th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}

th.right, td.right { text-align: right; }

td {
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tr:last-child td { border-bottom: none; }

tr.winner td {
  background: var(--accent-light);
  font-weight: 600;
}

tr.total-row td {
  border-top: 2px solid var(--border);
  font-weight: 600;
}

/* Bars */
.bar-container {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.bar {
  height: 8px;
  border-radius: 4px;
  background: var(--accent);
  min-width: 2px;
}

.bar.green { background: var(--green); }
.bar.red { background: var(--red); }
.bar.orange { background: var(--orange); }

/* Funnel */
.funnel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
}

.funnel-step {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  text-align: center;
}

.funnel-step .step-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.funnel-step .step-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.funnel-step .step-detail {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Campaign tabs */
.tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1rem;
  border-bottom: 2px solid var(--border);
}

.tab {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  color: var(--text-muted);
  background: none;
  border-top: none;
  border-left: none;
  border-right: none;
}

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Info icon button */
.info-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  margin-left: 6px;
  flex-shrink: 0;
  line-height: 1;
  vertical-align: middle;
}

.info-btn:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.desc-cell {
  display: flex;
  align-items: center;
  gap: 0;
}

.desc-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 180px;
}

/* Modal overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal {
  background: var(--card-bg);
  border-radius: 10px;
  max-width: 600px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 0.9rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-muted);
  padding: 0.25rem;
  line-height: 1;
}

.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 1.25rem;
}

.modal-subject {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.modal-subject strong {
  color: var(--text);
}

.modal-email {
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--text);
}

.modal-email p { margin-bottom: 0.5rem; }

/* Responsive */
@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .funnel-grid { grid-template-columns: 1fr; }
  main { padding: 1rem; }
  .desc-text { max-width: 100px; }
}
