:root {
    --bg: #F4F5F7;
    --surface: #FFFFFF;
    --surface-2: #F8F9FB;
    --line: #E3E5EA;
    --text: #16181D;
    --muted: #5B6170;
    --accent: #2552C9;
    --accent-hover: #1A3E9E;
    --on-accent: #FFFFFF;
    --accent-soft: #EEF2FD;
    --ok: #1E7A45;
    --ok-soft: #E5F4EA;
    --warning: #9A5800;
    --warning-soft: #FDF3E1;
    --critical: #C42D2D;
    --critical-soft: #FBE7E6;
    --on-critical: #FFFFFF;
    --track: #EDEFF3;
    --unknown: #8A9097;
    --radius: 12px;
    --mono: ui-monospace, "JetBrains Mono", SFMono-Regular, Consolas, "Liberation Mono", monospace;
    --sans: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0E1116;
        --surface: #151A22;
        --surface-2: #1A2029;
        --line: #262E3A;
        --text: #E6E9EF;
        --muted: #9AA3B2;
        --accent: #8AB6FF;
        --accent-hover: #B3CFFF;
        --on-accent: #0E1116;
        --accent-soft: #1E2838;
        --ok: #4CD38A;
        --ok-soft: #15291F;
        --warning: #F5B94A;
        --warning-soft: #2A2416;
        --critical: #FF8A80;
        --critical-soft: #331B1A;
        --on-critical: #0E1116;
        --track: #262E3A;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #0E1116;
    --surface: #151A22;
    --surface-2: #1A2029;
    --line: #262E3A;
    --text: #E6E9EF;
    --muted: #9AA3B2;
    --accent: #8AB6FF;
    --accent-hover: #B3CFFF;
    --on-accent: #0E1116;
    --accent-soft: #1E2838;
    --ok: #4CD38A;
    --ok-soft: #15291F;
    --warning: #F5B94A;
    --warning-soft: #2A2416;
    --critical: #FF8A80;
    --critical-soft: #331B1A;
    --on-critical: #0E1116;
    --track: #262E3A;
    color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 var(--sans);
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }

.mono, .num { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.lead { color: var(--muted); margin: 4px 0 0; font-size: 14px; }

.shell { display: flex; min-height: 100vh; }

.sidebar {
    position: sticky;
    top: 0;
    align-self: flex-start;
    width: 232px;
    flex: none;
    height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 18px 12px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 30;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; font-weight: 700; font-size: 16px; color: var(--text); }
.brand:hover { text-decoration: none; color: var(--text); }
.brand-mark { width: 28px; height: 28px; border-radius: 8px; background: var(--text); color: var(--bg); display: grid; place-items: center; font-size: 14px; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 10px;
    border-radius: 8px;
    color: var(--muted);
    font-size: 14px;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-link svg { flex: none; }
.nav-link .count { margin-left: auto; background: var(--critical); color: var(--on-critical); border-radius: 999px; font-size: 12px; font-weight: 600; padding: 1px 8px; }

.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 10px; }
.sidebar-foot .row { display: flex; gap: 6px; flex-wrap: wrap; }
.sidebar-foot form { margin: 0; }

.tool {
    height: 32px;
    padding: 0 10px;
    border: 1px solid var(--line);
    background: var(--bg);
    color: var(--text);
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
}
.tool:hover { border-color: var(--muted); }
.tool.active { font-weight: 700; border-color: var(--text); }
.tool .theme-dark-icon { display: none; }
:root[data-theme="dark"] .tool .theme-dark-icon { display: inline; }
:root[data-theme="dark"] .tool .theme-light-icon { display: none; }
@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .tool .theme-dark-icon { display: inline; }
    :root:not([data-theme="light"]) .tool .theme-light-icon { display: none; }
}

.whoami { font-size: 13px; color: var(--muted); }

.content { flex: 1 1 auto; min-width: 0; display: flex; }
.main { flex: 1 1 auto; min-width: 0; padding: 24px 28px 64px; display: flex; flex-direction: column; gap: 18px; max-width: 1280px; }
.aside {
    flex: none;
    width: 320px;
    border-left: 1px solid var(--line);
    background: var(--surface);
    padding: 24px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.topbar { display: none; }
.bottom-nav { display: none; }
.scrim { display: none; }

h1 { font-size: 26px; margin: 0; font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 17px; margin: 0; font-weight: 700; }
h3 { font-size: 15px; margin: 0 0 8px; font-weight: 600; }
.section-title { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: 0.06em; text-transform: uppercase; margin: 0; }

.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px; }
.page-head .actions { display: flex; flex-wrap: wrap; gap: 8px; }
.crumbs { font-size: 13px; color: var(--muted); margin: 0 0 4px; }

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px;
}
.card > h2, .card > h3 { margin-bottom: 10px; }
.card.flush { padding: 0; overflow: hidden; }

.grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi-label { font-size: 12px; color: var(--muted); }
.kpi-value { font-family: var(--mono); font-size: 26px; font-weight: 600; margin-top: 4px; line-height: 1.2; }
.kpi-value small { font-size: 14px; color: var(--muted); font-weight: 400; }
.kpi-note { font-size: 12px; color: var(--muted); }
.kpi-note.ok { color: var(--ok); }
.kpi-note.warning { color: var(--warning); }
.kpi-value.critical { color: var(--critical); }

.attention { display: flex; flex-direction: column; gap: 8px; }
.attention-item {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 12px;
    padding: 10px 12px;
    border-radius: 8px;
    background: var(--warning-soft);
    font-size: 14px;
}
.attention-item.critical { background: var(--critical-soft); }
.attention-item .label { font-weight: 700; font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--warning); }
.attention-item.critical .label { color: var(--critical); }
.attention-item .who { font-weight: 600; }
.attention-item .what { flex: 1 1 240px; }
.attention-item a { font-weight: 600; }

.server-head { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.server-title { display: flex; align-items: center; gap: 10px; flex: 1 1 280px; min-width: 0; flex-wrap: wrap; }
.server-title h2 a { color: var(--text); }
.server-meta { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; flex: 1 1 460px; max-width: 600px; font-size: 12px; }
.metric-row { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); }
.metric-row b { font-family: var(--mono); font-weight: 500; color: var(--text); white-space: nowrap; }
.metric-row b.warning { color: var(--warning); }
.server-note { margin: 0; padding: 10px 16px; font-size: 13px; border-top: 1px solid var(--line); }
.server-note.warning { color: var(--warning); }
.server-note .dot { margin-right: 6px; }

.meter { height: 5px; background: var(--track); border-radius: 3px; overflow: hidden; margin-top: 5px; min-width: 60px; }
.meter span { display: block; height: 100%; background: var(--ok); border-radius: 3px; }
.meter span.warning { background: var(--warning); }
.meter span.critical { background: var(--critical); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; vertical-align: top; }
thead th { font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase; white-space: nowrap; }
tbody tr { border-top: 1px solid var(--line); }
.table-wrap { overflow-x: auto; }
.card.table-wrap { padding: 4px 0; }
.card.table-wrap > p, .card.table-wrap > h2, .card.table-wrap > h3 { padding: 0 16px; }
.card.table-wrap > table > * > tr > :first-child, .card.flush table.stack > * > tr > :first-child { padding-left: 16px; }
.card.table-wrap > table > * > tr > :last-child, .card.flush table.stack > * > tr > :last-child { padding-right: 16px; }
.card > table td:first-child, .card > table th:first-child { padding-left: 0; }

.inst-name { font-weight: 600; font-size: 14px; color: var(--text); }
.spark { display: block; width: 120px; height: 24px; }
.spark polyline { fill: none; stroke: var(--accent); stroke-width: 1.5; vector-effect: non-scaling-stroke; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--unknown); vertical-align: middle; flex: none; }
.dot.ok { background: var(--ok); }
.dot.warning { background: var(--warning); }
.dot.critical { background: var(--critical); }
.status-line { display: inline-flex; align-items: baseline; gap: 8px; }
.status-line .dot { transform: translateY(-1px); }

.badge, .pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: var(--track);
    color: var(--muted);
    white-space: nowrap;
}
.badge.ok, .pill.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warning, .pill.warning { background: var(--warning-soft); color: var(--warning); }
.badge.critical, .pill.critical { background: var(--critical-soft); color: var(--critical); }
.t-ok { color: var(--ok); }
.t-warning { color: var(--warning); }
.t-critical { color: var(--critical); }

.problems { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.problems li { padding: 8px 12px; border-radius: 8px; background: var(--surface-2); font-size: 14px; }
.problems li.critical { background: var(--critical-soft); }
.problems li.warning { background: var(--warning-soft); }

.targets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; font-size: 13px; }
.target .num { color: var(--muted); display: block; margin-left: 15px; }
.target .dot { margin-right: 6px; }

