/*
   Theming
   -------
   The app ships DARK first. :root holds dark values; a small
   [data-theme="light"] block redefines the palette for light mode.
   The current theme is chosen in App.razor by an inline bootstrap
   script (runs before any CSS paints) that reads `iqs.theme` from
   localStorage and writes `document.documentElement.dataset.theme`.
   Default is "dark" when nothing is stored.

   New variables (--btn-bg, --input-bg, etc.) were added so that places
   where we used to hardcode #fff / #f9fafb / etc. can track the theme
   without per-selector overrides.
*/

:root {
    --bg: #0b0f1e;
    --surface: #151a2d;
    --surface-2: #1a2038;
    --text: #e6e9f2;
    --muted: #8b93a7;
    --border: #242a42;
    --border-strong: #343c5a;

    --sidebar-bg: #0a0d1d;
    --sidebar-text: #c8cad6;
    --sidebar-muted: #7c819a;

    --accent: #818cf8;
    --accent-2: #c084fc;
    --accent-soft: rgba(129, 140, 248, 0.22);

    --ok: #4ade80;
    --ok-soft: rgba(74, 222, 128, 0.16);
    --warn: #fbbf24;
    --warn-soft: rgba(251, 191, 36, 0.16);
    --err: #f87171;
    --err-soft: rgba(248, 113, 113, 0.16);
    --info: #60a5fa;
    --info-soft: rgba(96, 165, 250, 0.18);

    --btn-bg: var(--surface);
    --btn-hover-bg: #222a44;
    --btn-ghost-hover-bg: #252e4c;
    --primary-hover-bg: #6366f1;
    --danger-btn-hover-bg: #ef4444;
    --input-bg: #0f1426;
    --row-hover-bg: #1a2038;
    --code-bg: #06080f;
    --code-fg: #c8cedb;
    --pill-default-bg: rgba(129, 140, 248, 0.18);
    --pill-default-fg: #c7c9ff;
    --pill-muted-bg: #252d46;
    --pill-muted-fg: #aab2c8;
    --badge-bg: #252d46;
    --badge-fg: #aab2c8;
    --badge-muted-fg: #8b93a7;
    --danger-panel-bg: rgba(239, 68, 68, 0.08);
    --danger-panel-border: rgba(239, 68, 68, 0.38);
    --overlay-bg: rgba(0, 0, 0, 0.65);
    --login-bg: linear-gradient(135deg, #0b1020 0%, #1a1f3a 50%, #3730a3 100%);
    --login-card-bg: var(--surface);
    --finding-ok-border: rgba(74, 222, 128, 0.35);
    --finding-warn-border: rgba(251, 191, 36, 0.35);
    --finding-err-border: rgba(248, 113, 113, 0.35);
    --finding-info-border: rgba(96, 165, 250, 0.35);
    --alert-warn-border: rgba(251, 191, 36, 0.35);

    --radius: 10px;
    --radius-sm: 7px;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .28);

    color-scheme: dark;
}

