/* --- 1. ПЕРЕМЕННЫЕ И ОСНОВА --- */
:root {
    --bg: #f3f6f9;
    --card: #ffffff;
    --text: #333d47;
    --muted: #8e99a4;
    --accent: #24b09b;
    --accent-glow: rgba(36, 176, 155, 0.2);
    --danger: #eb4d4b;
}

body.dark-mode {
    --bg: #121212;
    --card: #1e1e1e;
    --text: #f5f5f5;
    --muted: #777;
    --accent-glow: rgba(36, 176, 155, 0.1);
}

body { 
    background: var(--bg) !important; 
    color: var(--text) !important; 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    margin: 0; 
    transition: 0.3s; 
    padding-bottom: 90px; 
    overflow-x: hidden;
}

/* --- 2. ШАПКА И УПРАВЛЕНИЕ --- */
header { background: var(--bg); padding-top: 10px; }

.header-actions { display: flex; align-items: center; gap: 10px; }

.btn-icon {
    background: var(--card) !important;
    border: 1px solid rgba(0,0,0,0.05) !important;
    border-radius: 12px !important;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text) !important;
    cursor: pointer;
}

body.dark-mode .btn-icon { border-color: rgba(255,255,255,0.1) !important; }

.currency-select {
    background: var(--card) !important;
    color: var(--text) !important;
    border: 1px solid rgba(0,0,0,0.05) !important;
    border-radius: 10px !important;
    font-weight: bold;
    padding: 6px 10px;
    outline: none;
}

/* --- 3. КАРТОЧКИ И БАЛАНС --- */
.balance-card {
    background: linear-gradient(135deg, #24b09b 0%, #1a7a6c 100%) !important;
    border-radius: 25px;
    padding: 30px;
    text-align: center;
    color: white !important;
    margin: 15px;
    box-shadow: 0 10px 20px var(--accent-glow);
}

.balance-amount { font-size: 2.5rem; font-weight: 800; margin: 0; }

.unallocated-card {
    background: var(--card) !important;
    border-left: 5px solid var(--accent) !important;
    margin: 15px;
    padding: 15px;
    border-radius: 15px;
    display: flex;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
}

.tiny-label { font-size: 0.65rem; font-weight: 800; color: var(--muted); letter-spacing: 0.5px; }

/* --- 4. КАТЕГОРИИ И КОЛЬЦА --- */
.categories-container { 
    display: flex; 
    overflow-x: auto; 
    gap: 20px; 
    padding: 10px 15px; 
    scrollbar-width: none; 
}

.categories-container::-webkit-scrollbar { display: none; }

.category-item { display: flex; flex-direction: column; align-items: center; min-width: 85px; cursor: pointer; }

.circle-wrap { position: relative; width: 80px; height: 80px; display: flex; align-items: center; justify-content: center; }

.ring-svg { position: absolute; transform: rotate(-90deg); }

.ring-bg { fill: none; stroke: #e0e0e0; stroke-width: 4; }
body.dark-mode .ring-bg { stroke: #333; }

.ring-bar { 
    fill: none; 
    stroke: var(--clr) !important; 
    stroke-width: 4; 
    stroke-linecap: round; 
    stroke-dasharray: 226; 
    stroke-dashoffset: 226; 
    transition: stroke-dashoffset 1.2s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Фиксированные размеры иконок SVG */
.cat-icon-svg {
    width: 20px !important;
    height: 20px !important;
    bottom: 8px !important; /* Опускаем чуть ниже */
}


body.dark-mode .cat-icon-svg { filter: invert(1); }

.cat-name { font-size: 13px; font-weight: 600; color: var(--text); margin-top: 8px; opacity: 0.8; }

/* --- 5. КНОПКИ (Улучшенная фиксация стилей) --- */
button.btn-save, button.btn-accent {
    background: var(--accent) !important;
    color: white !important;
    border: none !important;
    border-radius: 16px !important;
    padding: 16px !important;
    font-weight: 700 !important;
    width: 100% !important;
    display: block !important;
    box-shadow: 0 4px 15px var(--accent-glow) !important;
    transition: 0.2s !important;
    cursor: pointer;
}

button.btn-distribute {
    background: var(--accent) !important;
    color: white !important;
    border: none !important;
    border-radius: 10px !important;
    padding: 6px 15px !important;
    font-size: 0.85rem !important;
    font-weight: 600 !important;
    cursor: pointer;
}

button.btn-save:active, button.btn-distribute:active, button.fab:active { transform: scale(0.96); opacity: 0.9; }

/* --- 6. МОДАЛЬНОЕ ОКНО --- */
.bottom-sheet {
    position: fixed;
    bottom: -100%;
    left: 0;
    right: 0;
    background: var(--card) !important;
    border-radius: 30px 30px 0 0;
    z-index: 2000;
    transition: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    padding: 25px;
    box-shadow: 0 -10px 30px rgba(0,0,0,0.15);
    padding-bottom: calc(25px + env(safe-area-inset-bottom));
}

.bottom-sheet.active { bottom: 0; }

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    display: none;
    z-index: 1500;
    backdrop-filter: blur(5px);
}

.modal-overlay.active { display: block; }

/* --- 7. ИНПУТЫ И ВЫБОР ИКОНОК --- */
.input-block { margin-bottom: 20px; }
.input-block label { display: block; margin-bottom: 8px; font-size: 0.7rem; font-weight: 800; color: var(--muted); letter-spacing: 0.5px; }

.amount-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
}

.amount-input-group {
    display: flex;
    gap: 4px;
    /*background: rgba(100, 99, 99, 0.05); /* Легкий фон, чтобы было видно куда тыкать */
    padding: 8px 12px;
    border-radius: 12px;
    transition: 0.2s;
}

/* body.dark-mode .amount-input-group {
    background: rgba(255, 255, 255, 0.05);
} */

#expense-amount {
    font-size: 28px !important;
    font-weight: 800 !important;
    color: var(--text) !important; /* Теперь цвет меняется вместе с темой */
    width: 100%; /* Занимает всё доступное место в группе */
    border: none !important;
    background: transparent !important;
    outline: none !important;
    padding: 0 !important;
}

.description-area {
    padding: 16px;
    background: rgba(0, 0, 0, 0.015);
}

#expense-description {
    width: 100%;
    border: none !important;
    background: transparent !important;
    font-size: 15px;
    resize: none;
    color: var(--text) !important;
    /* Убираем рамку при клике */
    outline: none !important;
    /* Убираем синюю тень в Safari/Chrome */
    box-shadow: none !important;
}
#edit-tx-description {
    width: 100%;
    border: none !important;
    background: transparent !important;
    font-size: 15px;
    resize: none;
    color: var(--text) !important;
    /* Убираем рамку при клике */
    outline: none !important;
    /* Убираем синюю тень в Safari/Chrome */
    box-shadow: none !important;
}

