/* ==========================================================================
   Семейный бюджет — современная адаптивная тема (светлая/тёмная)
   ========================================================================== */

:root {
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .06);
    --shadow-lg: 0 12px 32px -8px rgba(16, 24, 40, .18);
    --transition: .18s ease;

    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e4e9f2;
    --text: #101828;
    --text-2: #475467;
    --text-3: #98a2b3;

    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-soft: #eef2ff;
    --income: #12b76a;
    --income-soft: #d1fadf;
    --expense: #f04438;
    --expense-soft: #fee4e2;
    --warning: #f79009;
    --warning-soft: #fef0c7;
    --danger: #d92d20;
    --sidebar-bg: #101828;
    --sidebar-text: #d0d5dd;
    /* Тёмные оттенки для текста на светлых плашках (контраст ≥ 4.5:1) */
    --success-ink: #067647;
    --danger-ink: #b42318;
    --warning-ink: #93370d;
}

[data-theme="dark"] {
    --bg: #0b1220;
    --surface: #131c2e;
    --surface-2: #1a2438;
    --border: #26334d;
    --text: #f2f4f7;
    --text-2: #b6c0d1;
    --text-3: #6b7a94;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --primary-soft: #232a4a;
    --income-soft: #06392b;
    --expense-soft: #4a1d1d;
    --warning-soft: #4a3208;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
    --shadow-lg: 0 16px 40px -8px rgba(0, 0, 0, .55);
    --sidebar-bg: #0d1526;
    --sidebar-text: #b6c0d1;
    --success-ink: #75e0a7;
    --danger-ink: #fda29b;
    --warning-ink: #fedf89;
}

* { box-sizing: border-box; }

html { scroll-padding-top: 84px; }
@media (prefers-reduced-motion: no-preference) { html { scroll-behavior: smooth; } }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

/* ---------- Каркас ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 264px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 40;
    transition: transform var(--transition);
}
.sidebar__brand {
    display: flex; align-items: center; gap: 10px;
    padding: 20px 22px; font-weight: 800; font-size: 17px; color: #fff;
}
.sidebar__logo { font-size: 24px; }
.sidebar__nav { padding: 8px 12px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-link {
    display: flex; align-items: center; gap: 12px;
    padding: 11px 14px; border-radius: var(--radius-sm);
    color: var(--sidebar-text); text-decoration: none; font-weight: 500;
    transition: background var(--transition), color var(--transition);
}
.nav-link:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-link--active { background: var(--primary); color: #fff; }
.nav-link__icon { font-size: 17px; }
.sidebar__footer { padding: 16px; border-top: 1px solid rgba(255, 255, 255, .08); }
.sidebar__user { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.sidebar__avatar {
    width: 38px; height: 38px; border-radius: 50%;
    background: var(--primary); color: #fff;
    display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.sidebar__user-name { font-weight: 600; color: #fff; font-size: 14px; }
.sidebar__user-role { font-size: 12px; color: var(--text-3); }
.btn.sidebar__logout {
    background: rgba(255, 255, 255, .06); color: var(--sidebar-text);
    border: 1px solid rgba(255, 255, 255, .14);
}
.btn.sidebar__logout:hover { background: rgba(255, 255, 255, .12); color: #fff; }
.sidebar-backdrop {
    display: none; position: fixed; inset: 0; z-index: 35;
    background: rgba(16, 24, 40, .5); backdrop-filter: blur(2px);
}

.main { flex: 1; margin-left: 264px; min-width: 0; display: flex; flex-direction: column; }
.main--full { margin-left: 0; }
/* Страница входа — во всю ширину, без отступов контента */
.main--full .content { padding: 0; max-width: none; }

.topbar {
    position: sticky; top: 0; z-index: 30;
    display: flex; align-items: center; gap: 14px;
    padding: 14px 24px;
    background: color-mix(in srgb, var(--surface) 85%, transparent);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
}
.topbar__burger {
    display: none; border: none; background: var(--surface-2); color: var(--text);
    width: 40px; height: 40px; border-radius: var(--radius-sm); font-size: 18px; cursor: pointer;
}
.topbar__title { font-size: 18px; font-weight: 700; flex: 1; }
.theme-toggle {
    border: 1px solid var(--border); background: var(--surface); color: var(--text);
    width: 40px; height: 40px; border-radius: 50%; cursor: pointer; font-size: 17px;
    transition: transform var(--transition);
}
.theme-toggle:hover { transform: rotate(20deg); }

