:root {
    --primary: #00d4aa;
    --primary-dim: rgba(0,212,170,0.15);
    --bg-main: #0b0f19;
    --surface: #151b2b;
    --surface-light: #1e2738;
    --border: #2a3447;
    --text-primary: #e6e8f0;
    --text-secondary: #8b90a5;
    --text-muted: #5a607a;
    --warning: #f59e0b;
    --info: #3b82f6;
    --success: #10b981;
    --radius: 16px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background: var(--bg-main);
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-primary);
    padding-bottom: 70px;
}

.container {
    max-width: 640px;
    margin: 0 auto;
    padding: 16px;
}

/* Страницы (переключаемые) */
.page {
    display: none;
    animation: fade 0.2s ease;
}
.page.active {
    display: block;
}
@keyframes fade {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Карточки */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}
h1, h2, h3 {
    color: var(--text-primary);
}
h1 { font-size: 24px; margin-bottom: 8px; }
h2 { font-size: 20px; margin-bottom: 16px; }
h3 { font-size: 16px; margin-bottom: 12px; color: var(--primary); }

/* Поля ввода */
.input-group {
    margin-bottom: 16px;
}
.input-group label {
    display: block;
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}
.input-group input,
.input-group select,
input[type="date"],
input[type="number"],
input[type="text"] {
    width: 100%;
    padding: 12px;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: 14px;
    color: var(--text-primary);
    font-size: 16px;
}
button {
    background: var(--primary);
    color: #000;
    border: none;
    padding: 12px;
    border-radius: 16px;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
}
button:active {
    transform: scale(0.98);
}
.reset-btn {
    background: #2a2a2a;
    color: white;
}
.toggle-btn {
    background: #2c2c2c;
    margin-bottom: 12px;
}
.button-group {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}
.button-group button {
    flex: 1;
}
@media (max-width: 480px) {
    .button-group {
        flex-direction: column;
        gap: 8px;
    }
}

/* Бары прогресса */
.bars-container {
    margin: 20px 0;
}
.bar-item {
    margin-bottom: 20px;
}
.bar-label {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}
.bar-bg {
    background: var(--surface-light);
    border-radius: 999px;
    height: 28px;
    overflow: hidden;
}
.bar-fill {
    height: 100%;
    width: 0%;
    transition: width 0.5s ease;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 10px;
    color: white;
    font-weight: bold;
    font-size: 11px;
    border-radius: 999px;
}
.fill-month, .fill-expense, .fill-year, .fill-savings, .fill-total {
    background: var(--primary);
}

/* Круговые диаграммы целей */
.goals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    margin: 20px 0;
    justify-items: center;
}
.goal-card {
    background: var(--surface-light);
    border-radius: 20px;
    padding: 12px;
    text-align: center;
    width: 100%;
    max-width: 180px;
    box-sizing: border-box;
}
.goal-card canvas {
    display: block;
    margin: 0 auto;
    max-width: 100%;
    height: auto;
}

.goal-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--primary);
    margin-top: 8px;
}
.goal-amount {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Категории, транзакции, списки */
.category-manager {
    background: var(--surface-light);
    padding: 16px;
    border-radius: 18px;
    margin-bottom: 20px;
}
.category-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0;
}
.category-item {
    background: #2a2a2a;
    padding: 6px 12px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.category-item button {
    background: var(--primary);
    width: auto;
    padding: 4px 8px;
    font-size: 11px;
}
.transaction-list {
    max-height: 400px;
    overflow-y: auto;
}
.transaction-item {
    background: var(--surface-light);
    padding: 12px;
    margin: 8px 0;
    border-radius: 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}
.transaction-info strong {
    display: block;
}
.transaction-info small {
    font-size: 11px;
    color: var(--text-muted);
}
.transaction-amount button {
    width: auto;
    padding: 6px 12px;
}

/* Статистика */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--surface-light);
    padding: 16px;
    border-radius: 18px;
    text-align: center;
}
.stat-card p {
    font-size: 24px;
    font-weight: bold;
    color: var(--primary);
}
.period-select {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
}
.period-select button {
    background: #2a2a2a;
    color: var(--text-secondary);
}
.period-select button.active {
    background: var(--primary);
    color: #000;
}
canvas {
    max-height: 220px;
    width: 100%;
    background: var(--surface-light);
    border-radius: 16px;
    padding: 8px;
    margin-top: 16px;
}