[data-theme="light"] {
    --bg: #f5f6fa;
    --surface: #ffffff;
    --surface-2: #fafbfd;
    --text: #1f2430;
    --muted: #6b7280;
    --border: #e5e7eb;
    --border-strong: #d1d5db;

    --sidebar-bg: #14172a;
    --sidebar-text: #c8cad6;
    --sidebar-muted: #7c819a;

    --accent: #4f46e5;
    --accent-2: #7c3aed;
    --accent-soft: rgba(79, 70, 229, 0.18);

    --ok: #15803d;
    --ok-soft: #dcfce7;
    --warn: #b45309;
    --warn-soft: #fef3c7;
    --err: #b91c1c;
    --err-soft: #fee2e2;
    --info: #1d4ed8;
    --info-soft: #dbeafe;

    --btn-bg: #fff;
    --btn-hover-bg: #f9fafb;
    --btn-ghost-hover-bg: #f3f4f6;
    --primary-hover-bg: #4338ca;
    --danger-btn-hover-bg: #b91c1c;
    --input-bg: #fff;
    --row-hover-bg: #f9fafc;
    --code-bg: #0f1117;
    --code-fg: #dbe1ea;
    --pill-default-bg: #eef2ff;
    --pill-default-fg: #3730a3;
    --pill-muted-bg: #f1f5f9;
    --pill-muted-fg: #475569;
    --badge-bg: #f1f5f9;
    --badge-fg: #475569;
    --badge-muted-fg: #94a3b8;
    --danger-panel-bg: #fff7f7;
    --danger-panel-border: #fecaca;
    --overlay-bg: rgba(15, 23, 42, 0.55);
    --login-bg: linear-gradient(135deg, #1e1b4b 0%, #312e81 50%, #4338ca 100%);
    --login-card-bg: #fff;
    --finding-ok-border: #bbf7d0;
    --finding-warn-border: #fde68a;
    --finding-err-border: #fecaca;
    --finding-info-border: #bfdbfe;
    --alert-warn-border: #fed7aa;

    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 4px 14px rgba(15, 23, 42, .04);

    color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
}

/* ---------- App shell (layout) ---------- */
.app-shell {
    display: grid;
    grid-template-columns: 248px 1fr;
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
}

.sidebar {
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 1.25rem 0.75rem 1rem;
    border-right: 1px solid var(--border);
    position: sticky;
    top: 0;
    height: 100vh;
    min-width: 0;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0 0.6rem 1rem;
    margin-bottom: 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
}

.brand-mark {
    width: 36px; height: 36px;
    border-radius: 9px;
    background: linear-gradient(135deg, var(--accent), var(--accent-2));
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
    display: grid; place-items: center;
    letter-spacing: 0.04em;
}

.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-size: 0.95rem; color: #fff; }
.brand-text span { font-size: 0.72rem; color: var(--sidebar-muted); }

.nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: 0.5rem;
    flex: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.55rem 0.75rem;
    border-radius: 8px;
    color: var(--sidebar-text);
    text-decoration: none;
    font-size: 0.92rem;
    transition: background .12s, color .12s;
}

