:root {
  --bg: #f3f5fb;
  --surface: #ffffff;
  --surface-2: #f8f9fd;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e4e8f1;
  --accent: #4f46e5;
  --accent-2: #7c3aed;
  --accent-soft: #eef0ff;
  --on-accent: #ffffff;
  --ok: #059669;   --ok-soft: #d9f5e9;
  --warn: #b45309; --warn-soft: #fdefcf;
  --bad: #dc2626;  --bad-soft: #fde4e4;
  --info: #2563eb; --info-soft: #e0ebff;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 4px 16px rgba(15, 23, 42, .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a0e17; --surface: #121927; --surface-2: #172033; --text: #e6eaf3; --muted: #8b97ad; --border: #243049;
    --accent: #8b8cf8; --accent-2: #a78bfa; --accent-soft: #1d2145; --on-accent: #0a0e17;
    --ok: #34d399;   --ok-soft: rgba(52, 211, 153, .14);
    --warn: #fbbf24; --warn-soft: rgba(251, 191, 36, .14);
    --bad: #f87171;  --bad-soft: rgba(248, 113, 113, .15);
    --info: #60a5fa; --info-soft: rgba(96, 165, 250, .15);
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0a0e17; --surface: #121927; --surface-2: #172033; --text: #e6eaf3; --muted: #8b97ad; --border: #243049;
  --accent: #8b8cf8; --accent-2: #a78bfa; --accent-soft: #1d2145; --on-accent: #0a0e17;
  --ok: #34d399;   --ok-soft: rgba(52, 211, 153, .14);
  --warn: #fbbf24; --warn-soft: rgba(251, 191, 36, .14);
  --bad: #f87171;  --bad-soft: rgba(248, 113, 113, .15);
  --info: #60a5fa; --info-soft: rgba(96, 165, 250, .15);
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 4px 16px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14.5px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; letter-spacing: -.01em; }
h2 { font-size: 22px; }
h3 { font-size: 16px; }
p { margin: 0; }
a { color: var(--accent); }
code, pre, .mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
svg { flex: none; }

/* ---------- buttons and form controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
  padding: 8px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); transition: .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--on-accent); border-color: transparent; }
.btn.primary:hover { filter: brightness(1.08); color: var(--on-accent); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); color: var(--bad); }
.btn.danger.solid { background: var(--bad); color: #fff; border-color: transparent; }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; padding: 11px 14px; }
.icon-btn {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 9px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

input, select, textarea {
  font: inherit; width: 100%; padding: 9px 12px; border-radius: 10px; color: var(--text);
  border: 1px solid var(--border); background: var(--surface-2); transition: .15s;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); background: var(--surface); }
textarea { min-height: 130px; resize: vertical; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.field { margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.pw { position: relative; }
.pw input { padding-right: 44px; }
.pw .icon-btn { position: absolute; right: 4px; top: 4px; width: 32px; height: 32px; border: 0; background: transparent; }
.switch { position: relative; display: inline-block; width: 40px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--border); cursor: pointer; transition: .2s; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.3); }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(18px); }
.switch input:disabled + span { opacity: .5; cursor: not-allowed; }

/* ---------- auth screens ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: minmax(320px, 1.1fr) minmax(360px, 1fr); }
.auth-brand {
  position: relative; overflow: hidden; color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(circle at 20% 15%, #7c3aed 0%, transparent 55%), radial-gradient(circle at 85% 90%, #0ea5e9 0%, transparent 50%), #3730a3;
}
.auth-brand::before, .auth-brand::after { content: ""; position: absolute; border-radius: 50%; border: 1px solid rgba(255,255,255,.14); }
.auth-brand::before { width: 520px; height: 520px; right: -200px; top: -160px; }
.auth-brand::after { width: 340px; height: 340px; left: -120px; bottom: -120px; }
.brand-mark { display: flex; align-items: center; gap: 12px; font-weight: 700; font-size: 20px; position: relative; z-index: 1; }
.brand-logo { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; background: rgba(255,255,255,.18); backdrop-filter: blur(4px); }
.auth-hero { position: relative; z-index: 1; max-width: 460px; }
.auth-hero h1 { font-size: 34px; margin-bottom: 14px; }
.auth-hero p { opacity: .85; font-size: 16px; }
.auth-points { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 14px; }
.auth-points li { display: flex; gap: 12px; align-items: flex-start; opacity: .95; }
.auth-points .dot { width: 30px; height: 30px; border-radius: 9px; background: rgba(255,255,255,.16); display: grid; place-items: center; }
.auth-foot { position: relative; z-index: 1; font-size: 13px; opacity: .7; }
.auth-form-wrap { display: grid; place-items: center; padding: 32px 20px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card h2 { font-size: 26px; margin-bottom: 6px; }
.auth-card > .muted { margin-bottom: 24px; }
.alert { padding: 10px 12px; border-radius: 10px; font-size: 13.5px; margin-bottom: 14px; background: var(--bad-soft); color: var(--bad); }
.alert.info { background: var(--info-soft); color: var(--info); }
@media (max-width: 860px) {
  .auth { grid-template-columns: 1fr; }
  .auth-brand { padding: 28px 24px; }
  .auth-hero h1 { font-size: 24px; }
  .auth-points, .auth-foot { display: none; }
}

/* ---------- app shell ---------- */
.shell { display: grid; grid-template-columns: 252px 1fr; min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 18px 14px;
  background: var(--surface); border-right: 1px solid var(--border);
}
.side-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; padding: 4px 8px 18px; }
.side-brand .brand-logo { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; width: 34px; height: 34px; }
.nav { display: grid; gap: 3px; overflow-y: auto; }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 14px 10px 5px; font-weight: 600; }
.nav a {
  display: flex; align-items: center; gap: 11px; padding: 9px 11px; border-radius: 10px; text-decoration: none;
  color: var(--muted); font-weight: 600; transition: .15s;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.side-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--border); display: grid; gap: 10px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 6px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); text-transform: uppercase; }
