:root {
    color-scheme: dark;
    --bg: #060a10;
    --panel: rgba(16, 25, 38, .94);
    --panel-solid: #0e1723;
    --panel-2: #142130;
    --panel-3: #1a2a3c;
    --line: rgba(154, 179, 201, .14);
    --line-strong: rgba(154, 179, 201, .28);
    --text: #f5f8fb;
    --muted: #91a4b5;
    --muted-2: #65798b;
    --primary: #48e7a6;
    --primary-2: #1fc889;
    --blue: #66a8ff;
    --amber: #ffc66e;
    --red: #ff6f84;
    --sidebar-width: 288px;
    --radius-lg: 20px;
    --radius-md: 14px;
    --shadow: 0 24px 70px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body {
    min-height: 100vh;
    margin: 0;
    overflow-x: hidden;
    background:
        radial-gradient(circle at 88% -12%, rgba(72, 231, 166, .13), transparent 36rem),
        radial-gradient(circle at 7% 88%, rgba(102, 168, 255, .07), transparent 34rem),
        var(--bg);
    color: var(--text);
    font-family: "Segoe UI Variable", "Segoe UI", Inter, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.7;
}

button, input, select, textarea { font: inherit; }
a { color: inherit; }
form { margin: 0; }
[hidden] { display: none !important; }
.ltr { direction: ltr; text-align: left; }
.mono { font-family: Consolas, "SFMono-Regular", monospace; }
.muted, .cell-sub { color: var(--muted); }
.cell-sub { display: block; margin-top: 3px; font-size: 12px; }
.truncate { display: block; max-width: 310px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.eyebrow { color: var(--primary); font-size: 10px; font-weight: 800; letter-spacing: .17em; }
.full { grid-column: 1 / -1; }

.sidebar {
    position: fixed;
    z-index: 50;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    border-right: 1px solid var(--line);
    background: rgba(7, 12, 19, .97);
    box-shadow: 16px 0 50px rgba(0, 0, 0, .18);
    backdrop-filter: blur(20px);
}

.brand { display: flex; align-items: center; gap: 12px; min-height: 62px; padding: 6px 9px 18px; color: var(--text); text-decoration: none; }
.brand-mark {
    width: 43px;
    height: 43px;
    flex: 0 0 43px;
    display: grid;
    place-items: center;
    border: 1px solid rgba(56, 229, 157, .5);
    border-radius: 14px;
    background: linear-gradient(145deg, var(--primary), var(--primary-2));
    box-shadow: 0 12px 32px rgba(32, 205, 135, .2);
    color: #042116;
    font-size: 22px;
    font-weight: 900;
}
.brand-copy { display: grid; line-height: 1.25; }
.brand-copy strong { font-size: 20px; letter-spacing: .02em; }
.brand-copy small { margin-top: 4px; color: var(--muted); font-size: 9px; letter-spacing: .14em; }

.sidebar-nav { display: grid; gap: 4px; min-height: 0; padding: 4px 2px 18px; overflow: auto; scrollbar-width: thin; scrollbar-color: var(--panel-3) transparent; }
.nav-caption { margin: 16px 12px 5px; color: var(--muted-2); font-size: 10px; font-weight: 800; }
.sidebar-nav a {
    position: relative;
    display: flex;
    align-items: center;
    gap: 11px;
    min-height: 45px;
    padding: 9px 11px;
    border: 1px solid transparent;
    border-radius: 13px;
    color: #b9c5ce;
    text-decoration: none;
    transition: .18s ease;
}
.sidebar-nav a:hover { border-color: var(--line); background: var(--panel-2); color: #fff; transform: translateX(2px); }
.sidebar-nav a.active { border-color: rgba(56, 229, 157, .2); background: linear-gradient(90deg, rgba(56, 229, 157, .16), rgba(56, 229, 157, .05)); color: var(--primary); }
.sidebar-nav a.active::after { position: absolute; inset: 9px auto 9px -3px; width: 3px; border-radius: 4px; background: var(--primary); box-shadow: 0 0 16px rgba(72, 231, 166, .55); content: ""; }
.nav-icon { width: 28px; height: 28px; flex: 0 0 28px; display: grid; place-items: center; border: 1px solid var(--line); border-radius: 9px; background: rgba(255, 255, 255, .025); font-size: 12px; font-weight: 800; }
.status-dot-icon::before { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 5px rgba(56, 229, 157, .1); content: ""; }

.sidebar-user { display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; align-items: center; gap: 10px; padding: 14px 10px 4px; border-top: 1px solid var(--line); }
.user-avatar { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 12px; background: var(--panel-3); color: var(--primary); font-weight: 900; }
.user-copy { display: grid; min-width: 0; line-height: 1.35; }
.user-copy strong, .user-copy small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-copy small { direction: ltr; color: var(--muted); font-size: 10px; text-align: left; }
.user-copy span { color: var(--primary); font-size: 10px; }
.sidebar-actions { display: flex; gap: 4px; }
.sidebar-actions a, .link-button { width: 30px; height: 30px; display: grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 9px; background: transparent; color: var(--muted); cursor: pointer; text-decoration: none; }
.sidebar-actions a:hover, .link-button:hover { border-color: var(--line-strong); color: var(--text); }

.main { min-height: 100vh; margin-left: var(--sidebar-width); }
.auth-main { min-height: 100vh; display: grid; place-items: center; padding: 30px 18px; }
.topbar {
    position: sticky;
    z-index: 30;
    top: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 80px;
    padding: 12px clamp(20px, 3vw, 42px);
    border-bottom: 1px solid var(--line);
    background: rgba(7, 11, 18, .78);
    backdrop-filter: blur(18px);
}
.topbar-title { display: grid; line-height: 1.45; }
.topbar-title strong { font-size: 16px; }
.topbar-state { display: flex; align-items: center; gap: 9px; color: var(--muted); font-size: 12px; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 5px rgba(56, 229, 157, .1); }
.icon-button { width: 42px; height: 42px; display: none; place-items: center; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); color: var(--text); cursor: pointer; }
.content-shell { width: min(1580px, 100%); margin: 0 auto; padding: clamp(22px, 3vw, 42px); animation: content-in .28s ease both; }
@keyframes content-in { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 22px; margin-bottom: 24px; }
.page-head h1 { margin: 4px 0 0; font-size: clamp(23px, 2.1vw, 34px); line-height: 1.3; letter-spacing: -.02em; }
.page-head p { max-width: 760px; margin: 6px 0 0; color: var(--muted); }
.actions { display: flex; flex-wrap: wrap; gap: 9px; align-items: center; }

.btn { min-height: 42px; display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 9px 16px; border: 1px solid transparent; border-radius: 11px; background: linear-gradient(145deg, var(--primary), var(--primary-2)); box-shadow: 0 8px 25px rgba(32, 205, 135, .12); color: #052318; cursor: pointer; font-weight: 750; letter-spacing: .01em; text-decoration: none; transition: .16s ease; }
.btn:hover { transform: translateY(-1px); filter: brightness(1.06); }
.btn:focus-visible, .input:focus-visible, select:focus-visible, textarea:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn.secondary { border-color: var(--line); background: var(--panel-2); box-shadow: none; color: var(--text); }
.btn.warning { border-color: rgba(255, 198, 110, .3); background: rgba(255, 198, 110, .11); box-shadow: none; color: var(--amber); }
.btn.danger { border-color: rgba(255, 111, 132, .3); background: rgba(255, 111, 132, .11); box-shadow: none; color: var(--red); }
.btn.small { min-height: 34px; padding: 5px 11px; border-radius: 9px; font-size: 12px; }
.btn[disabled], .is-loading .btn[type="submit"] { opacity: .55; pointer-events: none; }

.grid { display: grid; gap: 18px; }
.stats { grid-template-columns: repeat(4, minmax(0, 1fr)); margin-bottom: 20px; }
.two-col { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stat, .panel, .auth-card { border: 1px solid var(--line); border-radius: var(--radius-lg); background: linear-gradient(145deg, rgba(19, 30, 45, .93), rgba(11, 19, 29, .96)); box-shadow: var(--shadow); }
.stat { position: relative; min-height: 146px; padding: 22px; overflow: hidden; }
.stats a.stat { color: var(--text); text-decoration: none; transition: transform .16s ease, border-color .16s ease; }
.stats a.stat:hover { transform: translateY(-2px); border-color: var(--line-strong); }
.stat::after { position: absolute; inset: auto auto -35px -25px; width: 105px; height: 105px; border-radius: 50%; background: var(--stat-color, var(--primary)); opacity: .055; content: ""; }
.stat > span { color: var(--muted); font-size: 12px; }
.stat strong { display: block; margin: 7px 0 2px; font-size: 34px; line-height: 1.2; }
.stat small { color: var(--muted); }
.stat.blue { --stat-color: var(--blue); }
.stat.amber { --stat-color: var(--amber); }
.stat.red { --stat-color: var(--red); }
.panel { margin-bottom: 18px; padding: clamp(17px, 2vw, 24px); }
.panel > h2, .section-head h2 { margin: 0; font-size: 17px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 16px; }
.section-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.form-panel { max-width: 1040px; }
.danger-zone { border-color: rgba(255, 111, 132, .3); background: linear-gradient(145deg, rgba(47, 20, 29, .72), rgba(22, 17, 25, .9)); }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel-solid); scrollbar-width: thin; scrollbar-color: var(--panel-3) transparent; }
table { width: 100%; min-width: 820px; border-collapse: separate; border-spacing: 0; }
th, td { padding: 13px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { position: sticky; z-index: 2; top: 0; background: #131d2b; color: #a8b6c2; font-size: 11px; font-weight: 700; white-space: nowrap; }
tbody tr { transition: background .14s ease; }
tbody tr:hover { background: rgba(255, 255, 255, .018); }
tbody tr:last-child td { border-bottom: 0; }
td a:not(.btn) { color: var(--blue); text-decoration: none; }
td a:not(.btn):hover { text-decoration: underline; }

.badge { display: inline-flex; align-items: center; gap: 5px; min-height: 25px; padding: 3px 9px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-3); color: #bdcad4; font-size: 10px; font-weight: 800; white-space: nowrap; }
.badge.green { border-color: rgba(56, 229, 157, .22); background: rgba(56, 229, 157, .1); color: #79efbb; }
.badge.red { border-color: rgba(255, 111, 132, .24); background: rgba(255, 111, 132, .1); color: #ff9eac; }
.badge.amber { border-color: rgba(255, 198, 110, .24); background: rgba(255, 198, 110, .1); color: #ffd391; }
.badge.blue { border-color: rgba(102, 168, 255, .24); background: rgba(102, 168, 255, .1); color: #96c3ff; }

.filters { display: grid; grid-template-columns: minmax(230px, 1fr) repeat(2, minmax(150px, auto)) auto auto; align-items: end; gap: 10px; margin-bottom: 18px; padding: 14px; border: 1px solid var(--line); border-radius: var(--radius-md); background: var(--panel); }
.filter-grow { min-width: 0; }
.field { display: grid; align-content: start; gap: 7px; }
.field label, .label-row label { color: #c4ced6; font-size: 12px; font-weight: 700; }
.label-row { display: flex; justify-content: space-between; gap: 12px; }
.label-row small, .field > small { color: var(--muted); font-size: 11px; }
.input, select, textarea { width: 100%; min-height: 44px; padding: 10px 13px; border: 1px solid var(--line-strong); border-radius: 11px; background: #090f18; color: var(--text); outline: 0; transition: border .15s ease, box-shadow .15s ease; }
.input:hover, select:hover, textarea:hover { border-color: rgba(146, 171, 195, .43); }
.input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(56, 229, 157, .08); }
textarea { min-height: 180px; resize: vertical; }
.code-editor { min-height: 320px; direction: ltr; font-family: Consolas, monospace; font-size: 13px; text-align: left; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 17px; }
.check, .switch-card { display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 10px 13px; border: 1px solid var(--line); border-radius: 12px; background: rgba(7, 12, 20, .44); cursor: pointer; transition: border-color .15s ease, background .15s ease; }
.check:hover, .switch-card:hover { border-color: var(--line-strong); background: rgba(20, 33, 48, .66); }
.check.compact { min-height: 44px; white-space: nowrap; }
.check input, .switch-card input { accent-color: var(--primary); }
.switch-card > input { position: absolute; opacity: 0; pointer-events: none; }
.switch { position: relative; width: 43px; height: 24px; flex: 0 0 43px; border-radius: 999px; background: #263545; transition: .18s ease; }
.switch::after { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #a4b0ba; transition: .18s ease; content: ""; }
.switch-card input:checked + .switch { background: var(--primary-2); }
.switch-card input:checked + .switch::after { left: 22px; background: #fff; }
.switch-card > span:last-child { display: grid; }
.switch-card small { color: var(--muted); font-size: 10px; }
.field-validation-error, .validation-summary-errors, .validation-box { color: #ff9cab; font-size: 12px; }
.validation-summary-valid { display: none; }
.validation-summary-errors ul { margin: 0; padding-left: 20px; }
.optional { margin-left: 5px; color: var(--muted); font-size: 10px; font-weight: 500; }

.kv { display: grid; grid-template-columns: minmax(120px, 180px) minmax(0, 1fr); gap: 12px; padding: 12px 2px; border-bottom: 1px solid var(--line); }
.kv:last-child { border-bottom: 0; }
.kv b { color: var(--muted); font-size: 12px; }
.callout { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; border: 1px solid rgba(102, 168, 255, .22); border-radius: 13px; background: rgba(102, 168, 255, .07); color: #c8d7e5; }
.callout b { color: var(--blue); white-space: nowrap; }
.empty { padding: 46px 20px; color: var(--muted); text-align: center; }

.alert { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; padding: 13px 15px; border: 1px solid; border-radius: 13px; box-shadow: var(--shadow); }
.alert.success { border-color: rgba(56, 229, 157, .25); background: rgba(25, 95, 68, .55); color: #a4f6d0; }
.alert.error { border-color: rgba(255, 111, 132, .3); background: rgba(98, 31, 45, .58); color: #ffc0ca; }
.alert button { border: 0; background: transparent; color: inherit; cursor: pointer; font-size: 20px; }

.pager { display: flex; align-items: center; gap: 7px; margin-top: 15px; color: var(--muted); }
.pager a { min-width: 42px; padding: 7px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--panel-2); color: var(--text); text-decoration: none; text-align: center; }

.timeline-list { position: relative; display: grid; gap: 12px; }
.timeline-list::before { position: absolute; top: 26px; bottom: 26px; left: 10px; width: 1px; background: var(--line); content: ""; }
.audit-item { position: relative; display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 12px; }
.audit-marker { z-index: 1; width: 13px; height: 13px; margin: 24px 0 0 4px; border: 3px solid var(--bg); border-radius: 50%; background: var(--primary); box-shadow: 0 0 0 1px rgba(56, 229, 157, .4); }
.audit-body { padding: 16px 18px; border: 1px solid var(--line); border-radius: 15px; background: var(--panel); }
.audit-title { display: flex; justify-content: space-between; gap: 18px; }
.audit-title > div { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.audit-title time, .audit-meta { color: var(--muted); font-size: 11px; }
.audit-meta { display: flex; flex-wrap: wrap; gap: 15px; margin-top: 8px; }
details { margin-top: 12px; }
details summary { color: var(--blue); cursor: pointer; }
.audit-json-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-top: 10px; }
.audit-json-grid pre { max-height: 300px; margin: 6px 0 0; padding: 12px; overflow: auto; border-radius: 10px; background: #070c13; color: #afbdc8; white-space: pre-wrap; word-break: break-word; direction: ltr; text-align: left; }

.auth-card { width: min(470px, 100%); padding: clamp(24px, 5vw, 38px); }
.auth-card .brand { padding: 0 0 28px; }
.auth-card h1 { margin: 0; font-size: 29px; }
.auth-card > p { margin: 7px 0 22px; }
.auth-card .field { margin: 15px 0; }
.auth-card .btn.full { width: 100%; margin-top: 18px; }
.auth-footnote { margin: 20px 0 0; padding-top: 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; text-align: center; }
.status-panel { max-width: 760px; margin: 8vh auto 0; padding: clamp(28px, 5vw, 48px); text-align: center; }
.status-icon { width: 62px; height: 62px; display: grid; place-items: center; margin: 0 auto 18px; border: 1px solid rgba(255, 111, 132, .3); border-radius: 18px; background: rgba(255, 111, 132, .1); color: var(--red); font-size: 28px; font-weight: 900; }
.details-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 28px; }

.confirm-dialog { position: fixed; z-index: 100; inset: 0; display: grid; place-items: center; padding: 18px; }
.confirm-backdrop { position: absolute; inset: 0; background: rgba(1, 4, 8, .76); backdrop-filter: blur(6px); }
.confirm-card { position: relative; width: min(440px, 100%); padding: 28px; border: 1px solid var(--line-strong); border-radius: 22px; background: #101925; box-shadow: 0 30px 90px #000; text-align: center; }
.confirm-icon { width: 50px; height: 50px; display: grid; place-items: center; margin: 0 auto 12px; border: 1px solid rgba(255, 198, 110, .35); border-radius: 16px; background: rgba(255, 198, 110, .12); color: var(--amber); font-size: 25px; font-weight: 900; }
.confirm-card h2 { margin: 0; }
.confirm-card p { margin: 9px 0 20px; color: var(--muted); }
.confirm-card .actions { justify-content: center; }
.sidebar-backdrop { display: none; }

@media (max-width: 1260px) {
    .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .filters { grid-template-columns: minmax(240px, 1fr) repeat(2, minmax(140px, auto)); }
}
@media (max-width: 980px) {
    .sidebar { transform: translateX(-110%); transition: transform .22s ease; }
    body.sidebar-open .sidebar { transform: translateX(0); }
    .sidebar-backdrop { position: fixed; z-index: 45; inset: 0; background: rgba(0, 0, 0, .58); }
    body.sidebar-open .sidebar-backdrop { display: block; }
    .main { margin-left: 0; }
    .icon-button { display: grid; }
    .topbar { justify-content: flex-start; gap: 14px; }
    .topbar-state { margin-left: auto; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
    .content-shell { padding: 20px 14px 34px; }
    .topbar { min-height: 70px; padding: 10px 14px; }
    .topbar-state { display: none; }
    .page-head { align-items: flex-start; flex-direction: column; }
    .page-head .actions { width: 100%; }
    .page-head .actions .btn { flex: 1 1 auto; }
    .stats, .form-grid, .audit-json-grid, .details-grid { grid-template-columns: 1fr; }
    .stat { min-height: 122px; }
    .filters { grid-template-columns: 1fr; }
    .filters .btn { width: 100%; }
    .full { grid-column: auto; }
    .kv { grid-template-columns: 1fr; gap: 3px; }
    .audit-title { flex-direction: column; gap: 7px; }
    .sidebar { width: min(310px, 88vw); }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}