.nav-item:hover { background: rgba(255, 255, 255, .05); color: #fff; }
.nav-item.active { background: var(--accent-soft); color: #fff; }
.nav-icon { width: 18px; height: 18px; display: inline-flex; flex: 0 0 auto; }
.nav-icon svg { width: 100%; height: 100%; }

.nav-tree details.nav-group > summary,
.nav-tree details.nav-site > summary {
    list-style: none;
    cursor: pointer;
}
.nav-tree details.nav-group > summary::-webkit-details-marker,
.nav-tree details.nav-site > summary::-webkit-details-marker { display: none; }

.nav-tree .nav-summary {
    justify-content: flex-start;
    gap: 0.65rem;
}
.nav-tree .nav-summary::before {
    content: "▸";
    font-size: 0.7rem;
    color: var(--sidebar-muted);
    margin-right: 0.15rem;
    transition: transform .12s;
}
.nav-tree details[open] > summary.nav-summary::before { transform: rotate(90deg); display:inline-block; }

.nav-tree .nav-sub-link {
    margin-left: auto;
    color: var(--sidebar-muted);
    text-decoration: none;
    font-size: 0.85rem;
    padding: 0 .35rem;
    border-radius: 4px;
}
.nav-tree .nav-sub-link:hover { color: #fff; background: rgba(255,255,255,.05); }

.nav-tree .nav-sub {
    margin-left: 1rem;
    padding-left: .5rem;
    border-left: 1px solid rgba(255,255,255,.08);
    display: flex; flex-direction: column; gap: 1px;
    margin-top: 2px; margin-bottom: 4px;
}

.nav-tree .nav-empty { padding: .3rem .5rem; }

.nav-tree .nav-subitem {
    display: flex; align-items: center; gap: .4rem;
    padding: .35rem .5rem;
    border-radius: 6px;
    color: var(--sidebar-text);
    font-size: 0.88rem;
}
.nav-tree .nav-subitem::before {
    content: "▸";
    font-size: 0.65rem;
    color: var(--sidebar-muted);
    transition: transform .12s;
    display: inline-block;
}
.nav-tree details.nav-site[open] > summary.nav-subitem::before { transform: rotate(90deg); }
.nav-tree .nav-subitem:hover { background: rgba(255,255,255,.04); }

.nav-tree .nav-sitelink {
    color: inherit; text-decoration: none; flex: 1;
}
.nav-tree .nav-sitelink.active { color: #fff; font-weight: 600; }

.nav-tree .nav-agents {
    list-style: none; padding: 0; margin: 2px 0 4px;
    display: flex; flex-direction: column; gap: 1px;
}
.nav-tree .nav-agents li { margin: 0; }
.nav-tree .nav-agent {
    display: block;
    padding: .25rem .5rem .25rem 1.75rem;
    color: var(--sidebar-muted);
    text-decoration: none;
    font-size: 0.82rem;
    border-radius: 5px;
}
.nav-tree .nav-agent:hover { background: rgba(255,255,255,.04); color: #fff; }
.nav-tree .nav-agent.active { background: var(--accent-soft); color: #fff; }

.deploy-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
    margin-top: 0.75rem;
}
.deploy-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
    background: var(--surface);
}
.deploy-card-head { display: flex; flex-direction: column; gap: 0.2rem; margin-bottom: 0.5rem; }
.deploy-card-head h3 { margin: 0; font-size: 1rem; }
.deploy-card-head h3 a { color: var(--text); text-decoration: none; }
.deploy-card-head h3 a:hover { text-decoration: underline; }
.deploy-card-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.5rem; }

.traffic-table tr[data-kind="completed"] { background: rgba(22, 163, 74, 0.04); }
.traffic-table tr[data-kind="delivered"] { background: rgba(245, 158, 11, 0.06); }
.traffic-table tr[data-kind="queued"]    { background: rgba(148, 163, 184, 0.05); }
.traffic-table tr[data-kind="heartbeat"] { background: transparent; }
.text-err { color: var(--err); }

.sidebar-footer { padding-top: 0.75rem; border-top: 1px solid rgba(255, 255, 255, .06); }

.user-chip {
    display: flex; align-items: center; gap: 0.65rem;
    padding: 0.5rem 0.6rem;
    border-radius: 8px;
}

.avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: grid; place-items: center;
    font-weight: 600;
    font-size: 0.85rem;
}

.user-meta { display: flex; flex-direction: column; line-height: 1.15; }
.user-meta strong { font-size: 0.85rem; color: #fff; }
.user-meta a { font-size: 0.75rem; color: var(--sidebar-muted); text-decoration: none; }
.user-meta a:hover { color: #fff; text-decoration: underline; }

.main { display: flex; flex-direction: column; min-width: 0; }

.topbar {
    height: 56px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky; top: 0; z-index: 5;
}

.topbar-title { font-weight: 600; font-size: 0.95rem; color: var(--text); }
.topbar-actions { display: flex; align-items: center; gap: 1rem; }

.content { padding: 1.5rem; flex: 1; min-width: 0; }

#blazor-error-ui { display: none; }

@media (max-width: 900px) {
    .app-shell { grid-template-columns: 1fr; }
    .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; }
    .nav { flex-direction: row; flex-wrap: wrap; }
    .sidebar-footer { width: 100%; }
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI Variable", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

h1 { font-size: 1.6rem; font-weight: 650; letter-spacing: -0.01em; margin: 0 0 1rem; }
h2 { font-size: 1.15rem; font-weight: 600; margin: 0 0 0.75rem; }
h3 { font-size: 0.95rem; font-weight: 600; margin: 0 0 0.5rem; color: var(--text); }
h1:focus, h2:focus { outline: none; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

p { margin: 0 0 0.75rem; }
.muted { color: var(--muted); }
.small { font-size: 0.82rem; }
.text-warn { color: var(--warn, #c77700); }
.mono { font-family: "Cascadia Mono", "JetBrains Mono", Consolas, ui-monospace, monospace; font-size: 0.85em; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    border: 1px solid var(--border-strong);
    background: var(--btn-bg);
    color: var(--text);
    padding: 0.45rem 0.85rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font: inherit;
    font-weight: 500;
    transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--btn-hover-bg); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--primary-hover-bg); border-color: var(--primary-hover-bg); }
.btn-block { display: flex; width: 100%; justify-content: center; padding: 0.6rem 0.85rem; }

button { font: inherit; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 0.9rem; }
.field label { font-weight: 500; font-size: 0.85rem; color: var(--text); }

input[type=text], input[type=password], input[type=email], input[type=number], textarea, select {
    width: 100%;
    background: var(--input-bg);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.7rem;
    font: inherit;
    color: var(--text);
    transition: border-color .12s, box-shadow .12s;
}

input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

textarea { min-height: 5.5rem; resize: vertical; }

/* ---------- Cards / panels ---------- */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem 1.2rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow);
}

.panel h2 { display: flex; align-items: center; justify-content: space-between; }

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow);
    position: relative;
    overflow: hidden;
}
.kpi::before {
    content: "";
    position: absolute;
    inset: 0;
    border-left: 3px solid var(--accent);
    pointer-events: none;
    border-radius: var(--radius);
}
.kpi.kpi-ok::before { border-left-color: var(--ok); }
.kpi.kpi-warn::before { border-left-color: var(--warn); }
.kpi.kpi-err::before { border-left-color: var(--err); }
.kpi.kpi-info::before { border-left-color: var(--info); }

.kpi-label { font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.kpi-value { font-size: 2rem; font-weight: 650; margin-top: 0.25rem; line-height: 1.1; letter-spacing: -0.02em; }
.kpi-sub { font-size: 0.78rem; color: var(--muted); margin-top: 0.35rem; }

.split-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1.25rem; }
@media (max-width: 1100px) { .split-2 { grid-template-columns: 1fr; } }

/* ---------- Tables ---------- */
.table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: var(--surface);
}
.table th, .table td {
    padding: 0.65rem 0.85rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}