.user-chip .who { min-width: 0; line-height: 1.2; }
.user-chip .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip .who small { color: var(--muted); }
.foot-actions { display: flex; gap: 8px; }
.foot-actions .btn { flex: 1; }
.main { min-width: 0; padding: 26px clamp(16px, 3vw, 40px) 56px; width: 100%; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 14px; margin-bottom: 22px; }
.page-head .muted { margin-top: 4px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--border); }
  .side-brand { padding: 0 6px 0 0; }
  .nav { grid-auto-flow: column; overflow-x: auto; order: 3; width: 100%; padding-bottom: 2px; }
  .nav a { padding: 8px 12px; white-space: nowrap; }
  .nav a span.lbl { display: none; }
  .nav-label { display: none; }
  .side-foot { margin: 0 0 0 auto; border: 0; padding: 0; grid-auto-flow: column; align-items: center; }
  .user-chip .who { display: none; }
}

/* ---------- cards, tiles, tables ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.card.flush { padding: 0; overflow: hidden; }
.card.flush .card-head { padding: 18px 20px 0; }
.two-col { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; }
.two-col.even { grid-template-columns: 1fr 1fr; }
.two-col > .card { margin-bottom: 18px; }
@media (max-width: 1000px) { .two-col, .two-col.even { grid-template-columns: 1fr; } }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile { display: flex; gap: 14px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.tile-icon { width: 42px; height: 42px; border-radius: 12px; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); }
.tile-icon.ok { background: var(--ok-soft); color: var(--ok); }
.tile-icon.bad { background: var(--bad-soft); color: var(--bad); }
.tile-icon.warn { background: var(--warn-soft); color: var(--warn); }
.tile-icon.info { background: var(--info-soft); color: var(--info); }
.tile-n { font-size: 26px; font-weight: 700; line-height: 1.1; letter-spacing: -.02em; }
.tile-l { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 11px 16px; vertical-align: middle; border-bottom: 1px solid var(--border); }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; background: var(--surface-2); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.click { cursor: pointer; }
tbody tr:hover td { background: var(--surface-2); }
td.nowrap { white-space: nowrap; }
td.right, th.right { text-align: right; }
.cell-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.preview { color: var(--muted); max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
.empty { display: grid; place-items: center; gap: 10px; text-align: center; padding: 44px 20px; color: var(--muted); }
.empty .ring { width: 54px; height: 54px; border-radius: 16px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%); background-size: 200% 100%; animation: shimmer 1.2s infinite; margin-bottom: 18px; border: 1px solid var(--border); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---------- badges, chips, meters ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--info-soft); color: var(--info); white-space: nowrap; }
.badge.allowed, .badge.ok, .badge.active, .badge.login, .badge.admin { background: var(--ok-soft); color: var(--ok); }
.badge.redacted, .badge.flagged, .badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.blocked, .badge.error, .badge.bad, .badge.revoked, .badge.login_failed, .badge.disabled { background: var(--bad-soft); color: var(--bad); }
.badge.viewer, .badge.muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }
.chip { padding: 1px 8px; border-radius: 6px; font-size: 12px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-family: ui-monospace, Consolas, monospace; }
.chip.secrets, .chip.injection, .chip.custom { border-color: var(--bad); color: var(--bad); }
.chip.pii, .chip.output_secrets, .chip.output_pii { border-color: var(--warn); color: var(--warn); }
.meter-wrap { display: flex; align-items: center; gap: 8px; min-width: 96px; }
.meter { flex: 1; height: 6px; border-radius: 99px; background: var(--border); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 99px; }
.meter-fill.ok { background: var(--ok); } .meter-fill.warn { background: var(--warn); } .meter-fill.bad { background: var(--bad); }
.meter-wrap > span { font-variant-numeric: tabular-nums; font-size: 12.5px; color: var(--muted); width: 24px; text-align: right; }

/* ---------- toolbar, segmented control, pager ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.toolbar .grow { flex: 1 1 220px; position: relative; }
.toolbar .grow svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.toolbar .grow input { padding-left: 36px; }
.toolbar select { width: auto; min-width: 140px; }
.segmented { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.segmented button { font: inherit; font-weight: 600; font-size: 13px; padding: 5px 12px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; }
.segmented button.active { background: var(--surface); color: var(--accent); box-shadow: var(--shadow); }
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }

/* ---------- charts ---------- */
.bars { display: flex; align-items: flex-end; gap: 4px; height: 170px; padding-top: 6px; }
.bar { flex: 1; display: flex; flex-direction: column-reverse; min-height: 3px; background: var(--border); border-radius: 5px 5px 2px 2px; overflow: hidden; transition: filter .15s; }
.bar:hover { filter: brightness(1.12); }
.bar .seg-ok { background: var(--ok); } .bar .seg-warn { background: var(--warn); } .bar .seg-bad { background: var(--bad); }
.axis { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 6px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--muted); margin-top: 12px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.dot-ok { background: var(--ok); } .dot-info { background: var(--info); } .dot-warn { background: var(--warn); } .dot-bad { background: var(--bad); } .dot-muted { background: var(--muted); }
.donut-wrap { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; }
.donut { width: 150px; height: 150px; flex: none; }
.donut circle { fill: none; stroke-width: 5; }
.donut .track { stroke: var(--border); }
.donut .allowed { stroke: var(--ok); } .donut .redacted { stroke: var(--info); } .donut .flagged { stroke: var(--warn); }
.donut .blocked { stroke: var(--bad); } .donut .error { stroke: var(--muted); }
.donut text { fill: var(--text); font-weight: 700; text-anchor: middle; }
.donut .sub { fill: var(--muted); font-size: 3.4px; font-weight: 500; }
.rank { display: grid; gap: 12px; }
.rank-row .top { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 5px; font-size: 13.5px; }
.rank-row .top b { font-weight: 600; word-break: break-word; }
.rank-bar { height: 7px; border-radius: 99px; background: var(--border); overflow: hidden; }
.rank-bar div { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.feed { display: grid; }
.feed-item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--border); }
.feed-item:last-child { border-bottom: 0; padding-bottom: 0; }
.feed-item:first-child { padding-top: 0; }