/* На всякий случай отключаем выделение у контейнера, 
   если оно было добавлено ранее через :focus-within */
.description-area:focus-within {
    outline: none !important;
    border-color: transparent !important;
    box-shadow: none !important;
}

/* Настройка цвета плейсхолдера ("На что именно потратили?"), 
   чтобы он тоже был виден, но чуть тусклее */
#expense-description::placeholder {
    color: var(--muted);
    opacity: 0.6;
}

.main-select {
    width: 100%;
    padding: 14px;
    border-radius: 12px;
    border: 1px solid rgba(0,0,0,0.1);
    background: var(--bg) !important;
    color: var(--text) !important;
    font-weight: 600;
}

/* Сетка выбора иконок в редакторе */
.icon-picker-grid { display: flex; gap: 12px; overflow-x: auto; padding: 10px 0; scrollbar-width: none; }
.icon-option { 
    min-width: 50px; height: 50px; 
    display: flex; align-items: center; justify-content: center; 
    background: var(--bg); border-radius: 12px; border: 2px solid transparent; 
}
.icon-option.selected { border-color: var(--accent); background: var(--card); }
.icon-option img { width: 24px; height: 24px; filter: grayscale(1); }
body.dark-mode .icon-option img { filter: invert(1); }

/* Цвета */
.color-picker { display: flex; gap: 12px; overflow-x: auto; padding: 10px 0; }
.color-dot { min-width: 35px; height: 35px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; }
.color-dot.selected { border-color: var(--text); transform: scale(1.1); }

/* --- 8. ТАББАР И ПЕРЕКЛЮЧАТЕЛИ --- */
.type-switcher {
    background: var(--bg);
    padding: 4px;
    border-radius: 14px;
    display: flex;
    gap: 4px;
}