.feed { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.event { padding: 10px; border-radius: 8px; }
.event.warning { background: var(--warning-soft); }
.event.critical { background: var(--critical-soft); }
.event-time { font-family: var(--mono); font-size: 11px; color: var(--muted); }
.event.ok .event-time { color: var(--ok); }
.event.warning .event-time { color: var(--warning); }
.event.critical .event-time { color: var(--critical); }

.flash { padding: 10px 14px; border-radius: 8px; background: var(--ok-soft); }
.flash.error { background: var(--critical-soft); }

form.inline { display: inline; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
input[type=text], input[type=email], input[type=password], input[type=url], input[type=number], input[type=search], select {
    width: 100%;
    max-width: 420px;
    height: 38px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
    color: var(--text);
    font: inherit;
    font-size: 14px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.search { display: flex; align-items: center; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; height: 38px; width: 260px; color: var(--muted); }
.search input { border: 0; background: transparent; height: 36px; padding: 0; max-width: none; outline: none; }
.search:focus-within { outline: 2px solid var(--accent); outline-offset: 1px; }

button, .button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 38px;
    padding: 0 16px;
    border: 1px solid var(--accent);
    border-radius: 8px;
    background: var(--accent);
    color: var(--on-accent);
    font: inherit;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.button:hover { color: var(--on-accent); text-decoration: none; filter: brightness(1.08); }
button.secondary { background: transparent; color: var(--accent); }
button.danger { background: var(--critical); border-color: var(--critical); color: var(--on-critical); }
button.link { background: none; border: 0; padding: 0; height: auto; color: var(--muted); font-weight: 400; }
.error-text { color: var(--critical); font-size: 13px; margin-top: 4px; }

.command {
    font-family: var(--mono);
    font-size: 13px;
    background: var(--surface-2);
    border: 1px solid var(--line);
    padding: 12px;
    border-radius: 8px;
    word-break: break-all;
    user-select: all;
}

pre.log {
    max-height: 520px;
    overflow: auto;
    background: var(--surface-2);
    border: 1px solid var(--line);
    padding: 12px;
    border-radius: 8px;
    font-family: var(--mono);
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}

details > summary { cursor: pointer; }
.chart { width: 100%; height: auto; display: block; }
.chart .line { fill: none; stroke-width: 1.5; }
.chart .axis { stroke: var(--line); }
.chart text { fill: var(--muted); font-size: 11px; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--muted); }
.legend i { display: inline-block; width: 10px; height: 3px; margin-right: 4px; vertical-align: middle; }

.tabs { display: flex; gap: 8px; }
.tabs a { padding: 3px 12px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.tabs a.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.tabs a:hover { text-decoration: none; }

.auth-wrap { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; gap: 16px; }
.auth { width: 100%; max-width: 420px; }
.auth input { max-width: none; }
.auth-tools { display: flex; gap: 6px; }
.qr svg { width: 200px; height: 200px; background: #fff; padding: 8px; border-radius: 8px; }
.codes { columns: 2; font-family: var(--mono); }

.pagination { display: flex; gap: 6px; list-style: none; padding: 0; flex-wrap: wrap; }
.pagination li a, .pagination li span { padding: 4px 10px; border: 1px solid var(--line); border-radius: 6px; display: block; }

.hidden { display: none !important; }

@media (max-width: 1180px) {
    .aside { display: none; }
}

@media (max-width: 900px) {
    body { font-size: 15px; }
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        transform: translateX(-100%);
        transition: transform 0.2s ease;
        box-shadow: none;
    }
    body.menu-open .sidebar { transform: none; }
    body.menu-open .scrim { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, 0.4); z-index: 20; }
    .topbar {
        display: flex;
        position: sticky;
        top: 0;
        z-index: 10;
        align-items: center;
        gap: 10px;
        padding: 10px 12px 10px 16px;
        background: var(--surface);
        border-bottom: 1px solid var(--line);
    }
    .topbar .title { flex: 1 1 auto; font-weight: 700; }
    .main { padding: 14px 12px 96px; gap: 12px; }
    .page-head h1 { font-size: 22px; }
    .search { width: 100%; }
    .page-head .actions { width: 100%; }
    .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
    .kpi { padding: 10px 12px; }
    .kpi-value { font-size: 22px; }
    .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); flex-basis: 100%; }
    .targets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .bottom-nav {
        display: grid;
        grid-template-columns: repeat(4, minmax(0, 1fr));
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 10;
        background: var(--surface);
        border-top: 1px solid var(--line);
        padding: 4px 4px calc(8px + env(safe-area-inset-bottom));
    }
    .bottom-nav a, .bottom-nav button {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 2px;
        min-height: 48px;
        padding: 6px 0;
        font-size: 11px;
        color: var(--muted);
        background: none;
        border: 0;
        height: auto;
        font-weight: 400;
    }
    .bottom-nav .active { color: var(--accent); font-weight: 600; }
    .bottom-nav a:hover { text-decoration: none; }

    table.stack thead { display: none; }
    table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
    table.stack tr { padding: 10px 16px; }
    table.stack td { padding: 3px 0; }
    table.stack td[data-label]::before { content: attr(data-label) ": "; color: var(--muted); font-size: 12px; }
    table.stack td.first::before { content: none; }
}