/* ---------- policy, tester ---------- */
.setting { display: grid; grid-template-columns: 1fr minmax(150px, 220px); gap: 16px; align-items: center; padding: 14px 0; border-bottom: 1px solid var(--border); }
.setting:last-child { border-bottom: 0; }
.setting b { display: block; }
.setting .muted { font-size: 13px; }
@media (max-width: 640px) { .setting { grid-template-columns: 1fr; gap: 8px; } }
.verdict { display: flex; align-items: center; gap: 14px; padding: 16px; border-radius: 12px; margin-bottom: 16px; background: var(--ok-soft); color: var(--ok); }
.verdict.warn { background: var(--warn-soft); color: var(--warn); }
.verdict.bad { background: var(--bad-soft); color: var(--bad); }
.verdict h3 { color: inherit; text-transform: capitalize; }
.verdict .muted { color: inherit; opacity: .85; }
.output { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; white-space: pre-wrap; word-break: break-word; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
.output .redacted { background: var(--warn-soft); color: var(--warn); border-radius: 4px; padding: 0 4px; font-weight: 600; }
.samples { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 10px; }
pre.copy { background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px; margin: 8px 0; white-space: pre-wrap; word-break: break-all; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; font-size: 14px; }
.kv dt { color: var(--muted); } .kv dd { margin: 0; word-break: break-word; }

/* ---------- modal and toast ---------- */
dialog.modal { border: 1px solid var(--border); border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 28px)); background: var(--surface); color: var(--text); box-shadow: 0 24px 70px rgba(0,0,0,.35); }
dialog.modal::backdrop { background: rgba(8, 12, 24, .55); backdrop-filter: blur(3px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 0; }
.modal-body { padding: 16px 20px; max-height: 70vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 20px 18px; }
#toasts { position: fixed; right: 18px; bottom: 18px; display: grid; gap: 10px; z-index: 50; }
.toast { display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-radius: 12px; background: var(--text); color: var(--bg); font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.3); animation: pop .2s ease-out; max-width: 360px; }
.toast.error { background: var(--bad); color: #fff; }
.toast.success { background: var(--ok); color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
