:root {
    color-scheme: dark;
    --bg: #0b1220;
    --surface: #111a2b;
    --raised: #162235;
    --inset: #0d1524;
    --ink: #e8eef8;
    --ink-2: #b7c3d9;
    --muted: #93a0b8;
    --border: rgba(232, 238, 248, 0.09);
    --border-strong: rgba(232, 238, 248, 0.18);
    --accent: #3b82f6;
    --accent-soft: rgba(59, 130, 246, 0.16);
    --accent-ink: #dbeafe;
    --ok: #34d399;
    --ok-soft: rgba(52, 211, 153, 0.14);
    --ok-ink: #bbf7d0;
    --ok-border: rgba(52, 211, 153, 0.3);
    --bad: #f87171;
    --bad-soft: rgba(248, 113, 113, 0.13);
    --bad-ink: #fecaca;
    --bad-border: rgba(248, 113, 113, 0.32);
    --warn: #fbbf24;
    --warn-soft: rgba(251, 191, 36, 0.11);
    --warn-ink: #fde68a;
    --warn-border: rgba(251, 191, 36, 0.3);
    --radius: 12px;
    --radius-sm: 8px;
    --font: "IBM Plex Sans", "Segoe UI", "Helvetica Neue", sans-serif;
    --mono: "JetBrains Mono", "Cascadia Mono", "Consolas", monospace;
    --focus: 0 0 0 3px rgba(59, 130, 246, 0.38);
    --sidebar-width: 236px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
    margin: 0;
    line-height: 1.25;
    letter-spacing: -0.01em;
}

h1 {
    font-size: 24px;
    font-weight: 650;
}

h2 {
    font-size: 15px;
    font-weight: 650;
}

p {
    margin: 0;
}

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

a:hover {
    color: #fff;
    text-decoration: underline;
    text-underline-offset: 3px;
}

code,
.mono {
    font-family: var(--mono);
    font-size: 0.92em;
}

