/* Базовые настройки и шрифт */
:root {
    --bg-color: #ffffff;
    --text-color: #000000;
    --border-color: #000000;
    --btn-red: #e63946;
    --btn-blue: #457b9d;
    --btn-green: #2a9d8f;
    --btn-gray: #8d99ae;
    --warning: #f4d03f;
    --danger: #e74c3c;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden; /* Запрещаем скролл всей страницы */
}

body {
    font-family: 'Press Start 2P', cursive;
    background-color: var(--bg-color);
    color: var(--text-color);
    font-size: 10px;
    line-height: 1.5;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* Экраны */
.screen {
    display: none;
    flex-direction: column;
    height: 100%;
    padding: 10px;
}
.screen.active {
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 20px 10px;
}

/* Центрируем только экран авторизации */
#auth-screen.active {
    justify-content: center;
    align-items: center;
}

/* Ретро рамки и блоки */
.retro-box {
    border: 4px solid var(--border-color);
    padding: 20px;
    text-align: center;
    box-shadow: 8px 8px 0px var(--border-color);
    width: 90%;
    max-width: 400px;
    max-height: 90dvh; /* Не больше 90% высоты экрана */
    overflow-y: auto; /* Скролл внутри формы, если нужно */
}

/* Центрирование экрана авторизации */
#auth-screen {
    justify-content: center;
    align-items: center;
}

.retro-title {
    font-size: 24px;
    margin-bottom: 20px;
    line-height: 1.2;
    text-transform: uppercase;
}
.retro-title.small {
    font-size: 14px;
    margin-bottom: 15px;
    text-align: center;
}

/* Инпуты */
.retro-input {
    width: 100%;
    padding: 10px;
    margin-bottom: 15px;
    border: 4px solid var(--border-color);
    font-family: 'Press Start 2P', cursive;
    font-size: 10px;
    background: #fff;
    outline: none;
}
.retro-input:focus {
    background: #f0f0f0;
}

/* Кнопки */
.retro-btn {
    font-family: 'Press Start 2P', cursive;
    font-size: 10px;
    padding: 12px 15px;
    border: 4px solid var(--border-color);
    background: #fff;
    color: #fff;
    cursor: pointer;
    text-transform: uppercase;
    margin-bottom: 10px;
    box-shadow: 4px 4px 0px var(--border-color);
    transition: transform 0.1s, box-shadow 0.1s;
}
.retro-btn:active {
    transform: translate(4px, 4px);
    box-shadow: 0px 0px 0px var(--border-color);
}

.retro-btn.red { background: var(--btn-red); }
.retro-btn.blue { background: var(--btn-blue); }
.retro-btn.green { background: var(--btn-green); }
.retro-btn.gray { background: var(--btn-gray); }

.big-btn {
    width: 100%;
    font-size: 14px;
    padding: 15px;
    margin: 20px 0;
}
.small-btn {
    width: 100%;
    margin-bottom: 10px;
}
.full-width {
    width: 100%;
}

/* Верхняя панель */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 4px solid var(--border-color);
    padding-bottom: 10px;
    margin-bottom: 15px;
    font-size: 9px;
    gap: 10px; /* Добавили отступ между элементами */
}
.user-info, .month-selector {
    cursor: pointer;
}

/* Балансы */
.balance-box {
    border: 4px solid var(--border-color);
    padding: 10px;
    margin-bottom: 10px;
}
.balance-item {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 2px dashed #ccc;
}
.balance-item:last-child {
    border-bottom: none;
}
.balance-item .label { color: #555; }
.balance-item .value { font-size: 12px; }

/* Категории */
.categories-list {
    border: 4px solid var(--border-color);
    padding: 10px;
}
.category-item {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 2px dashed #ccc;
}
.category-item.warning { background-color: rgba(244, 208, 63, 0.3); }
.category-item.danger { background-color: rgba(231, 76, 60, 0.3); }

/* Нижнее меню */
.bottom-nav {
    margin-top: auto;
    display: flex;
    border-top: 4px solid var(--border-color);
    background: #fff;
}
.nav-btn {
    flex: 1;
    padding: 15px 5px;
    font-family: 'Press Start 2P', cursive;
    font-size: 9px;
    background: #fff;
    color: #e9a820; /* Янтарный вместо синего */
    border: none;
    border-right: 4px solid var(--border-color);
    cursor: pointer;
}
.nav-btn:last-child { border-right: none; }
.nav-btn.active {
    background: var(--text-color);
    color: #fff;
}

/* Вкладки контента */
.tab { 
    display: none; 
    flex: 1; 
    overflow-y: auto; 
    padding-bottom: 100px; /* Увеличили отступ */
}
.tab.active { 
    display: block; 
}

/* Модальные окна и оверлей */
.overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px); /* Эффект блюра */
    z-index: 100;
}
.overlay.active { display: block; }

