:root {
    color-scheme: dark;
    --bg: #07111f;
    --panel: rgba(15, 30, 49, .88);
    --panel-strong: #10243a;
    --line: rgba(143, 174, 204, .18);
    --text: #eff7ff;
    --muted: #8fa7bb;
    --cyan: #19d3c5;
    --blue: #3f8cff;
    --green: #2fd38b;
    --amber: #f3b957;
    --red: #ff5b69;
    --shadow: 0 24px 80px rgba(0, 0, 0, .35);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: var(--bg); color: var(--text); }
button, input { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.ambient { position: fixed; border-radius: 50%; filter: blur(100px); opacity: .15; pointer-events: none; }
.ambient-one { width: 420px; height: 420px; background: var(--cyan); top: -140px; left: -100px; }
.ambient-two { width: 500px; height: 500px; background: #405dff; bottom: -220px; right: -160px; }
.eyebrow { color: var(--cyan); font-size: .7rem; font-weight: 800; letter-spacing: .18em; margin: 0 0 .55rem; }
.muted { color: var(--muted); }
h1, h2, p { margin-top: 0; }
h1 { font-size: clamp(1.55rem, 3vw, 2.25rem); margin-bottom: .35rem; }
h2 { margin-bottom: .45rem; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(430px, 100%); padding: 40px; border: 1px solid var(--line); background: linear-gradient(145deg, rgba(20, 42, 64, .96), rgba(8, 20, 34, .96)); border-radius: 24px; box-shadow: var(--shadow); position: relative; }
.brand-mark { width: 58px; height: 58px; border-radius: 17px; display: grid; place-items: center; font-weight: 900; font-size: 1.35rem; color: #06111d; background: linear-gradient(135deg, var(--cyan), #74e9bb); margin-bottom: 24px; box-shadow: 0 10px 35px rgba(25, 211, 197, .25); }
.brand-mark.small { width: 38px; height: 38px; border-radius: 12px; margin: 0; font-size: 1rem; }
label { display: grid; gap: 7px; color: #b9cad7; font-size: .86rem; margin: 18px 0; }
input { width: 100%; border: 1px solid var(--line); border-radius: 11px; padding: 12px 14px; background: #091828; color: var(--text); outline: none; }
input:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(25, 211, 197, .12); }
button { border: 0; border-radius: 10px; padding: 11px 16px; color: var(--text); background: transparent; }
.primary { background: linear-gradient(135deg, var(--blue), #326fe4); font-weight: 750; box-shadow: 0 10px 24px rgba(63, 140, 255, .2); }
.secondary { border: 1px solid var(--line); background: #102239; }
.full { width: 100%; margin-top: 8px; }
.form-error { min-height: 20px; margin: 12px 0 0; color: #ff8d96; font-size: .84rem; }

.app-shell { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 26px 18px; border-right: 1px solid var(--line); background: rgba(6, 17, 30, .92); backdrop-filter: blur(18px); display: flex; flex-direction: column; z-index: 2; }
.brand-row { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; }
.brand-row strong, .brand-row span { display: block; }
.brand-row span { color: var(--muted); font-size: .73rem; margin-top: 2px; }
nav { display: grid; gap: 6px; }
.nav-item { text-align: left; color: var(--muted); padding: 12px 14px; }
.nav-item:hover, .nav-item.active { color: var(--text); background: rgba(25, 211, 197, .09); }
.nav-item.active { border-left: 2px solid var(--cyan); }
.sidebar-foot { margin-top: auto; border-top: 1px solid var(--line); padding: 18px 10px 0; display: grid; gap: 8px; color: var(--muted); font-size: .82rem; }
.text-button { padding: 0; width: max-content; color: var(--cyan); }
.content { padding: 34px clamp(20px, 4vw, 56px) 64px; min-width: 0; }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 20px; margin-bottom: 28px; }
.top-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.key-gate { display: flex; align-items: center; gap: 8px; }
.key-gate input { width: min(270px, 42vw); padding: 9px 12px; }
.key-gate.authorized input { border-color: rgba(47, 211, 139, .55); }
.key-gate.authorized button { color: #8cf1bd; border-color: rgba(47, 211, 139, .35); }
.health { display: flex; align-items: center; gap: 8px; color: var(--muted); border: 1px solid var(--line); padding: 9px 12px; border-radius: 999px; font-size: .78rem; }
.health span { width: 8px; height: 8px; border-radius: 50%; background: var(--amber); box-shadow: 0 0 10px var(--amber); }
.health.ok { color: #8cf1bd; }
.health.ok span { background: var(--green); box-shadow: 0 0 10px var(--green); }
.health.down { color: #ff9098; }
.health.down span { background: var(--red); box-shadow: 0 0 10px var(--red); }
.health.locked span { background: var(--amber); box-shadow: 0 0 10px var(--amber); }
.section { display: none; }
.section.active { display: block; animation: appear .22s ease; }
@keyframes appear { from { opacity: 0; transform: translateY(5px); } }
.hero-panel, .panel { border: 1px solid var(--line); background: var(--panel); border-radius: 20px; box-shadow: var(--shadow); }
.hero-panel { padding: clamp(24px, 4vw, 42px); display: flex; align-items: end; justify-content: space-between; gap: 24px; background: radial-gradient(circle at 80% 20%, rgba(25, 211, 197, .13), transparent 35%), var(--panel); }
.hero-panel p:not(.eyebrow) { color: var(--muted); max-width: 650px; margin-bottom: 0; }
.metric-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin: 18px 0; }
.metric { padding: 20px; border-radius: 16px; border: 1px solid var(--line); background: rgba(13, 30, 49, .78); }
.metric span, .metric strong, .metric small { display: block; }
.metric span { color: var(--muted); font-size: .75rem; }
.metric strong { font-size: 1.35rem; margin: 8px 0 5px; }
.metric small { color: #6e899f; }
.panel { padding: 24px; margin-bottom: 18px; }
.panel.narrow { max-width: 720px; }
.panel-head { display: flex; justify-content: space-between; gap: 16px; align-items: center; margin-bottom: 18px; }
.panel-head h2 { margin: 0; }
.search-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.empty { border: 1px dashed var(--line); color: var(--muted); padding: 24px; border-radius: 13px; margin-top: 18px; text-align: center; }
.result-table, table { width: 100%; border-collapse: collapse; }
th, td { padding: 13px 12px; border-bottom: 1px solid var(--line); text-align: left; font-size: .83rem; }
th { color: var(--muted); font-weight: 600; }
tr[data-device] { cursor: pointer; }
tr[data-device]:hover { background: rgba(25, 211, 197, .06); }
.device-meta { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; }
.device-meta div { padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #0a1a2b; overflow: hidden; }
.device-meta span, .device-meta strong { display: block; }
.device-meta span { color: var(--muted); font-size: .7rem; text-transform: uppercase; letter-spacing: .08em; }
.device-meta strong { margin-top: 7px; font-size: .85rem; overflow-wrap: anywhere; }
.action-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-top: 18px; }
.action-card { text-align: left; padding: 17px; border: 1px solid var(--line); background: #10243a; min-height: 95px; }
.action-card span, .action-card small { display: block; }
.action-card span { font-weight: 750; }
.action-card small { margin-top: 8px; color: var(--muted); line-height: 1.35; }
.action-card.warning { border-color: rgba(243, 185, 87, .35); }
.action-card.danger { border-color: rgba(255, 91, 105, .38); }
.output { white-space: pre-wrap; overflow-wrap: anywhere; background: #06121f; color: #abd1e5; border: 1px solid var(--line); border-radius: 12px; margin-top: 18px; padding: 16px; font: .78rem/1.55 ui-monospace, SFMono-Regular, Consolas, monospace; }
.table-wrap { overflow-x: auto; margin-top: 18px; border: 1px solid var(--line); border-radius: 12px; }
.table-wrap a { color: var(--cyan); }
.stack-form { max-width: 620px; }
.audit-event { display: grid; grid-template-columns: 170px 1fr auto; gap: 16px; padding: 13px 3px; border-bottom: 1px solid var(--line); align-items: center; font-size: .83rem; }
.audit-event span { color: var(--muted); }
.audit-event b { color: var(--cyan); }
.api-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-top: 20px; }
.api-list article { border: 1px solid var(--line); background: #0b1b2d; padding: 16px; border-radius: 13px; position: relative; }
.api-list code { display: block; color: #8de5dc; padding-right: 76px; overflow-wrap: anywhere; }
.api-list span { position: absolute; right: 13px; top: 13px; border: 1px solid var(--line); border-radius: 999px; padding: 4px 7px; color: var(--muted); font-size: .64rem; }
.api-list p { margin: 10px 0 0; color: var(--muted); font-size: .82rem; }
dialog { border: 0; border-radius: 20px; padding: 0; width: min(520px, calc(100% - 30px)); color: var(--text); background: #10243a; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(1, 8, 16, .78); backdrop-filter: blur(5px); }
.dialog-card { padding: 28px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.danger-button { background: var(--red); color: #190407; font-weight: 800; }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: 420px; padding: 13px 17px; border: 1px solid var(--line); border-radius: 12px; background: #16314a; box-shadow: var(--shadow); transform: translateY(130%); transition: transform .22s; z-index: 10; }
.toast.show { transform: translateY(0); }

@media (max-width: 1000px) {
    .metric-grid, .action-grid { grid-template-columns: repeat(2, 1fr); }
    .device-meta { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 760px) {
    .app-shell { display: block; }
    .sidebar { position: static; height: auto; border-right: 0; border-bottom: 1px solid var(--line); padding: 16px; }
    .brand-row { padding-bottom: 14px; }
    nav { grid-template-columns: repeat(5, minmax(100px, 1fr)); overflow-x: auto; }
    .nav-item { text-align: center; padding: 10px 8px; white-space: nowrap; }
    .nav-item.active { border-left: 0; border-bottom: 2px solid var(--cyan); }
    .sidebar-foot { display: none; }
    .content { padding: 22px 15px 50px; }
    .topbar, .hero-panel { align-items: flex-start; flex-direction: column; }
    .top-actions { width: 100%; justify-content: flex-start; }
    .key-gate { width: 100%; }
    .key-gate input { width: 100%; }
    .metric-grid, .api-list { grid-template-columns: 1fr 1fr; }
    .audit-event { grid-template-columns: 1fr; gap: 5px; }
}
@media (max-width: 520px) {
    .login-card { padding: 28px 22px; }
    .metric-grid, .action-grid, .api-list, .device-meta { grid-template-columns: 1fr; }
    .search-row { grid-template-columns: 1fr; }
    .panel { padding: 18px; }
}
