:root {
    --color-primary: #e53935;
    --color-primary-hover: #b71c1c;
    --color-success: #2e7d32;
    --color-bg: #fff5f7;
    --color-surface: #ffffff;
    --color-text: #2c1e1e;
    --color-text-light: #7f5f5f;
    --color-border: #ffc1c1;
    --grid-gap-color: #e57373; /* Red color for grid lines */
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    padding: 20px;
    min-height: 100vh;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding-bottom: 40px;
}

/* =========================================
   1. HEADER & GLOBAL STATS
   ========================================= */

.header {
    text-align: center;
    margin-bottom: 30px;
}

.header h1 {
    font-size: 32px;
    margin-bottom: 8px;
    color: var(--color-primary);
    font-weight: 800;
}

.header p {
    color: var(--color-text-light);
    font-size: 16px;
}

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
    margin-bottom: 30px;
}

.stat-card {
    background: var(--color-surface);
    padding: 20px;
    border-radius: 12px;
    border-left: 4px solid var(--color-primary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

.stat-card h3 {
    color: var(--color-text-light);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 8px;
    letter-spacing: 0.5px;
}

.stat-card .value {
    font-size: 28px;
    font-weight: 700;
    color: var(--color-primary);
}

/* Main Top Progress Bar */
.progress-bar {
    width: 100%;
    height: 8px;
    background: #ffebee;
    border-radius: 4px;
    margin-top: 12px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--color-primary), var(--color-success));
    transition: width 0.5s ease;
    border-radius: 4px;
}

/* =========================================
   2. LEGEND (LARGE & BOLD)
   ========================================= */

.legend {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin-bottom: 30px;
    flex-wrap: wrap;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 16px; /* Larger Text */
    font-weight: 600; /* Bolder Text */
    color: #444;
}

.legend-color {
    width: 24px;   /* Larger Box */
    height: 24px;
    border-radius: 6px;
    flex-shrink: 0;
}

.legend-color.incomplete { 
    background: #fff; 
    border: 2px solid var(--color-border); /* Thicker border */
}

.legend-color.completed { 
    background: #e8f5e9; 
    border: 2px solid var(--color-success); 
    position: relative; 
}

.legend-color.completed::after { 
    content: '✓'; 
    font-size: 16px; 
    color: var(--color-success); 
    position: absolute; 
    top: 50%; 
    left: 50%; 
    transform: translate(-50%, -50%);
    font-weight: 800; 
}

/* =========================================
   3. STAGE NAVIGATION
   ========================================= */

.stage-navigation {
    background: var(--color-primary);
    color: #fff;
    border-radius: 12px;
    position: relative;
    margin: 25px 0 35px 0;
    padding: 20px 60px;
    min-height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 15px rgba(229, 57, 53, 0.3);
}

.stage-navigation .stage-content { text-align: center; flex: 1; padding: 0 10px; }
.stage-navigation .stage-title { font-size: 20px; font-weight: 700; line-height: 1.2; margin-bottom: 4px; }
.stage-navigation .stage-months { font-size: 14px; opacity: 0.95; }

.stage-nav-btn {
    position: absolute; top: 50%; transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.2); color: #fff; border: none;
    width: 44px; height: 44px; border-radius: 50%;
    font-size: 24px; font-weight: bold; cursor: pointer;
    transition: all 0.2s; display: flex; align-items: center; justify-content: center; padding: 0; line-height: 1;
}
.stage-nav-btn:hover:not(:disabled) { background: rgba(255, 255, 255, 0.3); transform: translateY(-50%) scale(1.1); }
.stage-nav-btn:active:not(:disabled) { transform: translateY(-50%) scale(0.95); }
.stage-nav-btn[disabled] { opacity: 0.35; cursor: not-allowed; }
.stage-nav-btn-left { left: 15px; }
.stage-nav-btn-right { right: 15px; }

/* =========================================
   4. CALENDAR GRID & CARDS
   ========================================= */

.month-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 25px;
    margin-bottom: 30px;
}

.month-card {
    background: var(--color-surface);
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,0.06);
    transition: transform 0.2s;
    /* This fixes the footer sticking issue */
    display: flex;
    flex-direction: column; 
    height: 100%;
}