code {
    background: var(--inset);
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 1px 5px;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    box-shadow: var(--focus);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

.skip-link {
    position: absolute;
    top: -60px;
    left: 12px;
    z-index: 50;
    background: var(--accent);
    color: #fff;
    padding: 8px 14px;
    border-radius: var(--radius-sm);
    font-weight: 600;
}

.skip-link:focus {
    top: 12px;
}

/* ---- Shell ---- */

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    gap: 24px;
    height: 100vh;
    padding: 20px 14px 16px;
    background: linear-gradient(180deg, #0e1728 0%, #0a111f 100%);
    border-right: 1px solid var(--border);
    overflow-y: auto;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 6px;
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.brand-text {
    display: flex;
    flex-direction: column;
    font-size: 16px;
    font-weight: 650;
    line-height: 1.15;
}

.brand-text small {
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 500;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.primary-nav {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.nav-link {
    display: block;
    padding: 9px 10px;
    border-radius: var(--radius-sm);
    color: var(--ink-2);
    font-size: 13.5px;
    font-weight: 500;
}

.nav-link:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--ink);
    text-decoration: none;
}

.nav-link.is-active {
    background: var(--accent-soft);
    color: var(--accent-ink);
    font-weight: 600;
}

.sidebar-foot {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: auto;
    padding: 14px 6px 0;
    border-top: 1px solid var(--border);
}

.user-block {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    flex: none;
    border-radius: 50%;
    background: var(--raised);
    border: 1px solid var(--border-strong);
    font-size: 13px;
    font-weight: 650;
}

.user-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.user-text strong {
    font-size: 12.5px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.user-role {
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.07em;
}

.account-links {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 12px;
}

.account-links a,
.link-button {
    color: var(--muted);
}

.account-links a:hover,
.link-button:hover {
    color: var(--ink);
}

.link-button {
    padding: 0;
    background: none;
    border: 0;
    font: inherit;
    cursor: pointer;
}

.foot-host {
    color: var(--muted);
    font-family: var(--mono);
    font-size: 10.5px;
    opacity: 0.7;
}

.main-wrap {
    min-width: 0;
}

.content {
    width: 100%;
    max-width: 1240px;
    margin: 0 auto;
    padding: 30px clamp(16px, 3vw, 40px) 64px;
}

/* ---- Page furniture ---- */

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}

.page-sub {
    margin-top: 5px;
    color: var(--muted);
    font-size: 13px;
}

.head-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.back-link {
    margin-bottom: 12px;
    font-size: 12.5px;
}

.back-link a {
    color: var(--muted);
}

/* ---- Stats ---- */

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.stat {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 15px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.stat-label {
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.stat-value {
    font-family: var(--mono);
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.03em;
    font-variant-numeric: tabular-nums;
}

.stat-of {
    color: var(--muted);
    font-size: 15px;
    font-weight: 500;
}

.stat-note {
    color: var(--muted);
    font-size: 11.5px;
}

/* ---- Panels and tables ---- */

.panel {
    margin-top: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border);
}

.panel-head h2 {
    display: flex;
    align-items: center;
    gap: 8px;
}

.panel-link {
    font-size: 12.5px;
}

.panel-form {
    padding: 20px;
}

.panel-compact {
    padding: 16px 18px 18px;
}

.panel-compact .panel-head {
    padding: 0 0 10px;
    border-bottom: 0;
}

.panel-compact > p {
    margin-bottom: 12px;
    font-size: 13px;
}

.table-wrap {
    width: 100%;
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

th {
    padding: 9px 18px;
    background: var(--inset);
    border-bottom: 1px solid var(--border);
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-align: left;
    text-transform: uppercase;
    white-space: nowrap;
}

td {
    padding: 11px 18px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tbody tr:last-child td {
    border-bottom: 0;
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.025);
}

.row-title {
    color: var(--ink);
    font-weight: 600;
}

.row-title:hover {
    color: var(--accent-ink);
}

.row-sub {
    display: block;
    color: var(--muted);
    font-family: var(--mono);
    font-size: 11px;
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.num {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.muted {
    color: var(--muted);
}

.error-cell {
    max-width: 360px;
    overflow-wrap: anywhere;
}

.empty,
.empty-line {
    padding: 28px 18px;
    color: var(--muted);
    text-align: center;
}

.empty p {
    margin-bottom: 12px;
}

/* ---- Badges ---- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border: 1px solid var(--border-strong);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.03);
    color: var(--ink-2);
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}

.badge.is-ok {
    background: var(--ok-soft);
    border-color: var(--ok-border);
    color: var(--ok-ink);
}

.badge.is-bad {
    background: var(--bad-soft);
    border-color: var(--bad-border);
    color: var(--bad-ink);
}

.badge.is-warn {
    background: var(--warn-soft);
    border-color: var(--warn-border);
    color: var(--warn-ink);
}

.badge.is-owner {
    background: var(--accent-soft);
    border-color: rgba(59, 130, 246, 0.4);
    color: var(--accent-ink);
}

.badge.is-idle {
    color: var(--muted);
}

/* ---- Buttons ---- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 38px;
    padding: 0 15px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 120ms ease, border-color 120ms ease;
}

.btn:hover {
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

.btn-primary:hover {
    background: #2f74e6;
    color: #fff;
}

.btn-secondary {
    background: var(--raised);
    border-color: var(--border-strong);
    color: var(--ink);
}

.btn-secondary:hover {
    background: #1b2a41;
    color: var(--ink);
}

.btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--ink-2);
}

.btn-ghost:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--ink);
}

.btn-danger {
    background: var(--bad-soft);
    border-color: var(--bad-border);
    color: var(--bad-ink);
}

.btn-danger:hover {
    background: rgba(248, 113, 113, 0.22);
    color: #fff;
}

.btn-small {
    min-height: 31px;
    padding: 0 10px;
    font-size: 12px;
}

.btn-block {
    width: 100%;
}

/* ---- Forms ---- */

.form {
    display: flex;
    flex-direction: column;
    gap: 15px;
    max-width: 460px;
}

.form-spaced {
    margin-top: 18px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

label {
    color: var(--ink-2);
    font-size: 12.5px;
    font-weight: 600;
}

input,
select {
    width: 100%;
    min-height: 40px;
    padding: 8px 11px;
    background: var(--inset);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    color: var(--ink);
    font: inherit;
    font-size: 14px;
}

input::placeholder {
    color: #6b7a91;
}

input:hover,
select:hover {
    border-color: rgba(232, 238, 248, 0.26);
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--focus);
}

.help {
    color: var(--muted);
    font-size: 11.5px;
    line-height: 1.45;
}

.label-optional {
    color: var(--muted);
    font-weight: 500;
}

.form-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 9px;
    align-items: center;
}

/* ---- Alerts and callouts ---- */

.alert {
    margin-bottom: 16px;
    padding: 11px 13px;
    background: var(--bad-soft);
    border: 1px solid var(--bad-border);
    border-radius: var(--radius-sm);
    color: var(--bad-ink);
    font-size: 13px;
}

.alert-info {
    background: var(--accent-soft);
    border-color: rgba(59, 130, 246, 0.35);
    color: var(--accent-ink);
}

.callout {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
    padding: 14px 16px;
    background: var(--raised);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    font-size: 13px;
}

.callout-warn {
    background: var(--warn-soft);
    border-color: var(--warn-border);
}

.callout p {
    margin-top: 4px;
    color: var(--ink-2);
}

.key-reveal {
    display: block;
    margin-top: 9px;
    padding: 8px 10px;
    background: rgba(0, 0, 0, 0.3);
    border-color: var(--warn-border);
    font-size: 13px;
    overflow-wrap: anywhere;
    user-select: all;
}

.key-facts {
    display: grid;
    gap: 6px;
    margin: 10px 0 0;
}

.key-facts > div {
    display: grid;
    grid-template-columns: 64px minmax(0, 1fr);
    gap: 8px;
    align-items: baseline;
}

.key-facts dt {
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.key-facts dd {
    margin: 0;
    min-width: 0;
}

.key-facts code {
    display: block;
    padding: 7px 9px;
    background: rgba(0, 0, 0, 0.3);
    border-color: var(--warn-border);
    font-size: 12.5px;
    overflow-wrap: anywhere;
    user-select: all;
}

/* ---- Meta / detail lists ---- */

.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 12px;
    margin-top: 20px;
}

.meta {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 13px 15px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.meta-label {
    color: var(--muted);
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.meta-note {
    color: var(--muted);
    font-size: 11px;
}

.detail-list {
    display: grid;
    gap: 10px;
    margin: 0;
}

.detail-list > div {
    display: grid;
    grid-template-columns: 170px 1fr;
    gap: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}

.detail-list > div:last-child {
    padding-bottom: 0;
    border-bottom: 0;
}

.detail-list dt {
    color: var(--muted);
    font-size: 12.5px;
}

.detail-list dd {
    margin: 0;
    font-size: 13px;
}

/* ---- Activity ---- */

.activity {
    margin: 0;
    padding: 0;
    list-style: none;
}

.activity li {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 18px;
    border-bottom: 1px solid var(--border);
    font-size: 12.5px;
}

.activity li:last-child {
    border-bottom: 0;
}

.activity-dot {
    width: 7px;
    height: 7px;
    margin-top: 6px;
    flex: none;
    border-radius: 50%;
    background: var(--muted);
}

.activity-dot.is-ok {
    background: var(--ok);
}

.activity-dot.is-bad {
    background: var(--bad);
}

.activity-main {
    flex: 1;
    min-width: 0;
    overflow-wrap: anywhere;
}

.activity time {
    flex: none;
    font-size: 11.5px;
}

/* ---- Auth screens ---- */

.auth-body {
    background:
        radial-gradient(900px 500px at 50% -10%, rgba(59, 130, 246, 0.13), transparent 65%),
        var(--bg);
}

.auth-shell {
    display: grid;
    place-items: center;
    min-height: 100vh;
    padding: 30px 16px;
}

.auth-frame {
    width: min(430px, 100%);
}

.auth-brand {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    margin-bottom: 18px;
}

.auth-card {
    padding: 26px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

.auth-card h1 {
    font-size: 21px;
}

.auth-sub {
    margin: 6px 0 18px;
    color: var(--muted);
    font-size: 13px;
}

.auth-note {
    margin-top: 16px;
    color: var(--muted);
    font-size: 12px;
    text-align: center;
}

.auth-foot {
    margin-top: 16px;
    color: var(--muted);
    font-size: 11px;
    text-align: center;
}

.auth-card-plain {
    max-width: 430px;
}

.divider {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px 0;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.divider::before,
.divider::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

.qr-block {
    display: flex;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 18px;
    padding: 14px;
    background: #fff;
    border-radius: var(--radius);
    color: #0b1220;
}

.qr-block img {
    display: block;
    width: 170px;
    height: 170px;
    flex: none;
}

.qr-block p {
    font-size: 12px;
}

.qr-block .help {
    color: #475569;
}

.qr-block .muted {
    color: #475569;
}

.manual-key {
    display: block;
    margin: 6px 0;
    padding: 7px 9px;
    background: #f1f5f9;
    border-color: #cbd5e1;
    color: #0f172a;
    font-size: 12.5px;
    letter-spacing: 0.06em;
    overflow-wrap: anywhere;
}

.backup-codes {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 7px;
    margin: 0 0 16px;
    padding: 0;
    list-style: none;
}

.backup-codes li {
    padding: 7px 9px;
    background: var(--inset);
    border: 1px solid var(--border);
    border-radius: 6px;
    text-align: center;
}

.backup-codes code {
    background: none;
    border: 0;
    padding: 0;
    font-size: 13.5px;
    letter-spacing: 0.05em;
}

/* ---- Responsive ---- */

@media (max-width: 900px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        position: static;
        height: auto;
        gap: 14px;
        padding: 14px 16px;
        border-right: 0;
        border-bottom: 1px solid var(--border);
        overflow: visible;
    }

    .brand {
        padding: 0;
    }

    .primary-nav {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 4px;
    }

    .nav-link {
        padding: 7px 11px;
        border: 1px solid var(--border);
        font-size: 12.5px;
    }

    .sidebar-foot {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: 10px 18px;
        margin-top: 0;
        padding: 10px 0 0;
    }

    .account-links {
        flex-direction: row;
        gap: 14px;
    }

    .foot-host {
        display: none;
    }

    .content {
        padding: 22px 16px 56px;
    }

    .stat-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 620px) {
    h1 {
        font-size: 21px;
    }

    .page-head {
        flex-direction: column;
        align-items: stretch;
    }

    .page-head .btn {
        align-self: flex-start;
    }

    .stat-value {
        font-size: 23px;
    }

    .callout {
        flex-direction: column;
    }

    .qr-block {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .detail-list > div {
        grid-template-columns: 1fr;
        gap: 3px;
    }

    .activity li {
        flex-direction: column;
        gap: 4px;
    }

    .activity time {
        padding-left: 17px;
    }
}

@media print {
    body {
        background: #fff;
        color: #000;
    }

    .sidebar,
    .btn,
    .auth-brand,
    .auth-foot,
    .skip-link {
        display: none !important;
    }

    .app-shell {
        display: block;
    }

    .content,
    .auth-shell {
        padding: 0;
        max-width: none;
    }

    .auth-card,
    .panel,
    .callout {
        background: #fff;
        color: #000;
        border-color: #999;
        box-shadow: none;
    }

    .backup-codes li,
    .backup-codes code,
    .key-reveal {
        background: #fff;
        color: #000;
        border-color: #999;
    }
}
