/* ── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #222536;
  --border: #2d3148;
  --text: #e2e8f0;
  --muted: #8892a4;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #38bdf8;
  --radius: 8px;
  --sidebar-width: 220px;
}

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

/* ── Login Page ───────────────────────────────────────────────────────────── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 24px;
}

.login-container h1 {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}

.login-subtitle {
  color: var(--muted);
  margin-bottom: 28px;
  font-size: 13px;
}

/* ── Forms ────────────────────────────────────────────────────────────────── */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.form-group input,
.form-group select {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--primary);
}

.error-message {
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); }
.btn-danger { background: rgba(239,68,68,0.15); color: #fca5a5; border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover:not(:disabled) { background: rgba(239,68,68,0.25); }
.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Spinner ──────────────────────────────────────────────────────────────── */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── App Layout ───────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 15px;
}

.sidebar-section-title {
  font-size: 10px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 12px 14px 4px;
}

.campaign-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 8px;
}

.campaign-item {
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.1s;
  border: 1px solid transparent;
}

.campaign-item:hover { background: var(--surface2); }
.campaign-item.active { background: rgba(37, 99, 235, 0.12); border-color: rgba(37, 99, 235, 0.3); }

.campaign-item-name {
  font-size: 12px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.campaign-item-meta {
  font-size: 11px;
  color: var(--muted);
  margin-top: 2px;
}

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.user-email {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 130px;
}

/* ── Main Content ─────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.main-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
  flex-shrink: 0;
}

.main-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.campaign-name-heading {
  font-size: 16px;
  font-weight: 600;
}

.main-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* ── Tabs ─────────────────────────────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}

.tab {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Phase Badge ──────────────────────────────────────────────────────────── */
.phase-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.phase-observation  { background: rgba(56, 189, 248, 0.12); color: var(--info); border: 1px solid rgba(56,189,248,0.25); }
.phase-optimization { background: rgba(34, 197, 94, 0.12); color: var(--success); border: 1px solid rgba(34,197,94,0.25); }
.phase-paused       { background: rgba(245, 158, 11, 0.12); color: var(--warning); border: 1px solid rgba(245,158,11,0.25); }
.phase-excluded     { background: rgba(239, 68, 68, 0.12); color: var(--danger); border: 1px solid rgba(239,68,68,0.25); }
.phase-ineligible   { background: rgba(100, 116, 139, 0.12); color: #94a3b8; border: 1px solid rgba(100,116,139,0.25); }

/* ── Cards & Grids ────────────────────────────────────────────────────────── */
.cards-row {
  display: grid;
  gap: 14px;
  margin-bottom: 20px;
}
.cards-row.cols-2 { grid-template-columns: 1fr 1fr; }
.cards-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.cards-row.cols-4 { grid-template-columns: repeat(4, 1fr); }

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

.card-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.card-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
}

.card-sub {
  font-size: 12px;
  color: var(--muted);
}

.card-value.green { color: var(--success); }
.card-value.amber { color: var(--warning); }
.card-value.red   { color: var(--danger); }

/* ── Condition Cards ──────────────────────────────────────────────────────── */
.condition-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.condition-icon {
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
  font-weight: 700;
}
.condition-icon.met     { background: rgba(34,197,94,0.15); color: var(--success); }
.condition-icon.not-met { background: rgba(239,68,68,0.15); color: var(--danger); }

.condition-body { flex: 1; }
.condition-label { font-size: 13px; font-weight: 600; margin-bottom: 3px; }
.condition-detail { font-size: 12px; color: var(--muted); }

/* ── Chart Containers ─────────────────────────────────────────────────────── */
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.chart-card-title {
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 14px;
}

.chart-container {
  position: relative;
}

/* ── Forecast Table ───────────────────────────────────────────────────────── */
.forecast-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.forecast-table th,
.forecast-table td {
  padding: 8px 10px;
  text-align: right;
  border-bottom: 1px solid var(--border);
}

.forecast-table th {
  color: var(--muted);
  font-weight: 500;
  text-transform: uppercase;
  font-size: 10px;
  letter-spacing: 0.05em;
}

.forecast-table td:first-child,
.forecast-table th:first-child {
  text-align: left;
}

.forecast-table tr.active-goal td {
  background: rgba(34, 197, 94, 0.05);
}

.forecast-table tr:hover td { background: var(--surface2); }

.confidence-badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 99px;
  font-size: 10px;
  font-weight: 600;
}
.confidence-HIGH   { background: rgba(34,197,94,0.12); color: var(--success); }
.confidence-MEDIUM { background: rgba(245,158,11,0.12); color: var(--warning); }
.confidence-LOW    { background: rgba(239,68,68,0.12);  color: var(--danger); }

