/* ===== Токены ===== */
:root {
    --bg: #f6f7f9;
    --surface: #ffffff;
    --surface-2: #f1f3f6;
    --border: #e3e6eb;
    --text: #151821;
    --muted: #697084;
    --accent: #7c3aed;
    --accent-strong: #6d28d9;
    --accent-soft: #f1eafe;
    --on-accent: #ffffff;
    --success: #0f7b4b;
    --success-soft: #e6f6ee;
    --danger: #c2261d;
    --danger-soft: #fdecea;
    --info: #1f5fbf;
    --info-soft: #e8f0fc;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 4px 16px rgba(16, 24, 40, .06);
    --sidebar-w: 248px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1116;
        --surface: #171a21;
        --surface-2: #1e222b;
        --border: #2a2f3a;
        --text: #e8eaf0;
        --muted: #9aa1b2;
        --accent: #a78bfa;
        --accent-strong: #c4b5fd;
        --accent-soft: #2a2240;
        --on-accent: #14101f;
        --success: #4ade80;
        --success-soft: #13291d;
        --danger: #f87171;
        --danger-soft: #2f1717;
        --info: #7cb0ff;
        --info-soft: #152238;
        --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
        color-scheme: dark;
    }
}

/* ===== База ===== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
h1 { font-size: 24px; line-height: 1.25; margin: 0 0 8px; letter-spacing: -.01em; }
h2 { font-size: 17px; line-height: 1.3; margin: 0 0 8px; }
p { margin: 0 0 12px; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font: 14px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
em.muted { font-style: normal; font-weight: 400; }

.icon {
    width: 20px; height: 20px; flex: none;
    fill: none; stroke: currentColor; stroke-width: 1.8;
    stroke-linecap: round; stroke-linejoin: round;
}

/* ===== Кнопки и формы ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 44px; padding: 0 18px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text);
    font: inherit; font-weight: 600; cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-block { width: 100%; }
.btn:focus-visible, input:focus-visible, .nav-item:focus-visible, summary:focus-visible {
    outline: 2px solid var(--accent); outline-offset: 2px;
}

.form { display: grid; gap: 14px; margin-top: 16px; }
.field { display: grid; gap: 6px; }
.field > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.field input {
    width: 100%; min-height: 44px; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text); font: inherit;
}
.field input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.code-input { font: 600 24px/1 ui-monospace, SFMono-Regular, Menlo, monospace !important; letter-spacing: .25em; text-align: center; }

.alert { padding: 10px 14px; border-radius: var(--radius-sm); margin: 0 0 14px; font-size: 14px; }
.alert-error { background: var(--danger-soft); color: var(--danger); }
.alert-success { background: var(--success-soft); color: var(--success); }
.alert-info { background: var(--info-soft); color: var(--info); }

/* ===== Страницы входа ===== */
body.auth {
    min-height: 100vh; display: grid; place-items: center;
    padding: 24px 16px;
}
.auth-card {
    width: 100%; max-width: 420px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 28px 24px;
}
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; margin-bottom: 20px; }
.brand-mark {
    display: inline-grid; place-items: center;
    width: 28px; height: 28px; border-radius: 8px;
    background: var(--accent); color: var(--on-accent);
    font-weight: 800; font-size: 15px;
}
.steps { padding-left: 20px; margin: 12px 0 16px; display: grid; gap: 6px; }
.qr {
    display: grid; place-items: center;
    width: 240px; height: 240px; margin: 0 auto 12px;
    padding: 18px; background: #fff; border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}
.qr svg { width: 100%; height: 100%; display: block; }
.manual-key { margin: 0 0 4px; font-size: 14px; }
.manual-key summary { cursor: pointer; color: var(--accent); margin-bottom: 8px; }
.secret {
    display: block; padding: 10px 12px; margin: 0 0 8px;
    background: var(--surface-2); border-radius: var(--radius-sm);
    word-break: break-all; letter-spacing: .04em;
}

/* ===== Админка ===== */
.topbar { display: none; }
.sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
    display: flex; flex-direction: column; gap: 8px;
    padding: 16px 12px;
    background: var(--surface); border-right: 1px solid var(--border);
    z-index: 30;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; padding: 4px 10px 14px; }
.nav { display: grid; gap: 2px; }
.nav-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%; min-height: 40px; padding: 8px 10px;
    border-radius: var(--radius-sm); border: 0; background: none;
    color: var(--text); font: inherit; text-align: left; cursor: pointer;
    text-decoration: none;
}
.nav-item:hover { background: var(--surface-2); text-decoration: none; }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.is-disabled { color: var(--muted); cursor: default; }
.nav-item.is-disabled:hover { background: none; }
.badge {
    margin-left: auto; padding: 1px 8px; border-radius: 999px;
    background: var(--surface-2); color: var(--muted);
    font-size: 11px; font-weight: 600;
}
.sidebar-foot { margin-top: auto; display: grid; gap: 2px; border-top: 1px solid var(--border); padding-top: 10px; }
.sidebar-foot form { margin: 0; }
.backdrop { display: none; }

.main { margin-left: var(--sidebar-w); padding: 28px 32px 48px; max-width: 1280px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow);
    padding: 20px; margin-bottom: 16px;
}
.card.narrow { max-width: 520px; }
.card.empty { text-align: center; padding: 48px 20px; }
.empty-icon {
    width: 44px; height: 44px; margin-bottom: 12px;
    fill: none; stroke: var(--accent); stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round;
}

/* ===== Телефон ===== */
@media (max-width: 860px) {
    .topbar {
        position: sticky; top: 0; z-index: 20;
        display: flex; align-items: center; gap: 10px;
        height: 56px; padding: 0 12px;
        background: var(--surface); border-bottom: 1px solid var(--border);
    }
    .topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; }
    .menu-toggle {
        display: grid; place-items: center; width: 44px; height: 44px;
        border: 0; background: none; color: var(--text); cursor: pointer; border-radius: var(--radius-sm);
    }
    .sidebar { transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow); }
    .sidebar-brand { display: none; }
    body.menu-open .sidebar { transform: none; }
    body.menu-open .backdrop { display: block; position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 25; }
    .main { margin-left: 0; padding: 18px 16px 40px; }
    h1 { font-size: 21px; }
}

@media (prefers-reduced-motion: reduce) {
    .sidebar { transition: none; }
}
