:root {
    --bg: #f6f5f0;
    --panel: #ffffff;
    --ink: #1d2525;
    --muted: #65716f;
    --line: #d8ded8;
    --brand: #0d5c63;
    --brand-ink: #effaf8;
    --accent: #d88a35;
    --danger: #a93434;
    --danger-bg: #fff1f1;
    --ok: #15724f;
    --shadow: 0 18px 55px rgba(25, 43, 42, 0.12);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html {
    color-scheme: light;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--bg);
    color: var(--ink);
    font-family: "Aptos", "Segoe UI", sans-serif;
    letter-spacing: 0;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

button,
.btn,
.nav-item,
input,
select,
textarea {
    transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, box-shadow 160ms ease, transform 160ms ease, opacity 160ms ease;
}

.login-body {
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(135deg, rgba(13, 92, 99, 0.14), rgba(216, 138, 53, 0.16)),
        var(--bg);
}

.login-shell {
    width: min(100%, 440px);
}

.login-panel,
.panel,
.metric,
.dialog-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.login-panel {
    padding: 32px;
}

.brand-row {
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    background: var(--brand);
    color: var(--brand-ink);
    font-weight: 800;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--accent);
    font-size: 0.76rem;
    font-weight: 800;
    text-transform: uppercase;
}

h1,
h2 {
    margin: 0;
    line-height: 1.05;
}

h1 {
    font-size: clamp(1.9rem, 3vw, 3rem);
}

h2 {
    font-size: 1.25rem;
}

p {
    color: var(--muted);
    line-height: 1.55;
}

.stack-form {
    display: grid;
    gap: 16px;
    margin-top: 28px;
}

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

label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffdf8;
    color: var(--ink);
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
    outline: 3px solid rgba(13, 92, 99, 0.24);
    outline-offset: 2px;
}

.check-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.check-row input {
    width: 18px;
    min-height: 18px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 14px;
    border: 1px solid transparent;
    border-radius: 8px;
    font-weight: 800;
    text-decoration: none;
}

.btn:hover,
.nav-item:hover {
    transform: translateY(-1px);
}

.btn:active,
.nav-item:active {
    transform: translateY(0);
}

.btn:disabled,
.btn[data-busy="1"] {
    cursor: wait;
    opacity: 0.68;
}

.btn-primary {
    background: var(--brand);
    color: var(--brand-ink);
}

.btn-light {
    background: #fffdf8;
    border-color: var(--line);
    color: var(--ink);
}

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

.btn-danger {
    background: var(--danger-bg);
    border-color: #efb7b7;
    color: var(--danger);
}

.btn-small {
    min-height: 34px;
    padding: 7px 10px;
    font-size: 0.86rem;
}

.alert {
    margin-top: 22px;
    padding: 12px 14px;
    border-radius: 8px;
    font-weight: 700;
}

.alert-error {
    background: var(--danger-bg);
    color: var(--danger);
}

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

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    padding: 22px;
    border-right: 1px solid var(--line);
    background: #fbfaf6;
}

.sidebar-brand {
    margin-bottom: 28px;
}

.nav-list {
    display: grid;
    gap: 8px;
}

.nav-item {
    min-height: 42px;
    padding: 10px 12px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    text-align: left;
    font-weight: 800;
}

.nav-item.is-active,
.nav-item:hover {
    border-color: var(--line);
    background: #ffffff;
    color: var(--ink);
}

.logout-form {
    position: absolute;
    right: 22px;
    bottom: 22px;
    left: 22px;
}

.logout-form .btn {
    width: 100%;
}

.main-panel {
    min-width: 0;
    padding: 28px;
}

