/* ============================================================
   Бюджет — design system
   ============================================================ */

:root {
    --bg: #ffffff;
    --bg-elevated: #f7f8fa;
    --bg-card: #ffffff;
    --bg-input: #f5f6f8;
    --bg-pressed: #eaecf0;

    --text: #11141a;
    --text-secondary: #5f6470;
    --text-tertiary: #9aa0aa;

    --border: rgba(0, 0, 0, 0.08);
    --border-strong: rgba(0, 0, 0, 0.12);

    --accent: #2b7fff;
    --accent-hover: #1f6ae6;
    --accent-bg: rgba(43, 127, 255, 0.10);

    --success: #16a34a;
    --success-bg: rgba(22, 163, 74, 0.10);
    --danger: #ef4444;
    --danger-bg: rgba(239, 68, 68, 0.10);
    --warning: #f59e0b;
    --warning-bg: rgba(245, 158, 11, 0.10);

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);

    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;

    --tap-size: 44px;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0a0b0d;
        --bg-elevated: #14161b;
        --bg-card: #1a1d24;
        --bg-input: #1f232c;
        --bg-pressed: #2a2f3a;

        --text: #eef0f3;
        --text-secondary: #9ba3b0;
        --text-tertiary: #6b7280;

        --border: rgba(255, 255, 255, 0.06);
        --border-strong: rgba(255, 255, 255, 0.10);

        --accent: #4a8eff;
        --accent-hover: #5fa0ff;
        --accent-bg: rgba(74, 142, 255, 0.16);

        --success: #22c55e;
        --danger: #f87171;
        --warning: #fbbf24;

        --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.40);
        --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.30);
    }
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.4;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent); text-decoration: none; }
input, button, select, textarea { font: inherit; color: inherit; }

/* SVG defaults — критически важно чтобы не разъехались */
svg {
    width: 1em;
    height: 1em;
    flex-shrink: 0;
    display: inline-block;
    vertical-align: middle;
}

/* ============================================================
   Layout
   ============================================================ */

.app {
    max-width: 720px;
    margin: 0 auto;
    padding: 0 16px;
    padding-top: max(20px, env(safe-area-inset-top));
    padding-bottom: 96px;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 8px 0 20px;
    gap: 12px;
}

.page-header h1 {
    margin: 0;
    font-size: 26px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.page-header .subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    margin: 0;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin: 24px 0 12px;
}
.section-header h2 {
    margin: 0;
    font-size: 17px;
    font-weight: 600;
}
.section-header a {
    font-size: 14px;
    color: var(--text-secondary);
}

.icon-btn {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text);
    transition: background 0.15s;
    flex-shrink: 0;
}
.icon-btn:hover, .icon-btn:active { background: var(--bg-pressed); }
.icon-btn svg { width: 20px; height: 20px; }

/* ============================================================
   Карточка общего баланса
   ============================================================ */

.total-balance {
    background: var(--bg-elevated);
    border-radius: var(--radius-lg);
    padding: 18px;
    margin-bottom: 16px;
    border: 1px solid var(--border);
}

.total-balance__label {
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.total-balance__value {
    font-size: 30px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.02em;
}
.total-balance__value.negative { color: var(--danger); }

.total-balance__breakdown {
    display: flex;
    gap: 20px;
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px solid var(--border);
    font-size: 13px;
    flex-wrap: wrap;
}

.total-balance__breakdown-item span:first-child {
    color: var(--text-secondary);
    margin-right: 6px;
}

.total-balance__breakdown-item span:last-child {
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.total-balance__breakdown-item .positive { color: var(--success); }
.total-balance__breakdown-item .negative { color: var(--danger); }

/* ============================================================
   3 главные кнопки действий
   ============================================================ */

.action-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 24px;
}

.action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 18px 8px;
    border-radius: var(--radius-lg);
    text-decoration: none;
    color: var(--text);
    border: 1px solid var(--border);
    background: var(--bg-card);
    transition: transform 0.1s, background 0.15s;
    font-size: 14px;
    font-weight: 500;
}
.action-btn:active { transform: scale(0.97); }

