:root {
    color-scheme: dark;
    --bg: #070910;
    --surface: #101520;
    --surface-raised: #151c28;
    --surface-soft: #0c111b;
    --border: #242d3b;
    --border-strong: #344154;
    --text: #f3f7fb;
    --text-soft: #c7d1de;
    --muted: #8491a3;
    --accent: #62e6ff;
    --accent-soft: rgba(98, 230, 255, 0.1);
    --green: #49e890;
    --green-soft: rgba(73, 232, 144, 0.11);
    --yellow: #f4c95d;
    --yellow-soft: rgba(244, 201, 93, 0.11);
    --red: #ff6b7a;
    --red-soft: rgba(255, 107, 122, 0.11);
    --radius: 18px;
    --radius-small: 11px;
    --shadow: 0 24px 70px rgba(0, 0, 0, 0.26);
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    background:
        radial-gradient(circle at 76% -10%, rgba(36, 200, 236, 0.08), transparent 34rem),
        var(--bg);
    font-family: Inter, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

button,
select,
input {
    font: inherit;
}

a {
    color: inherit;
}

.skip-link {
    position: fixed;
    z-index: 100;
    top: 0.75rem;
    left: 0.75rem;
    padding: 0.7rem 1rem;
    border-radius: 0.5rem;
    color: #001015;
    background: var(--accent);
    font-weight: 800;
    transform: translateY(-180%);
    transition: transform 160ms ease;
}

.skip-link:focus {
    transform: translateY(0);
}

.app-shell {
    display: grid;
    grid-template-columns: 15rem minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    display: flex;
    flex-direction: column;
    height: 100vh;
    padding: 1.5rem 1rem;
    border-right: 1px solid var(--border);
    background: rgba(11, 14, 22, 0.96);
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 3.25rem;
    padding: 0.25rem 0.5rem;
    color: inherit;
    text-decoration: none;
}

.brand-mark {
    display: grid;
    flex: 0 0 auto;
    width: 2.75rem;
    height: 2.75rem;
    place-items: center;
    border: 1px solid rgba(98, 230, 255, 0.4);
    border-radius: 0.75rem;
    color: #061016;
    background: var(--accent);
    box-shadow: 0 0 2rem rgba(98, 230, 255, 0.12);
    font-size: 1.1rem;
    font-weight: 950;
    letter-spacing: -0.06em;
}

.brand-copy {
    min-width: 0;
}

.brand-copy strong,
.brand-copy span {
    display: block;
}

.brand-copy strong {
    overflow: hidden;
    font-size: 0.95rem;
    letter-spacing: -0.02em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand-copy span {
    margin-top: 0.12rem;
    color: var(--muted);
    font-size: 0.75rem;
}

.navigation {
    display: grid;
    gap: 1.5rem;
    margin-top: 2.4rem;
}

.nav-label,
.footer-kicker,
.eyebrow {
    color: var(--muted);
    font-size: 0.75rem;
    font-weight: 850;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.nav-label {
    margin: 0 0.7rem 0.55rem;
}

.nav {
    display: grid;
    gap: 0.25rem;
}

.nav a {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-height: 2.7rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid transparent;
    border-radius: 0.7rem;
    color: var(--text-soft);
    font-size: 0.9rem;
    font-weight: 650;
    text-decoration: none;
    transition:
        color 160ms ease,
        border-color 160ms ease,
        background 160ms ease;
}

.nav a:hover {
    color: var(--text);
    background: rgba(255, 255, 255, 0.025);
}

.nav a.active {
    border-color: rgba(98, 230, 255, 0.16);
    color: var(--accent);
    background: var(--accent-soft);
}

.nav a.active::before {
    position: absolute;
    top: 0.65rem;
    bottom: 0.65rem;
    left: -1.05rem;
    width: 2px;
    border-radius: 2px;
    background: var(--accent);
    content: "";
}

.nav-index {
    color: #5d6878;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.72rem;
    font-weight: 750;
}

.nav a.active .nav-index {
    color: var(--accent);
}

.sidebar-footer {
    display: grid;
    gap: 0.32rem;
    margin-top: auto;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 0.85rem;
    background: var(--surface-soft);
}

.sidebar-footer strong {
    display: flex;
    align-items: center;
    gap: 0.45rem;
    color: var(--text-soft);
    font-size: 0.88rem;
}

.sidebar-footer small {
    color: var(--muted);
    font-size: 0.75rem;
}

.dot {
    display: inline-block;
    flex: 0 0 auto;
    width: 0.48rem;
    height: 0.48rem;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 0.8rem rgba(73, 232, 144, 0.48);
}

.main {
    min-width: 0;
    padding: 0 2rem 1.5rem;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    min-height: 8.4rem;
    border-bottom: 1px solid var(--border);
}

.page-title h1 {
    margin: 0.35rem 0 0;
    font-size: clamp(1.8rem, 3vw, 2.6rem);
    line-height: 1.08;
    letter-spacing: -0.055em;
}

.page-title p {
    max-width: 44rem;
    margin: 0.65rem 0 0;
    color: var(--muted);
    font-size: 0.95rem;
}

.top-actions {
    display: flex;
    align-items: center;
    gap: 0.65rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.55rem;
    min-height: 2.55rem;
    padding: 0.55rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-soft);
    background: var(--surface-soft);
    font-size: 0.8rem;
    font-weight: 750;
    white-space: nowrap;
}

.account-badge {
    text-decoration: none;
}

.logout-form {
    margin: 0;
}

.page-content {
    padding-top: 1.5rem;
}

.stats {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.8rem;
    margin-bottom: 1rem;
}

.stat {
    position: relative;
    min-height: 7.1rem;
    overflow: hidden;
    padding: 1.05rem 1.1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    background: var(--surface);
}

.stat::after {
    position: absolute;
    top: 0;
    right: 0;
    width: 2.7rem;
    height: 2px;
    background: var(--accent);
    content: "";
}

.stat span {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 700;
}

.stat strong {
    display: block;
    margin-top: 0.55rem;
    font-size: 1.65rem;
    line-height: 1.1;
    letter-spacing: -0.045em;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 24rem), 1fr));
    gap: 1rem;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 28rem), 1fr));
    gap: 1rem;
}

