/* ═══════════════════════════════════════
   KUDADENGI.RU — PWA Стили
   Mobile-first подход
   ═══════════════════════════════════════ */

/* ─── ПЕРЕМЕННЫЕ ─── */
:root {
    --bg-primary: #f8fafc;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f1f5f9;
    --bg-card: #ffffff;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 2px 8px rgba(0,0,0,.08);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.12);
    --primary: #6366f1;
    --primary-light: #818cf8;
    --primary-bg: rgba(99,102,241,.1);
    --success: #10b981;
    --success-bg: rgba(16,185,129,.1);
    --warning: #f59e0b;
    --warning-bg: rgba(245,158,11,.1);
    --danger: #ef4444;
    --danger-bg: rgba(239,68,68,.1);
    --info: #3b82f6;
    --radius: 16px;
    --radius-sm: 10px;
    --radius-xs: 6px;
    --nav-height: 64px;
    --header-height: 56px;
    --safe-top: env(safe-area-inset-top);
    --safe-bottom: env(safe-area-inset-bottom);
    --safe-left: env(safe-area-inset-left);
    --safe-right: env(safe-area-inset-right);
}

[data-theme="dark"] {
    --bg-primary: #0a0e1a;
    --bg-secondary: #131829;
    --bg-tertiary: #1c2237;
    --bg-card: #181d30;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #4b5563;
    --border: #232940;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.2);
    --shadow: 0 2px 8px rgba(0,0,0,.3);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.5);
}