.table th {
    font-weight: 600;
    color: var(--muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--surface-2);
}
.table tbody tr:hover { background: var(--row-hover-bg); }
.table tbody tr:last-child td { border-bottom: none; }

.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    box-shadow: var(--shadow);
}
.table-wrap > .table-header {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; justify-content: space-between;
    background: var(--surface);
}
.table-wrap > .table-header h2 { margin: 0; }

/* ---------- Status pills ---------- */
.pill {
    display: inline-flex; align-items: center; gap: 0.35rem;
    padding: 0.18rem 0.55rem;
    border-radius: 999px;
    font-size: 0.74rem;
    font-weight: 600;
    line-height: 1.4;
    background: var(--pill-default-bg);
    color: var(--pill-default-fg);
}
.pill::before {
    content: "";
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
}
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-err { background: var(--err-soft); color: var(--err); }
.pill-info { background: var(--info-soft); color: var(--info); }
.pill-muted { background: var(--pill-muted-bg); color: var(--pill-muted-fg); }

/* ---------- Alerts ---------- */
.alert {
    padding: 0.7rem 0.9rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    margin: 0 0 1rem;
    font-size: 0.9rem;
}
.alert-error { background: var(--err-soft); color: var(--err); border-color: var(--finding-err-border); }
.alert-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--finding-ok-border); }
.alert-info { background: var(--info-soft); color: var(--info); border-color: var(--finding-info-border); }

/* ---------- Empty state ---------- */
.empty {
    text-align: center;
    padding: 2.5rem 1rem;
    color: var(--muted);
}
.empty strong { display: block; color: var(--text); font-size: 1rem; margin-bottom: 0.25rem; }

/* ---------- Definition list ---------- */
.kv {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.45rem 1.25rem;
    margin: 0;
}
.kv dt { color: var(--muted); font-size: 0.82rem; font-weight: 500; }
.kv dd { margin: 0; color: var(--text); font-size: 0.92rem; word-break: break-word; }

/* ---------- Code block ---------- */
.codeblock {
    background: var(--code-bg);
    color: var(--code-fg);
    font-family: "Cascadia Mono", "JetBrains Mono", Consolas, ui-monospace, monospace;
    font-size: 0.82rem;
    padding: 0.75rem 0.9rem;
    border-radius: 8px;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0 0 0.5rem;
    overflow-x: auto;
}

/* ---------- Deploy page ---------- */
.install-row {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem 0.9rem;
    margin-bottom: 0.75rem;
    background: var(--surface);
}
.install-row-head {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.5rem;
}
.install-row-head .muted { font-size: 0.85rem; }
.btn.small-btn {
    margin-left: auto;
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
    border-radius: 6px;
}

