:root {
  --bg: #0b1220;
  --bg-elevated: #111827;
  --panel: #151f32;
  --panel-2: #1a253a;
  --line: #243044;
  --line-strong: #334155;
  --ink: #e8eef7;
  --muted: #94a3b8;
  --accent: #3b82f6;
  --accent-2: #60a5fa;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --crit: #b91c1c;
  --sidebar-w: 248px;
  --topbar-h: 56px;
  --radius: 10px;
  --focus: #fbbf24;
  --font: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Menlo, Consolas, monospace;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font: 400 15px/1.5 var(--font);
  color: var(--ink);
  background: var(--bg);
}
img { max-width: 100%; height: auto; }
a { color: var(--accent-2); }
a:hover { color: #93c5fd; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.skip {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--accent);
  color: #041018;
  padding: 0.65rem 1rem;
  font-weight: 700;
  text-decoration: none;
  border-radius: 0 0 8px 0;
}
.skip:focus { left: 0; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Author styles often set display and defeat the UA [hidden] rule — restore it. */
[hidden] {
  display: none !important;
}

/* ---- login ---- */
.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(59, 130, 246, 0.22), transparent 55%),
    radial-gradient(700px 400px at 90% 110%, rgba(14, 165, 233, 0.12), transparent 50%),
    var(--bg);
}
.login-page[hidden] {
  display: none !important;
}
.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 2rem 1.75rem;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}
.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(145deg, #3b82f6, #0ea5e9);
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #041018;
  letter-spacing: -0.04em;
}
.login-brand h1 {
  margin: 0;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}
.login-brand p {
  margin: 0.15rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}
.password-row {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
}
.password-row input {
  flex: 1 1 auto;
  min-width: 0;
}
.password-row .btn {
  flex: 0 0 auto;
  white-space: nowrap;
}
.form-error {
  margin: 0 0 0.85rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid rgba(248, 113, 113, 0.45);
  background: rgba(127, 29, 29, 0.28);
  color: #fecaca;
  font-size: 0.88rem;
}
.form-error[hidden] {
  display: none !important;
}

.callout {
  margin: 0 0 1rem;
  padding: 0.85rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--line-strong);
  background: #0d1628;
}
.callout-warn {
  border-color: rgba(245, 158, 11, 0.45);
  background: rgba(120, 53, 15, 0.28);
  color: #fde68a;
}
.callout-warn strong { color: #fef3c7; }
.key-reveal {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: stretch;
  margin-top: 0.65rem;
}
.key-reveal code {
  flex: 1 1 220px;
  display: block;
  padding: 0.65rem 0.75rem;
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: #0b1424;
  color: var(--ink);
  word-break: break-all;
  font-family: var(--mono);
  font-size: 0.82rem;
  line-height: 1.4;
}
.admin-key-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 650;
  background: rgba(245, 158, 11, 0.18);
  color: #fde68a;
  border: 1px solid rgba(245, 158, 11, 0.35);
}

/* ---- app shell ---- */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
.app-shell.hidden { display: none; }

.sidebar {
  background: #070d18;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: auto;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 1rem 1rem 0.85rem;
  border-bottom: 1px solid var(--line);
  text-decoration: none;
  color: var(--ink);
}
.sidebar-brand strong {
  display: block;
  font-size: 0.95rem;
  letter-spacing: -0.02em;
}
.sidebar-brand span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  margin-top: 0.1rem;
}
.nav {
  padding: 0.85rem 0.65rem;
  display: grid;
  gap: 0.2rem;
}
.nav a {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  color: #cbd5e1;
  text-decoration: none;
  font-weight: 500;
  font-size: 0.92rem;
  min-height: 44px;
}
.nav a:hover { background: rgba(255, 255, 255, 0.04); color: #fff; }
.nav a[aria-current="page"] {
  background: var(--accent-soft);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-icon {
  width: 1.15rem;
  text-align: center;
  opacity: 0.85;
}
.sidebar-foot {
  margin-top: auto;
  padding: 0.85rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.78rem;
}

.main-wrap {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background:
    linear-gradient(180deg, rgba(15, 23, 42, 0.55), transparent 180px),
    var(--bg);
}
.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.25rem;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 18, 32, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.menu-btn {
  display: none;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  border-radius: 8px;
  min-width: 44px;
  min-height: 44px;
  cursor: pointer;
}
.topbar h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 650;
  letter-spacing: -0.01em;
}
.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
  background: #1e293b;
  color: #cbd5e1;
  border: 1px solid var(--line);
}
.badge.on { background: rgba(34, 197, 94, 0.15); color: #86efac; border-color: rgba(34, 197, 94, 0.35); }
.badge.off { background: rgba(148, 163, 184, 0.12); color: #94a3b8; }

.content {
  padding: 1.25rem 1.35rem 2.5rem;
  max-width: 1280px;
  width: 100%;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1.15rem;
}
.page-head h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2.2vw, 1.75rem);
  letter-spacing: -0.03em;
}
.page-head p {
  margin: 0.35rem 0 0;
  color: var(--muted);
  max-width: 62ch;
}