/* ─── СБРОС ─── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { height: 100%; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 100%;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}
input, select, textarea, button { font-family: inherit; font-size: inherit; }
a { color: var(--primary); text-decoration: none; }
img { max-width: 100%; display: block; }

/* Скроллбар */
::-webkit-scrollbar { width: 4px; height: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::selection { background: var(--primary); color: #fff; }

/* ═══════════════════════
   SPLASH SCREEN
   ═══════════════════════ */
.splash-screen {
    position: fixed; inset: 0; z-index: 9999;
    background: linear-gradient(135deg, #4f46e5, #6366f1, #818cf8);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    transition: opacity .4s, visibility .4s;
}
.splash-screen.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-icon { font-size: 72px; margin-bottom: 16px; animation: splashPulse 1.5s infinite; }
.splash-title { font-size: 28px; font-weight: 700; color: #fff; margin-bottom: 8px; }
.splash-subtitle { font-size: 14px; color: rgba(255,255,255,.7); margin-bottom: 32px; }
.splash-loader {
    width: 40px; height: 40px;
    border: 3px solid rgba(255,255,255,.2);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .8s linear infinite;
}
@keyframes splashPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══════════════════════
   PIN-КОД
   ═══════════════════════ */
.pin-screen {
    position: fixed; inset: 0; z-index: 9998;
    background: var(--bg-primary);
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 24px;
}
.pin-header { text-align: center; margin-bottom: 32px; }
.pin-icon { font-size: 48px; margin-bottom: 12px; }
.pin-title { font-size: 22px; font-weight: 700; }
.pin-subtitle { font-size: 14px; color: var(--text-secondary); margin-top: 4px; }
.pin-dots {
    display: flex; gap: 16px;
    margin-bottom: 12px;
}
.pin-dot {
    width: 16px; height: 16px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: transparent;
    transition: all .2s;
}
.pin-dot.filled {
    background: var(--primary);
    border-color: var(--primary);
    transform: scale(1.15);
}
.pin-dot.error {
    background: var(--danger);
    border-color: var(--danger);
    animation: pinShake .4s;
}
.pin-error {
    height: 20px;
    font-size: 13px;
    color: var(--danger);
    margin-bottom: 16px;
    text-align: center;
}
.pin-keypad {
    display: grid;
    grid-template-columns: repeat(3, 72px);
    gap: 12px;
    justify-content: center;
}
.pin-key {
    width: 72px; height: 72px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 28px; font-weight: 500;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all .15s;
    -webkit-user-select: none; user-select: none;
}
.pin-key:active { background: var(--primary); color: #fff; transform: scale(.92); }
.pin-key-empty { border: none; background: transparent; pointer-events: none; }
.pin-key-delete { font-size: 22px; border: none; background: transparent; }
.pin-key-delete:active { background: var(--danger-bg); color: var(--danger); }
.pin-skip {
    margin-top: 24px;
    background: none; border: none;
    color: var(--text-secondary);
    font-size: 14px; cursor: pointer;
    padding: 8px 16px;
}
@keyframes pinShake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-8px); }
    40%, 80% { transform: translateX(8px); }
}

/* ═══════════════════════
   ОНБОРДИНГ
   ═══════════════════════ */
.onboarding {
    position: fixed; inset: 0; z-index: 9997;
    background: var(--bg-primary);
    display: flex; flex-direction: column;
}
.onboarding-slides {
    flex: 1;
    position: relative; overflow: hidden;
}
.onboarding-slide {
    position: absolute; inset: 0;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 40px 32px;
    text-align: center;
    opacity: 0; transform: translateX(60px);
    transition: all .4s ease;
    pointer-events: none;
}
.onboarding-slide.active {
    opacity: 1; transform: translateX(0);
    pointer-events: auto;
}
.onboarding-slide.exit {
    opacity: 0; transform: translateX(-60px);
}
.slide-illustration { font-size: 80px; margin-bottom: 32px; }
.onboarding-slide h2 {
    font-size: 24px; font-weight: 700;
    margin-bottom: 12px;
}
.onboarding-slide p {
    font-size: 15px; color: var(--text-secondary);
    max-width: 320px; line-height: 1.6;
}
.onboarding-setup {
    margin-top: 24px; width: 100%; max-width: 280px;
    text-align: left;
}
.onboarding-footer {
    padding: 24px 32px;
    padding-bottom: calc(24px + var(--safe-bottom));
    display: flex; align-items: center; justify-content: space-between;
}
.onboarding-dots { display: flex; gap: 8px; }
.onboarding-dots .dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: var(--border);
    transition: all .3s;
}
.onboarding-dots .dot.active {
    background: var(--primary);
    width: 24px; border-radius: 4px;
}
.onboarding-actions { display: flex; align-items: center; gap: 16px; }
.btn-text {
    background: none; border: none;
    color: var(--text-secondary); font-size: 14px;
    cursor: pointer; padding: 8px;
}
.btn-primary-round {
    background: var(--primary); color: #fff;
    border: none; border-radius: 24px;
    padding: 12px 28px; font-size: 15px; font-weight: 600;
    cursor: pointer; transition: all .2s;
}
.btn-primary-round:active { transform: scale(.95); background: #4f46e5; }

/* ═══════════════════════
   LAYOUT ПРИЛОЖЕНИЯ
   ═══════════════════════ */
.app {
    display: flex; flex-direction: column;
    min-height: 100vh; min-height: 100dvh;
}

/* ─── HEADER ─── */
.app-header {
    position: sticky; top: 0; z-index: 100;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    padding: calc(var(--safe-top) + 8px) 16px 12px;
}
.header-top {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 8px;
}
.header-title { font-size: 20px; font-weight: 700; }
.header-actions { display: flex; gap: 8px; }
.header-btn {
    width: 40px; height: 40px;
    border: none; border-radius: 50%;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer; display: flex;
    align-items: center; justify-content: center;
    transition: all .2s;
}
.header-btn:active { transform: scale(.9); }
.header-btn svg { display: block; }

/* Баланс */
.header-balance { padding: 4px 0 0; }
.balance-row {
    display: flex; align-items: baseline;
    justify-content: space-between; margin-bottom: 6px;
}
.balance-left-label { font-size: 13px; color: var(--text-secondary); }
.balance-left-amount { font-size: 22px; font-weight: 700; color: var(--success); }
.balance-left-amount.negative { color: var(--danger); }
.balance-bar-wrap { margin-top: 2px; }
.balance-bar {
    height: 6px; border-radius: 3px;
    background: var(--bg-tertiary); overflow: hidden;
}
.balance-bar-fill {
    height: 100%; border-radius: 3px;
    background: linear-gradient(90deg, var(--success), var(--primary));
    transition: width .6s ease;
}
.balance-bar-labels {
    display: flex; justify-content: space-between;
    font-size: 11px; color: var(--text-muted); margin-top: 4px;
}

/* ─── КОНТЕНТ ─── */
.app-content {
    flex: 1;
    padding: 16px 16px calc(var(--nav-height) + var(--safe-bottom) + 16px);
    overflow-y: auto;
}

/* Страницы */
.page {
    display: none;
    animation: pageIn .3s ease;
}
.page.active { display: block; }
@keyframes pageIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ─── BOTTOM NAVIGATION ─── */
.bottom-nav {
    position: fixed; bottom: 0; left: 0; right: 0;
    z-index: 100;
    height: calc(var(--nav-height) + var(--safe-bottom));
    padding-bottom: var(--safe-bottom);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border);
    display: flex; align-items: stretch;
}
.nav-tab {
    flex: 1;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    gap: 2px;
    border: none; background: none;
    color: var(--text-muted);
    font-size: 10px; font-weight: 500;
    cursor: pointer; transition: all .2s;
    position: relative;
    -webkit-user-select: none; user-select: none;
}
.nav-tab svg { transition: all .2s; }
.nav-tab.active {
    color: var(--primary);
}
.nav-tab.active svg { stroke: var(--primary); }
.nav-tab.active::before {
    content: '';
    position: absolute; top: 0; left: 50%;
    transform: translateX(-50%);
    width: 32px; height: 3px;
    border-radius: 0 0 3px 3px;
    background: var(--primary);
}
.nav-tab:active { transform: scale(.9); }

/* ─── FAB ─── */
.fab {
    position: fixed;
    bottom: calc(var(--nav-height) + var(--safe-bottom) + 16px);
    right: 16px; z-index: 101;
    width: 56px; height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: #fff;
    box-shadow: 0 4px 16px rgba(99,102,241,.4);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all .2s;
}
.fab:active { transform: scale(.9); box-shadow: 0 2px 8px rgba(99,102,241,.3); }
.fab svg { display: block; }
.fab.hidden { transform: scale(0); opacity: 0; pointer-events: none; }

/* ─── КАРТОЧКИ СТАТИСТИКИ ─── */
.stats-row {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 12px; margin-bottom: 20px;
}
.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid var(--border);
    transition: transform .2s;
}
.stat-card:active { transform: scale(.97); }
.stat-top {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 8px;
}
.stat-emoji { font-size: 20px; }
.stat-label { font-size: 12px; color: var(--text-secondary); }
.stat-value { font-size: 22px; font-weight: 700; display: block; }
.stat-card.income .stat-value { color: var(--success); }
.stat-card.expense .stat-value { color: var(--danger); }