.card {
    min-width: 0;
    padding: 1.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: linear-gradient(145deg, var(--surface-raised), var(--surface));
    box-shadow: var(--shadow);
}

.client-card {
    border-top-color: rgba(98, 230, 255, 0.4);
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
}

.card h2 {
    margin: 0;
    font-size: 1.2rem;
    line-height: 1.25;
    letter-spacing: -0.025em;
}

.card small {
    display: block;
    margin-top: 0.3rem;
    color: var(--muted);
    font-size: 0.78rem;
}

.supporting-text {
    margin: 0.9rem 0 0;
    color: var(--muted);
}

.status-pill {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    min-height: 1.7rem;
    padding: 0.25rem 0.55rem;
    border: 1px solid;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 850;
    letter-spacing: 0.045em;
    line-height: 1;
    text-transform: uppercase;
    white-space: nowrap;
}

.online {
    border-color: rgba(73, 232, 144, 0.28);
    color: var(--green);
    background: var(--green-soft);
}

.offline {
    border-color: rgba(255, 107, 122, 0.3);
    color: var(--red);
    background: var(--red-soft);
}

.warning {
    border-color: rgba(244, 201, 93, 0.3);
    color: var(--yellow);
    background: var(--yellow-soft);
}

.info {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 1rem 0;
    border-top: 1px solid var(--border);
    border-left: 1px solid var(--border);
}

.info-item {
    min-width: 0;
    padding: 0.85rem 0.9rem;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
    background: rgba(7, 9, 16, 0.2);
}

.info-item--full {
    grid-column: 1 / -1;
}

.info-item > span {
    display: block;
    margin-bottom: 0.28rem;
    color: var(--muted);
    font-size: 0.74rem;
    font-weight: 700;
}