button.sw-btn {
    flex: 1;
    border: none;
    background: transparent;
    padding: 10px;
    border-radius: 10px;
    font-weight: 700;
    color: var(--muted);
    transition: 0.3s;
}

button.sw-btn.active {
    background: var(--card) !important;
    color: var(--accent) !important;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.footer-nav {
    position: fixed;
    bottom: 0;
    width: 100%;
    height: 75px;
    background: var(--card) !important;
    display: flex;
    justify-content: space-around;
    align-items: center;
    border-top: 1px solid rgba(0,0,0,0.05);
    z-index: 1000;
}

.nav-btn {
    background: none;
    border: none;
    color: var(--muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 11px;
    font-weight: 600;
    gap: 4px;
    cursor: pointer;
}

.nav-btn.active { color: var(--accent) !important; }

.fab-center { position: relative; top: -25px; background: var(--bg); padding: 6px; border-radius: 50%; }

button.fab {
    width: 58px;
    height: 58px;
    background: var(--accent) !important;
    border: none !important;
    border-radius: 50% !important;
    color: white !important;
    font-size: 30px !important;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 6px 15px var(--accent-glow) !important;
    cursor: pointer;
}

/* --- 9. СПЕЦ-ЭФФЕКТЫ --- */
@keyframes pulse-dist {
    0% { transform: scale(1); box-shadow: 0 0 0 0 rgba(36, 176, 155, 0.4); }
    50% { transform: scale(1.05); box-shadow: 0 0 0 10px rgba(36, 176, 155, 0); }
    100% { transform: scale(1); }
}

.distribute-active .circle-wrap {
    animation: pulse-dist 1.5s infinite;
    border: 2px solid var(--accent);
    border-radius: 50%;
}

.distribute-active * { pointer-events: none; }

/* Иконка теперь в центре */
.cat-icon-main {
    width: 30px !important;
    height: 30px !important;
    position: absolute !important;
    z-index: 2;
    object-fit: contain;
    transition: 0.3s;
    top: 60% !important;
    left: 50% !important;
    transform: translate(-50%, -80%) !important; /* Центрируем и чуть приподнимаем над цифрами */
}

body.dark-mode .cat-icon-main { filter: invert(1); }

/* Контейнер для цифр под иконкой */
.cat-stats-minimal {
    position: absolute;
    display: flex;
    align-items: center;
    bottom: 18px; /* Размещаем в нижней части круга */
    gap: 2px;
    z-index: 3;
    font-family: 'Inter', sans-serif;
}

/* Стили для чисел */
.spent-tiny {
    font-size: 10px;
    font-weight: 600;
    color: var(--muted);
}

.separator {
    font-size: 9px;
    color: var(--muted);
    opacity: 0.5;
}

.left-tiny {
    font-size: 10px;
    font-weight: 800;
    color: var(--text);
}

/* Кольца (без изменений, из твоего рабочего CSS) */
.ring-svg { position: absolute; transform: rotate(-90deg); }
.ring-bg { fill: none; stroke: #e0e0e0; stroke-width: 4; }
body.dark-mode .ring-bg { stroke: #333; }
.ring-bar { 
    fill: none; stroke: var(--clr) !important; stroke-width: 4; 
    stroke-linecap: round; stroke-dasharray: 226; transition: 1.2s; 
}

/* Кнопка отмены распределения */
button.btn-cancel {
    background: #e9ecef !important;
    color: #495057 !important;
    border: none !important;
    border-radius: 10px !important;
    padding: 6px 15px !important;
    font-size: 0.85rem !important;
    font-weight: 600 !important;
    cursor: pointer;
}

body.dark-mode button.btn-cancel {
    background: #2d2d2d !important;
    color: #f5f5f5 !important;
}

/* Визуальный эффект для категорий в режиме распределения */
.distribute-active {
    filter: brightness(1.1);
    transform: scale(1.02);
}

.main-input-text {
    background: var(--bg) !important;
    border: 1px solid rgba(0,0,0,0.1) !important;
    border-radius: 12px !important;
    color: var(--text) !important;
    font-size: 1rem !important;
    font-weight: 600 !important;
    width: 100%;
    padding: 12px !important;
    outline: none !important;
}
/* Карточка общего итога в статс */
.stats-summary-card {
    background: var(--accent) !important;
    border-radius: 20px;
    padding: 20px;
    color: white !important;
    box-shadow: 0 8px 15px var(--accent-glow);
}

/* Список деталей */
.stats-list { display: flex; flex-direction: column; gap: 12px; padding-bottom: 20px; }

.stats-row {
    background: var(--card) !important;
    padding: 15px;
    border-radius: 18px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.stats-row-header { display: flex; justify-content: space-between; align-items: center; }

/* Мини прогресс-бар для списка */
.stats-progress-container {
    width: 100%;
    height: 6px;
    background: var(--bg);
    border-radius: 10px;
    overflow: hidden;
}

.stats-progress-fill {
    height: 100%;
    border-radius: 10px;
    transition: width 0.5s ease;
}

/* Контейнер графика */
.chart-box {
    position: relative;
    width: 100%;
    max-width: 300px; /* Ограничиваем ширину для ПК */
    margin: 30px auto; /* Центрируем сам блок по горизонтали */
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Центрирование текста внутри кольца */
.chart-center-info {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    pointer-events: none; /* Чтобы текст не мешал кликам по графику */
    z-index: 10;
}

#chart-pct-label {
    font-size: 28px;
    font-weight: 800;
    color: var(--text);
    line-height: 1;
}

.chart-center-info small {
    font-size: 10px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-top: 4px;
}
/* Стильный бейдж MAX */
.max-badge {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: var(--accent-glow);
    color: var(--accent);
    padding: 4px 10px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 800;
    cursor: pointer;
    letter-spacing: 0.5px;
    transition: 0.2s;
    border: 1px solid transparent;
}

.max-badge:active {
    background: var(--accent);
    color: white;
}

/* Центрируем ввод для красоты в этом окне */
#distribute-ui .main-input {
    padding-right: 60px; /* Оставляем место для бейджа */
}

.btn-danger-outline {
    background: transparent;
    color: #ff3b30; /* Стандартный красный Apple/Telegram */
    border: 1px solid #ff3b30;
    border-radius: 12px;
    padding: 14px;
    font-size: 16px;
    font-weight: 600;
    width: 100%;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 12px;
}

.btn-danger-outline:active {
    background: rgba(255, 59, 48, 0.1);
    transform: scale(0.98);
}

.btn-danger-outline i {
    font-size: 18px;
}

.tx-icon-circle {
    width: 40px;
    height: 40px;
    border-radius: 12px; /* Слегка закругленные квадраты выглядят современнее */
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.tx-icon-circle img {
    width: 20px;
    height: 20px;
    /* Убираем жесткий инверт, если иконки цветные, 
       или оставляем, если они всегда белые в цветном фоне */
    filter: brightness(0) saturate(100%) invert(35%) sepia(10%) saturate(1000%) hue-rotate(130deg); 
}

/* Если хочешь оставить иконки белыми на цветном фоне: */
.tx-icon-circle img {
    filter: brightness(0) invert(1);
}

.section-title {
    font-size: 12px;
    font-weight: 800;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-left: 5px;
}
.timeline-container {
    background: var(--card);
    border-radius: 24px;
    padding: 8px 0;
    box-shadow: 0 4px 15px rgba(0,0,0,0.02);
}

.tx-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 20px;
    transition: background 0.2s;
    border-bottom: 1px solid rgba(0,0,0,0.03);
}

.tx-item:last-child { border-bottom: none; }

.tx-item:active { background: rgba(0,0,0,0.03); }

.tx-icon-circle {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.tx-info { display: flex; flex-direction: column; gap: 2px; }

.tx-title { font-size: 14px; font-weight: 600; color: var(--text); }

.tx-sub { font-size: 11px; color: var(--muted); font-weight: 500; }

.tx-amount-block { text-align: right; }

.timeline-label { font-size: 13px; font-weight: 800; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }

.view-all-link { font-size: 12px; color: var(--accent); font-weight: 600; cursor: pointer; }


.history-sheet {
    height: 80vh !important; /* Окно на 80% высоты экрана */
    display: flex;
    flex-direction: column;
}

.history-scroll-container {
    flex-grow: 1;
    overflow-y: auto;
    padding-bottom: 40px;
    /* Убираем полосу прокрутки для чистоты */
    -ms-overflow-style: none;
    scrollbar-width: none;
}

.history-scroll-container::-webkit-scrollbar { display: none; }

.modal-header-line {
    width: 40px;
    height: 4px;
    background: rgba(0,0,0,0.1);
    border-radius: 2px;
    margin: 10px auto;
}

.no-border-input {
    border: none !important;                /* Убирает границу */
    background: transparent !important;
    box-shadow: none !important;          /* Убирает тень/свечение при фокусе */
    background-color: transparent;        /* По желанию: делает фон прозрачным */
    color: var(--text) !important;
}

.no-border-input:focus {
    border: none !important;
    background: transparent !important;
    box-shadow: none !important;          /* Гарантирует отсутствие обводки при фокусе */
}

/* Блокировщик с эффектом размытия */
.distribution-blocker {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.2); /* Легкое затемнение */
    backdrop-filter: blur(8px);    /* Размытие */
    -webkit-backdrop-filter: blur(8px);
    z-index: 1000;
    display: none; /* По умолчанию скрыт */
    opacity: 0;
    transition: opacity 0.3s ease;
}

.distribution-blocker.active {
    display: block;
    opacity: 1;
}

/* Выводим блок распределения и категории над блюром */
#unallocated-box, 
.category-item, 
#btn-cancel-dist {
    position: relative !important;
    z-index: 1001 !important; /* Выше уровня блюра (1000) */
}

/* Чтобы unallocated-box не просвечивал фон при блюре */
#unallocated-box {
    background: var(--card) !important;
    isolation: isolate; /* Создает чистый контекст наложения */
}
/* Кнопка закрытия */
.btn-close-modal {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 36px; /* Чуть больше для удобства нажатия */
    height: 36px;
    border-radius: 50%;
    background: var(--bg);
    border: none;
    color: var(--muted);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1100; /* Гарантированно выше контента */
    padding: 0;
    transition: all 0.2s ease;
}

.btn-close-modal:active {
    transform: scale(0.9);
    background: rgba(0,0,0,0.05);
}

/* ИСПРАВЛЕНИЕ НАЛЕЗАНИЯ: Резервируем место под кнопку в заголовке */
.modal-content h5 {
    margin-top: 5px;
    padding-right: 45px; /* Резерв места для крестика */
    line-height: 1.4;
    word-break: break-word; /* Чтобы длинные слова не ломали верстку */
}

/* Фикс для темной темы */
body.dark-mode .btn-close-modal {
    background: #2c2c2c;
    color: #fff;
}

.category-item:active {
    transform: scale(0.92);
    transition: transform 0.1s ease;
}

/* Контейнер модального окна истории */
#history-modal {
    display: flex;
    flex-direction: column;
    max-height: 85vh; /* Ограничиваем высоту до 85% экрана */
    padding-bottom: env(safe-area-inset-bottom);
}

/* Заголовок окна (фиксированный) */
.modal-header-custom {
    padding: 10px 0 20px 0;
    flex-shrink: 0; /* Чтобы заголовок не сжимался */
}

/* Область со списком (скроллируемая) */
#full-history-list {
    overflow-y: auto; /* Включаем вертикальный скролл */
    flex-grow: 1;    /* Занимает всё свободное пространство */
    padding-bottom: 20px;
    
    /* Плавный скролл на iOS */
    -webkit-overflow-scrolling: touch; 
}