.action-btn__icon {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
}
.action-btn__icon svg { width: 22px; height: 22px; }

.action-btn--expense .action-btn__icon { background: #ef4444; }
.action-btn--income .action-btn__icon { background: #16a34a; }
.action-btn--transfer .action-btn__icon { background: #2b7fff; }

.action-btn:hover { background: var(--bg-elevated); }

/* ============================================================
   Группы счетов + карточка счёта/операции
   ============================================================ */

.group-title {
    font-size: 12px;
    color: var(--text-secondary);
    margin: 18px 0 8px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 500;
}
.group-title:first-of-type { margin-top: 0; }

.account-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.account-card {
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px;
    text-decoration: none;
    color: inherit;
    transition: background 0.15s, transform 0.1s;
    cursor: pointer;
}
.account-card:hover { background: var(--bg-elevated); }
.account-card:active { transform: scale(0.99); }

.account-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.account-icon svg { width: 22px; height: 22px; }

.account-info {
    flex: 1;
    min-width: 0;
}

.account-name {
    font-size: 15px;
    font-weight: 500;
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-meta {
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.account-balance {
    font-size: 15px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: nowrap;
}

.account-balance.negative { color: var(--danger); }
.account-balance.positive { color: var(--success); }

.badge-debt {
    display: inline-block;
    background: var(--danger-bg);
    color: var(--danger);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
}

/* Дневной заголовок в списке операций */
.day-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 20px 0 8px;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
}
.day-header .positive { color: var(--success); font-variant-numeric: tabular-nums; }
.day-header .negative { color: var(--danger); font-variant-numeric: tabular-nums; }

/* Подсчёт за месяц на странице операций */
.month-summary {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 14px;
}
.month-summary__item { text-align: center; }
.month-summary__label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 4px;
}
.month-summary__value {
    font-size: 15px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.month-summary__value.positive { color: var(--success); }
.month-summary__value.negative { color: var(--danger); }

/* Фильтры (чипсы) */
.filter-chips {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
}
.filter-chips::-webkit-scrollbar { display: none; }
.filter-chip {
    padding: 8px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    font-size: 13px;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.15s;
}
.filter-chip:hover { background: var(--bg-pressed); }
.filter-chip--active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

/* Большое поле суммы при создании операции */
.amount-input {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 8px;
    padding: 32px 16px;
    margin-bottom: 16px;
}
.amount-input input {
    background: transparent;
    border: none;
    outline: none;
    font-size: 48px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    text-align: right;
    width: auto;
    max-width: 80%;
    min-width: 60px;
    color: var(--danger);
    letter-spacing: -0.03em;
}
.amount-input input::placeholder { color: var(--text-tertiary); }
.amount-input__currency {
    font-size: 28px;
    font-weight: 500;
    color: var(--text-secondary);
}
.amount-input--income input { color: var(--success); }
.amount-input--transfer input { color: var(--accent); }

/* ============================================================
   Empty state
   ============================================================ */

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-secondary);
}
.empty-state__icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 16px;
    background: var(--bg-elevated);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.empty-state__icon svg { width: 28px; height: 28px; color: var(--text-tertiary); }
.empty-state__title { font-size: 17px; font-weight: 500; color: var(--text); margin-bottom: 6px; }
.empty-state__text { font-size: 14px; }

/* ============================================================
   Нижняя навигация
   ============================================================ */

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--bg);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    padding: 8px 0 max(8px, env(safe-area-inset-bottom));
    z-index: 100;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

.bottom-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.15s;
    font-size: 11px;
    max-width: 80px;
}
.bottom-nav__item:hover { color: var(--text); }
.bottom-nav__item--active { color: var(--accent); }

