:root {
  --bg: #f4f6fb;
  --bg-elevated: #ffffff;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.14);
  --text: #0b1e3f;
  --text-muted: #64748b;
  --accent: #2563eb;
  --accent-2: #7c3aed;
  --accent-3: #ec4899;
  --success: #059669;
  --warning: #d97706;
  --danger: #dc2626;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow-md: 0 10px 30px rgba(37, 99, 235, 0.08);
  --shadow-lg: 0 20px 60px rgba(37, 99, 235, 0.12);
  --r-md: 12px;
  --r-lg: 16px;
  --r-pill: 999px;
}

[data-theme="dark"] {
  --bg: #0a0e1a;
  --bg-elevated: #111827;
  --border: rgba(148, 163, 184, 0.12);
  --border-strong: rgba(148, 163, 184, 0.22);
  --text: #e6ecff;
  --text-muted: #94a3b8;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 10px 30px rgba(0, 0, 0, 0.5);
  --shadow-lg: 0 20px 60px rgba(0, 0, 0, 0.6);
}
[data-theme="dark"] header { background: rgba(17, 24, 39, 0.85); }
[data-theme="dark"] th { background: rgba(148, 163, 184, 0.06); }
[data-theme="dark"] tbody tr:hover { background: rgba(122, 162, 255, 0.06); }
[data-theme="dark"] .code-output { background: #05080f; }

.theme-toggle {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  width: 56px;
  height: 30px;
  padding: 0 8px;
  background: rgba(37, 99, 235, 0.08);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  color: var(--text-muted);
  cursor: pointer;
  box-shadow: none;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.theme-toggle:hover { background: rgba(37, 99, 235, 0.14); border-color: var(--border-strong); transform: none; box-shadow: none; filter: none; }
.theme-toggle svg { position: relative; z-index: 2; pointer-events: none; transition: color 0.25s ease, opacity 0.25s ease; }
.theme-toggle .icon-sun { color: #f59e0b; }
.theme-toggle .icon-moon { color: #64748b; }
.theme-toggle::before {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffffff, #f1f5f9);
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.2);
  transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1), background 0.25s ease;
  z-index: 1;
}
[data-theme="dark"] .theme-toggle { background: rgba(148, 163, 184, 0.10); }
[data-theme="dark"] .theme-toggle::before { transform: translateX(26px); background: linear-gradient(135deg, #1e293b, #0f172a); }
[data-theme="dark"] .theme-toggle .icon-sun { color: #94a3b8; }
[data-theme="dark"] .theme-toggle .icon-moon { color: #e2e8f0; }

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

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14.5px;
  -webkit-font-smoothing: antialiased;
}

.screen { min-height: 100vh; }
.screen.hidden { display: none !important; }

h1, h2, h3, h4 { letter-spacing: -0.02em; }

/* ---------------- Login ---------------- */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(circle at 15% 20%, rgba(37, 99, 235, 0.12), transparent 50%),
    radial-gradient(circle at 85% 80%, rgba(236, 72, 153, 0.10), transparent 50%),
    var(--bg);
}
.login-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 48px 40px;
  width: 100%;
  max-width: 440px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}
.login-card h1 {
  font-size: 36px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 50%, var(--accent-3) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 8px;
}
.subtitle { color: var(--text-muted); margin-bottom: 32px; font-size: 15px; }
.hint { color: var(--text-muted); margin-top: 18px; font-size: 13px; }
.hint a { color: var(--accent); text-decoration: none; font-weight: 600; }
.hint a:hover { text-decoration: underline; }

/* ---------------- Inputs ---------------- */
input, select, textarea {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 10px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

/* ---------------- Buttons ---------------- */
button {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #ffffff;
  border: none;
  padding: 11px 20px;
  border-radius: var(--r-pill);
  font-weight: 600;
  cursor: pointer;
  font-size: 14px;
  font-family: inherit;
  transition: transform .15s, filter .15s, box-shadow .15s;
  box-shadow: 0 6px 16px rgba(37, 99, 235, 0.22);
}
button:hover { filter: brightness(1.07); transform: translateY(-1px); box-shadow: 0 10px 20px rgba(37, 99, 235, 0.28); }
button:active { transform: translateY(0); }
.login-card button { width: 100%; margin-top: 18px; padding: 14px; font-size: 15px; }

/* ---------------- Header ---------------- */
header {
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: saturate(1.4) blur(12px);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 14px 32px;
  display: flex;
  align-items: center;
  gap: 24px;
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand {
  font-weight: 800;
  font-size: 20px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 50%, var(--accent-3) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.02em;
}
nav { display: flex; gap: 4px; flex: 1; }
.nav-btn {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: var(--r-pill);
  box-shadow: none;
  font-weight: 500;
}
.nav-btn:hover { background: rgba(37, 99, 235, 0.06); color: var(--text); transform: none; box-shadow: none; filter: none; }
.nav-btn.active {
  background: rgba(37, 99, 235, 0.10);
  color: var(--accent);
  font-weight: 600;
  box-shadow: none;
}

#logout-btn {
  background: transparent;
  color: var(--text-muted);
  box-shadow: none;
  padding: 8px 14px;
}
#logout-btn:hover { color: var(--danger); background: rgba(220, 38, 38, 0.08); transform: none; box-shadow: none; filter: none; }

/* ---------------- Main ---------------- */
main { padding: 36px; max-width: 1240px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }
.tab h2 { margin: 32px 0 20px; font-size: 26px; font-weight: 800; }
.tab h3 { margin: 28px 0 14px; font-size: 16px; font-weight: 700; color: var(--text); }

/* ---------------- Cards ---------------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 22px;
  box-shadow: var(--shadow-sm);
  transition: transform .2s, box-shadow .2s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-label {
  color: var(--text-muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 8px;
  font-weight: 600;
}
.stat-value {
  font-size: 30px;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

/* ---------------- Playground ---------------- */
.playground {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 24px;
  box-shadow: var(--shadow-sm);
}
.playground-form { display: flex; flex-direction: column; gap: 12px; }
.playground-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.code-output {
  background: #0b1e3f;
  color: #e2e8f5;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  font-family: "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px;
  white-space: pre-wrap;
  overflow: auto;
  max-height: 420px;
  line-height: 1.55;
}

/* ---------------- Tables ---------------- */
.filters { display: flex; gap: 12px; margin-bottom: 18px; }
.filters select { width: auto; min-width: 180px; }
table {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  border-collapse: separate;
  border-spacing: 0;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}
th, td {
  padding: 14px 18px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
th {
  color: var(--text-muted);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  background: #f8fafc;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(37, 99, 235, 0.035); }
td code { font-size: 12px; color: var(--accent); background: rgba(37, 99, 235, 0.08); padding: 2px 6px; border-radius: 4px; }

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge.approved { background: rgba(5, 150, 105, 0.12); color: var(--success); }
.badge.declined { background: rgba(220, 38, 38, 0.12); color: var(--danger); }
.badge.step_up_required { background: rgba(217, 119, 6, 0.12); color: var(--warning); }

/* ---------------- Webhooks ---------------- */
.webhook-form {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}
.webhook-form input { flex: 1; min-width: 200px; }
.webhook-form button { white-space: nowrap; }

/* ---------------- Config ---------------- */
#config-editor {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 26px;
  margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.config-row {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 0;
  border-bottom: 1px dashed var(--border);
}
.config-row:last-child { border-bottom: none; }
.config-row label { flex: 1; color: var(--text-muted); font-weight: 500; }
.config-row input { width: 140px; }

.muted { color: var(--text-muted); margin-bottom: 16px; font-size: 13.5px; }

/* ---------------- Charts ---------------- */
.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 18px;
  margin-top: 8px;
}
.chart-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: transform .2s, box-shadow .2s;
}
.chart-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.chart-card canvas { width: 100% !important; height: 240px !important; }
.chart-card h3 {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

@media (max-width: 960px) {
  .charts-grid { grid-template-columns: 1fr; }
  .playground { grid-template-columns: 1fr; }
  main { padding: 24px 18px; }
  header { padding: 12px 18px; gap: 14px; flex-wrap: wrap; }
  nav { order: 3; flex-basis: 100%; overflow-x: auto; }
}