.content { padding: 24px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* ---------- Кнопки ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 7px;
    border: 1px solid transparent; border-radius: var(--radius-sm);
    padding: 9px 16px; font: inherit; font-weight: 600; font-size: 14px;
    cursor: pointer; text-decoration: none; color: var(--text);
    background: var(--surface-2); transition: all var(--transition); white-space: nowrap;
}
.btn:hover { filter: brightness(.97); }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-hover); }
.btn--ghost { background: transparent; border-color: var(--border); }
.btn--danger { background: var(--expense-soft); color: var(--danger); }
.btn--warning { background: var(--warning-soft); color: var(--warning); }
.btn--success { background: var(--income-soft); color: var(--income); }
.btn--light { background: rgba(255, 255, 255, .2); color: #fff; }
.btn--sm { padding: 6px 11px; font-size: 13px; }
.btn--lg { padding: 13px 20px; font-size: 15px; }
.btn--block { width: 100%; }

/* ---------- Карточки ---------- */
.card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 22px;
    overflow: hidden;
}
.card__header {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.card__header--wrap { flex-wrap: wrap; }
.card__title { margin: 0; font-size: 16px; font-weight: 700; }
.card__header .badge { flex-shrink: 0; white-space: nowrap; }
.card__body { padding: 20px 22px; }

/* 6-колоночная сетка: остаток и «можно тратить» — по половине ряда,
   три остальные карточки — по трети. На широком экране — все 5 в ряд. */
.stats-grid {
    display: grid; grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 16px; margin-bottom: 22px;
}
.stats-grid > .stat-card { grid-column: span 2; order: 3; min-width: 0; }
.stats-grid > .stat-card--balance { grid-column: span 3; order: 1; }
.stats-grid > .stat-card--safe { grid-column: span 3; order: 2; }
@media (min-width: 1360px) {
    .stats-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); }
    .stats-grid > .stat-card,
    .stats-grid > .stat-card--balance,
    .stats-grid > .stat-card--safe { grid-column: auto; order: 0; }
    .stats-grid .stat-card__value { font-size: 23px; }
}
.stat-card {
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 6px;
}
.stat-card--balance {
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    color: #fff; border: none;
}
.stat-card--balance .stat-card__label { color: rgba(255, 255, 255, .8); }
.stat-card--safe {
    background: linear-gradient(135deg, #059669, #10b981);
    color: #fff; border: none;
}
.stat-card--safe .stat-card__label { color: rgba(255, 255, 255, .85); }
.stat-card--safe .stat-card__hint { color: rgba(255, 255, 255, .85); }
.stat-card--safe.stat-card--danger { background: linear-gradient(135deg, #d92d20, #f04438); }
.stat-card__label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.stat-card__value { font-size: 26px; font-weight: 800; letter-spacing: -.5px; overflow-wrap: anywhere; }
.stat-card__value--income { color: var(--income); }
.stat-card__value--expense { color: var(--expense); }
.stat-card__hint { font-size: 12px; color: var(--text-3); }
.stat-card .btn { align-self: flex-start; margin-top: 6px; }

/* ---------- Ближайшие платежи ---------- */
.upcoming-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.upcoming-item {
    display: flex; align-items: center; gap: 14px;
    padding: 12px 8px; border-bottom: 1px solid var(--border);
}
.upcoming-item:last-child { border-bottom: none; }
.upcoming-item--today { background: var(--primary-soft); border-radius: var(--radius-sm); }
.upcoming-item__date {
    width: 52px; height: 52px; flex-shrink: 0;
    background: var(--surface-2); border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.upcoming-item__day { font-size: 19px; font-weight: 800; line-height: 1; }
.upcoming-item__month { font-size: 11px; color: var(--text-3); }
.upcoming-item__info { flex: 1; min-width: 0; }
.upcoming-item__title { font-weight: 600; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.upcoming-item__category { font-size: 12px; color: var(--text-3); }
.upcoming-item__amount { font-weight: 700; font-size: 15px; white-space: nowrap; }
.upcoming-item__amount--income { color: var(--income); }
.upcoming-item__amount--expense { color: var(--expense); }
.upcoming-item--extra { display: none; }
.upcoming-list--expanded .upcoming-item--extra { display: flex; }
.upcoming-more { margin-top: 12px; }

/* ---------- Бейджи ---------- */
.badge {
    display: inline-flex; align-items: center; padding: 3px 10px;
    border-radius: 999px; font-size: 12px; font-weight: 600;
    background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
}
.badge--today { background: var(--primary); color: #fff; border: none; }
.badge--on { background: var(--income-soft); color: var(--income); border: none; }
.badge--off { background: var(--expense-soft); color: var(--danger); border: none; }
.badge--admin { background: var(--primary-soft); color: var(--primary); border: none; }

/* ---------- Таблицы ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
    text-align: left; padding: 10px 12px; font-size: 12px; text-transform: uppercase;
    letter-spacing: .4px; color: var(--text-3); border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.table td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tr:last-child td { border-bottom: none; }
.table .num { text-align: right; white-space: nowrap; }
.table__loading { text-align: center; color: var(--text-3); padding: 24px !important; }
.table tbody tr { transition: background var(--transition); }
.table tbody tr:hover { background: var(--surface-2); }
.row--today { background: var(--primary-soft) !important; }
.row--snapshot { background: var(--warning-soft) !important; }
.row--snapshot .balance-badge--manual { background: var(--warning-soft); color: var(--warning); }
.row--negative td:last-child { color: var(--expense); font-weight: 700; }

/* ---------- Предупреждения ---------- */
.alert {
    padding: 10px 13px; border-radius: var(--radius-sm);
    font-size: 13px; font-weight: 500; margin-top: 8px;
    border: 1px solid transparent;
}
.alert--warning {
    background: var(--warning-soft); color: var(--warning-ink);
    border-color: color-mix(in srgb, var(--warning) 30%, transparent);
}
.alert--success {
    background: var(--income-soft); color: var(--success-ink);
    border-color: color-mix(in srgb, var(--income) 30%, transparent);
}

/* ---------- Настройки уведомлений ---------- */
.notify-types { display: flex; flex-direction: column; gap: 8px; }
.notify-option {
    display: flex; align-items: center; justify-content: space-between;
    gap: 8px 16px; flex-wrap: wrap;
    padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--surface-2);
}
.notify-option .form-check { margin: 0; flex: 1 1 220px; }
.notify-option__param {
    display: flex; align-items: center; gap: 8px;
    font-size: 14px; color: var(--text-2); white-space: nowrap;
}

/* ---------- Бейджи источника остатка ---------- */
.balance-badge {
    display: inline-flex; align-items: center; gap: 3px;
    font-size: 11px; font-weight: 600; padding: 1px 8px;
    border-radius: 999px; margin-top: 3px;
}
.balance-badge--auto { background: var(--primary-soft); color: var(--primary); }
.balance-badge--manual { background: var(--warning-soft); color: var(--warning); }
.row--muted { opacity: .55; }
.table-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.inline-form { display: inline; }
.cell-in { color: var(--income); font-weight: 600; }
.cell-out { color: var(--expense); font-weight: 600; }
.cell-ops { font-size: 12.5px; color: var(--text-2); }
.cell-ops div { padding: 1px 0; }

.user-cell { display: flex; align-items: center; gap: 10px; }
.user-cell__avatar {
    width: 32px; height: 32px; border-radius: 50%; background: var(--primary-soft);
    color: var(--primary); display: flex; align-items: center; justify-content: center; font-weight: 700;
}

/* ---------- Формы ---------- */
.form-group { margin-bottom: 16px; }
.form-group--grow { flex: 1; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row .form-group { flex: 1; min-width: 150px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-2); }
.form-label--inline { margin: 0; align-self: center; }
.form-input, .form-select {
    width: 100%; padding: 10px 13px; font: inherit; font-size: 14px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--text);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-input:focus, .form-select:focus {
    outline: none; border-color: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 18%, transparent);
}
/* Компактные поля (селектор с двумя классами — сильнее, чем .form-input { width: 100% }) */
.form-input.form-input--xs { width: 76px; padding: 7px 9px; }
.form-select.form-select--xs { width: auto; padding: 7px 9px; }
.form-hint { display: block; font-size: 12px; color: var(--text-3); margin-top: 5px; }
.form-check { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; margin-bottom: 14px; }
.form-check input { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; }
.form-error { color: var(--danger); font-size: 13px; font-weight: 600; min-height: 18px; }
.radio-row { display: flex; gap: 18px; flex-wrap: wrap; }
.radio-row .form-check { margin-bottom: 0; }

/* ---------- Конструктор повторений ---------- */
.recurrence-builder {
    border: 1px dashed var(--border); border-radius: var(--radius);
    padding: 16px; margin: 0 0 16px;
}
.recurrence-builder legend { font-weight: 700; font-size: 13px; padding: 0 8px; color: var(--text-2); }
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
    border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
    border-radius: 999px; padding: 7px 14px; font: inherit; font-size: 13px; font-weight: 600;
    cursor: pointer; transition: all var(--transition);
}
.chip--active { background: var(--primary); border-color: var(--primary); color: #fff; }
.recurrence-preview {
    margin-top: 10px; padding: 10px 14px; border-radius: var(--radius-sm);
    background: var(--primary-soft); color: var(--primary);
    font-size: 13px; font-weight: 600; min-height: 20px;
}

/* ---------- Итоги и вкладки операций ---------- */
.ops-summary {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 14px; margin-bottom: 18px;
}
.ops-summary__card {
    display: flex; align-items: center; gap: 14px;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.ops-summary__icon {
    width: 44px; height: 44px; border-radius: 12px; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; font-weight: 800;
}
.ops-summary__card--income .ops-summary__icon { background: var(--income-soft); color: var(--income); }
.ops-summary__card--expense .ops-summary__icon { background: var(--expense-soft); color: var(--expense); }
.ops-summary__card--net .ops-summary__icon { background: var(--primary-soft); color: var(--primary); }
.ops-summary__label { font-size: 12.5px; color: var(--text-2); font-weight: 500; }
.ops-summary__value { font-size: 20px; font-weight: 800; letter-spacing: -.3px; }
.ops-summary__value--pos { color: var(--income); }
.ops-summary__value--neg { color: var(--expense); }

.ops-tabs {
    display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 6px; box-shadow: var(--shadow);
    width: fit-content; max-width: 100%;
}
.ops-tab {
    border: none; background: transparent; color: var(--text-2);
    padding: 8px 16px; border-radius: var(--radius-sm);
    font: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
    display: inline-flex; align-items: center; gap: 7px;
    transition: all var(--transition); white-space: nowrap;
}
.ops-tab:hover { background: var(--surface-2); color: var(--text); }
.ops-tab--active { background: var(--primary); color: #fff; }
.ops-tab--active .ops-tab__count { background: rgba(255, 255, 255, .25); color: #fff; }
.ops-tab--income.ops-tab--active { background: var(--income); }
.ops-tab--expense.ops-tab--active { background: var(--expense); }
.ops-tab__count {
    background: var(--surface-2); color: var(--text-3);
    border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 700;
}

/* ---------- Карточки операций ---------- */
.ops-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.op-card {
    background: var(--surface); border: 1px solid var(--border);
    border-left: 4px solid var(--expense);
    border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow);
    display: flex; flex-direction: column; gap: 8px;
}
.op-card--income { border-left-color: var(--income); }
.op-card--disabled { opacity: .6; }
.op-card__head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.op-card__kind-badge {
    font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
    padding: 3px 10px; border-radius: 999px;
}
.op-card__kind-badge--income { background: var(--income-soft); color: var(--income); }
.op-card__kind-badge--expense { background: var(--expense-soft); color: var(--expense); }
.op-card__category { font-size: 12px; color: var(--text-3); }
.op-card__title { margin: 0; font-size: 16px; }
.op-card__amount { font-size: 22px; font-weight: 800; }
.op-card--income .op-card__amount { color: var(--income); }
.op-card--expense .op-card__amount { color: var(--expense); }
.op-card__schedule { font-size: 13px; color: var(--text-2); }
.op-card__next {
    display: flex; align-items: center; gap: 8px;
    font-size: 13px; color: var(--text-2);
    background: var(--surface-2); border-radius: var(--radius-sm);
    padding: 7px 11px; width: fit-content;
}
.op-card__next-date { font-weight: 700; color: var(--primary); }
.op-card__next-label { color: var(--text-3); font-size: 12px; }
.op-card__next--none { background: transparent; padding: 0; color: var(--text-3); }
.op-card__note { font-size: 12.5px; color: var(--text-3); font-style: italic; }
.op-card__actions { display: flex; gap: 6px; flex-wrap: nowrap; align-items: center; margin-top: auto; padding-top: 6px; }
.op-card__actions .btn--sm { padding: 6px 10px; }
.op-card__delete { margin-left: auto; }

/* ---------- Модальные окна ---------- */
.modal { display: none; position: fixed; inset: 0; z-index: 100; }
.modal--open { display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(16, 24, 40, .55); backdrop-filter: blur(3px); }
.modal__dialog {
    position: relative; background: var(--surface); border-radius: var(--radius);
    box-shadow: var(--shadow-lg); width: 100%; max-width: 480px;
    max-height: 92vh; overflow-y: auto; animation: modalIn .2s ease;
}
.modal--wide .modal__dialog { max-width: 640px; }
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(.98); } to { opacity: 1; transform: none; } }
.modal__header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 22px; border-bottom: 1px solid var(--border);
    position: sticky; top: 0; background: var(--surface); z-index: 1;
}
.modal__header h3 { margin: 0; font-size: 17px; }
.modal__close {
    border: none; background: var(--surface-2); color: var(--text-2);
    width: 32px; height: 32px; border-radius: 50%; font-size: 18px; cursor: pointer;
}
.modal__body { padding: 20px 22px; }
.modal__footer {
    display: flex; justify-content: flex-end; gap: 10px;
    padding: 16px 22px; border-top: 1px solid var(--border);
    position: sticky; bottom: 0; background: var(--surface);
}

/* ---------- Флэш-сообщения ---------- */
.flash-stack { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.flash {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 12px 16px; border-radius: var(--radius-sm); font-size: 14px; font-weight: 500;
    animation: modalIn .25s ease;
}
.flash--success { background: var(--income-soft); color: var(--success-ink); }
.flash--danger { background: var(--expense-soft); color: var(--danger-ink); }
.flash--warning { background: var(--warning-soft); color: var(--warning-ink); }
.flash--info { background: var(--primary-soft); color: var(--primary); }
.flash__close { border: none; background: none; font-size: 18px; cursor: pointer; color: inherit; opacity: .7; }

/* ---------- Пустые состояния ---------- */
.empty-state { text-align: center; padding: 32px 16px; color: var(--text-2); }
.empty-state--page { padding: 64px 16px; }
.empty-state__icon { font-size: 44px; margin-bottom: 10px; }
.empty-state h3 { margin: 0 0 6px; }

/* ---------- Страница входа ---------- */
.auth-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 50%, #2563eb 100%);
}
.auth-card {
    width: 100%; max-width: 400px; background: var(--surface);
    border-radius: 20px; padding: 36px 32px; box-shadow: var(--shadow-lg); text-align: center;
}
.auth-card__logo { font-size: 46px; }
.auth-card__title { margin: 8px 0 4px; font-size: 22px; }
.auth-card__subtitle { margin: 0 0 24px; color: var(--text-2); font-size: 14px; }
.auth-form { text-align: left; }
.auth-card__hint { margin: 18px 0 0; font-size: 13px; color: var(--text-3); }
.auth-card a { color: var(--primary); font-weight: 600; text-decoration: none; }
.auth-card a:hover { text-decoration: underline; }
.auth-card .btn--primary { color: #fff; text-decoration: none; }
.auth-card .flash-stack { margin: 0 0 16px; text-align: left; }
.auth-card .flash { animation: none; }
.auth-tip {
    margin: 0 0 16px; padding: 10px 13px; border-radius: var(--radius-sm);
    background: var(--surface-2); color: var(--text-2); font-size: 13px; text-align: left;
}
.form-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.form-label-row .form-label { margin-bottom: 6px; }
.form-label-row__link { font-size: 12.5px; }
.form-label__optional { font-weight: 500; color: var(--text-3); }
/* Поле-ловушка для ботов: убрано с экрана, но остаётся в разметке */
.hp-field {
    position: absolute !important; left: -10000px; top: auto;
    width: 1px; height: 1px; overflow: hidden;
}

/* ---------- Прочее ---------- */
.page-header {
    display: flex; align-items: flex-start; justify-content: space-between;
    gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.page-header__hint { margin: 0; color: var(--text-2); font-size: 14px; max-width: 640px; }
.forecast-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.forecast-controls .form-select { width: auto; }
.forecast-filter { margin: 0 0 8px; font-size: 13px; color: var(--text-2); }
.page-header__actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chart-wrap { margin-bottom: 18px; }

/* ---------- Аналитика ---------- */
.analytics-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 20px; align-items: start; }
.chart-wrap--pie { height: 260px; }
.table .category-item__dot {
    display: inline-block; width: 10px; height: 10px;
    margin-right: 8px; vertical-align: middle;
}
.settings-grid { display: flex; flex-direction: column; gap: 20px; max-width: 760px; }
.profile-row { display: flex; align-items: center; gap: 14px; }
.profile-row__avatar {
    width: 52px; height: 52px; border-radius: 50%; background: var(--primary);
    color: #fff; display: flex; align-items: center; justify-content: center;
    font-size: 22px; font-weight: 800;
}
.profile-row__name { font-weight: 700; font-size: 16px; }
.profile-row__meta { font-size: 13px; color: var(--text-2); }
code { background: var(--surface-2); padding: 2px 7px; border-radius: 6px; font-size: 13px; }

/* ---------- Категории ---------- */
.category-list { display: flex; flex-direction: column; gap: 8px; }
.category-item {
    display: flex; align-items: center; gap: 12px;
    padding: 10px 12px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--surface-2);
}
.category-item__dot {
    width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0;
    box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 18%, transparent);
}
.category-item__name { font-weight: 600; flex: 1; min-width: 0; }
.category-item__kind { font-size: 12px; color: var(--text-3); white-space: nowrap; }
.category-item__actions { display: flex; gap: 6px; }

/* Цветные чипы и точки категорий (цвет задаётся инлайн-стилем --cat-color) */
.cat-chip {
    display: inline-flex; align-items: center; gap: 5px;
    font-size: 12px; font-weight: 600; line-height: 1.4;
    padding: 2px 9px; border-radius: 999px;
    background: color-mix(in srgb, var(--cat-color, #64748b) 14%, transparent);
    color: var(--cat-color, #64748b);
    white-space: nowrap;
}
.cat-chip::before {
    content: ""; width: 8px; height: 8px; border-radius: 50%;
    background: var(--cat-color, #64748b); flex-shrink: 0;
}
.cat-dot {
    display: inline-block; width: 8px; height: 8px; border-radius: 50%;
    margin-right: 4px; vertical-align: middle; flex-shrink: 0;
}
.form-color {
    width: 100%; height: 42px; padding: 4px; border: 1px solid var(--border);
    border-radius: var(--radius-sm); background: var(--surface); cursor: pointer;
}

/* ---------- Прогноз: «только дни с операциями» ---------- */
.table--only-ops .row--no-ops:not(.row--today):not(.row--snapshot) { display: none; }

/* ---------- Быстрая навигация по разделам настроек ---------- */
.section-nav { display: flex; gap: 8px; flex-wrap: wrap; }
.section-nav a {
    padding: 6px 13px; border-radius: 999px; border: 1px solid var(--border);
    background: var(--surface); color: var(--text-2); text-decoration: none;
    font-size: 13px; font-weight: 600; white-space: nowrap;
    transition: color var(--transition), border-color var(--transition);
}
.section-nav a:hover { color: var(--primary); border-color: var(--primary); }

/* ---------- Подписи кнопок, видимые только в мобильной раскладке ---------- */
.btn__label { display: none; }

/* ---------- Нижняя навигация и плавающая кнопка (телефон/планшет) ---------- */
.bottom-nav { display: none; }
.fab { display: none; }

/* ---------- Адаптивность ---------- */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); padding-bottom: env(safe-area-inset-bottom); }
    .sidebar--open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .sidebar-backdrop--visible { display: block; }
    .main { margin-left: 0; }
    .topbar__burger { display: block; }

    .bottom-nav {
        display: grid; grid-template-columns: repeat(4, 1fr);
        position: fixed; left: 0; right: 0; bottom: 0; z-index: 32;
        background: color-mix(in srgb, var(--surface) 92%, transparent);
        backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
        border-top: 1px solid var(--border);
        padding-bottom: env(safe-area-inset-bottom);
    }
    .bottom-nav__item {
        display: flex; flex-direction: column; align-items: center; justify-content: center;
        gap: 3px; min-height: 58px; padding: 6px 4px;
        color: var(--text-3); text-decoration: none; font-size: 11px; font-weight: 600;
        -webkit-tap-highlight-color: transparent;
    }
    .bottom-nav__icon { font-size: 20px; line-height: 1; filter: grayscale(1); opacity: .65; }
    .bottom-nav__item--active { color: var(--primary); }
    .bottom-nav__item--active .bottom-nav__icon { filter: none; opacity: 1; }
    body.has-bottom-nav .content { padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
}

@media (max-width: 640px) {
    .content { padding: 14px 14px 20px; }
    body.has-bottom-nav .content { padding-bottom: calc(140px + env(safe-area-inset-bottom)); }

    /* Шапка: компактнее, длинный заголовок не переносится */
    .topbar { padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); gap: 10px; }
    .topbar__title { font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
    .topbar__burger, .theme-toggle { width: 38px; height: 38px; flex-shrink: 0; }

    /* Поля ввода 16px — иначе iOS увеличивает страницу при фокусе */
    .form-input, .form-select { font-size: 16px; }

    .card { margin-bottom: 16px; }
    .card__header { padding: 14px 16px; }
    .card__body { padding: 14px 16px; }
    .form-row { flex-direction: column; gap: 0; }
    .ops-grid { grid-template-columns: 1fr; }
    .hide-mobile { display: none !important; }

    /* Шапка страницы: пояснение скрываем, кнопки — в ряд */
    .page-header { flex-direction: column; align-items: stretch; gap: 12px; margin-bottom: 14px; }
    .page-header__hint { display: none; }
    .page-header__actions { width: 100%; justify-content: flex-end; }
    .page-header__actions .btn { flex: 0 0 auto; }
    .page-header > .btn { width: 100%; }

    /* Дашборд: карточки в 2 колонки, остаток и «можно тратить» — на всю ширину */
    .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; }
    .stats-grid > .stat-card { grid-column: span 1; padding: 14px; gap: 4px; }
    .stats-grid > .stat-card--balance { grid-column: span 2; order: 1; }
    .stats-grid > .stat-card--expense { order: 2; }
    .stats-grid > .stat-card--income { order: 3; }
    .stats-grid > .stat-card--min { order: 4; }
    .stats-grid > .stat-card--safe { grid-column: span 1; order: 5; }
    .stat-card__label { font-size: 12px; }
    .stat-card__value { font-size: 17px; letter-spacing: -.2px; }
    .stat-card--balance .stat-card__value { font-size: 26px; }
    .stat-card__hint { font-size: 11px; }
    .stat-card--balance { flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; }
    .stat-card--balance .stat-card__label { flex-basis: 100%; }
    .stat-card--balance .btn { margin-top: 0; }

    .upcoming-item { gap: 12px; padding: 10px 2px; }
    .upcoming-item__date { width: 46px; height: 46px; }
    .upcoming-item__day { font-size: 17px; }
    .upcoming-item__amount { font-size: 14px; }

    /* Управление прогнозом в одну строку */
    .forecast-controls { width: 100%; flex-wrap: nowrap; }
    .forecast-controls .form-select { flex: 1; min-width: 0; width: auto; }
    .forecast-controls__label { display: none; }

    /* Таблица прогноза → карточки: дата и остаток сверху, операции ниже */
    .table--forecast thead { display: none; }
    .table--forecast, .table--forecast tbody { display: block; }
    .table--forecast tr {
        display: flex; flex-wrap: wrap; align-items: flex-start; gap: 2px 12px;
        padding: 10px 6px; border-bottom: 1px solid var(--border);
    }
    .table--forecast td { padding: 0; border: none; }
    .table--forecast .cell-date { order: 1; flex: 1 1 auto; }
    .table--forecast .cell-balance { order: 2; margin-left: auto; text-align: right; }
    .table--forecast .cell-ops-wrap { order: 3; flex-basis: 100%; }
    .table--forecast .cell-in, .table--forecast .cell-out { order: 4; text-align: left; font-size: 13px; }
    .table--forecast .cell-in:empty, .table--forecast .cell-out:empty,
    .table--forecast .row--no-ops .cell-ops-wrap { display: none; }
    .table--forecast .table__loading { flex-basis: 100%; }

    /* Универсальная «карточная» таблица: строка → карточка с подписями */
    .table--stack thead { display: none; }
    .table--stack, .table--stack tbody, .table--stack tr, .table--stack td { display: block; width: 100%; }
    .table--stack tr {
        border: 1px solid var(--border); border-radius: var(--radius-sm);
        padding: 8px 12px; margin-bottom: 10px; background: var(--surface);
    }
    .table--stack tbody tr:hover { background: var(--surface); }
    .table--stack td {
        display: flex; align-items: center; justify-content: space-between; gap: 12px;
        border: none; padding: 5px 0; text-align: right; white-space: normal;
    }
    .table--stack td[data-label]::before {
        content: attr(data-label); color: var(--text-3);
        font-size: 12px; font-weight: 600; text-align: left; flex-shrink: 0;
    }
    .table--stack td.cell-title { justify-content: flex-start; font-weight: 600; padding-bottom: 8px; }
    .table--stack td.cell-actions { justify-content: flex-start; padding-top: 8px; border-top: 1px solid var(--border); margin-top: 4px; }
    .table--stack .table-actions { justify-content: flex-start; }
    .table--stack .table__loading { display: block; text-align: center; }
    .table--users .btn__label { display: inline; }
    .table--users .table-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
    .table--users .table-actions > * { min-width: 0; }
    .table--users .table-actions .btn { width: 100%; white-space: normal; padding: 8px 6px; }

    /* Аналитика: легенда под кольцом */
    .analytics-grid { grid-template-columns: minmax(0, 1fr); gap: 0; }
    .chart-wrap--pie { height: 330px; }

    /* Операции: итоги в 2 колонки, вкладки на всю ширину */
    .ops-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
    .ops-summary__card { padding: 12px 14px; gap: 10px; }
    .ops-summary__card--net { grid-column: span 2; }
    .ops-summary__icon { display: none; }
    .ops-summary__value { font-size: 16px; white-space: nowrap; }
    .ops-summary__label { font-size: 12px; }
    .ops-tabs { display: grid; grid-template-columns: repeat(3, 1fr); width: 100%; gap: 4px; margin-bottom: 14px; }
    .ops-tab { justify-content: center; padding: 8px 4px; font-size: 13px; gap: 5px; }
    #addOperationBtn { display: none; }

    /* Плавающая кнопка «добавить» над нижней навигацией */
    .fab {
        display: flex; align-items: center; justify-content: center;
        position: fixed; right: 16px; bottom: calc(74px + env(safe-area-inset-bottom)); z-index: 33;
        width: 56px; height: 56px; border-radius: 50%; border: none;
        background: var(--primary); color: #fff; font-size: 28px; line-height: 1;
        box-shadow: 0 8px 20px -4px color-mix(in srgb, var(--primary) 60%, transparent);
        cursor: pointer;
    }

    /* Настройки */
    .section-nav {
        flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
        margin: 0 -14px; padding: 0 14px 2px;
    }
    .section-nav::-webkit-scrollbar { display: none; }
    .settings-grid { gap: 14px; }
    .settings-grid .card { margin-bottom: 0; }

    /* Модальные окна — «шторка» снизу, кнопки на всю ширину */
    .modal--open { align-items: flex-end; padding: 0; }
    .modal__dialog {
        max-width: 100%; border-radius: 18px 18px 0 0;
        max-height: 94vh; max-height: 94dvh; animation: sheetIn .22s ease;
    }
    .modal__header { padding: 16px 18px; }
    .modal__body { padding: 16px 18px; }
    .modal__footer { padding: 12px 18px; padding-bottom: max(12px, env(safe-area-inset-bottom)); }
    .modal__footer .btn { flex: 1; }

    .auth-card { padding: 28px 22px; }
}
@keyframes sheetIn { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