.month-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
}

.month-header {
    background: var(--color-primary);
    color: white;
    padding: 15px;
    font-size: 18px;
    font-weight: 700;
    text-align: center;
}

/* THE RED GRID (Same as Admin) */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px; /* The red lines */
    background: #e57373; 
    border: 1px solid #e57373;
    border-radius: 8px;
    overflow: hidden;
    margin: 15px 15px 5px 15px;
}

.day-header {
    text-align: center;
    padding: 8px 2px;
    font-weight: 600;
    font-size: 11px;
    text-transform: uppercase;
    background: #ef5350;
    color: white;
}

.day-cell {
    aspect-ratio: 1;
    background: #fff;
    position: relative;
    cursor: pointer;
    transition: background 0.1s;
}

.day-number {
    font-size: 12px;
    font-weight: 600;
    padding: 4px;
    color: #555;
    position: absolute; top: 0; right: 0;
}

/* --- Day States --- */

.day-cell:hover { background: rgba(229, 57, 53, 0.05); z-index: 2; }

/* Empty cells */
.day-cell.empty { background: #fff9f9; cursor: default; }
.day-cell.empty:hover { background: #fff9f9; }

/* Today */
.day-cell.today .day-number {
    background: var(--color-primary);
    color: #fff;
    border-radius: 50%;
    width: 24px; height: 24px;
    display: flex; align-items: center; justify-content: center;
    margin: 3px;
    box-shadow: 0 2px 4px rgba(229, 57, 53, 0.4);
}

/* Completed by User */
.day-cell.completed { background: #e8f5e9; }
.day-cell.completed::after {
    content: '✓';
    position: absolute;
    bottom: 4px; right: 6px;
    font-size: 14px;
    font-weight: 800;
    color: var(--color-success);
}

/* Frozen days */
.day-cell.frozen {
    opacity: 0.5; cursor: not-allowed;
    background: repeating-linear-gradient(45deg, #fff, #fff 10px, #ffebee 10px, #ffebee 20px);
}

/* =========================================
   5. MONTH STATS (TRACKER AT BOTTOM)
   ========================================= */

.month-progress {
    /* Pushes this section to the bottom of the flex container */
    margin-top: auto; 
    padding: 15px 20px; /* Comfortable spacing */
    font-size: 13px;
    color: var(--color-text-light);
    text-align: center;
    font-weight: 500;
}

.month-progress-bar {
    width: 100%;
    height: 8px; /* Thicker bar */
    background: #ffebee;
    border-radius: 4px;
    margin-top: 8px;
    overflow: hidden;
}

.month-progress-fill {
    height: 100%;
    background: var(--color-success);
    transition: width 0.3s ease;
    border-radius: 4px;
}

/* =========================================
   6. USER DAY POPUP
   ========================================= */

.user-popup-overlay {
    position: fixed; z-index: 1000;
    left: 0; top: 0; bottom: 0; right: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    opacity: 0; pointer-events: none;
    transition: opacity 0.3s ease;
}
.user-popup-overlay.active { opacity: 1; pointer-events: all; }

.user-popup {
    background: #fff;
    width: 600px; max-width: 95vw;
    height: 85vh; max-height: 850px;
    border-radius: 24px;
    box-shadow: 0 25px 50px rgba(0,0,0,0.3);
    position: relative;
    overflow: hidden;
    transform: translateY(20px); transition: transform 0.3s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    display: flex; flex-direction: column;
}
.user-popup-overlay.active .user-popup { transform: translateY(0); }

.user-popup-close {
    position: absolute; top: 20px; right: 20px;
    background: #f5f5f5; border: none;
    width: 36px; height: 36px; border-radius: 50%;
    font-size: 24px; line-height: 1; color: #555;
    cursor: pointer; z-index: 20;
    transition: background 0.2s;
}
.user-popup-close:hover { background: #e0e0e0; color: #000; }

.popup-layout { display: flex; flex-direction: column; height: 100%; }

.popup-header {
    padding: 30px 30px 10px 30px; background: #fff;
    flex-shrink: 0;
}

.popup-date-badge {
    display: inline-block;
    background: #ffebee; color: #b71c1c;
    padding: 6px 12px; border-radius: 8px;
    font-size: 13px; font-weight: 700; margin-bottom: 10px;
}

.popup-title {
    font-size: 26px; font-weight: 800; color: #222;
    line-height: 1.2;
    /* ВАЖНО: Перенос длинных слов */
    word-break: break-word;
    overflow-wrap: break-word;
}

/* Область контента */
.popup-scroll-area {
    flex: 1; overflow-y: auto;
    padding: 10px 30px 30px 30px; 
    background: #fff;
    /* Скрываем горизонтальный скролл */
    overflow-x: hidden; 
}

/* --- БЛОКИ КОНТЕНТА --- */

.user-block {
    margin-bottom: 25px;
    animation: fadeIn 0.4s ease forwards;
    width: 100%; /* Чтобы не вылезало */
}

/* Заголовки блоков (Вопрос, текст слайдера) */
.user-block-label {
    font-size: 16px; 
    font-weight: 700; 
    color: #2c1e1e; 
    margin-bottom: 8px;
    /* Перенос длинного текста */
    word-break: break-word;
    overflow-wrap: break-word;
    line-height: 1.4;
}

/* Текст поста */
.user-block-text p {
    font-size: 17px; 
    line-height: 1.6; 
    color: #444; 
    white-space: pre-wrap; 
    margin: 0;
    /* Перенос длинных слов (типа bebebe...) */
    word-break: break-word; 
    overflow-wrap: break-word;
    max-width: 100%;
}

/* Картинка (Исправлено: ограничение высоты) */
.user-block-image {
    width: 100%;
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 10px;
    /* Убрали фон и рамки */
    background: transparent; 
    border: none;
    display: flex;
    justify-content: center; /* Центрируем, если картинка узкая */
}

.user-block-image img {
    /* Увеличили высоту до 500px */
    max-height: 500px; 
    width: auto;
    max-width: 100%;
    display: block; 
    /* Contain сохраняет пропорции, но теперь без серого фона вокруг */
    object-fit: contain; 
}

/* Инпут (Вопрос) */
.user-input-field {
    width: 100%; padding: 15px;
    background: #fafafa;
    border: 2px solid #eee; border-radius: 12px;
    font-family: inherit; font-size: 16px; resize: vertical;
    transition: all 0.2s; color: #333;
    /* Перенос текста внутри инпута */
    word-break: break-word;
}
.user-input-field:focus { 
    outline: none; 
    border-color: var(--color-primary); 
    background: #fff;
}

/* Слайдер (Шкала) */
.user-rate-wrapper {
    background: #fff;
    padding: 15px 20px;
    border-radius: 16px;
    border: 1px solid #ffcdd2;
    box-shadow: 0 4px 15px rgba(229, 57, 53, 0.05);
}
.user-range-input {
    width: 100%;
    height: 6px;
    background: #e0e0e0;
    border-radius: 3px;
    outline: none;
    -webkit-appearance: none;
    margin-top: 10px;
}
.user-range-input::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 24px; height: 24px;
    background: var(--color-primary);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(229, 57, 53, 0.4);
    transition: transform 0.1s;
}
.user-range-input::-webkit-slider-thumb:active { transform: scale(1.2); }

/* --- ССЫЛКИ НА ТГ --- */
.popup-tg-links-area {
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px dashed #eee;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.tg-link-btn {
    text-decoration: none;
    background: #f0f9ff;
    color: #0088cc;
    padding: 14px 20px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.2s;
    border: 1px solid #b3e5fc;
}
.tg-link-btn:hover {
    background: #0088cc;
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 136, 204, 0.25);
    border-color: #0088cc;
}

/* Footer */
.popup-footer {
    padding: 20px 30px; background: #fff;
    border-top: 1px solid #f0f0f0; flex-shrink: 0; text-align: center;
}

.btn-complete {
    background: #f5f5f5; color: #777;
    border: none; padding: 16px 20px;
    width: 100%; border-radius: 14px;
    font-size: 16px; font-weight: 700; cursor: pointer;
    transition: all 0.3s;
    display: flex; align-items: center; justify-content: center; gap: 8px;
}
.btn-complete.active {
    background: var(--color-success); color: #fff;
    box-shadow: 0 8px 20px rgba(46, 125, 50, 0.25);
}

.locked-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    
    background: #fdfdfd;       /* Очень светлый фон */
    border: 2px dashed #e0e0e0; /* Пунктирная рамка */
    border-radius: 16px;       /* Скругление */
    
    padding: 50px 20px;        /* Большие отступы внутри */
    margin-bottom: 25px;       /* Отступ снизу от других блоков */
    
    color: #888;               /* Цвет текста серый */
    transition: all 0.3s ease;
}

.locked-block:hover {
    background: #fcfcfc;
    border-color: #ccc;        /* При наведении рамка чуть темнее */
}

.locked-icon {
    font-size: 48px;           /* Большой размер замка */
    margin-bottom: 15px;       /* Отступ от замка до текста */
    line-height: 1;
    opacity: 0.8;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* Адаптив */
@media (max-width: 600px) {
    .user-popup { width: 100%; height: 100%; border-radius: 0; max-height: none; }
    .popup-header { padding: 20px 20px 5px 20px; }
    .popup-scroll-area { padding: 10px 20px 30px 20px; }
    .popup-title { font-size: 22px; }
    .user-block-text p { font-size: 16px; }
}

/* =========================================
   7. FINAL STAGE & RESPONSIVE
   ========================================= */

.final-stage-card {
    background: var(--color-surface);
    border-radius: 14px;
    padding: 40px 20px;
    text-align: center;
    box-shadow: 0 8px 30px rgba(0,0,0,0.05);
}
.final-stage-title { font-size: 24px; font-weight: 700; color: var(--color-primary); margin-bottom: 10px; }
.final-stage-date { font-size: 16px; color: var(--color-text-light); margin-bottom: 20px; }

@media (max-width: 768px) {
    .month-grid { grid-template-columns: 1fr; }
    .header h1 { font-size: 24px; }
    .stats { grid-template-columns: repeat(2, 1fr); }
    .stage-navigation { padding: 16px 30px; min-height: auto; }
    .user-popup { width: 100%; height: 100%; max-height: none; border-radius: 0; }
}
@media (max-width: 480px) {
    .container { padding: 10px 10px 30px; }
    .stage-navigation .stage-nav-btn { width: 32px; height: 32px; font-size: 18px; }
    .legend { gap: 15px; }
}

/* =========================================
   8. УПРАВЛЕНИЕ ДАННЫМИ (ИМПОРТ/ЭКСПОРТ)
   ========================================= */

.data-management {
    background: #fff;
    border: 2px dashed #ffcdd2; /* Красная пунктирная рамка */
    border-radius: 16px;
    padding: 30px;
    text-align: center;
    margin-top: 50px;
    margin-bottom: 20px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.03);
}

.data-management h3 {
    font-size: 18px;
    color: #2c1e1e;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.data-management p {
    font-size: 14px;
    color: #7f5f5f;
    margin-bottom: 25px;
}

.data-buttons {
    display: flex;
    justify-content: center;
    gap: 20px;
    flex-wrap: wrap;
}

/* Общий стиль для кнопок данных */
.data-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 14px 24px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    line-height: 1;
    min-width: 200px; /* Чтобы кнопки были одинаковой ширины */
}

/* Кнопка ЭКСПОРТА (Красная) */
.btn-export {
    background: var(--color-primary); /* #e53935 */
    color: white;
    box-shadow: 0 4px 10px rgba(229, 57, 53, 0.2);
}

.btn-export:hover {
    background: var(--color-primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 6px 15px rgba(229, 57, 53, 0.3);
}

.btn-export:active {
    transform: translateY(0);
}

/* Кнопка ИМПОРТА (Белая с обводкой) */
.btn-import {
    background: #fff;
    color: var(--color-primary);
    border: 2px solid #ffcdd2;
}

.btn-import:hover {
    border-color: var(--color-primary);
    background: #fff5f5;
    transform: translateY(-2px);
    color: var(--color-primary-hover);
}

/* Скрываем реальный инпут файла */
.btn-import input[type="file"] {
    display: none;
}

/* Подсказка внизу */
.data-hint {
    font-size: 12px;
    color: #bbb;
    margin-top: 15px;
    font-family: monospace;
}