/* ---------- Login page ---------- */
.login-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    background: var(--login-bg);
    padding: 1.25rem;
}
.login-card {
    background: var(--login-card-bg);
    color: var(--text);
    width: 100%;
    max-width: 380px;
    padding: 2rem 2rem 1.75rem;
    border-radius: 14px;
    box-shadow: 0 30px 60px -15px rgba(0, 0, 0, .5);
}
.login-card h1 { margin-top: 1rem; margin-bottom: 1.25rem; font-size: 1.35rem; }
.login-card .brand-mark { width: 40px; height: 40px; border-radius: 10px; }

/* ---------- Validation styling defaults ---------- */
.valid.modified:not([type=checkbox]) { outline: 1px solid #26b050; }
.invalid { outline: 1px solid var(--err); }
.validation-message { color: var(--err); font-size: 0.82rem; }

.blazor-error-boundary {
    background: #b91c1c;
    color: #fff;
    padding: 1rem;
    border-radius: var(--radius-sm);
}
.blazor-error-boundary::after { content: "An error has occurred."; }

/* ---------- Defender panels (M3) ---------- */
.defender-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
    margin-bottom: 1rem;
}
.defender-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.1rem;
    box-shadow: var(--shadow);
}
.defender-panel h3 {
    margin: 0 0 0.6rem;
    font-size: 0.92rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}
.defender-panel .kv { gap: 0.35rem 1rem; }
.defender-panel .kv dt { font-size: 0.8rem; }
.defender-panel .kv dd { font-size: 0.88rem; }

.exclusion-list {
    margin: 0;
    padding-left: 0;
    list-style: none;
    max-height: 220px;
    overflow-y: auto;
    font-family: "Cascadia Mono", Consolas, ui-monospace, monospace;
    font-size: 0.78rem;
}
.exclusion-list li {
    padding: 0.18rem 0;
    border-bottom: 1px dashed var(--border);
    word-break: break-all;
}
.exclusion-list li:last-child { border-bottom: none; }
.exclusion-empty { color: var(--muted); font-style: italic; font-size: 0.82rem; }

.findings { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.5rem 0 1rem; }
.finding {
    display: inline-flex; align-items: center; gap: 0.4rem;
    padding: 0.3rem 0.6rem;
    border-radius: 8px;
    font-size: 0.82rem;
    border: 1px solid transparent;
}
.finding.finding-ok { background: var(--ok-soft); color: var(--ok); border-color: var(--finding-ok-border); }
.finding.finding-info { background: var(--info-soft); color: var(--info); border-color: var(--finding-info-border); }
.finding.finding-warn { background: var(--warn-soft); color: var(--warn); border-color: var(--finding-warn-border); }
.finding.finding-err { background: var(--err-soft); color: var(--err); border-color: var(--finding-err-border); }
.finding strong { font-weight: 600; }
.finding small { opacity: 0.85; }

.badge-row { display: inline-flex; gap: 0.25rem; flex-wrap: wrap; }
.badge {
    display: inline-flex; align-items: center;
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    line-height: 1.4;
    background: var(--badge-bg); color: var(--badge-fg);
}
.badge.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge.badge-err { background: var(--err-soft); color: var(--err); }
.badge.badge-muted { background: var(--badge-bg); color: var(--badge-muted-fg); }