.info-item strong {
    color: var(--text-soft);
    font-size: 0.9rem;
    overflow-wrap: anywhere;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    margin-top: 1rem;
}

.actions--operations {
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.actions--navigation {
    margin-top: 0.65rem;
}

.actions--compact {
    margin-top: 0.5rem;
}

.actions form {
    margin: 0;
}

button,
.button-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2.55rem;
    padding: 0.58rem 0.85rem;
    border: 1px solid transparent;
    border-radius: 0.65rem;
    cursor: pointer;
    font-size: 0.82rem;
    font-weight: 800;
    line-height: 1.2;
    text-align: center;
    text-decoration: none;
    transition:
        transform 140ms ease,
        border-color 140ms ease,
        background 140ms ease;
}

button:hover,
.button-link:hover {
    transform: translateY(-1px);
}

button:active,
.button-link:active {
    transform: translateY(0);
}

button:focus-visible,
.button-link:focus-visible,
.nav a:focus-visible,
.brand:focus-visible,
select:focus-visible,
input:focus-visible {
    outline: 3px solid rgba(98, 230, 255, 0.35);
    outline-offset: 2px;
}

.primary {
    border-color: var(--accent);
    color: #041116;
    background: var(--accent);
}

.primary:hover {
    background: #8bedff;
}

.secondary {
    border-color: var(--border-strong);
    color: var(--text-soft);
    background: var(--surface-soft);
}

.secondary:hover {
    border-color: #4d5c70;
    background: #121925;
}

.danger {
    border-color: rgba(255, 107, 122, 0.3);
    color: #ff9ba6;
    background: var(--red-soft);
}

.ghost {
    border-color: var(--border);
    color: var(--text-soft);
    background: transparent;
}

.topbar-link {
    white-space: nowrap;
}

code {
    padding: 0.16rem 0.4rem;
    border: 1px solid rgba(98, 230, 255, 0.12);
    border-radius: 0.35rem;
    color: #a8f1ff;
    background: rgba(98, 230, 255, 0.06);
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.8rem;
}

pre {
    max-height: 62vh;
    margin: 1rem 0 0;
    overflow: auto;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-small);
    color: #d9e4ef;
    background: #080b12;
    font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
    font-size: 0.84rem;
    line-height: 1.6;
    tab-size: 4;
    white-space: pre-wrap;
    word-break: break-word;
}

.filter-form {
    margin: 1rem 0 0;
}

.field-select {
    width: 100%;
    min-height: 2.7rem;
    margin-top: 0.45rem;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border-strong);
    border-radius: 0.6rem;
    color: var(--text);
    background: var(--surface-soft);
}

.qr-frame {
    display: inline-block;
    margin-top: 1rem;
    padding: 0.85rem;
    border-radius: 0.8rem;
    background: #fff;
}

.qr-image {
    display: block;
    width: 20rem;
    max-width: 100%;
    height: auto;
}

.message {
    margin: 1rem 0 0;
    padding: 0.75rem 0.9rem;
    border-left: 2px solid;
    border-radius: 0.35rem;
}

.message--danger {
    border-color: var(--red);
    color: #ffb2bb;
    background: var(--red-soft);
}

.message--success {
    border-color: var(--green);
    color: #a8f8ca;
    background: var(--green-soft);
}

.message--warning {
    border-color: var(--yellow);
    color: #ffe4a1;
    background: var(--yellow-soft);
}

.stack-form,
.login-form {
    display: grid;
    gap: 0.9rem;
}

.stack-form label,
.login-form label {
    display: grid;
    gap: 0.35rem;
    color: var(--text-soft);
    font-size: 0.82rem;
    font-weight: 750;
}

.stack-form input,
.login-form input {
    width: 100%;
    min-height: 2.9rem;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: 0.65rem;
    color: var(--text);
    background: var(--surface-soft);
}

.credential-row,
.storage-list > div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--border);
}

.credential-row:last-child,
.storage-list > div:last-child {
    border-bottom: 0;
}

