:root {
  --bg-deep: #060913;
  --bg-surface: #0d1424;
  --bg-elevated: #131d33;
  --border-subtle: #1e2d4a;
  --border-bright: #2e446e;
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #94a3b8;
  --emerald: #10b981;
  --emerald-glow: rgba(16, 185, 129, 0.16);
  --cyan: #06b6d4;
  --cyan-glow: rgba(6, 182, 212, 0.16);
  --violet: #8b5cf6;
  --violet-glow: rgba(139, 92, 246, 0.16);
  --amber: #f59e0b;
  --amber-glow: rgba(245, 158, 11, 0.16);
  --rose: #f43f5e;
  --rose-glow: rgba(244, 63, 94, 0.16);
  --radius-lg: 16px;
  --radius-md: 12px;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  max-width: 100%;
  overflow-x: clip;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(1100px 500px at 15% -5%, rgba(16, 185, 129, 0.13), transparent 60%),
    radial-gradient(900px 450px at 88% 0%, rgba(6, 182, 212, 0.12), transparent 58%),
    var(--bg-deep);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  line-height: 1.5;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.88em;
  padding: 2px 5px;
  border-radius: 6px;
  background: rgba(15, 23, 42, 0.85);
  border: 1px solid var(--border-subtle);
  color: #67e8f9;
  overflow-wrap: anywhere;
}

/* Auth Overlay */
.auth-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
  background: rgba(4, 7, 15, 0.92);
  backdrop-filter: blur(12px);
}

.auth-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-surface);
  border: 1px solid var(--border-bright);
  border-radius: 20px;
  padding: 30px 26px;
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.65);
}

.brand-chip {
  display: inline-block;
  padding: 5px 11px;
  border-radius: 999px;
  background: var(--emerald-glow);
  color: #6ee7b7;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-bottom: 12px;
  max-width: 100%;
}

.auth-card h1 {
  margin: 0 0 8px;
  font-size: 23px;
  line-height: 1.25;
}

.auth-card p {
  margin: 0 0 20px;
  color: var(--text-secondary);
  font-size: 14px;
}

.auth-error,
.api-error-banner {
  margin-top: 12px;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--rose-glow);
  border: 1px solid rgba(244, 63, 94, 0.45);
  color: #fecdd3;
  font-size: 13px;
}

.api-error-banner {
  margin: 0 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

/* Topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 28px;
  background: rgba(13, 20, 36, 0.92);
  border-bottom: 1px solid var(--border-subtle);
  position: relative;
  z-index: 10;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-copy {
  min-width: 0;
}

.logo-orb {
  width: 44px;
  height: 44px;
  flex-shrink: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--emerald), var(--cyan));
  color: #031519;
  font-weight: 900;
  font-size: 17px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 0 24px rgba(16, 185, 129, 0.35);
}

.brand-title {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.brand-sub {
  font-size: 12.5px;
  color: var(--text-muted);
  overflow-wrap: anywhere;
}

.topbar-status {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 6px 13px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 700;
  background: var(--emerald-glow);
  border: 1px solid rgba(16, 185, 129, 0.35);
  color: #6ee7b7;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--emerald);
  box-shadow: 0 0 10px var(--emerald);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.25); opacity: 0.65; }
}

.score-pill {
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--cyan-glow);
  border: 1px solid rgba(6, 182, 212, 0.35);
  color: #a5f3fc;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

/* Navigation */
.nav-tabs {
  display: flex;
  gap: 12px;
  padding: 10px 28px;
  background: rgba(9, 14, 26, 0.8);
  border-bottom: 1px solid var(--border-subtle);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.nav-tab {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.16s ease;
}

.nav-tab:hover {
  color: var(--text-primary);
  background: rgba(30, 45, 74, 0.45);
}

.nav-tab.active {
  color: #04131a;
  background: linear-gradient(135deg, var(--emerald), var(--cyan));
  font-weight: 700;
  box-shadow: 0 6px 18px rgba(6, 182, 212, 0.25);
}

/* Main Content */
.main-container {
  max-width: 1380px;
  width: 100%;
  margin: 0 auto;
  padding: 28px;
}

.hero-strip,
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.hero-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.hero-strip h1,
.hero-strip h2,
.section-header h1,
.section-header h2 {
  margin: 0 0 4px;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.hero-strip p,
.section-header p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 14px;
  max-width: 780px;
}

/* KPI Cards */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 245px), 1fr));
  gap: 18px;
  margin-bottom: 20px;
}

.ops-three-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr));
  gap: 18px;
  margin-bottom: 24px;
}

.kpi-card {
  position: relative;
  overflow: hidden;
  min-width: 0;
  padding: 20px 22px;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  transition: transform 0.18s ease, border-color 0.18s ease;
}

.kpi-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-bright);
}

.kpi-card.emerald { border-top: 3px solid var(--emerald); }
.kpi-card.cyan { border-top: 3px solid var(--cyan); }
.kpi-card.violet { border-top: 3px solid var(--violet); }
.kpi-card.amber { border-top: 3px solid var(--amber); }

.kpi-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 36px;
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  margin-bottom: 8px;
}

.kpi-value small {
  font-size: 17px;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 3px;
}

.kpi-meta {
  font-size: 13px;
  color: var(--text-secondary);
}

.progress-track {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--emerald), var(--cyan));
  transition: width 0.25s ease;
}

/* Layout Grids & Surfaces */
.two-col-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 380px), 1fr));
  gap: 20px;
}