/* ---------- Defender editor (M4) ---------- */
.editor-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.9rem 1.5rem;
}
.editor-grid .field { margin: 0; }
.editor-grid select, .editor-grid input[type="number"], .editor-grid input[type="text"] {
    width: 100%;
}
.editor-actions {
    margin-top: 1rem;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.policy-source {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    margin-left: 0.5rem;
}
.policy-source.from-policy { color: var(--accent); }
.policy-source.from-override { color: var(--accent-2); }

/* ---------- Tab nav (M4) ---------- */
.tab-nav {
    display: flex;
    gap: 0.25rem;
    border-bottom: 1px solid var(--border);
    margin: 1rem 0 0;
}
.tab-nav a {
    padding: 0.55rem 0.95rem;
    text-decoration: none;
    color: var(--muted);
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
}
.tab-nav a.active {
    color: var(--text);
    border-bottom-color: var(--accent);
}
.tab-nav a:hover { color: var(--text); }

/* ---------- Machine switcher (AgentDetail) ---------- */
.machine-switcher {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.55rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin: 0 0 0.75rem;
}
.machine-switcher .machine-select {
    padding: 0.25rem 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-weight: 500;
    min-width: 12rem;
}
.machine-switcher .btn-sm {
    padding: 0.15rem 0.5rem;
    line-height: 1;
    font-size: 0.85rem;
}

/* ---------- Drift list (M6) ---------- */
.drift-list {
    margin: 0.5rem 0;
    padding: 0;
    list-style: none;
    font-size: 0.85rem;
}
.drift-list li {
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    background: var(--warn-soft);
    color: var(--warn);
    margin-bottom: 0.3rem;
}
.drift-list li .mono { font-weight: 600; margin-right: 0.4rem; }

/* ---------- Site recycle bin + delete flow ---------- */
.panel-cta {
    max-width: 560px;
    margin: 1rem auto 2rem;
    padding: 1.6rem 1.75rem;
}
.panel-cta h2 { margin-top: 0; }
.panel-cta .actions { display: flex; gap: 0.6rem; margin-top: 1rem; }

.panel-danger {
    border: 1px solid var(--danger-panel-border);
    background: var(--danger-panel-bg);
}
.panel-danger h2 { color: var(--err); }
.panel-danger .actions { display: flex; gap: 0.6rem; margin-top: 0.5rem; }

.btn-danger {
    background: var(--err);
    border-color: var(--err);
    color: #fff;
}
.btn-danger:hover { background: var(--danger-btn-hover-bg); border-color: var(--danger-btn-hover-bg); }

.btn-ghost {
    background: transparent;
    border-color: var(--border-strong);
    color: var(--muted);
}
.btn-ghost:hover { background: var(--btn-ghost-hover-bg); color: var(--text); }

.alert-warn {
    background: var(--warn-soft);
    color: var(--warn);
    border-color: var(--alert-warn-border);
}

.text-right { text-align: right; }

.inline-form { display: inline; }
.inline-form button { margin-right: 0.35rem; }

.actions { display: flex; gap: 0.6rem; }

/* Sidebar — empty-state action + recycle bin link */
.nav-empty-action {
    display: flex;
    align-items: center;
    padding: 0.35rem 0.65rem;
    margin: 0.15rem 0.5rem;
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--accent);
    text-decoration: none;
    border: 1px dashed rgba(79, 70, 229, 0.35);
    background: var(--accent-soft);
}
.nav-empty-action:hover {
    background: rgba(79, 70, 229, 0.12);
    color: var(--accent);
}

.nav-recycle {
    margin-top: 0.3rem;
    padding-top: 0.4rem;
    border-top: 1px dashed var(--border);
    gap: 0.5rem;
    color: var(--muted);
}
.nav-recycle .nav-icon { width: 16px; height: 16px; display: inline-flex; }
.nav-recycle .nav-icon svg { width: 14px; height: 14px; }

/* ---------- Reconnect modal (Blazor Server circuit) ---------- */
/*
  Blazor toggles one of three classes on #components-reconnect-modal:
    components-reconnect-show     - trying to reconnect
    components-reconnect-failed   - couldn't reconnect, offer retry
    components-reconnect-rejected - server restarted, session lost
  When none of those classes is present the modal is hidden.
*/
#components-reconnect-modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 10000;
    align-items: center;
    justify-content: center;
    background: var(--overlay-bg);
    backdrop-filter: blur(2px);
    animation: reconnect-fade 0.18s ease-out;
}
#components-reconnect-modal.components-reconnect-show,
#components-reconnect-modal.components-reconnect-failed,
#components-reconnect-modal.components-reconnect-rejected {
    display: flex;
}

.reconnect-card {
    background: var(--surface);
    color: var(--text);
    padding: 1.5rem 2rem;
    border-radius: var(--radius);
    border: 1px solid var(--border-strong);
    box-shadow: 0 12px 40px rgba(15, 23, 42, .35);
    text-align: center;
    max-width: 420px;
    min-width: 280px;
}
.reconnect-title {
    font-weight: 600;
    font-size: 1.05rem;
    margin-top: 0.5rem;
}
.reconnect-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    margin: 0 auto 0.5rem;
    animation: reconnect-spin 0.9s linear infinite;
}
.reconnect-actions {
    margin-top: 0.9rem;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}
.reconnect-actions button {
    padding: 0.45rem 0.95rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--accent);
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-size: 0.9rem;
}
.reconnect-actions button.secondary {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border-strong);
}