/* Скрываем полосу прокрутки, если хочешь "чистый" вид */
#full-history-list::-webkit-scrollbar {
    width: 0px;
    background: transparent;
}

/* Фикс скролла для модального окна истории */
#history-modal {
    max-height: 85vh !important;
    display: flex !important;
    flex-direction: column !important;
}

#full-history-list {
    overflow-y: auto !important; /* Разрешаем скролл */
    flex: 1 !important;         /* Занимаем всё свободное место */
    -webkit-overflow-scrolling: touch;
    padding-bottom: 20px;
}

button:disabled {
    background-color: #ccc !important;
    cursor: not-allowed;
    pointer-events: none; /* Чтобы нельзя было нажать */
}
.tutorial-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    z-index: 3000;
    pointer-events: auto;
}

.tutorial-highlight {
    position: absolute;
    box-shadow: 0 0 0 9999px rgba(0,0,0,0.7);
    border-radius: 15px;
    transition: all 0.3s ease;
    z-index: 3001;
    pointer-events: none; /* Пропускает клики к элементу под ним */
}

.tutorial-tooltip {
    position: absolute;
    background: var(--card);
    color: var(--text);
    padding: 15px;
    border-radius: 15px;
    width: 250px;
    z-index: 3002;
    box-shadow: 0 10px 25px rgba(0,0,0,0.2);
    transition: all 0.3s ease;
}