.modal {
    display: none;
    position: fixed;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    z-index: 101;
    width: 90%;
    max-width: 400px;
}
.modal.active { display: block; }

.modal-content {
    background: #fff;
    border: 4px solid var(--border-color);
    padding: 20px;
    box-shadow: 8px 8px 0px var(--border-color);
    position: relative;
}
.close-btn {
    position: absolute;
    top: 10px; right: 15px;
    font-size: 16px;
    cursor: pointer;
    font-weight: bold;
}

.settings-block {
    border: 4px solid var(--border-color);
    padding: 10px;
    margin-bottom: 15px;
    font-size: 9px;
}
.settings-footer {
    margin-top: 30px;
}

/* Фикс для iOS PWA */
html {
    width: 100%;
    height: 100%;
}

/* Фикс для iOS PWA */
body {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    /* ВАЖНО: сохраняем отступы для статус-бара, а не обнуляем их! */
    padding-top: env(safe-area-inset-top) !important;
    padding-bottom: env(safe-area-inset-bottom) !important;
    padding-left: env(safe-area-inset-left) !important;
    padding-right: env(safe-area-inset-right) !important;
}
#app-screen {
    width: 100% !important;
    max-width: 100% !important;
    padding: 10px !important;
}

.content-area {
    width: 100% !important;
    max-width: 100% !important;
}

.bottom-nav {
    width: 100% !important;
    max-width: 100% !important;
    position: fixed;
    bottom: 0;
    left: 0;
}

.tab {
    width: 100% !important;
    max-width: 100% !important;
}

.balance-box,
.categories-list,
.retro-btn.big-btn {
    width: 100% !important;
    max-width: 100% !important;
    box-sizing: border-box;
}

.top-bar {
    width: 100% !important;
    max-width: 100% !important;
}

/* Предотвращаем zoom на iOS */
input, select, textarea {
    font-size: 12px !important;
}

.retro-input {
    font-size: 12px !important;
    padding: 8px !important;
    width: 100%;
    box-sizing: border-box;
}

/* Запрещаем горизонтальный скролл */
html, body {
    overflow-x: hidden;
    max-width: 100vw;
}

.screen {
    max-width: 100vw;
    overflow-x: hidden;
}

.delete-btn {
    font-family: 'Press Start 2P', cursive;
    font-size: 8px;
    background: #e74c3c;
    color: #fff;
    border: 2px solid #000;
    padding: 4px 6px;
    cursor: pointer;
    box-shadow: 2px 2px 0px #000;
}

.delete-btn:active {
    transform: translate(2px, 2px);
    box-shadow: 0px 0px 0px #000;
}

/* Отступы для секций в настройках */
#tab-settings .categories-list {
    margin-bottom: 15px;
}

#tab-settings .retro-title.small {
    margin-top: 20px;
    margin-bottom: 10px;
}

#tab-settings .settings-block {
    margin-bottom: 20px;
}

/* Отступ перед кнопками добавления */
#tab-settings .retro-btn.small-btn {
    margin-top: 10px;
    margin-bottom: 10px;
}

/* Отступ перед кнопками выхода и удаления */
.settings-footer {
    margin-top: 30px;
    margin-bottom: 20px;
}

/* Общий отступ внизу вкладки настроек */
#tab-settings {
    padding-bottom: 80px;
}

/* Дополнительный отступ для вкладки настроек */
#tab-settings {
    padding-bottom: 120px;
}

.settings-footer {
    margin-top: 30px;
    margin-bottom: 30px;
}

/* Цвета рамок для секций в настройках */
.account-item {
    border: 3px solid #000;
}

.cash-item {
    border: 3px solid #000;
}

.income-cat-item {
    border: 3px solid #2d5016; /* Темно-зеленый */
}

.expense-cat-item {
    border: 3px solid #8b0000; /* Бордовый */
}

.savings-item {
    border: 3px solid #808080; /* Серый */
}

/* Кнопка редактирования */
.edit-btn {
    font-family: 'Press Start 2P', cursive;
    font-size: 8px;
    background: #e9a820; /* Янтарный */
    color: #fff;
    border: 2px solid #000;
    padding: 4px 6px;
    cursor: pointer;
    box-shadow: 2px 2px 0px #000;
    margin-right: 5px;
}

.edit-btn:active {
    transform: translate(2px, 2px);
    box-shadow: 0px 0px 0px #000;
}

/* Цвета рамок для секций в настройках */
.account-item {
    border: 3px solid #000;
}

.cash-item {
    border: 3px solid #000;
}

.income-cat-item {
    border: 3px solid #2d5016;
}