/* Per-state sections. Hide everything, then reveal exactly one group. */
#components-reconnect-modal .reconnect-show-only,
#components-reconnect-modal .reconnect-failed-only,
#components-reconnect-modal .reconnect-rejected-only { display: none; }

#components-reconnect-modal.components-reconnect-show .reconnect-show-only { display: block; }
#components-reconnect-modal.components-reconnect-failed .reconnect-failed-only { display: block; }
#components-reconnect-modal.components-reconnect-rejected .reconnect-rejected-only { display: block; }

/* When the modal is in failed / rejected state we stop the spinner. */
#components-reconnect-modal.components-reconnect-failed .reconnect-spinner,
#components-reconnect-modal.components-reconnect-rejected .reconnect-spinner {
    animation: none;
    border-top-color: var(--warn);
}
#components-reconnect-modal.components-reconnect-rejected .reconnect-spinner {
    border-top-color: var(--err);
}

@keyframes reconnect-fade { from { opacity: 0 } to { opacity: 1 } }
@keyframes reconnect-spin { to { transform: rotate(360deg) } }

/* ---------- Toast (interactive save feedback) ---------- */
.toast-stack {
    position: fixed;
    right: 1.25rem;
    bottom: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 9000;
    pointer-events: none;
}
.toast {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-left: 4px solid var(--accent);
    padding: 0.6rem 0.9rem;
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    font-size: 0.9rem;
    min-width: 240px;
    max-width: 360px;
    pointer-events: auto;
    animation: toast-in 0.18s ease-out;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--err); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toast-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- Confirm modal (in-page, replaces type-the-name POSTs) ---------- */
.confirm-modal-backdrop {
    position: fixed;
    inset: 0;
    background: var(--overlay-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9500;
    animation: reconnect-fade 0.15s ease-out;
}
.confirm-modal {
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: 0 12px 40px rgba(15, 23, 42, .35);
    padding: 1.25rem 1.5rem;
    max-width: 520px;
    width: calc(100% - 2rem);
}
.confirm-modal h3 { margin-top: 0; }
.confirm-modal .confirm-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1rem;
}
.confirm-modal input[type="text"] {
    width: 100%;
    padding: 0.5rem 0.65rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    font: inherit;
}

/* ---------- Live row-change highlight ---------- */
.row-flash {
    animation: row-flash 1.4s ease-out;
}
@keyframes row-flash {
    0%   { background: var(--accent-soft); }
    100% { background: transparent; }
}


/* ---------- Revision history ---------- */
.revision-highlights {
    margin: 0;
    padding-left: 1.1rem;
    color: var(--text);
}
.revision-highlights li {
    margin: 0.15rem 0;
    line-height: 1.35;
}
/* When the page scrolls to #v<version> pulse the row so the user can find it. */
tr[id^="v"]:target {
    animation: revision-target 2.2s ease-out;
}
@keyframes revision-target {
    0%   { background: var(--accent-soft); }
    100% { background: transparent; }
}

/* ---------- Site detail: two-column layout (main + right action aside) ---------- */
.site-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 300px;
    gap: 1.25rem;
    align-items: start;
    margin-top: .75rem;
}
@media (max-width: 1100px) {
    .site-layout { grid-template-columns: 1fr; }
}

.site-aside {
    position: sticky;
    top: .5rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
}
@media (max-width: 1100px) {
    .site-aside { position: static; }
}

.action-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: .9rem 1rem;
    box-shadow: var(--shadow);
}
.action-card h3 {
    margin: 0 0 .6rem;
    font-size: .82rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
}
.action-card .action-list {
    display: flex;
    flex-direction: column;
    gap: .4rem;
}
.action-card .action-list .btn {
    justify-content: flex-start;
    width: 100%;
}
.action-card .kv-small {
    margin: 0;
    font-size: .85rem;
}
.action-card .kv-small dt {
    color: var(--muted);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-top: .4rem;
}
.action-card .kv-small dt:first-child { margin-top: 0; }
.action-card .kv-small dd {
    margin: .1rem 0 0;
    word-break: break-all;
}

/* Compact vertical KPIs for the aside */
.kpi-stack {
    display: flex;
    flex-direction: column;
    gap: .5rem;
}
.kpi-stack .kpi {
    padding: .6rem .75rem;
}
.kpi-stack .kpi-value { font-size: 1.35rem; }
.kpi-stack .kpi-label { font-size: .72rem; }
.kpi-stack .kpi-sub { font-size: .72rem; }