.grid-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.15rem;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.05rem;
}
.stat-card .label {
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 650;
}
.stat-card .value {
  margin-top: 0.45rem;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}
.panel h3 {
  margin: 0 0 0.85rem;
  font-size: 0.95rem;
}
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}
.panel-head h3 { margin: 0; }

.grid2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.85rem;
}
.field { margin-bottom: 0.75rem; }
.field label {
  display: block;
  margin-bottom: 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: #cbd5e1;
}
.field .hint {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}
input[type="text"],
input[type="password"],
input[type="url"],
input[type="search"],
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: #0b1424;
  color: var(--ink);
}
textarea { min-height: 96px; resize: vertical; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  outline: none;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 44px;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 650;
  text-decoration: none;
  background: var(--accent);
  color: #041018;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-ghost {
  background: transparent;
  color: var(--ink);
  border-color: var(--line-strong);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.04); }
.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: #fecaca;
  border-color: rgba(239, 68, 68, 0.35);
}
.btn-sm {
  min-height: 36px;
  padding: 0.35rem 0.7rem;
  font-size: 0.82rem;
}
.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.engine-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.45rem;
}
.engine-grid label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-height: 44px;
  margin: 0;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d1628;
  font-weight: 500;
  font-size: 0.85rem;
  cursor: pointer;
}
.engine-grid input { width: auto; accent-color: var(--accent); }

.exploit-box {
  margin-top: 0.85rem;
  padding: 0.85rem;
  border-radius: 10px;
  border: 1px solid rgba(239, 68, 68, 0.35);
  background: rgba(127, 29, 29, 0.18);
}
.exploit-box.disabled { opacity: 0.65; }
.exploit-box .warn {
  color: #fecaca;
  font-weight: 700;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
}
table {
  width: 100%;
  border-collapse: collapse;
  min-width: 640px;
  font-size: 0.86rem;
}
th, td {
  padding: 0.7rem 0.8rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
th {
  background: #0d1628;
  color: #cbd5e1;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
tbody tr:hover { background: rgba(255, 255, 255, 0.02); }
tbody tr:last-child td { border-bottom: 0; }
.mono { font-family: var(--mono); font-size: 0.78rem; }
.muted { color: var(--muted); }
.pill {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  background: #1e293b;
  border: 1px solid var(--line);
  font-size: 0.72rem;
  font-weight: 650;
}
.sev {
  display: inline-block;
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}
.sev-critical { background: var(--crit); }
.sev-high { background: var(--danger); }
.sev-medium { background: var(--warn); color: #1a1200; }
.sev-low { background: #2563eb; }
.sev-info { background: #475569; }
.fp-likely_true { color: #86efac; }
.fp-review { color: #fcd34d; }
.fp-likely_false { color: #fca5a5; }

.empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 10px;
}

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  max-width: min(420px, calc(100vw - 2rem));
  background: #020617;
  color: #f8fafc;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 0.8rem 1rem;
  font-size: 0.85rem;
  white-space: pre-wrap;
  display: none;
  z-index: 50;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.tabs {
  display: flex;
  gap: 0.35rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.tabs button {
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--ink);
  border-radius: 999px;
  min-height: 40px;
  padding: 0.35rem 0.9rem;
  cursor: pointer;
  font-weight: 600;
}
.tabs button[aria-selected="true"] {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: #fff;
}

.quick-actions {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 0.75rem;
}
.quick-actions a, .quick-actions button {
  text-align: left;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 1rem;
  color: var(--ink);
  text-decoration: none;
  cursor: pointer;
  min-height: 88px;
}
.quick-actions strong { display: block; margin-bottom: 0.25rem; }
.quick-actions span { color: var(--muted); font-size: 0.82rem; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(280px, 86vw);
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    z-index: 40;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    z-index: 35;
  }
  .sidebar-backdrop.show { display: block; }
  .menu-btn { display: inline-flex; }
  .grid2 { grid-template-columns: 1fr; }
  table { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none; }
}
