/* --- ПЕРЕМЕННЫЕ ТЁМНОЙ ТЕМЫ --- */
:root {
    --theme-bg: #0f0c29;
    --bg-gradient: linear-gradient(135deg, #0f0c29 0%, #302b63 50%, #24243e 100%);
    
    --text-main: #ffffff;
    --text-muted: #a0a0b0;
    --active-nav: #ffffff;
    
    --glass-bg: rgba(30, 30, 45, 0.4);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);
    
    /* Делаем панели более прозрачными, чтобы был виден блюр */
    --panel-bg: rgba(15, 12, 41, 0.4); 
    --panel-border: rgba(255, 255, 255, 0.08);
    
    --section-bg: rgba(0,0,0,0.2);
    --formula-bg: rgba(0,0,0,0.3);
    --cal-day-bg: rgba(255,255,255,0.05);
    --cal-day-border: transparent;
    --cal-day-today: rgba(255,255,255,0.5);
    
    --btn-bg: rgba(255,255,255,0.1);
    --btn-hover: rgba(255,255,255,0.2);

    --accent: #ff4757;
    --phase-1: #ff4757; 
    --phase-2: #2ed573; 
    --phase-3: #ffa502; 
    --phase-4: #1e90ff; 
    --phase-5: #9c88ff; 
}

/* --- ПЕРЕМЕННЫЕ СВЕТЛОЙ ТЕМЫ --- */
body.light-theme {
    --theme-bg: #f5f7fa;
    --bg-gradient: linear-gradient(135deg, #fdfbfb 0%, #ebedee 50%, #f5f7fa 100%);
    
    --text-main: #222222;
    --text-muted: #666666;
    --active-nav: #111111;
    
    --glass-bg: rgba(255, 255, 255, 0.6);
    --glass-border: rgba(0, 0, 0, 0.05);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
    
    /* Делаем панели более прозрачными, чтобы был виден блюр */
    --panel-bg: rgba(245, 247, 250, 0.5); 
    --panel-border: rgba(0, 0, 0, 0.05);
    
    --section-bg: rgba(0,0,0,0.03);
    --formula-bg: rgba(0,0,0,0.05);
    --cal-day-bg: rgba(0,0,0,0.03);
    --cal-day-border: rgba(0,0,0,0.05);
    --cal-day-today: rgba(0,0,0,0.5);
    
    --btn-bg: rgba(0,0,0,0.05);
    --btn-hover: rgba(0,0,0,0.1);
}

/* --- 1. ЖЕСТКАЯ БЛОКИРОВКА СИСТЕМЫ --- */
* { 
    box-sizing: border-box !important; /* Жестко фиксируем ширину всех элементов */
    -webkit-tap-highlight-color: transparent; 
    scrollbar-width: none; 
    -ms-overflow-style: none; 
}
*::-webkit-scrollbar { display: none; }

html, body {
    margin: 0; padding: 0; 
    width: 100%; height: 100%;
    position: fixed; 
    overflow: hidden;
    overscroll-behavior: none; 
    touch-action: none; 
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--theme-bg);
    background-image: var(--bg-gradient);
    color: var(--text-main);
    transition: background 0.4s ease, color 0.4s ease;
}

.app-container { 
    position: relative;
    width: 100%; height: 100%; 
}

/* --- 2. ШАПКА И МЕНЮ (ПРИКОЛОЧЕНЫ И РАЗМЫТЫ) --- */
.app-header { 
    position: absolute; top: 0; left: 0; width: 100%; z-index: 100;
    background: var(--panel-bg);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--panel-border);
    padding-top: calc(15px + env(safe-area-inset-top)); 
    padding-bottom: 15px; 
    touch-action: none; 
}
.header-content { display: flex; justify-content: center; align-items: center; position: relative; width: 100%; max-width: 600px; margin: 0 auto; }
.header-content h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; color: var(--text-main); }
.theme-btn {
    position: absolute; right: 20px; top: 50%; transform: translateY(-50%);
    background: var(--btn-bg); border: 1px solid var(--glass-border); color: var(--text-main);
    border-radius: 50%; width: 34px; height: 34px; display: flex; justify-content: center; align-items: center; cursor: pointer;
    font-size: 16px; transition: all 0.2s;
}