/* ---------- Check-list (inline checkbox list for rule/schedule forms) ---------- */
.check-list {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem .75rem;
    padding: .5rem .6rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 6px;
}
.check-item {
    display: inline-flex;
    align-items: center;
    gap: .35rem;
    font-size: .9rem;
    cursor: pointer;
}

/* ---------- Policy editor: section heading with trailing action ---------- */
.section-heading {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1.5rem;
}
.section-heading h2 { margin: 0; }

/* Small decorative chip used in help text to point at the "?" icons below. */
.info-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.1rem;
    height: 1.1rem;
    margin: 0 0.15rem;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: 50%;
    vertical-align: baseline;
}

/* ---------- Info bubbles (policy help popovers) ---------- */
.info-bubble {
    display: inline-block;
    position: relative;
    margin-left: 0.35rem;
    vertical-align: middle;
}
/* The little "?" pill */
.info-bubble-summary {
    list-style: none;
    cursor: help;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.1rem;
    height: 1.1rem;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1;
    color: var(--accent);
    background: var(--accent-soft);
    border-radius: 50%;
    user-select: none;
    transition: background 0.12s ease;
}
.info-bubble-summary:hover { background: rgba(79, 70, 229, 0.3); }
.info-bubble-summary::-webkit-details-marker { display: none; } /* Chrome/Safari */
.info-bubble-summary::marker { content: ''; }                   /* Firefox */
.info-bubble[open] .info-bubble-summary {
    background: var(--accent);
    color: white;
}

.info-bubble-pop {
    position: absolute;
    top: calc(100% + 0.4rem);
    /* Anchor the popover's RIGHT edge near the "?" so it always grows
       leftward. That way it can't overflow the right edge of the viewport
       even when the field/column itself is right-aligned or narrow. */
    right: -0.4rem;
    left: auto;
    z-index: 60;
    width: 22rem;
    max-width: min(22rem, calc(100vw - 2rem));
    padding: 0.75rem 0.9rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.12);
    font-size: 0.85rem;
    line-height: 1.45;
    font-weight: 400;
}
.info-bubble-title {
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.25rem;
}
.info-bubble-body { color: var(--muted); }
.info-bubble-body p { margin: 0.35rem 0; }
.info-bubble-body code {
    font-size: 0.8em;
    padding: 0.05rem 0.3rem;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 4px;
}
.info-bubble-learn {
    display: inline-block;
    margin-top: 0.45rem;
    font-size: 0.8rem;
    color: var(--accent);
    text-decoration: none;
}
.info-bubble-learn:hover { text-decoration: underline; }

/* A small caret nub pointing up to the "?" (sits near the right side
   of the popover since the popover is right-anchored). */
.info-bubble-pop::before {
    content: '';
    position: absolute;
    top: -6px;
    right: 0.5rem;
    left: auto;
    width: 10px;
    height: 10px;
    background: var(--surface);
    border-left: 1px solid var(--border-strong);
    border-top: 1px solid var(--border-strong);
    transform: rotate(45deg);
}

.threats-top {
    margin-top: 1rem;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 8px;
    padding: .25rem .75rem .75rem;
}

.threats-top .table-header {
    padding-top: .5rem;
}

.threats-top .table-header h2 {
    margin: 0;
    font-size: 1rem;
}

/* ---------- Theme toggle (topbar) ---------- */
.theme-toggle {
    appearance: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: 999px;
    border: 1px solid var(--border-strong);
    background: var(--btn-bg);
    color: var(--text);
    cursor: pointer;
    transition: background .12s, border-color .12s, color .12s;
    padding: 0;
}
.theme-toggle:hover { background: var(--btn-hover-bg); border-color: var(--accent); color: var(--accent); }
.theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.theme-toggle svg { width: 16px; height: 16px; }
.theme-toggle .theme-icon-sun { display: none; }
.theme-toggle .theme-icon-moon { display: inline-flex; }
[data-theme="light"] .theme-toggle .theme-icon-sun { display: inline-flex; }
[data-theme="light"] .theme-toggle .theme-icon-moon { display: none; }

