:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --surface-2: #f0f2f5;
    --border: #e2e5ea;
    --text: #17202b;
    --muted: #667085;
    --primary: #1f5eff;
    --primary-text: #ffffff;
    --danger: #d92d20;
    --ok-bg: #e7f6ec; --ok-text: #157f3b;
    --warn-bg: #fff4e0; --warn-text: #9a5b00;
    --err-bg: #fdecea; --err-text: #a3261b;
    --radius: 12px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
    color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1318;
        --surface: #171c23;
        --surface-2: #1f262f;
        --border: #2a323d;
        --text: #e7ebf0;
        --muted: #98a2b3;
        --primary: #5b8cff;
        --ok-bg: #12301f; --ok-text: #6fd492;
        --warn-bg: #36280e; --warn-text: #f5c26b;
        --err-bg: #3a1714; --err-text: #ff9b91;
        --shadow: none;
    }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0; background: var(--bg); color: var(--text);
    font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 1.6rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.1rem; margin: 0 0 12px; }
code { font: .9em ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-2); padding: 1px 5px; border-radius: 4px; word-break: break-all; }
.icon { width: 18px; height: 18px; flex: none; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.mt { margin-top: 12px; }
.right { text-align: right; }

/* Topbar */
.topbar {
    position: sticky; top: 0; z-index: 10;
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-right form { margin: 0; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; color: var(--text); }
.brand-lg { font-size: 1.3rem; justify-content: center; margin-bottom: 20px; }
.brand-mark {
    display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 8px;
    background: var(--primary); color: var(--primary-text); font-size: .95rem;
}
.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px 48px; }
.page-head { margin-bottom: 20px; }
.page-head p { margin: 4px 0 0; }
.back { display: inline-flex; align-items: center; gap: 2px; font-size: .9rem; margin-bottom: 6px; }

/* Tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; }
.tile {
    display: flex; flex-direction: column; gap: 6px; padding: 18px;
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); color: var(--text); transition: border-color .15s, transform .15s;
}
a.tile:hover { border-color: var(--primary); transform: translateY(-1px); }
.tile-icon {
    display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px;
    background: var(--surface-2); color: var(--primary); margin-bottom: 4px;
}
.tile-icon .icon { width: 22px; height: 22px; }
.tile-name { font-weight: 600; font-size: 1.05rem; display: flex; align-items: center; gap: 8px; }
.tile-desc { color: var(--muted); font-size: .9rem; }
.tile-disabled { opacity: .6; }

/* Module layout */
.module { display: grid; grid-template-columns: 220px 1fr; gap: 20px; align-items: start; }
.subnav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: 72px; }
.subnav a {
    display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--text);
}
.subnav a:hover { background: var(--surface-2); }
.subnav a.active { background: var(--surface); box-shadow: var(--shadow); color: var(--primary); font-weight: 600; }
.module-body { min-width: 0; }
@media (max-width: 760px) {
    .module { grid-template-columns: 1fr; }
    .subnav { position: static; flex-direction: row; overflow-x: auto; gap: 6px; padding-bottom: 4px; }
    .subnav a { white-space: nowrap; background: var(--surface); border: 1px solid var(--border); }
    .hide-sm { display: none; }
}

/* Cards, forms */
.card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 20px; margin-bottom: 16px; overflow-x: auto;
}
.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row form { margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: end; }
.grid-2 .span-2 { grid-column: 1 / -1; }
@media (max-width: 600px) { .grid-2 { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 5px; font-size: .9rem; font-weight: 500; }
input[type=text], input[type=email], input[type=password], input[type=url], input:not([type]), textarea, select {
    width: 100%; font: inherit; color: var(--text); background: var(--surface);
    border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-weight: 400;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: transparent; }
.row input { width: auto; flex: 1 1 200px; }
.input-code { max-width: 160px; letter-spacing: .2em; font-variant-numeric: tabular-nums; }
.check { display: flex; align-items: center; gap: 8px; font-size: .9rem; }

/* Buttons */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    font: inherit; font-weight: 600; padding: 9px 16px; border-radius: 8px; cursor: pointer;
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }
.btn-primary:hover { background: var(--primary); filter: brightness(1.08); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 6px 10px; font-size: .85rem; }
.btn-block { width: 100%; padding: 11px; }

/* Feedback */
.alert { display: block; padding: 12px 14px; border-radius: 10px; margin-bottom: 16px; font-size: .92rem; }
.alert-success { background: var(--ok-bg); color: var(--ok-text); }
.alert-error { background: var(--err-bg); color: var(--err-text); }
.alert-warn { background: var(--warn-bg); color: var(--warn-text); }
.badge { display: inline-block; font-size: .75rem; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: var(--surface-2); color: var(--muted); }
.badge-ok { background: var(--ok-bg); color: var(--ok-text); }
.badge-warn { background: var(--warn-bg); color: var(--warn-text); }

/* Tables, lists */
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.table th, .table td { padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table form { margin: 0; }
.row-warn td { color: var(--warn-text); }
.item { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.item summary { cursor: pointer; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.codes { columns: 2; list-style: none; padding: 12px; background: var(--surface-2); border-radius: 8px; font-family: ui-monospace, Menlo, monospace; }
.qr { background: #fff; display: inline-block; padding: 12px; border-radius: 8px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 8px 24px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
nav[role=navigation] { margin-top: 12px; }
nav[role=navigation] ul { display: flex; gap: 8px; list-style: none; padding: 0; }

/* Guest */
body.guest { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card {
    width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
    border-radius: 16px; padding: 28px; box-shadow: var(--shadow);
}
.auth-card details summary { cursor: pointer; font-size: .9rem; }