.mobile-nav {
    position: absolute; bottom: 0; left: 0; width: 100%; z-index: 100;
    background: var(--panel-bg);
    backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--panel-border);
    display: flex; justify-content: space-between; align-items: center;
    padding-top: 10px; padding-bottom: calc(10px + env(safe-area-inset-bottom));
    touch-action: none;
}
.nav-item { 
    flex: 1 1 0; width: 25%; min-width: 0;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    color: var(--text-muted); text-align: center; cursor: pointer; transition: color 0.2s; 
}
.nav-item.active { color: var(--active-nav); }
.nav-icon { font-size: 22px; margin-bottom: 4px; opacity: 0.6; transition: opacity 0.2s; filter: grayscale(100%);}
.nav-item.active .nav-icon { opacity: 1; filter: grayscale(0%); }
.nav-text { font-size: 10px; font-weight: 600; white-space: nowrap; }

/* --- 3. ВКЛАДКИ (ПРОКРУТКА ВНУТРИ) --- */
.dashboard { 
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; 
    overflow: hidden; 
}
.tab { 
    display: none; position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    overflow-y: auto; 
    -webkit-overflow-scrolling: touch; 
    touch-action: pan-y; 
    overscroll-behavior-y: contain; 
    padding-top: calc(75px + env(safe-area-inset-top)); 
    padding-bottom: calc(100px + env(safe-area-inset-bottom));
    padding-left: 20px; padding-right: 20px;
    animation: fadeIn 0.2s ease;
}
.tab.active { display: block; }

/* ХАК ДЛЯ SAFARI: Невидимая распорка. Заставляет короткие страницы (Настройки/Тело) пружинить (желешка) */
.tab::after {
    content: ''; display: block;
    position: absolute; top: 0; left: 0;
    width: 1px; height: calc(100% + 2px);
    z-index: -10; pointer-events: none;
}

.tab > .glass-panel { max-width: 600px; margin: 0 auto; }

/* --- 4. ВНУТРЕННИЕ ЭЛЕМЕНТЫ (КАРТОЧКИ) --- */
.glass-panel {
    background: var(--glass-bg); backdrop-filter: var(--glass-blur); -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--glass-border); box-shadow: var(--glass-shadow);
    border-radius: 24px; padding: 24px; display: flex; flex-direction: column;
}
.card-header { border-bottom: 1px solid var(--glass-border); padding-bottom: 12px; margin-bottom: 16px; }
.card-header h2 { font-size: 16px; color: var(--text-main); margin: 0; font-weight: 600; text-transform: uppercase; letter-spacing: 1px; }