.credential-row small,
.storage-list span {
    display: block;
    color: var(--muted);
    font-size: 0.76rem;
}

.storage-list > div {
    align-items: flex-start;
    flex-direction: column;
}

.storage-list code {
    max-width: 100%;
    overflow-wrap: anywhere;
}

.login-page {
    display: grid;
    min-height: 100vh;
    min-height: 100dvh;
    place-items: center;
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}

.login-shell {
    width: min(100%, 28rem);
}

.login-card {
    padding: clamp(1.25rem, 5vw, 2rem);
    border: 1px solid var(--border);
    border-top-color: rgba(98, 230, 255, 0.45);
    border-radius: 1.35rem;
    background: linear-gradient(145deg, var(--surface-raised), var(--surface));
    box-shadow: var(--shadow);
}

.login-brand {
    display: flex;
    align-items: center;
    gap: 0.8rem;
}

.login-brand strong,
.login-brand span {
    display: block;
}

.login-brand span {
    color: var(--muted);
    font-size: 0.78rem;
}

.login-copy {
    margin: 2rem 0 1.3rem;
}

.login-copy h1 {
    margin: 0.4rem 0 0;
    font-size: 2rem;
    letter-spacing: -0.05em;
}

.login-copy p,
.login-help {
    color: var(--muted);
    font-size: 0.88rem;
}

.login-divider {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin: 1.1rem 0;
    color: var(--muted);
    font-size: 0.75rem;
}

.login-divider::before,
.login-divider::after {
    flex: 1;
    height: 1px;
    background: var(--border);
    content: "";
}

.login-passkey,
.login-form button {
    width: 100%;
}

[hidden] {
    display: none !important;
}

.system-alert {
    display: grid;
    gap: 0.25rem;
    margin-bottom: 1rem;
    padding: 0.9rem 1rem;
    border: 1px solid rgba(255, 107, 122, 0.26);
    border-left: 3px solid var(--red);
    border-radius: var(--radius-small);
    color: #ffc4ca;
    background: var(--red-soft);
}

.system-alert strong {
    font-size: 0.92rem;
}

.system-alert span {
    color: #f2aeb6;
    font-size: 0.85rem;
}

.footer {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    color: #657184;
    font-size: 0.75rem;
}

@media (max-width: 68rem) {
    .stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 52rem) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        padding: 1rem;
        border-right: 0;
        border-bottom: 1px solid var(--border);
        padding-top: max(1rem, env(safe-area-inset-top));
    }

    .navigation {
        display: flex;
        gap: 0.7rem;
        margin-top: 1rem;
        overflow-x: auto;
        padding-bottom: 0.25rem;
    }

    .nav-section {
        flex: 0 0 auto;
    }

    .nav-label,
    .sidebar-footer {
        display: none;
    }

    .nav {
        display: flex;
    }

    .nav a {
        min-height: 2.5rem;
        white-space: nowrap;
    }

    .nav a.active::before {
        top: auto;
        right: 0.7rem;
        bottom: -0.3rem;
        left: 0.7rem;
        width: auto;
        height: 2px;
    }

    .main {
        padding: 0 1rem 1.25rem;
    }

    .topbar {
        min-height: auto;
        padding: 1.4rem 0;
    }
}

@media (max-width: 38rem) {
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        gap: 1rem;
    }

    .top-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .topbar-link {
        flex: 1;
    }

    .account-badge {
        flex: 1;
        justify-content: center;
    }

    .credential-row {
        align-items: stretch;
        flex-direction: column;
    }

    .stats,
    .info {
        grid-template-columns: 1fr;
    }

    .info-item--full {
        grid-column: auto;
    }

    .grid {
        grid-template-columns: 1fr;
    }

    .card {
        padding: 1rem;
    }

    .card-header {
        align-items: flex-start;
    }

    .actions,
    .actions form,
    .actions button,
    .actions .button-link {
        width: 100%;
    }

    .footer {
        flex-direction: column;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
    }
}