/* ─── СЕКЦИИ DASHBOARD ─── */
.dash-section { margin-bottom: 20px; }
.dash-section-header {
    display: flex; align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.dash-section-header h2 { font-size: 16px; font-weight: 600; }
.link-btn {
    background: none; border: none;
    color: var(--primary); font-size: 13px;
    cursor: pointer; padding: 4px 8px;
    font-weight: 500;
}
.link-btn:active { opacity: .7; }
/* ═══════════════════════
   МИНИ-КАЛЕНДАРЬ (Dashboard)
   ═══════════════════════ */
.mini-cal {
    display: grid; grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 12px;
    border: 1px solid var(--border);
}
.mini-cal .mc-head {
    font-size: 10px; font-weight: 600;
    color: var(--text-muted);
    text-align: center; padding: 4px 0 8px;
}
.mini-cal .mc-day {
    aspect-ratio: 1; display: flex;
    align-items: center; justify-content: center;
    font-size: 12px; border-radius: 50%;
    cursor: pointer; position: relative;
    transition: all .15s;
    -webkit-user-select: none; user-select: none;
}
.mini-cal .mc-day:active { transform: scale(.85); }
.mini-cal .mc-day.other { color: var(--text-muted); opacity: .3; pointer-events: none; }
.mini-cal .mc-day.today {
    background: var(--primary); color: #fff; font-weight: 700;
}
.mini-cal .mc-day.has-pay::after {
    content: ''; position: absolute; bottom: 2px;
    width: 4px; height: 4px; border-radius: 50%;
    background: var(--danger);
}
.mini-cal .mc-day.today.has-pay::after { background: #fff; }

/* ═══════════════════════
   БЛИЖАЙШИЕ ПЛАТЕЖИ (Dashboard)
   ═══════════════════════ */
.upcoming-list { display: flex; flex-direction: column; gap: 8px; }
.upcoming-item {
    display: flex; align-items: center; gap: 12px;
    padding: 12px; border-radius: var(--radius-sm);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    transition: transform .15s;
}
.upcoming-item:active { transform: scale(.98); }
.upcoming-item.urgent { border-left-color: var(--danger); background: var(--danger-bg); }
.up-date {
    display: flex; flex-direction: column;
    align-items: center; min-width: 40px;
}
.up-date .up-day { font-size: 20px; font-weight: 700; line-height: 1; }
.up-date .up-mon { font-size: 10px; color: var(--text-muted); text-transform: uppercase; }
.up-info { flex: 1; min-width: 0; }
.up-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.up-cat { font-size: 11px; color: var(--text-secondary); }
.up-amount { font-size: 16px; font-weight: 700; color: var(--danger); white-space: nowrap; }
.upcoming-empty {
    text-align: center; padding: 32px 16px;
    color: var(--text-muted); font-size: 13px;
}

/* Категории бары (Dashboard) */
.cat-bars { display: flex; flex-direction: column; gap: 12px; }
.cat-bar-item { display: flex; flex-direction: column; gap: 4px; }
.cat-bar-top {
    display: flex; justify-content: space-between;
    font-size: 13px;
}
.cat-bar-top span:last-child { color: var(--text-secondary); }
.cat-bar {
    height: 8px; border-radius: 4px;
    background: var(--bg-tertiary); overflow: hidden;
}
.cat-bar-fill {
    height: 100%; border-radius: 4px;
    transition: width .5s ease;
}

/* ═══════════════════════
   ПОИСК
   ═══════════════════════ */
.search-wrap {
    position: relative; margin-bottom: 12px;
}
.search-ico {
    position: absolute; left: 14px; top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted); pointer-events: none;
}
.search-input {
    width: 100%; padding: 12px 16px 12px 42px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 15px;
    transition: all .2s;
    -webkit-appearance: none;
}
.search-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}
.search-input::placeholder { color: var(--text-muted); }