.status-controls, .calendar-controls { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.nav-btn { background: var(--btn-bg); border: none; color: var(--text-main); width: 36px; height: 36px; border-radius: 50%; cursor: pointer; display: flex; justify-content: center; align-items: center; font-size: 16px; transition: all 0.2s;}
.nav-btn:hover { background: var(--btn-hover); }
.date-title { font-size: 15px; font-weight: 600; color: var(--text-muted); }
.month-title { margin: 0; color: var(--text-main); font-size: 16px; text-transform: none; }

.day-number { font-size: 42px; font-weight: 800; color: var(--text-main); margin: 0 0 5px 0; }
.phase-name { font-size: 20px; font-weight: 600; margin-bottom: 20px; }

.section { margin-top: 16px; background: var(--section-bg); padding: 16px; border-radius: 16px; border: 1px solid var(--glass-border); }
.section-title { font-size: 12px; color: var(--text-muted); text-transform: uppercase; margin-bottom: 8px; font-weight: bold; letter-spacing: 1px;}
.section-content { font-size: 15px; line-height: 1.5; }
.formula { margin-top: 20px; padding: 16px; background: var(--formula-bg); border-left: 4px solid var(--accent); font-weight: bold; border-radius: 12px; }

.calendar-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; text-align: center; }
.day-name { font-size: 12px; color: var(--text-muted); padding-bottom: 8px; font-weight: bold; }
.cal-day { aspect-ratio: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; background: var(--cal-day-bg); border-radius: 12px; font-size: 14px; cursor: pointer; border: 1px solid var(--cal-day-border); transition: all 0.2s;}
.cal-day:active { transform: scale(0.92); }
.cal-day.empty { background: transparent; border: none; cursor: default; }
.cal-day.today { border: 1px solid var(--cal-day-today); font-weight: bold; }
.cal-day.selected { border: 2px solid var(--text-main); background: var(--glass-border); }
.phase-dot { width: 6px; height: 6px; border-radius: 50%; margin-top: 4px; }
.legend { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--glass-border); font-size: 13px; color: var(--text-muted); line-height: 2;}

.input-group { margin-bottom: 20px; width: 100%; }
label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.5px;}

/* Исправление выпирающих полей */
input[type="date"], input[type="number"] { 
    width: 100%; margin: 0; padding: 14px; 
    background: var(--section-bg); border: 1px solid var(--glass-border); 
    color: var(--text-main); border-radius: 12px; font-size: 16px; 
    outline: none; font-family: inherit; color-scheme: dark;
}
.light-theme input[type="date"], .light-theme input[type="number"] { color-scheme: light; }
input:focus { border-color: var(--accent); }

.mode-toggle { display: flex; gap: 10px; background: var(--section-bg); padding: 4px; border-radius: 14px; border: 1px solid var(--glass-border); width: 100%;}
.mode-btn { flex: 1; padding: 12px 0; border: none; background: transparent; color: var(--text-muted); border-radius: 10px; font-size: 13px; font-weight: bold; cursor: pointer; transition: all 0.2s;}
.mode-btn.active { background: var(--btn-bg); color: var(--text-main); box-shadow: 0 2px 8px rgba(0,0,0,0.1); border: 1px solid var(--glass-border);}

.btn-save { 
    width: 100%; margin: 10px 0; padding: 16px; 
    background: var(--accent); color: #fff; border: none; 
    border-radius: 12px; font-size: 16px; font-weight: bold; cursor: pointer; 
    transition: transform 0.1s, filter 0.2s;
}
.btn-save:active { transform: scale(0.98); filter: brightness(0.9); }
.sync-status { font-size: 11px; color: var(--text-muted); text-align: center; width: 100%; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: translateY(0); } }

/* --- 5. УМНАЯ СЕТКА ДЛЯ ПК И ПЛАНШЕТОВ --- */
@media (min-width: 1024px) {
    body { touch-action: auto; position: relative; overflow-y: auto; } 
    .app-container { height: auto; min-height: 100dvh; }
    
    .mobile-nav { display: none; }
    .app-header { position: static; background: transparent; backdrop-filter: none; border: none; padding-top: 40px; }
    
    .dashboard {
        position: static;
        /* Умная сетка: автоматически подстраивает колонки под ширину экрана. Минимальная ширина карточки 320px */
        display: grid; 
        grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
        gap: 24px; max-width: 1600px; width: 100%; height: auto;
        margin: 0 auto; padding: 20px 40px 60px;
        align-items: stretch; overflow: visible;
    }
    
    .tab { 
        display: block !important; position: relative; padding: 0; height: 100%; 
        overflow: visible; animation: none;
    }
    .tab::after { display: none; } /* Убираем распорку для желешки на ПК */
    
    .tab > .glass-panel { max-width: 100%; height: 100%; }
    .formula, .legend, .btn-save, .sync-status { margin-top: auto; } /* Прижимаем кнопки к низу карточки */
}