:root {
  --bg: #0a0e1a;
  --surface: #111626;
  --surface-2: #18203a;
  --surface-3: #1e2944;
  --border: #283353;
  --border-soft: #1d2742;
  --text: #e4e8f5;
  --text-muted: #8c95b3;
  --accent: #22d3ee;
  --accent-strong: #06b6d4;
  --accent-soft: rgba(34, 211, 238, 0.14);
  --magenta: #d946ef;
  --green: #22c55e;
  --yellow: #fbbf24;
  --red: #ef4444;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
  --radius: 12px;
  --radius-sm: 8px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --mono: 'JetBrains Mono', 'SFMono-Regular', Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

input, select, textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  width: 100%;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { font-family: var(--mono); font-size: 13px; }

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

.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.mono { font-family: var(--mono); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.05s;
}
.btn:hover { border-color: var(--accent); background: var(--surface-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: linear-gradient(135deg, var(--accent-strong), var(--magenta));
  border-color: transparent;
  color: #04111a;
}
.btn-primary:hover { filter: brightness(1.05); border-color: transparent; }
.btn-ghost { background: transparent; }
.btn-danger { background: var(--surface-2); color: #fda4af; border-color: rgba(239, 68, 68, 0.4); }
.btn-danger:hover { background: rgba(239, 68, 68, 0.12); border-color: var(--red); color: #fecaca; }
.btn-warning { color: var(--yellow); border-color: rgba(251, 191, 36, 0.35); }
.btn-warning:hover { background: rgba(251, 191, 36, 0.1); border-color: var(--yellow); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn.full { width: 100%; }

/* ---------- alerts / toasts ---------- */
.alert {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
}
.alert-error { background: rgba(239, 68, 68, 0.12); border-color: rgba(239, 68, 68, 0.4); color: #fecaca; }
.alert-success { background: rgba(34, 197, 94, 0.12); border-color: rgba(34, 197, 94, 0.4); color: #bbf7d0; }
.alert-warning { background: rgba(251, 191, 36, 0.12); border-color: rgba(251, 191, 36, 0.4); color: #fde68a; }
.alert-info { background: var(--accent-soft); border-color: rgba(34, 211, 238, 0.4); color: #a5f3fc; }

.toast-host {
  position: fixed;
  bottom: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  max-width: 380px;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.18s, transform 0.18s;
  font-size: 13px;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.toast-error { border-color: rgba(239, 68, 68, 0.5); }
.toast.toast-success { border-color: rgba(34, 197, 94, 0.5); }

/* ---------- login ---------- */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-wrap { padding: 24px; width: 100%; max-width: 420px; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow);
}
.login-card form { display: grid; gap: 16px; margin-top: 8px; }
.login-card .footer-note { margin-top: 18px; text-align: center; }

.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand h1 { margin: 0; font-size: 18px; }
.brand p { margin: 0; }
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), var(--magenta));
  box-shadow: 0 6px 18px rgba(34, 211, 238, 0.25);
}
.brand-compact .brand-mark { width: 30px; height: 30px; border-radius: 8px; }
.brand-compact h1 { font-size: 14px; }

/* ---------- app shell ---------- */
.dashboard-body { background: var(--bg); }
.app-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: block;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-weight: 500;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid rgba(34, 211, 238, 0.3);
}
.sidebar-footer { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border-soft); }

.content { padding: 22px 28px 60px; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.topbar-title { font-size: 22px; font-weight: 700; }
.topbar-title small { display: block; font-size: 12px; color: var(--text-muted); font-weight: 500; margin-top: 4px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.health-pill {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-muted);
}
.health-pill.ok { color: var(--green); border-color: rgba(34, 197, 94, 0.4); }
.health-pill.err { color: var(--red); border-color: rgba(239, 68, 68, 0.5); }

.view { display: none; }
.view.active { display: block; }

/* ---------- cards / panels ---------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.2);
}
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.panel-header h2 { margin: 0; font-size: 15px; font-weight: 700; }
.panel-actions { display: flex; gap: 8px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat-card .label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.stat-card .value { font-size: 28px; font-weight: 700; margin-top: 4px; }
.stat-card .sub { font-size: 12px; color: var(--text-muted); }

/* ---------- tables ---------- */
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.data th, table.data td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--border-soft);
}
table.data th {
  background: var(--surface-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  font-weight: 700;
}
table.data tr:hover td { background: rgba(255, 255, 255, 0.02); }
table.data .actions { white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}
.badge-success { color: var(--green); border-color: rgba(34, 197, 94, 0.4); background: rgba(34, 197, 94, 0.08); }
.badge-danger { color: var(--red); border-color: rgba(239, 68, 68, 0.4); background: rgba(239, 68, 68, 0.08); }
.badge-warning { color: var(--yellow); border-color: rgba(251, 191, 36, 0.4); background: rgba(251, 191, 36, 0.08); }
.badge-accent { color: var(--accent); border-color: rgba(34, 211, 238, 0.4); background: var(--accent-soft); }

/* ---------- forms ---------- */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display: block; }
.form-row { display: flex; gap: 8px; align-items: center; }
.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }
.help { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.key-display {
  background: #04111a;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  font-family: var(--mono);
  font-size: 13px;
  word-break: break-all;
  color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  user-select: all;
}

pre.policy {
  background: #04111a;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text);
  max-height: 460px;
  overflow: auto;
  white-space: pre;
}
.policy-diff-line-add { color: var(--green); }
.policy-diff-line-del { color: var(--red); }

.empty {
  padding: 28px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

dialog.modal {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius);
  padding: 0;
  width: min(520px, 92vw);
  box-shadow: var(--shadow);
}
dialog.modal::backdrop { background: rgba(0, 0, 0, 0.55); backdrop-filter: blur(2px); }
dialog.modal .modal-head { padding: 16px 20px; border-bottom: 1px solid var(--border-soft); }
dialog.modal .modal-head h3 { margin: 0; font-size: 15px; }
dialog.modal .modal-body { padding: 20px; }
dialog.modal .modal-foot { padding: 12px 20px; border-top: 1px solid var(--border-soft); display: flex; justify-content: flex-end; gap: 8px; }