/* ═══════════════════════
   ЧИПЫ (фильтры)
   ═══════════════════════ */
.chip-scroll {
    display: flex; gap: 8px;
    overflow-x: auto; padding: 0 0 12px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.chip-scroll::-webkit-scrollbar { display: none; }
.chip {
    flex-shrink: 0;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 13px; font-weight: 500;
    cursor: pointer; transition: all .2s;
    white-space: nowrap;
    -webkit-user-select: none; user-select: none;
}
.chip:active { transform: scale(.95); }
.chip.active {
    background: var(--primary); color: #fff;
    border-color: var(--primary);
}
.chip-sm {
    flex-shrink: 0;
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 16px;
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 12px; cursor: pointer;
    transition: all .2s; white-space: nowrap;
}
.chip-sm.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.status-chips { margin-bottom: 12px; }

/* ═══════════════════════
   КАРТОЧКИ ПЛАТЕЖЕЙ
   ═══════════════════════ */
.payments-list { display: flex; flex-direction: column; gap: 12px; }
.pay-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    overflow: hidden;
    transition: transform .15s;
    position: relative;
}
.pay-card:active { transform: scale(.98); }
.pay-card.is-paid { opacity: .65; }

/* Свайп-слой */
.pay-swipe {
    position: relative; overflow: hidden;
}
.pay-swipe-actions {
    position: absolute; top: 0; bottom: 0;
    display: flex; align-items: stretch;
}
.pay-swipe-actions.left { left: 0; }
.pay-swipe-actions.right { right: 0; }
.swipe-action {
    width: 72px;
    display: flex; align-items: center; justify-content: center;
    font-size: 24px; color: #fff;
}
.swipe-action.pay-action { background: var(--success); }
.swipe-action.del-action { background: var(--danger); }
.pay-swipe-inner {
    position: relative; z-index: 1;
    background: var(--bg-card);
    transition: transform .2s ease;
}

/* Содержимое карточки */
.pay-top {
    display: flex; align-items: center;
    padding: 14px 16px 10px; gap: 12px;
}
.pay-color {
    width: 4px; height: 36px;
    border-radius: 2px; flex-shrink: 0;
}
.pay-main { flex: 1; min-width: 0; }
.pay-name {
    font-size: 15px; font-weight: 600;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    display: flex; align-items: center; gap: 6px;
}
.pay-meta {
    font-size: 12px; color: var(--text-secondary);
    display: flex; align-items: center; gap: 6px;
    margin-top: 2px;
}
.pay-amount {
    font-size: 18px; font-weight: 700;
    color: var(--danger); white-space: nowrap;
}
.pay-bottom {
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 8px 16px 12px;
    border-top: 1px solid var(--border);
}
.pay-status {
    font-size: 12px; padding: 3px 10px;
    border-radius: 12px; font-weight: 500;
}
.pay-status.paid { background: var(--success-bg); color: var(--success); }
.pay-status.unpaid { background: var(--warning-bg); color: var(--warning); }
.pay-actions { display: flex; gap: 4px; }
.pay-act {
    width: 32px; height: 32px;
    border: none; border-radius: 50%;
    background: transparent; color: var(--text-muted);
    cursor: pointer; display: flex;
    align-items: center; justify-content: center;
    font-size: 16px; transition: all .15s;
}
.pay-act:active { background: var(--bg-tertiary); transform: scale(.85); }
.pay-act.check.is-paid { color: var(--success); }

/* Бейдж периодичности */
.freq-badge {
    display: inline-flex; padding: 1px 6px;
    border-radius: 8px; font-size: 10px;
    font-weight: 600; letter-spacing: .3px;
    text-transform: uppercase;
}
.freq-badge.monthly { background: var(--success-bg); color: var(--success); }
.freq-badge.quarterly { background: var(--warning-bg); color: var(--warning); }
.freq-badge.yearly { background: var(--primary-bg); color: var(--primary); }
.freq-badge.once { background: var(--bg-tertiary); color: var(--text-muted); }