.topbar,
.topbar-actions,
.section-head,
.toolbar,
.inline-form {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.topbar-actions {
    justify-content: flex-end;
}

.topbar {
    margin-bottom: 22px;
}

.admin-chip {
    display: grid;
    gap: 3px;
    min-width: 160px;
    padding: 11px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffdf8;
}

.admin-chip small,
.muted {
    color: var(--muted);
}

.metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.metric {
    padding: 18px;
}

.metric span {
    display: block;
    color: var(--muted);
    font-weight: 800;
}

.metric strong {
    display: block;
    margin-top: 8px;
    font-size: 1.8rem;
}

.view {
    display: none;
}

.view.is-active {
    display: block;
    animation: view-in 180ms ease-out;
}

@keyframes view-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section-head {
    margin: 4px 0 16px;
}

.section-head p {
    margin: 7px 0 0;
}

.section-head.compact {
    align-items: flex-start;
}

.toolbar {
    justify-content: flex-start;
    margin-bottom: 12px;
}

.toolbar input {
    max-width: 360px;
}

.table-wrap {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

table {
    width: 100%;
    min-width: 760px;
    border-collapse: collapse;
}

th,
td {
    padding: 13px 14px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-size: 0.8rem;
    text-transform: uppercase;
}

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

.right {
    text-align: right;
}

.action-row {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.status {
    display: inline-flex;
    align-items: center;
    min-height: 26px;
    padding: 3px 9px;
    border-radius: 999px;
    border: 1px solid var(--line);
    font-weight: 800;
    font-size: 0.82rem;
}

.status-ok {
    color: var(--ok);
    background: #ecfff7;
    border-color: #b7e5d0;
}

.status-danger {
    color: var(--danger);
    background: var(--danger-bg);
    border-color: #efb7b7;
}

.split-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.panel {
    padding: 18px;
}

.list-stack {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.list-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffdf8;
}

.code-box {
    overflow: auto;
    max-height: 420px;
    padding: 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #151d1d;
    color: #eef7f5;
    font-size: 0.86rem;
    white-space: pre-wrap;
}

.inline-form {
    justify-content: flex-start;
    margin-bottom: 14px;
}

.inline-form input {
    max-width: 320px;
}

.toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 20;
    display: none;
    max-width: 360px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #ffffff;
    box-shadow: var(--shadow);
    font-weight: 800;
}

.toast.is-visible {
    display: block;
    animation: toast-in 180ms ease-out;
}

@keyframes toast-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal {
    width: min(94vw, 520px);
    padding: 0;
    border: 0;
    background: transparent;
}

.modal::backdrop {
    background: rgba(17, 24, 24, 0.44);
}

.dialog-card {
    position: relative;
    display: grid;
    gap: 14px;
    padding: 22px;
    animation: dialog-in 180ms ease-out;
}

@keyframes dialog-in {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.password-tools {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
}

.dialog-card h2 {
    margin-bottom: 4px;
}

.dialog-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 34px;
    height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fffdf8;
    color: var(--ink);
}

@media (max-width: 920px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        height: auto;
        padding: 16px;
    }

    .nav-list {
        display: flex;
        overflow-x: auto;
        padding-bottom: 4px;
    }

    .nav-item {
        flex: 0 0 auto;
    }

    .logout-form {
        position: static;
        margin-top: 14px;
    }

    .main-panel {
        padding: 18px;
    }

    .topbar,
    .topbar-actions,
    .section-head,
    .toolbar,
    .inline-form {
        align-items: stretch;
        flex-direction: column;
    }

    .metrics,
    .split-grid {
        grid-template-columns: 1fr;
    }

    .admin-chip,
    .topbar-actions .btn,
    .toolbar input,
    .inline-form input {
        max-width: none;
        width: 100%;
    }

    .password-tools {
        grid-template-columns: 1fr 1fr;
    }

    .password-tools input {
        grid-column: 1 / -1;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 1ms !important;
        scroll-behavior: auto !important;
        transition-duration: 1ms !important;
    }
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #111817;
        --panel: #182321;
        --ink: #eef5f2;
        --muted: #c2cfca;
        --line: #465854;
        --brand: #4eb3aa;
        --brand-ink: #061211;
        --accent: #f0aa5d;
        --danger: #ff9a9a;
        --danger-bg: #391c1e;
        --ok: #78e2b3;
        --shadow: 0 18px 55px rgba(0, 0, 0, 0.24);
    }

    body,
    p,
    label,
    th,
    td,
    .metric span,
    .admin-chip small,
    .muted {
        color: var(--ink);
    }

    p,
    label,
    th,
    .metric span,
    .admin-chip small,
    .muted {
        color: var(--muted);
    }

    input,
    select,
    textarea,
    .admin-chip,
    .nav-item.is-active,
    .nav-item:hover,
    .table-wrap,
    .btn-light,
    .dialog-close,
    .list-item {
        background: #111817;
        color: var(--ink);
    }

    input::placeholder,
    textarea::placeholder {
        color: #8fa09a;
    }

    .btn-ghost {
        color: var(--ink);
    }

    .btn-danger {
        color: var(--danger);
        background: #351d20;
        border-color: #7a3b3f;
    }

    .status-ok {
        color: var(--ok);
        background: #102720;
        border-color: #2f795c;
    }

    .status-danger {
        color: var(--danger);
        background: #351d20;
        border-color: #7a3b3f;
    }

    .toast,
    .login-panel,
    .panel,
    .metric,
    .dialog-card {
        background: var(--panel);
        color: var(--ink);
    }

    .sidebar {
        background: #131c1a;
    }
}
