:root {
    color-scheme: dark;
    --bg: #0b0f17;
    --surface: #121925;
    --surface-2: #182233;
    --surface-3: #202c40;
    --border: #2b3a50;
    --text: #edf3fb;
    --muted: #9cabc0;
    --accent: #61a9ff;
    --accent-strong: #3187f3;
    --success: #50d890;
    --warning: #ffbd59;
    --danger: #ff737b;
    --shadow: 0 18px 50px rgb(0 0 0 / 28%);
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 16px;
}

* { box-sizing: border-box; }

body {
    min-width: 320px;
    min-height: 100vh;
    margin: 0;
    color: var(--text);
    background:
        radial-gradient(circle at 90% -10%, rgb(49 135 243 / 14%), transparent 35rem),
        var(--bg);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: #91c4ff; }
button, input, select { font: inherit; }

.skip-link {
    position: fixed;
    z-index: 100;
    top: .5rem;
    left: .5rem;
    padding: .65rem 1rem;
    color: #07111f;
    background: var(--accent);
    border-radius: .5rem;
    transform: translateY(-150%);
}
.skip-link:focus { transform: none; }

.topbar {
    position: sticky;
    z-index: 20;
    top: 0;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 1.5rem;
    min-height: 4.5rem;
    padding: .75rem clamp(1rem, 3vw, 2.5rem);
    background: rgb(11 15 23 / 92%);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(16px);
}

.brand { display: inline-flex; align-items: center; gap: .7rem; color: var(--text); font-weight: 700; }
.brand:hover { color: var(--text); }
.brand-mark, .auth-logo {
    display: inline-grid;
    place-items: center;
    color: #07111f;
    background: linear-gradient(145deg, #78bbff, #4b8fff);
    box-shadow: 0 8px 25px rgb(49 135 243 / 24%);
    font-weight: 900;
    letter-spacing: -.08em;
}
.brand-mark { width: 2.35rem; height: 2.35rem; border-radius: .7rem; font-size: .76rem; }
.auth-logo { width: 4.2rem; height: 4.2rem; margin-bottom: 1rem; border-radius: 1.2rem; font-size: 1.25rem; }

.primary-nav { display: flex; align-items: center; gap: .25rem; overflow-x: auto; scrollbar-width: thin; }
.primary-nav a { padding: .65rem .78rem; color: var(--muted); border-radius: .55rem; white-space: nowrap; }
.primary-nav a:hover { color: var(--text); background: var(--surface-2); }

.user-menu { display: flex; align-items: center; gap: .65rem; }
.user-menu form { margin: 0; }
.user-name { max-width: 12rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role-badge, .count-badge {
    display: inline-flex;
    align-items: center;
    min-height: 1.8rem;
    padding: .25rem .6rem;
    color: #bcd9ff;
    background: rgb(97 169 255 / 13%);
    border: 1px solid rgb(97 169 255 / 25%);
    border-radius: 999px;
    font-size: .78rem;
}
.count-badge { justify-content: center; min-width: 2.5rem; min-height: 2.5rem; font-size: 1rem; }

.page-shell { width: min(1480px, 100%); margin: 0 auto; padding: 2rem clamp(1rem, 3vw, 2.5rem) 4rem; }
.page-shell-auth { display: grid; place-items: center; min-height: 100vh; }
.page-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 2rem; margin: 0 0 1.6rem; }
h1, h2 { margin: 0; line-height: 1.18; }
h1 { font-size: clamp(1.75rem, 3vw, 2.6rem); letter-spacing: -.035em; }
h2 { font-size: 1.13rem; }
.eyebrow { margin: 0 0 .45rem; color: var(--accent); font-size: .74rem; font-weight: 750; letter-spacing: .13em; text-transform: uppercase; }
.muted { color: var(--muted); }
.page-heading .muted { max-width: 55rem; margin: .6rem 0 0; }
.updated-at { color: var(--muted); font-size: .85rem; white-space: nowrap; }

.auth-card {
    width: min(31rem, 100%);
    padding: clamp(1.5rem, 4vw, 2.5rem);
    background: linear-gradient(160deg, rgb(24 34 51 / 96%), rgb(18 25 37 / 96%));
    border: 1px solid var(--border);
    border-radius: 1.15rem;
    box-shadow: var(--shadow);
}
.auth-card h1 { margin-bottom: .65rem; }
.auth-card > .muted { margin: 0 0 1.4rem; }
.security-note { margin: 1.25rem 0 0; color: var(--muted); font-size: .82rem; line-height: 1.45; }

.form-stack { display: grid; gap: .55rem; }
.form-stack label, .form-grid label, .compact-form label { color: #cad7e8; font-size: .87rem; font-weight: 600; }
input, select {
    width: 100%;
    min-height: 2.75rem;
    padding: .65rem .78rem;
    color: var(--text);
    background: #0d1420;
    border: 1px solid #34465f;
    border-radius: .58rem;
    outline: 0;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgb(97 169 255 / 16%); }
.field-hint { margin-top: -.2rem; color: var(--muted); font-size: .76rem; }
.validation { color: var(--danger); font-size: .8rem; }
.validation:empty { display: none; }

.button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.75rem;
    padding: .58rem .9rem;
    color: var(--text);
    background: var(--surface-3);
    border: 1px solid #3b4d66;
    border-radius: .58rem;
    cursor: pointer;
}
.button:hover { color: #fff; background: #2a3850; }
.button-primary { color: #07111f; background: var(--accent); border-color: var(--accent); font-weight: 750; }
.button-primary:hover { color: #07111f; background: #87c3ff; }
.button-danger { color: #ffd9dc; background: rgb(255 115 123 / 13%); border-color: rgb(255 115 123 / 40%); }
.button-quiet { color: var(--muted); background: transparent; border-color: transparent; }
.button-wide { width: 100%; margin-top: .7rem; }

.notice { margin: 0 0 1.3rem; padding: .9rem 1rem; border: 1px solid var(--border); border-radius: .7rem; line-height: 1.45; }
.notice-error { color: #ffd9dc; background: rgb(255 115 123 / 10%); border-color: rgb(255 115 123 / 35%); }
.notice-success { color: #caffdf; background: rgb(80 216 144 / 10%); border-color: rgb(80 216 144 / 30%); }
.notice-info { color: #c9dffb; background: rgb(97 169 255 / 8%); border-color: rgb(97 169 255 / 24%); }
.notice-warning { color: #ffe4b3; background: rgb(255 189 89 / 9%); border-color: rgb(255 189 89 / 32%); }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.metric-card {
    position: relative;
    display: grid;
    grid-template-columns: 2.8rem 1fr;
    gap: .15rem 1rem;
    min-height: 8.2rem;
    padding: 1.25rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: .9rem;
}
.metric-card:hover { color: var(--text); background: var(--surface-2); border-color: #405777; transform: translateY(-1px); }
.metric-icon { grid-row: span 2; align-self: center; display: block; width: 2.8rem; height: 2.8rem; border: 1px solid rgb(97 169 255 / 28%); border-radius: .75rem; background-color: rgb(97 169 255 / 10%); background-position: center; background-repeat: no-repeat; background-size: 1.45rem; }
.metric-value { align-self: end; font-size: 2rem; font-weight: 760; line-height: 1; }
.metric-label { align-self: start; color: var(--muted); font-size: .85rem; }
.metric-warn { border-color: rgb(255 189 89 / 35%); }
.icon-device { background-image: linear-gradient(#70b5ff,#70b5ff), linear-gradient(#70b5ff,#70b5ff); background-size: .95rem 1.45rem, .3rem .12rem; }
.icon-computer { background-image: linear-gradient(#70b5ff,#70b5ff), linear-gradient(#70b5ff,#70b5ff); background-size: 1.45rem 1rem, .8rem .18rem; background-position: center 42%, center 75%; }
.icon-link { background-image: radial-gradient(circle, transparent 34%, #70b5ff 36% 48%, transparent 50%); }
.icon-job { background-image: conic-gradient(from 30deg, #70b5ff 0 72%, transparent 72%); border-radius: 50%; }

.panel-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.panel { margin: 0 0 1rem; padding: 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: .9rem; }
.panel-narrow { max-width: 58rem; }
.panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; }
.summary-list { margin: 0; }
.summary-list div { display: flex; justify-content: space-between; gap: 1rem; padding: .72rem 0; border-top: 1px solid var(--border); }
.summary-list dt { color: var(--muted); }
.summary-list dd { margin: 0; font-weight: 750; }

.table-wrap { overflow: auto; margin-bottom: 1.25rem; background: var(--surface); border: 1px solid var(--border); border-radius: .9rem; }
.table-wrap-flat { margin: 0 -1.25rem -1.25rem; border-right: 0; border-bottom: 0; border-left: 0; border-radius: 0 0 .9rem .9rem; }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th { padding: .8rem 1rem; color: #aebdd1; background: #0f1622; border-bottom: 1px solid var(--border); font-size: .75rem; text-align: left; text-transform: uppercase; letter-spacing: .045em; white-space: nowrap; }
td { padding: .9rem 1rem; border-bottom: 1px solid rgb(43 58 80 / 72%); vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: rgb(255 255 255 / 1.8%); }
td strong, td small { display: block; }
td small { max-width: 20rem; margin-top: .25rem; color: var(--muted); font-size: .72rem; overflow: hidden; text-overflow: ellipsis; }
.empty-state { padding: 3rem 1rem; color: var(--muted); text-align: center; }
.link-arrow { color: var(--accent); font-size: 1.2rem; text-align: center; }
.endpoint-line { display: block; margin-bottom: .45rem; }
.endpoint-line:last-child { margin-bottom: 0; }

.state { display: inline-flex; align-items: center; gap: .35rem; padding: .27rem .55rem; color: #c9d4e2; background: var(--surface-3); border-radius: 999px; font-size: .72rem; white-space: nowrap; }
.state::before { width: .42rem; height: .42rem; background: currentColor; border-radius: 50%; content: ""; }
.state-active, .state-enrolled, .state-connected, .state-completed, .state-success, .state-ok, .state-applied { color: var(--success); background: rgb(80 216 144 / 10%); }
.state-pending, .state-temporary, .state-awaiting_manager, .state-awaiting_agent, .state-running { color: var(--warning); background: rgb(255 189 89 / 10%); }
.state-revoked, .state-disabled, .state-failed, .state-fail_closed { color: var(--danger); background: rgb(255 115 123 / 10%); }
.state-degraded { color: var(--warning); background: rgb(255 190 92 / 12%); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.error-detail { max-width: 32rem; color: #ffc8cc; white-space: normal; }

.filter-bar { display: grid; grid-template-columns: minmax(15rem, 1fr) minmax(10rem, 14rem) auto auto; gap: .7rem; margin-bottom: 1rem; }
details summary {
    min-width: 2.75rem;
    min-height: 2.75rem;
    padding: .35rem .25rem;
    color: var(--accent);
    cursor: pointer;
}
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
}
pre { max-width: 32rem; margin: .65rem 0 0; padding: .75rem; overflow: auto; color: #c9d6e8; background: #090e16; border-radius: .45rem; font: .73rem/1.45 Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
code { color: #b8d9ff; }
.pagination { display: flex; align-items: center; justify-content: center; gap: 1rem; }

.action-details { min-width: 10rem; }
.audit-storage-heading { align-items: flex-start; flex-wrap: wrap; }
.audit-storage-heading > div:first-child { flex: 1 1 24rem; min-width: 0; }
.audit-clear { min-width: 0; }
.audit-clear > summary { width: max-content; max-width: 100%; list-style: none; white-space: normal; }
.audit-clear > summary::-webkit-details-marker { display: none; }
.compact-form { display: grid; gap: .7rem; width: min(24rem, 78vw); margin-top: .8rem; padding: .9rem; background: #0d1420; border: 1px solid var(--border); border-radius: .7rem; }
.compact-form label { display: grid; gap: .35rem; }
.enrollment-approval { grid-template-columns: minmax(0, 1fr); width: min(32rem, 100%); max-width: 100%; min-width: 0; }
.enrollment-approval > *, .enrollment-approval .checkbox-row > span { min-width: 0; overflow-wrap: anywhere; }
.enrollment-approval .button { width: 100%; max-width: 100%; white-space: normal; overflow-wrap: anywhere; text-align: center; }
.enrollment-approval .checkbox-row { align-items: flex-start; }
.enrollment-approval .checkbox-row input[type="checkbox"] { flex: 0 0 1.1rem; margin-top: .15rem; }
.enrollment-result { overflow-wrap: anywhere; }
.enrollment-result small { display: block; }
.checkbox-row { display: flex !important; align-items: center; gap: .6rem; }
.checkbox-row input[type="checkbox"] { width: 1.1rem; min-height: 1.1rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .9rem 1rem; }
.form-grid label { display: grid; gap: .4rem; }
.form-span { grid-column: 1 / -1; }
.form-actions { display: flex; justify-content: flex-end; }
.status-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1rem; }
.status-grid > div { display: grid; gap: .35rem; }
.status-grid > .form-span { grid-column: 1 / -1; }
.mono { overflow-wrap: anywhere; font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .78rem; }
.traffic-set > .table-wrap { margin-top: .75rem; }
.traffic-set .panel-heading > div { display: flex; align-items: center; flex-wrap: wrap; gap: .65rem; }
.add-rule { margin-top: 1rem; }
.add-rule > summary { width: max-content; list-style: none; }
.add-rule > summary::-webkit-details-marker { display: none; }
.rule-form { margin-top: 1rem; padding: 1rem; background: #0d1420; border: 1px solid var(--border); border-radius: .7rem; }
.compact-form-danger { border-color: rgb(255 115 123 / 35%); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@media (max-width: 1100px) {
    .topbar { grid-template-columns: auto 1fr; }
    .primary-nav { grid-column: 1 / -1; grid-row: 2; }
    .user-menu { justify-self: end; }
    .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 680px) {
    .topbar { gap: .7rem; }
    .brand > span:last-child, .role-badge { display: none; }
    .user-name { max-width: 8rem; }
    .page-shell { padding-top: 1.25rem; }
    .page-heading { align-items: center; gap: .75rem; }
    .page-heading > div { min-width: 0; }
    .page-heading h1 { overflow-wrap: anywhere; }
    .count-badge { flex: 0 0 auto; }
    .updated-at { display: none; }
    .metric-grid, .panel-grid, .form-grid { grid-template-columns: 1fr; }
    .status-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-span { grid-column: auto; }
    .filter-bar { grid-template-columns: 1fr 1fr; }
    .filter-bar input { grid-column: 1 / -1; }
    .audit-storage-heading { display: grid; grid-template-columns: 1fr; }
    .audit-clear, .audit-clear > summary { width: 100%; }
}

@media (prefers-reduced-motion: no-preference) {
    a, button, input, select, .metric-card { transition: color .15s, background-color .15s, border-color .15s, box-shadow .15s, transform .15s; }
}