/* Прогресс кредита */
.pay-progress { padding: 0 16px 12px; }
.progress-bar {
    height: 6px; border-radius: 3px;
    background: var(--bg-tertiary); overflow: hidden;
}
.progress-fill {
    height: 100%; border-radius: 3px;
    background: var(--success);
    transition: width .4s ease;
}
.progress-label {
    display: flex; justify-content: space-between;
    font-size: 11px; color: var(--text-secondary); margin-top: 4px;
}

/* Пустое состояние */
.empty-state {
    text-align: center; padding: 48px 24px;
    color: var(--text-muted);
}
.empty-ico { font-size: 56px; margin-bottom: 12px; }
.empty-title { font-size: 16px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.empty-text { font-size: 13px; margin-bottom: 20px; line-height: 1.5; }

/* ═══════════════════════
   ФОРМЫ (общие)
   ═══════════════════════ */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block; font-size: 13px;
    font-weight: 500; color: var(--text-secondary);
    margin-bottom: 5px;
}
.form-row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-divider {
    font-size: 13px; font-weight: 600;
    color: var(--text-secondary);
    padding: 12px 0 8px;
    border-top: 1px solid var(--border);
    margin-top: 4px;
}
.input, .textarea {
    width: 100%; padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    font-size: 15px;
    transition: all .2s;
    -webkit-appearance: none;
}
.input:focus, .textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}
.textarea { resize: vertical; min-height: 64px; }
.input-color {
    width: 100%; height: 44px; padding: 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    cursor: pointer;
}