.surface-card {
  min-width: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.drawer-card {
  margin-bottom: 22px;
  border-color: var(--cyan);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.card-header h3 {
  margin: 0;
  font-size: 16px;
}

.badge-subtle,
.badge-emerald,
.badge-warn,
.badge-danger {
  display: inline-flex;
  align-items: center;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  max-width: 100%;
}

.badge-subtle { background: var(--bg-elevated); color: var(--text-secondary); border: 1px solid var(--border-subtle); }
.badge-emerald { background: var(--emerald-glow); color: #6ee7b7; border: 1px solid rgba(16, 185, 129, 0.35); }
.badge-warn { background: var(--amber-glow); color: #fde68a; border: 1px solid rgba(245, 158, 11, 0.35); }
.badge-danger { background: var(--rose-glow); color: #fecdd3; border: 1px solid rgba(244, 63, 94, 0.35); }

/* Guardrails & Checks */
.guardrail-list,
.stack-list,
.data-card-list,
.campaigns-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.guard-item,
.row-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
}

.guard-item {
  justify-content: flex-start;
}

.guard-icon {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  flex-shrink: 0;
}

.guard-icon.ok { background: var(--emerald-glow); color: var(--emerald); }
.guard-icon.fail { background: var(--rose-glow); color: var(--rose); }

.guard-item strong { display: block; font-size: 14px; margin-bottom: 2px; }
.guard-item p { margin: 0; font-size: 13px; color: var(--text-secondary); overflow-wrap: anywhere; }

.checks-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 290px), 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.check-card {
  min-width: 0;
  padding: 18px;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
}

.check-card.pass { border-left: 4px solid var(--emerald); }
.check-card.fail { border-left: 4px solid var(--rose); }

.check-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  flex-wrap: wrap;
}

.check-title { font-weight: 700; font-size: 14.5px; }
.check-detail { font-size: 12.5px; color: var(--text-secondary); overflow-wrap: anywhere; }

/* Forms & Inputs */
label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 13px;
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-deep);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
}

textarea {
  min-height: 96px;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px rgba(6, 182, 212, 0.22);
}

.form-stack { display: flex; flex-direction: column; gap: 12px; }
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 210px), 1fr));
  gap: 14px;
}
.full-span { grid-column: 1 / -1; }
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.checkbox-inline {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  gap: 8px;
  margin: 0;
  cursor: pointer;
}
.checkbox-inline input { width: 18px; height: 18px; min-height: 18px; flex-shrink: 0; }

.inline-validator {
  display: flex;
  gap: 12px;
}

.validator-result {
  margin-top: 14px;
  padding: 14px;
  border-radius: 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-bright);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.filter-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.filter-row input, .filter-row select { width: auto; min-width: 180px; }

/* Buttons — strict >= 44px tap targets on mobile & desktop */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 18px;
  border-radius: 10px;
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  transition: transform 0.12s ease, opacity 0.12s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.btn-block { width: 100%; margin-top: 14px; white-space: normal; text-align: center; }
.btn-sm { min-height: 44px; padding: 8px 14px; font-size: 12.5px; border-radius: 9px; }

.btn-primary {
  background: linear-gradient(135deg, var(--emerald), var(--cyan));
  color: #031519;
}

.btn-secondary {
  background: var(--bg-elevated);
  border-color: var(--border-bright);
  color: var(--text-primary);
}

.btn-danger {
  background: rgba(244, 63, 94, 0.18);
  border-color: rgba(244, 63, 94, 0.45);
  color: #fecdd3;
}

.btn-ghost {
  background: transparent;
  border-color: var(--border-subtle);
  color: var(--text-secondary);
}

/* Campaign Card & Variant Matrix */
.campaign-card {
  min-width: 0;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.campaign-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.campaign-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

.campaign-metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 112px), 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.mini-stat {
  min-width: 0;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--bg-elevated);
}
.mini-stat span { display: block; font-size: 11px; color: var(--text-muted); text-transform: uppercase; }
.mini-stat strong { font-size: 17px; font-variant-numeric: tabular-nums; }

.variant-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
  gap: 10px;
  margin: 12px 0;
}

.variant-pill-card {
  padding: 12px;
  border-radius: 10px;
  background: rgba(19, 29, 51, 0.72);
  border: 1px solid var(--border-subtle);
}

.muted-copy { color: var(--text-secondary); font-size: 13.5px; margin: 0 0 14px; }
.empty-state {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-secondary);
  border: 1px dashed var(--border-subtle);
  border-radius: var(--radius-md);
}

/* Toasts */
.toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  left: 16px;
  max-width: 420px;
  margin-left: auto;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--cyan);
  color: var(--text-primary);
  font-size: 13.5px;
  font-weight: 600;
  box-shadow: 0 14px 36px rgba(0, 0, 0, 0.5);
}

@media (max-width: 768px) {
  .topbar {
    position: static;
    padding: 14px 16px;
    flex-direction: column;
    align-items: stretch;
  }
  .nav-tabs {
    padding: 10px 16px;
  }
  .main-container {
    padding: 16px;
  }
  .two-col-grid,
  .ops-three-grid {
    grid-template-columns: 1fr;
  }
  .inline-validator {
    flex-direction: column;
  }
  .filter-row {
    width: 100%;
  }
  .filter-row input,
  .filter-row select {
    width: 100%;
    min-width: 0;
  }
  .row-card {
    flex-direction: column;
  }
  .hero-actions .btn {
    width: 100%;
    white-space: normal;
  }
}

@media (max-width: 380px) {
  .auth-overlay {
    padding: 12px;
  }
  .auth-card {
    padding: 20px 16px;
  }
  .auth-card h1 {
    font-size: 20px;
  }
  .surface-card,
  .campaign-card,
  .kpi-card {
    padding: 16px;
  }
  .kpi-value {
    font-size: 30px;
  }
  .btn {
    white-space: normal;
    text-align: center;
  }
}