.expense-cat-item {
    border: 3px solid #8b0000;
}

.savings-item {
    border: 3px solid #808080;
}

/* Убираем рамку у контейнера в настройках */
#tab-settings .categories-list {
    border: none;
    padding: 0;
}

/* Добавляем цветные рамки напрямую к элементам */
#tab-settings .account-item {
    border: 3px solid #000 !important;
    padding: 10px;
    margin-bottom: 10px;
}

#tab-settings .cash-item {
    border: 3px solid #000 !important;
    padding: 10px;
    margin-bottom: 10px;
}

#tab-settings .income-cat-item {
    border: 3px solid #2d5016 !important;
    padding: 10px;
    margin-bottom: 10px;
}

#tab-settings .expense-cat-item {
    border: 3px solid #8b0000 !important;
    padding: 10px;
    margin-bottom: 10px;
}

#tab-settings .savings-item {
    border: 3px solid #808080 !important;
    padding: 10px;
    margin-bottom: 10px;
}

/* Отступы между элементами внутри категорий */
.categories-list .category-item {
    margin-bottom: 10px;
    padding-bottom: 10px;
}

.categories-list .category-item:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
}

/* Блок графика */
.chart-box {
    border: 4px solid #000;
    padding: 15px;
    margin-bottom: 10px;
    min-height: 200px;
}

.chart-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 2px dashed #ccc;
}

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

.chart-color {
    width: 20px;
    height: 20px;
    border: 2px solid #000;
    margin-right: 10px;
}

.chart-label {
    flex: 1;
    font-size: 9px;
}

.chart-value {
    font-size: 11px;
    text-align: right;
    min-width: 80px;
}

.chart-percent {
    font-size: 9px;
    color: #666;
    margin-left: 5px;
}

/* Отступы для блоков на главной странице */
#tab-home .balance-box {
    margin-bottom: 20px;
}

#tab-home .retro-btn.big-btn {
    margin-bottom: 30px;
}

#tab-home .categories-list {
    margin-bottom: 20px;
}

#tab-home .chart-box {
    margin-bottom: 30px;
}

#tab-home .retro-title.small {
    margin-top: 25px;
    margin-bottom: 10px;
}

/* Дополнительный отступ внизу главной вкладки */
#tab-home {
    padding-bottom: 120px;
}

/* Список месяцев */
.month-list {
    max-height: 60vh;
    overflow-y: auto;
    margin-top: 15px;
}

.month-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 10px;
    border-bottom: 2px dashed #ccc;
    cursor: pointer;
    transition: background 0.2s;
}

.month-item:hover {
    background: #f0f0f0;
}

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

.month-item.active {
    background: #000;
    color: #fff;
}

.month-item.active:hover {
    background: #333;
}

.month-label {
    font-size: 10px;
}

.month-badge {
    font-size: 8px;
    color: #e9a820;
    margin-left: 10px;
}

.month-item.active .month-badge {
    color: #e9a820;
}

/* Растягиваем кнопку FACE ID на экране входа */
#auth-screen #btn-faceid-login {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    margin-top: 10px;
}

/* Фикс поля даты — не даем ему вылезать за экран */
#tx-date {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box !important;
    padding: 8px !important;
    font-size: 12px !important;
    display: block;
}

/* ====== ТУТОРИАЛ ====== */
.tutorial-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 10001;
    pointer-events: none;
}
.tutorial-backdrop {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 10000;
    pointer-events: auto;
}
.tutorial-spotlight {
    position: absolute;
    border: 4px solid #e9a820;
    border-radius: 8px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.7), 0 0 30px rgba(233, 168, 32, 0.8);
    transition: all 0.4s ease;
    z-index: 10002;
    pointer-events: none;
}
.tutorial-tooltip {
    position: fixed;
    background: #fff;
    border: 4px solid #000;
    padding: 15px;
    font-size: 10px;
    line-height: 1.6;
    max-width: 90%;
    width: 320px;
    z-index: 10003;
    pointer-events: auto;
    box-shadow: 6px 6px 0 #000;
}
.tutorial-tooltip h3 {
    font-size: 12px;
    margin: 0 0 10px 0;
    color: #e63946;
}
.tutorial-tooltip p {
    margin: 0 0 15px 0;
}
.tutorial-tooltip-buttons {
    display: flex;
    gap: 8px;
}
.tutorial-step-counter {
    font-size: 8px;
    color: #666;
    margin-bottom: 10px;
}
.tutorial-highlight-pulse {
    animation: tutorialPulse 1s infinite;
}
@keyframes tutorialPulse {
    0%, 100% { box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.7), 0 0 30px rgba(233, 168, 32, 0.8); }
    50% { box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.7), 0 0 50px rgba(233, 168, 32, 1); }
}