/* ── Signal Cards ─────────────────────────────────────────────────────────── */
.signal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

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

.signal-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.band-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 600;
}
.band-scarce   { background: rgba(239,68,68,0.15); color: #fca5a5; }
.band-normal   { background: rgba(34,197,94,0.12); color: var(--success); }
.band-ample    { background: rgba(56,189,248,0.12); color: var(--info); }
.band-high     { background: rgba(239,68,68,0.15); color: #fca5a5; }
.band-moderate { background: rgba(245,158,11,0.12); color: var(--warning); }
.band-fresh    { background: rgba(34,197,94,0.12); color: var(--success); }
.band-HIGH     { background: rgba(34,197,94,0.12); color: var(--success); }
.band-MEDIUM   { background: rgba(245,158,11,0.12); color: var(--warning); }
.band-LOW      { background: rgba(239,68,68,0.15); color: #fca5a5; }

.progress-bar-outer {
  height: 6px;
  background: var(--surface2);
  border-radius: 3px;
  overflow: hidden;
}

.progress-bar-inner {
  height: 100%;
  border-radius: 3px;
  transition: width 0.4s;
}

.modifier-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 16px;
  border-radius: var(--radius);
  font-size: 20px;
  font-weight: 700;
  background: var(--surface2);
  border: 1px solid var(--border);
}

/* ── Alert Cards ──────────────────────────────────────────────────────────── */
.alert-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}

.alert-severity-bar {
  width: 4px;
  border-radius: 2px;
  flex-shrink: 0;
  align-self: stretch;
  min-height: 40px;
}
.sev-info     { background: var(--info); }
.sev-warning  { background: var(--warning); }
.sev-critical { background: var(--danger); }

.alert-body { flex: 1; }
.alert-type { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 3px; }
.alert-title { font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.alert-detail { font-size: 12px; color: var(--muted); margin-bottom: 8px; }
.alert-action-label { font-size: 11px; color: var(--warning); font-weight: 500; }
.alert-time { font-size: 11px; color: var(--muted); margin-top: 4px; }
.alert-actions { display: flex; align-items: flex-start; padding-top: 2px; }

/* ── Misc ─────────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
}

.empty-state p { margin-top: 8px; font-size: 13px; }

.loading-overlay {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
  color: var(--muted);
  gap: 10px;
  font-size: 13px;
}

.readiness-score-big {
  font-size: 52px;
  font-weight: 800;
  line-height: 1;
  margin: 8px 0 4px;
}

.section-title {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin: 20px 0 10px;
}

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

.modal-overlay.hidden { display: none; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 20px 20px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.modal-title { font-size: 16px; font-weight: 700; }

.modal-close {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
  padding: 4px;
}

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

.modal-body { padding: 0 20px 20px; }

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.campaign-select-item {
  padding: 10px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
  cursor: pointer;
  transition: background 0.1s, border-color 0.1s;
}

.campaign-select-item:hover { background: var(--surface2); }
.campaign-select-item.selected { border-color: var(--primary); background: rgba(37,99,235,0.08); }
.campaign-select-item.ineligible { opacity: 0.5; cursor: not-allowed; }

.campaign-select-name { font-size: 13px; font-weight: 500; }
.campaign-select-meta { font-size: 11px; color: var(--muted); margin-top: 2px; }
.campaign-select-reason { font-size: 11px; color: #fca5a5; margin-top: 2px; }

.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ── Heatmap ──────────────────────────────────────────────────────────────── */
.heatmap-grid {
  display: grid;
  gap: 2px;
}

.heatmap-cell {
  width: 100%;
  aspect-ratio: 1;
  border-radius: 2px;
  background: var(--surface2);
}

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .cards-row.cols-4 { grid-template-columns: 1fr 1fr; }
  .cards-row.cols-3 { grid-template-columns: 1fr 1fr; }
}