.bottom-nav__icon {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.bottom-nav__icon svg { width: 24px; height: 24px; }

/* ============================================================
   Кнопки
   ============================================================ */

.btn {
    appearance: none;
    border: none;
    font: inherit;
    font-size: 15px;
    font-weight: 500;
    padding: 14px 20px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--tap-size);
    transition: background 0.15s, transform 0.1s;
    text-decoration: none;
}
.btn:active { transform: scale(0.98); }
.btn svg { width: 18px; height: 18px; }

.btn-primary {
    background: var(--accent);
    color: white;
    width: 100%;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
    background: var(--bg-elevated);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-pressed); }

.btn-danger {
    background: var(--bg-elevated);
    color: var(--danger);
    border: 1px solid var(--border);
}
.btn-danger:hover { background: var(--danger-bg); }

/* ============================================================
   Формы
   ============================================================ */

.form-page .page-header { margin-bottom: 24px; }

.form-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 4px 16px;
    margin-bottom: 16px;
}

.form-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 0;
    border-bottom: 1px solid var(--border);
}
.form-row:last-child { border-bottom: none; }

.form-row label {
    flex-shrink: 0;
    color: var(--text-secondary);
    font-size: 14px;
    min-width: 110px;
}

.form-row input[type="text"],
.form-row input[type="number"],
.form-row input[type="date"],
.form-row select {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    font-size: 15px;
    text-align: right;
    min-width: 0;
    padding: 4px 0;
    color: var(--text);
}

.form-row input::placeholder { color: var(--text-tertiary); }

/* Селекторы икон/цветов */
/* Цветовые чипы — ярче на темной теме */
@media (prefers-color-scheme: dark) {
    .choice-chip[data-color] {
        opacity: 0.85;
    }
    .choice-chip[data-color].selected {
        opacity: 1;
    }
}

.choice-row {
    display: flex;
    gap: 10px;
    overflow-x: auto;
    padding: 6px 0;
    -webkit-overflow-scrolling: touch;
}
.choice-row::-webkit-scrollbar { display: none; }

.choice-chip {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.15s, transform 0.1s;
}
.choice-chip:active { transform: scale(0.95); }
.choice-chip.selected { border-color: var(--text); }
.choice-chip svg { width: 22px; height: 22px; color: white; }

.form-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
}
.form-actions .btn { flex: 1; }

/* ============================================================
   Сообщения
   ============================================================ */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 14px;
    margin-bottom: 16px;
}
.alert-error { background: var(--danger-bg); color: var(--danger); }
.alert-success { background: var(--success-bg); color: var(--success); }

/* ============================================================
   Вход
   ============================================================ */

.auth-body {
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    padding-bottom: env(safe-area-inset-bottom);
}
.auth-shell { width: 100%; max-width: 380px; }
.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 36px 24px 28px;
    box-shadow: var(--shadow-md);
}
.auth-title {
    margin: 0 0 6px;
    text-align: center;
    font-size: 28px;
    font-weight: 600;
    letter-spacing: -0.02em;
}
.auth-subtitle {
    margin: 0 0 24px;
    text-align: center;
    color: var(--text-secondary);
    font-size: 14px;
}
.auth-form { display: flex; flex-direction: column; gap: 16px; }
.auth-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid transparent;
    color: var(--text);
    font-size: 16px;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    outline: none;
    transition: border-color 0.15s, background 0.15s;
}
.auth-input:focus {
    border-color: var(--accent);
    background: var(--bg-elevated);
}

.password-wrap { position: relative; }
.password-wrap input { padding-right: 48px; }
.password-toggle {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: none;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 8px;
}
.password-toggle:hover { background: var(--bg-pressed); color: var(--text); }
.password-toggle svg { width: 20px; height: 20px; }

/* ============================================================
   Setup page
   ============================================================ */