/* Тоггл переключатель */
.toggle-row {
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 12px 0; cursor: pointer;
    -webkit-user-select: none; user-select: none;
}
.toggle-row span:first-child { font-size: 14px; }
.toggle-input { display: none; }
.toggle-slider {
    position: relative;
    width: 48px; height: 28px;
    background: var(--border);
    border-radius: 14px;
    transition: all .3s;
    flex-shrink: 0;
}
.toggle-slider::after {
    content: ''; position: absolute;
    top: 3px; left: 3px;
    width: 22px; height: 22px;
    background: #fff; border-radius: 50%;
    transition: all .3s;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-input:checked + .toggle-slider {
    background: var(--primary);
}
.toggle-input:checked + .toggle-slider::after {
    transform: translateX(20px);
}

/* ═══════════════════════
   КНОПКИ
   ═══════════════════════ */
.btn-primary-full {
    width: 100%; padding: 14px;
    background: var(--primary); color: #fff;
    border: none; border-radius: var(--radius-sm);
    font-size: 16px; font-weight: 600;
    cursor: pointer; transition: all .2s;
    margin-top: 8px;
}
.btn-primary-full:active { transform: scale(.98); background: #4f46e5; }
.btn-outline {
    padding: 12px 20px;
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 500;
    cursor: pointer; transition: all .2s;
    width: 100%; text-align: center;
}
.btn-outline:active { background: var(--bg-tertiary); }
.btn-danger {
    padding: 12px 20px;
    background: var(--danger); color: #fff;
    border: none; border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 600;
    cursor: pointer; transition: all .2s;
    width: 100%;
}
.btn-danger:active { background: #dc2626; }
.btn-danger-outline {
    padding: 12px 20px;
    background: transparent; color: var(--danger);
    border: 1px solid var(--danger);
    border-radius: var(--radius-sm);
    font-size: 14px; font-weight: 500;
    cursor: pointer; transition: all .2s;
    width: 100%; text-align: center;
}
.btn-danger-outline:active { background: var(--danger-bg); }
.btn-icon-sm {
    width: 36px; height: 36px;
    border-radius: 50%; border: 1px solid var(--border);
    background: var(--bg-tertiary); color: var(--text-primary);
    font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all .15s;
}
.btn-icon-sm:active { transform: scale(.9); background: var(--primary); color: #fff; }
.section-header-row {
    display: flex; align-items: center;
    justify-content: space-between;
    margin-bottom: 12px;
}
.section-title { font-size: 16px; font-weight: 600; }
.settings-btns { display: flex; flex-direction: column; gap: 10px; }
/* ═══════════════════════
   КАЛЕНДАРЬ (полная страница)
   ═══════════════════════ */
.cal-nav {
    display: flex; align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}
.cal-nav-btn {
    width: 40px; height: 40px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all .15s;
}
.cal-nav-btn:active { transform: scale(.9); background: var(--primary); color: #fff; }
.cal-nav-btn svg { display: block; }
.cal-month-title { font-size: 18px; font-weight: 700; }

.cal-grid {
    display: grid; grid-template-columns: repeat(7, 1fr);
    gap: 4px;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 12px 8px;
    border: 1px solid var(--border);
}
.cal-grid .cg-head {
    font-size: 11px; font-weight: 600;
    color: var(--text-muted);
    text-align: center; padding: 4px 0 8px;
}
.cal-grid .cg-day {
    min-height: 48px; padding: 4px 2px;
    border-radius: var(--radius-xs);
    cursor: pointer; position: relative;
    display: flex; flex-direction: column;
    align-items: center; gap: 2px;
    transition: all .15s;
    -webkit-user-select: none; user-select: none;
}
.cal-grid .cg-day:active { transform: scale(.92); }
.cal-grid .cg-day.other { opacity: .25; pointer-events: none; }
.cal-grid .cg-day.today {
    background: var(--primary-bg);
    border: 2px solid var(--primary);
}
.cal-grid .cg-day.selected {
    background: var(--primary); color: #fff;
}
.cal-grid .cg-day.selected .cg-dots span { background: #fff; }
.cg-num { font-size: 13px; font-weight: 600; line-height: 1; }
.cg-dots { display: flex; gap: 2px; flex-wrap: wrap; justify-content: center; }
.cg-dots span {
    width: 5px; height: 5px; border-radius: 50%;
    flex-shrink: 0;
}

/* Детали дня */
.cal-details {
    margin-top: 16px;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid var(--border);
}
.cal-details-hint { color: var(--text-muted); font-size: 13px; text-align: center; padding: 16px 0; }
.cal-details h3 {
    font-size: 15px; font-weight: 600;
    margin-bottom: 12px;
}
.cal-det-list { display: flex; flex-direction: column; gap: 8px; }
.cal-det-item {
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    border-left: 4px solid var(--primary);
}
.cal-det-info { display: flex; align-items: center; gap: 10px; }
.cal-det-name { font-size: 14px; font-weight: 600; }
.cal-det-cat { font-size: 11px; color: var(--text-secondary); }
.cal-det-amount { font-size: 16px; font-weight: 700; color: var(--danger); }
.cal-det-total {
    display: flex; justify-content: space-between;
    padding: 12px 0 0; margin-top: 8px;
    border-top: 1px solid var(--border);
    font-weight: 700;
}

/* ═══════════════════════
   АНАЛИТИКА
   ═══════════════════════ */
.card-section {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid var(--border);
    margin-bottom: 16px;
}
.pie-wrap {
    display: flex; justify-content: center;
    padding: 8px 0 16px;
}
.pie-wrap canvas { max-width: 220px; max-height: 220px; }
.pie-legend {
    display: flex; flex-direction: column; gap: 8px;
}
.pie-leg-item {
    display: flex; align-items: center; gap: 10px;
    font-size: 13px;
}
.pie-leg-color {
    width: 12px; height: 12px;
    border-radius: 3px; flex-shrink: 0;
}
.pie-leg-label { flex: 1; }
.pie-leg-val { font-weight: 600; color: var(--text-secondary); }

.line-chart-wrap {
    overflow-x: auto;
    padding: 8px 0;
    -webkit-overflow-scrolling: touch;
}
.line-chart-wrap canvas { min-width: 300px; width: 100%; height: 180px; }

/* Сравнение */
.compare-selects {
    display: flex; align-items: center; gap: 8px;
    margin-bottom: 16px;
}
.compare-selects .input { flex: 1; font-size: 13px; padding: 10px; }
.compare-vs { color: var(--text-muted); font-size: 13px; font-weight: 600; }
.compare-result {
    display: grid; grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.cmp-item {
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    padding: 14px; text-align: center;
}
.cmp-item.full { grid-column: 1 / -1; }
.cmp-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.cmp-value { font-size: 20px; font-weight: 700; }
.cmp-change {
    font-size: 12px; margin-top: 4px;
}
.cmp-change.up { color: var(--danger); }
.cmp-change.down { color: var(--success); }

/* ═══════════════════════
   ЦЕЛИ
   ═══════════════════════ */
.goals-list { display: flex; flex-direction: column; gap: 12px; }
.goal-card {
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    border: 1px solid var(--border);
    position: relative; overflow: hidden;
}
.goal-card::before {
    content: ''; position: absolute;
    top: 0; left: 0; right: 0; height: 3px;
}
.goal-top {
    display: flex; align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 12px;
}
.goal-name { font-size: 16px; font-weight: 600; }
.goal-actions { display: flex; gap: 2px; }
.goal-progress { margin-bottom: 10px; }
.goal-progress .progress-bar { height: 10px; }
.goal-stats {
    display: flex; justify-content: space-between;
    font-size: 13px; margin-bottom: 10px;
}
.goal-stats .g-current { color: var(--success); font-weight: 600; }
.goal-stats .g-target { color: var(--text-secondary); }
.goal-footer {
    display: flex; justify-content: space-between;
    align-items: center;
    padding-top: 10px; border-top: 1px solid var(--border);
    font-size: 12px; color: var(--text-secondary);
}
.goal-monthly { color: var(--primary); font-weight: 600; }
.goal-add {
    display: flex; gap: 8px;
    margin-top: 12px; padding-top: 10px;
    border-top: 1px solid var(--border);
}
.goal-add .input { flex: 1; padding: 10px 12px; font-size: 14px; }
.goal-add-btn {
    width: 40px; height: 40px;
    border: none; border-radius: var(--radius-sm);
    background: var(--primary); color: #fff;
    font-size: 18px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all .15s;
}
.goal-add-btn:active { transform: scale(.9); }
.goals-empty {
    text-align: center; padding: 48px 24px;
    color: var(--text-muted);
}
.goals-empty-ico { font-size: 56px; margin-bottom: 12px; }

/* ═══════════════════════
   НАСТРОЙКИ
   ═══════════════════════ */
.income-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.inc-card {
    display: flex; align-items: center;
    padding: 12px; gap: 12px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-sm);
    border-left: 4px solid var(--success);
}
.inc-icon {
    width: 36px; height: 36px; border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 18px; background: var(--bg-card);
}
.inc-info { flex: 1; min-width: 0; }
.inc-name { font-size: 14px; font-weight: 600; }
.inc-meta { font-size: 11px; color: var(--text-secondary); }
.inc-amount { font-size: 16px; font-weight: 700; color: var(--success); white-space: nowrap; }
.inc-actions { display: flex; gap: 2px; }
.inc-empty { text-align: center; padding: 24px; color: var(--text-muted); font-size: 13px; }

/* Тема */
.theme-picker {
    display: grid; grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}
.theme-option {
    display: flex; flex-direction: column;
    align-items: center; gap: 8px;
    padding: 14px 8px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--bg-tertiary);
    cursor: pointer; transition: all .2s;
    font-size: 13px; color: var(--text-secondary);
}
.theme-option.active { border-color: var(--primary); color: var(--primary); }
.theme-option:active { transform: scale(.95); }
.theme-preview {
    width: 40px; height: 28px;
    border-radius: 6px; border: 1px solid var(--border);
}
.theme-preview.light { background: linear-gradient(135deg, #f8fafc, #e2e8f0); }
.theme-preview.dark { background: linear-gradient(135deg, #1e293b, #0f172a); }
.theme-preview.auto { background: linear-gradient(135deg, #f8fafc 50%, #1e293b 50%); }

/* О приложении */
.about-section { text-align: center; padding: 24px 16px; }
.about-logo { font-size: 48px; margin-bottom: 8px; }
.about-name { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.about-version { font-size: 12px; color: var(--text-muted); margin-bottom: 12px; }
.about-text { font-size: 13px; color: var(--text-secondary); margin-bottom: 12px; line-height: 1.5; }
.about-link { font-size: 13px; }

/* ═══════════════════════
   BOTTOM SHEETS
   ═══════════════════════ */
.bottom-sheet {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: flex-end;
    visibility: hidden; pointer-events: none;
}
.bottom-sheet.open { visibility: visible; pointer-events: auto; }
.sheet-overlay {
    position: absolute; inset: 0;
    background: rgba(0,0,0,.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0; transition: opacity .3s;
}
.bottom-sheet.open .sheet-overlay { opacity: 1; }
.sheet-content {
    position: relative; z-index: 1;
    width: 100%;
    max-height: 92vh; max-height: 92dvh;
    background: var(--bg-secondary);
    border-radius: 20px 20px 0 0;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform .35s cubic-bezier(.32,.72,0,1);
    padding-bottom: calc(16px + var(--safe-bottom));
}
.bottom-sheet.open .sheet-content { transform: translateY(0); }
.sheet-sm .sheet-content { max-height: 50vh; max-height: 50dvh; }
.sheet-handle {
    width: 36px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 10px auto 0;
}
.sheet-header {
    display: flex; align-items: center;
    justify-content: space-between;
    padding: 16px 20px 12px;
}
.sheet-header h2 { font-size: 18px; font-weight: 700; }
.sheet-close {
    width: 32px; height: 32px;
    border: none; border-radius: 50%;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 16px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    transition: all .15s;
}
.sheet-close:active { transform: scale(.85); }
.sheet-body { padding: 0 20px 16px; }

/* Confirm sheet */
.confirm-body {
    padding: 24px 20px;
    text-align: center;
}
.confirm-icon { font-size: 48px; margin-bottom: 12px; }
.confirm-body h3 { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.confirm-body p { font-size: 14px; color: var(--text-secondary); margin-bottom: 20px; }
.confirm-actions {
    display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}

/* ═══════════════════════
   TOAST
   ═══════════════════════ */
.toast-wrap {
    position: fixed;
    top: calc(var(--safe-top) + 12px);
    left: 16px; right: 16px;
    z-index: 9999;
    display: flex; flex-direction: column; gap: 8px;
    pointer-events: none;
}
.toast {
    display: flex; align-items: center; gap: 10px;
    padding: 14px 16px;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    border: 1px solid var(--border);
    pointer-events: auto;
    animation: toastIn .35s ease;
}
.toast.out { animation: toastOut .3s ease forwards; }
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--danger); }
.toast.warning { border-left: 4px solid var(--warning); }
.toast.info { border-left: 4px solid var(--info); }
.toast-ico { font-size: 18px; flex-shrink: 0; }
.toast-msg { flex: 1; font-size: 14px; }
.toast-x {
    background: none; border: none;
    color: var(--text-muted); cursor: pointer;
    font-size: 16px; padding: 4px;
}
@keyframes toastIn {
    from { opacity: 0; transform: translateY(-20px) scale(.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes toastOut {
    to { opacity: 0; transform: translateY(-20px) scale(.95); }
}

/* ═══════════════════════
   АДАПТИВНОСТЬ
   ═══════════════════════ */

/* Планшет 768+ */
@media (min-width: 768px) {
    .app-content { padding: 24px 32px calc(var(--nav-height) + var(--safe-bottom) + 24px); }
    .stats-row { gap: 16px; }
    .payments-list {
        display: grid; grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
    .goals-list {
        display: grid; grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }
    .cal-grid .cg-day { min-height: 64px; }
    .sheet-content { max-width: 480px; margin: 0 auto; border-radius: 20px 20px 0 0; }
    .bottom-nav { max-width: 480px; left: 50%; transform: translateX(-50%); border-radius: 20px 20px 0 0; }
    .fab { right: calc(50% - 220px); }
}

/* Десктоп 1024+ */
@media (min-width: 1024px) {
    .app-content {
        max-width: 800px; margin: 0 auto;
        padding: 32px 24px calc(var(--nav-height) + var(--safe-bottom) + 32px);
    }
    .stats-row { grid-template-columns: repeat(4, 1fr); }
    .compare-result { grid-template-columns: repeat(3, 1fr); }
    .cmp-item.full { grid-column: auto; }
    .cal-grid .cg-day { min-height: 80px; padding: 6px; }
    .cg-num { font-size: 14px; }
}

/* Маленькие экраны */
@media (max-width: 359px) {
    .app-content { padding: 12px 12px calc(var(--nav-height) + var(--safe-bottom) + 12px); }
    .stats-row { grid-template-columns: 1fr; }
    .stat-value { font-size: 18px; }
    .pin-key { width: 60px; height: 60px; font-size: 24px; }
    .pin-keypad { grid-template-columns: repeat(3, 60px); gap: 8px; }
    .header-title { font-size: 18px; }
}

/* Landscape */
@media (max-height: 480px) and (orientation: landscape) {
    .pin-screen { flex-direction: row; gap: 32px; }
    .pin-header { margin-bottom: 0; }
    .onboarding-slide { padding: 20px; }
    .slide-illustration { font-size: 48px; margin-bottom: 16px; }
}

/* Режим standalone (установленное PWA) */
@media (display-mode: standalone) {
    .app-header { padding-top: calc(var(--safe-top) + 12px); }
}

/* Тёмная тема системная (для auto) */
@media (prefers-color-scheme: dark) {
    [data-theme="auto"] {
        --bg-primary: #0a0e1a;
        --bg-secondary: #131829;
        --bg-tertiary: #1c2237;
        --bg-card: #181d30;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --text-muted: #4b5563;
        --border: #232940;
        --shadow-sm: 0 1px 2px rgba(0,0,0,.2);
        --shadow: 0 2px 8px rgba(0,0,0,.3);
        --shadow-lg: 0 8px 32px rgba(0,0,0,.5);
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        transition-duration: .01ms !important;
    }
}

/* Print */
@media print {
    .bottom-nav, .fab, .app-header, .bottom-sheet, .toast-wrap { display: none !important; }
    .app-content { padding: 0; }
    .page { display: block !important; page-break-inside: avoid; }
}