/* Нижняя панель навигации */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px));
    z-index: 100;
}
.nav-btn {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px 8px;
    border-radius: 30px;
    transition: 0.2s;
    cursor: pointer;
    flex: 1;
}
.nav-icon {
    font-size: 22px;
    color: var(--text-muted);
    transition: 0.2s;
}
.nav-label {
    font-size: 11px;
    font-weight: 500;
    color: var(--text-muted);
    transition: 0.2s;
}
.nav-btn.active {
    background: var(--primary-dim);
}
.nav-btn.active .nav-icon,
.nav-btn.active .nav-label {
    color: var(--primary);
    font-weight: 600;
}
.nav-btn:active {
    transform: scale(0.96);
}
/* Инфо-блоки */
.info-box {
    background: var(--surface-light);
    color: var(--primary);
    padding: 12px;
    border-radius: 14px;
    margin: 12px 0;
    border-left: 4px solid var(--primary);
}
.warning {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning);
    padding: 12px;
    border-radius: 14px;
    margin-top: 12px;
}

/* Модальное окно настроек */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 24px;
    width: 90%;
    max-width: 320px;
    position: relative;
    text-align: center;
}
.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.close-modal {
    position: absolute;
    top: 12px;
    right: 16px;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-muted);
}

/* Адаптив */
@media (max-width: 640px) {
    .container {
        padding: 12px;
    }
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .goals-grid {
        gap: 12px;
        grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    }
    .goal-card canvas {
        width: 100px;
        height: 100px;
    }
}
/* Принудительные стили для всех select */
select,
select:focus,
select option {
    background-color: var(--surface-light) !important;
    color: var(--text-primary) !important;
    border: 1px solid var(--border) !important;
    border-radius: 14px !important;
    padding: 12px !important;
    font-size: 16px !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='white'><path d='M7 10l5 5 5-5z'/></svg>") !important;
    background-repeat: no-repeat !important;
    background-position: right 12px center !important;
    cursor: pointer !important;
}

/* Для выпадающих опций (в Chrome/Edge) */
select option {
    background: var(--surface) !important;
    color: var(--text-primary) !important;
}

/* Специально для select внутри модальных окон и форм */
.modal-content select,
.category-manager select,
.input-group select {
    width: 100% !important;
    margin-bottom: 12px !important;
}
/* Принудительное исправление для date-полей на iOS */
input[type="date"] {
    display: block;
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    -webkit-appearance: none;
    appearance: none;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
    font-size: 16px;
    color: var(--text-primary);
}

/* Убираем лишние внутренние отступы у календаря */
input[type="date"]::-webkit-calendar-picker-indicator {
    opacity: 0.6;
    filter: invert(1);
    cursor: pointer;
}

/* Отступы между полями в блоках добавления расходов и доходов */
.category-manager input,
.category-manager select,
.category-manager button {
    margin-bottom: 16px;
}
.category-manager button:last-child {
    margin-bottom: 0;
}

/* Блок «Новая цель» (отдельные поля) */
#savings > .card > div:first-child input,
#savings > .card > div:first-child button {
    margin-bottom: 16px;
}
#savings > .card > div:first-child button:last-child {
    margin-bottom: 0;
}

/* Блок «Добавить взнос» внутри .category-manager (уже покрыт, но уточним) */
#contributionGoalSelect,
#contributionAmount,
#contributionDesc,
#contributionDate,
#savings .category-manager button {
    margin-bottom: 16px;
}
#savings .category-manager button:last-child {
    margin-bottom: 0;
}

.sub-nav-btn {
    background: var(--surface-light);
    border: 1px solid var(--border);
    color: var(--text-secondary);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
    flex: 1;
}
.sub-nav-btn.active {
    background: var(--primary);
    color: #000;
    border-color: var(--primary);
}
.sub-page {
    display: none;
}
.sub-page.active {
    display: block;
}
/* Стили для фильтров истории */
.filter-bar {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
    align-items: center;
}
.filter-input {
    flex: 1;
    background: var(--surface-light);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px;
    color: var(--text-primary);
    font-size: 16px;
    font-family: inherit;
}
.filter-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-dim);
}
/* Кнопка сброса фильтра (стиль как у reset-btn) */
.filter-bar .reset-btn {
    background: #2a2a2a;
    color: white;
    width: auto;
    padding: 12px 20px;
    font-size: 14px;
}
.filter-bar .reset-btn:hover {
    background: #3a3a3a;
}