.setup-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
}
.setup-card h2 { margin: 0 0 12px; font-size: 17px; font-weight: 600; }
.setup-card p { margin: 8px 0; line-height: 1.5; }
.setup-card .ok { color: var(--success); }
.setup-card .error { color: var(--danger); }
.setup-card .muted { color: var(--text-secondary); font-size: 14px; }
.hash-box {
    width: 100%;
    height: 60px;
    font-family: ui-monospace, SFMono-Regular, monospace;
    font-size: 13px;
    word-break: break-all;
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px;
    resize: none;
}
.setup-card code {
    background: var(--bg-input);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: ui-monospace, SFMono-Regular, monospace;
    font-size: 13px;
}

.muted { color: var(--text-secondary); font-size: 13px; margin: 0; }
.text-right { text-align: right; }
.positive { color: var(--success); }
.negative { color: var(--danger); }

/* Сетка иконок для категорий */
.choice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 8px;
    padding: 6px 0;
}

.choice-grid .choice-chip {
    width: 100%;
    aspect-ratio: 1;
    height: auto;
}

/* Сетка иконок — горизонтальная решётка */
.choice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(48px, 1fr));
    gap: 8px;
    padding: 6px 0;
}

.choice-grid .choice-chip {
    width: 100%;
    height: auto;
    aspect-ratio: 1;
}

/* ============================================================
   Аналітика — добавь это в КОНЕЦ assets/css/app.css
   ============================================================ */

/* Индикатор изменения */
.change-indicator {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 16px;
    padding: 0 8px;
}
.change-indicator .positive { color: var(--success); font-weight: 600; }
.change-indicator .negative { color: var(--danger); font-weight: 600; }

/* Кругова діаграма */
.donut-wrap {
    display: flex;
    justify-content: center;
    padding: 8px 0;
}
.donut-chart {
    position: relative;
    width: 180px;
    height: 180px;
}
.donut-center {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    pointer-events: none;
}
.donut-center__label {
    font-size: 11px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.donut-center__value {
    font-size: 18px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    margin-top: 2px;
}

/* SVG диаграмм НЕ подчиняются глобальному size 1em */
.donut-chart svg {
    width: 180px !important;
    height: 180px !important;
}
.bars-chart svg {
    width: 100% !important;
    height: 120px !important;
}

/* Карточки аналитики — заметный фон как у блока сверху */
.app .card {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 18px;
    margin-bottom: 16px;
}

/* Топ категорій */
.top-categories {
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.top-cat__head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.top-cat__name {
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
}
.top-cat__dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}
.top-cat__amount {
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}
.top-cat__bar {
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
}
.top-cat__bar-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.4s ease;
}
.top-cat__meta {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Стовпчиковий графік */
.bars-chart {
    width: 100%;
    height: 120px;
}
.bars-axis {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 6px;
}

/* ============================================================
   Банер встановлення PWA — додай у КІНЕЦЬ assets/css/app.css
   ============================================================ */

.pwa-banner {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(76px + env(safe-area-inset-bottom)); /* над нижньою навігацією */
    background: var(--bg-card);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-lg);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-md);
    z-index: 200;
    max-width: 696px;
    margin: 0 auto;
    transform: translateY(140%);
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
}
.pwa-banner--visible {
    transform: translateY(0);
    opacity: 1;
}

.pwa-banner__icon { flex-shrink: 0; }

.pwa-banner__text {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.pwa-banner__text strong { font-size: 14px; font-weight: 600; }
.pwa-banner__text span { font-size: 12px; color: var(--text-secondary); line-height: 1.3; }
.pwa-banner__text b { color: var(--text); }

.pwa-banner__install {
    flex-shrink: 0;
    background: var(--accent);
    color: white;
    border: none;
    font-size: 14px;
    font-weight: 500;
    padding: 10px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
}
.pwa-banner__install:hover { background: var(--accent-hover); }

.pwa-banner__close {
    flex-shrink: 0;
    background: transparent;
    border: none;
    color: var(--text-tertiary);
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    padding: 0 4px;
    width: 32px;
    height: 32px;
}
.pwa-banner__close:hover { color: var(--text); }
