/* === БАЗОВЫЕ НАСТРОЙКИ === */
:root {
    --bg-color: #f4f6f8;
    --text-color: #2c3e50;
    --card-bg: #ffffff;
    --dynamic-font-size: 16px; 
}
body.dark-theme { 
    --bg-color: #0f2027; 
    --text-color: #ffffff; 
    --card-bg: #1e2a31;
}

body {
    font-family: 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-color);
    color: var(--text-color);
    margin: 0; padding: 0;
    display: flex; flex-direction: column;
    min-height: 100vh;
}

html, body {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* === ШАПКА === */
.app-header {
    width: 100%; 
    padding: 10px 15px; 
    background: var(--card-bg); 
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    position: sticky; top: 0; z-index: 100; 
    box-sizing: border-box;
    display: flex; 
    justify-content: space-between; 
    align-items: center;
}

.back-btn { text-decoration: none; font-size: 16px; color: var(--text-color); font-weight: bold; }
.header-title { font-size: 18px; font-weight: bold; margin: 0; position: absolute; left: 50%; transform: translateX(-50%); }

/* === ВЫПАДАЮЩЕЕ МЕНЮ ШАПКИ (КЕБАБ-МЕНЮ) === */
.header-menu-container {
    position: relative;
}

.menu-dots-btn {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--text-color);
    cursor: pointer;
    padding: 5px 10px;
    line-height: 1;
    font-weight: bold;
}

.dropdown-menu {
    position: absolute;
    top: 40px;
    right: 0;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 5px 20px rgba(0,0,0,0.15);
    min-width: 180px;
    z-index: 1000;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    border: 1px solid rgba(0,0,0,0.05);
}
body.dark-theme .dropdown-menu {
    box-shadow: 0 5px 20px rgba(0,0,0,0.5);
    border: 1px solid rgba(255,255,255,0.05);
}

.dropdown-item {
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    padding: 12px 15px;
    font-size: 15px;
    color: var(--text-color);
    cursor: pointer;
    transition: background 0.2s;
}
.dropdown-item:active { background: rgba(0,0,0,0.05); }
body.dark-theme .dropdown-item:active { background: rgba(255,255,255,0.05); }

.dropdown-divider {
    height: 1px;
    background: rgba(0,0,0,0.1);
    margin: 0;
}
body.dark-theme .dropdown-divider { background: rgba(255,255,255,0.1); }

.dropdown-row {
    display: flex;
    justify-content: space-around;
    padding: 8px;
    background: rgba(0,0,0,0.02);
}
body.dark-theme .dropdown-row { background: rgba(255,255,255,0.02); }

.dropdown-font-btn {
    background: var(--bg-color);
    border: 1px solid var(--text-color);
    color: var(--text-color);
    border-radius: 5px;
    width: 40px;
    height: 35px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.8;
    transition: 0.2s;
}
.dropdown-font-btn:active { transform: scale(0.9); }

/* === КОМНАТА И КАРУСЕЛИ === */
.announcements-room { 
    padding: 0 15px; 
    flex-grow: 1; 
    display: flex; 
    flex-direction: column;
    justify-content: center; /* 🔥 Центрируем карусель по вертикали экрана */
    align-items: center;     /* Центрируем по горизонтали */
    /* Вычитаем примерную высоту шапки, чтобы не было смещения вниз */
    min-height: calc(100vh - 60px); 
}

.announcements-section { 
    width: 100%;
    max-width: 600px; /* На планшетах не будет растягиваться в бесконечность */
    position: relative; 
}

.section-title { 
    font-size: 18px; 
    font-weight: bold; 
    margin-bottom: 20px; 
    text-align: center; /* Красиво выровняем заголовок по центру */
}

/* ❌ Класс .section-divider мы удалили за ненадобностью */

.carousel-container {
    display: flex; 
    overflow-x: auto; 
    scroll-snap-type: x mandatory; 
    gap: 15px; 
    padding-bottom: 20px; 
    scrollbar-width: none; 
    align-items: center;
}

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

/* === КАРТОЧКА === */
.announce-card {
    min-width: 85%; 
    height: 65vh; /* 🔥 Высота ровно 2/3 экрана телефона */
    max-height: 550px; /* Защита от очень вытянутых экранов */
    scroll-snap-align: center;
    scroll-snap-stop: always;
    background: var(--card-bg);
    border-radius: 16px; 
    padding: 20px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.08); /* Чуть более мягкая и глубокая тень */
    display: flex; 
    flex-direction: column;
    cursor: pointer; 
    box-sizing: border-box;
}

.card-header { 
    font-size: 13px; 
    text-transform: uppercase; 
    color: #e67e22; 
    font-weight: bold; 
    margin-bottom: 10px; 
}

.card-image-wrapper {
    width: 100%;
    min-height: 120px; /* Минимальная высота, чтобы фото не сплющило в ноль */
    flex-grow: 1; /* 🔥 ГЛАВНАЯ МАГИЯ: Теперь фото забирает всё пустое место! */
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.03); 
    border-radius: 10px;
    overflow: hidden;
    /* Убрали жесткую высоту 140px и flex-shrink */
}
body.dark-theme .card-image-wrapper { background: rgba(255,255,255,0.05); }

.card-image-preview {
    width: 100%;
    height: 100%;
    object-fit: contain; /* Картинка увеличивается, но не обрезается */
}

/* Заголовок не трогаем, он остается как был */
.card-title { 
    font-size: 18px; 
    margin: 0 0 8px 0; 
    font-weight: bold; 
}

.card-text { 
    font-size: var(--dynamic-font-size); 
    line-height: 1.4; 
    opacity: 0.9; 
    display: -webkit-box;
    -webkit-line-clamp: 6; /* Максимум 4 строки */
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0; 
    /* 🔥 УБРАЛИ flex-grow: 1. Теперь текст не выталкивает элементы, а занимает только свой размер */
}

.read-more-indicator {
    font-size: 14px;
    color: #007bff;
    font-weight: bold;
    margin-top: 12px;
    text-align: right;
    text-transform: uppercase;
}
body.dark-theme .read-more-indicator { color: #4dabf7; }

/* === НОВАЯ ШАПКА КАРУСЕЛИ (ЗАГОЛОВОК + СЧЕТЧИК + ПЛЮС) === */
.carousel-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 15px;
    width: 100%;
}

.carousel-header .section-title {
    margin: 0 0 10px 0; /* Отступ только снизу */
    text-align: center;
}

.carousel-controls-top {
    display: flex;
    align-items: center;
    justify-content: center; /* Счетчик строго по центру */
    width: 100%;
    position: relative; /* Чтобы прижать кнопку вправо */
    min-height: 36px;
}

.carousel-counter {
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-color);
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 14px;
    font-weight: bold;
    letter-spacing: 1px;
}
body.dark-theme .carousel-counter { background: rgba(255, 255, 255, 0.1); }

.top-add-btn {
    position: absolute;
    right: 5px; /* Аккуратно прижимаем вправо */
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, #007bff, #0056b3);
    color: white;
    border: none;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 3px 8px rgba(0,0,0,0.2);
    transition: transform 0.2s;
}
.top-add-btn:active { transform: scale(0.9); }

/* === ТОЧКИ ПОД КАРУСЕЛЬЮ === */
.carousel-dots {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 15px;
    width: 100%;
    height: 12px;
}

.carousel-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #ccc;
    transition: all 0.3s ease;
}
body.dark-theme .carousel-dot { background: #555; }

/* Активная точка становится длинненькой "колбаской" */
.carousel-dot.active {
    width: 24px;
    border-radius: 4px;
    background: #e67e22; /* Оранжевый цвет в стиле твоего дизайна */
}
body.dark-theme .carousel-dot.active { background: #e67e22; }

/* === МОДАЛЬНОЕ ОКНО (ФОРМА ДОБАВЛЕНИЯ) === */
.modal-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000; padding: 20px;
}

.modal-content {
    background: var(--card-bg); width: 100%; max-width: 400px;
    border-radius: 16px; padding: 25px; box-sizing: border-box;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    animation: slideUp 0.3s ease;
}

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

.modal-title { margin-top: 0; margin-bottom: 20px; font-size: 20px; color: var(--text-color); }

.form-input {
    width: 100%; padding: 12px; margin-bottom: 15px; border-radius: 8px;
    border: 1px solid #ccc; background: var(--bg-color); color: var(--text-color);
    box-sizing: border-box; font-family: inherit; font-size: 14px;
}
body.dark-theme .form-input { border-color: #444; }

.file-upload-wrapper { width: 100%; margin-bottom: 15px; }
.file-upload-label {
    display: block; padding: 12px; background: #eef2f5;
    color: #333; border-radius: 8px; cursor: pointer; 
    font-size: 14px; text-align: center; box-sizing: border-box; font-weight: bold;
}
body.dark-theme .file-upload-label { background: #2a3b45; color: #ddd; }

.settings-group { background: var(--bg-color); padding: 15px; border-radius: 8px; margin-bottom: 15px; }
.form-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 14px; }
.form-row:last-child { margin-bottom: 0; }
.select-short { width: auto; min-width: 130px; margin-bottom: 0; padding: 8px; }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.modal-actions button { padding: 10px 20px; border-radius: 8px; border: none; font-weight: bold; cursor: pointer; font-size: 14px; transition: 0.2s; }
.btn-cancel { background: #ddd; color: #333; }
body.dark-theme .btn-cancel { background: #444; color: #fff; }
.btn-submit { background: #27ae60; color: white; }
.btn-submit:active { transform: scale(0.95); }

/* === ФУЛЛСКРИН-ЭКРАНЫ (ПРОСМОТР) === */
.fullscreen-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    width: 100vw; height: 100vh; z-index: 2000;
    display: flex; flex-direction: column;
    animation: fadeInScale 0.2s ease-out;
}

@keyframes fadeInScale {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

/* 1. Режим Галереи (Фото) */
.fullscreen-overlay.dark-mode {
    background: #000;
}
.fs-image-container {
    flex-grow: 1; display: flex; align-items: center; justify-content: center;
    overflow: hidden;
}
#fs_image {
    max-width: 100%; max-height: 100%; object-fit: contain;
}
.fs-caption {
    position: absolute; bottom: 30px; left: 20px; right: 20px;
    color: #fff; font-size: 18px; font-weight: bold; text-align: center;
    text-shadow: 0 2px 4px rgba(0,0,0,0.8);
}
.fs-close-btn {
    position: absolute; top: 20px; right: 20px; z-index: 2010;
    background: rgba(255,255,255,0.2); border: none; color: #fff;
    width: 40px; height: 40px; border-radius: 50%; font-size: 28px;
    line-height: 1; cursor: pointer; display: flex; align-items: center; justify-content: center;
}

/* 2. Режим Читалки (Текст) */
.fullscreen-overlay.reader-mode {
    background: var(--bg-color); /* Используем цвет фона приложения */
    overflow-y: auto;
}
.fs-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 15px 20px; background: var(--card-bg); box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    position: sticky; top: 0;
}
.fs-back-btn {
    background: none; border: none; font-size: 18px; font-weight: bold;
    color: var(--text-color); cursor: pointer; padding: 0;
}
.fs-author { font-size: 14px; color: #3498db; font-weight: bold; }

.fs-text-content {
    padding: 25px 20px;
}
.fs-title { margin-top: 0; margin-bottom: 20px; font-size: 24px; color: var(--text-color); }
.fs-text { font-size: var(--dynamic-font-size); line-height: 1.6; white-space: pre-wrap; word-wrap: break-word; color: var(--text-color); }
.fs-link { display: inline-block; margin-top: 20px; color: #3498db; font-weight: bold; text-decoration: none; font-size: 16px; }
.fs-date { margin-top: 30px; font-size: 12px; color: #888; border-top: 1px solid var(--text-color); opacity: 0.5; padding-top: 15px; }

.fs-edit-btn {
    width: 100%; margin-top: 30px; background: #f39c12; color: white;
    padding: 15px; border: none; border-radius: 12px; font-weight: bold; font-size: 16px; cursor: pointer;
}

/* === УНИВЕРСАЛЬНЫЕ СТРЕЛКИ (ДЛЯ ВСЕХ ЭКРАНОВ) === */
.scroll-btn {
    display: flex; /* Возвращаем кнопки на мобилки! */
    position: absolute; 
    top: 50%; transform: translateY(-50%);
    z-index: 10; 
    width: 35px; height: 35px; /* Маленькие и аккуратные для телефона */
    background: rgba(255, 255, 255, 0.95); 
    border: 1px solid #ddd; border-radius: 50%;
    align-items: center; justify-content: center;
    font-size: 18px; color: var(--text-color); cursor: pointer;
    box-shadow: 0 4px 10px rgba(0,0,0,0.15); transition: 0.2s;
}
.scroll-btn:hover { background: #007bff; color: white; border-color: #007bff; }
.left-btn { left: 5px; }
.right-btn { right: 5px; }

/* МАГИЯ ЦЕНТРОВКИ: Обязательно добавь это к карточке */
.announce-card {
    scroll-snap-align: center; /* Заставляет браузер ВСЕГДА ставить карточку ровно по центру */
}

/* === ДЕСКТОПНАЯ ВЕРСИЯ (ШИРОКИЕ БАННЕРЫ) === */
@media (min-width: 768px) {

    /* 👇 ДОБАВЛЯЕМ ВОТ ЭТОТ БЛОК 👇 */
    .announcements-section {
        max-width: 100%; /* Снимаем жесткое мобильное ограничение */
    }

    .announcements-room { 
        max-width: 1400px; /* Расширяем комнату, чтобы влезла огромная карточка и боковые "соседи" */
        margin: 0 auto; 
        padding: 40px 20px; 
        overflow: hidden; 
    }
    
    .carousel-container { 
        padding: 50px 0; /* Даем больше воздуха для 3D-увеличения */
    }
    
    .announce-card {
        min-width: 700px !important; /* 🔥 Делаем её по-настоящему широкой */
        max-width: 800px !important;
        height: 450px !important; /* Фиксируем комфортную высоту, чтобы получился горизонтальный прямоугольник */
        
        transform: scale(0.85); 
        opacity: 0.5;
        transition: transform 0.4s ease, opacity 0.4s ease, box-shadow 0.4s ease;
    }
    
    .announce-card.active-center {
        transform: scale(1.05); 
        opacity: 1; 
        z-index: 2;
        box-shadow: 0 20px 40px rgba(0,0,0,0.15); /* Делаем тень более глубокой для массивной карточки */
    }

    /* Адаптируем картинку под панорамный вид */
    .card-image-preview {
        height: 55%; /* На широкой карточке фото будет смотреться как киношный кадр */
        border-radius: 12px;
    }

    /* Увеличиваем стрелочки для удобства клика мышкой */
    .scroll-btn { 
        width: 50px; 
        height: 50px; 
        font-size: 24px; 
    }
    .left-btn { left: 10px; }
    .right-btn { right: 10px; }
}

/* =========================================
   СТИЛИ ДЛЯ ОКНА ПРОСМОТРА ОБЪЯВЛЕНИЯ
========================================= */

.view-modal-content {
    max-width: 600px; 
    max-height: 90dvh; 
    overflow: hidden; /* 🔥 Теперь само окно НЕ скроллится! */
    padding: 0; 
    position: relative;
    border-radius: 16px;
    background: var(--card-bg);
    display: flex;
    flex-direction: column;
}

/* 🔥 ВЕРХНЯЯ ПОЛОСКА С КРЕСТИКОМ (ЧУТЬ БОЛЕЕ СЕРАЯ И КОНТРАСТНАЯ) 🔥 */
.view-modal-header {
    display: flex;
    justify-content: flex-end; 
    align-items: center;
    padding: 4px 8px; 
    background: #e4e7eb; /* Сделали цвет чуть более плотным серым */
    border-bottom: 1px solid #d1d5db; /* Нижнюю границу тоже выделили сильнее */
    border-radius: 16px 16px 0 0; 
    z-index: 10; 
    flex-shrink: 0; 
}
body.dark-theme .view-modal-header { 
    background: #1e293b; /* Красивый глубокий серый для темной темы */
    border-bottom: 1px solid #0f172a; 
}

.view-modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px; 
    height: 32px;
    background: transparent; /* Убрали тяжелый фоновый кружок, оставили только крестик */
    font-size: 28px; 
    line-height: 1;
    cursor: pointer; 
    color: #888; /* Спокойный серый цвет иконки */
    transition: color 0.2s;
}
.view-modal-close:active { color: #333; /* Темнеет при нажатии */ }
body.dark-theme .view-modal-close { color: #aaa; }
body.dark-theme .view-modal-close:active { color: #fff; }

/* 🔥 ЗОНА КОНТЕНТА (Скроллится под шапку) 🔥 */
.view-modal-body {
    overflow-y: auto; 
    flex-grow: 1; /* Занимает всё оставшееся место */
    display: flex;
    flex-direction: column;
}

.view-modal-image {
    width: 100%; 
    height: auto; /* Позволяем картинке строиться по её родным пропорциям */
    max-height: 70vh; /* Даем постерам гораздо больше места по высоте */
    object-fit: contain; /* 🔥 ГЛАВНЫЙ ФИКС: Вмещать целиком, НИКАКОЙ ОБРЕЗКИ! */
    border-radius: 0; 
    margin: 0; 
    display: block;
    flex-shrink: 0;
}

.view-modal-title { 
    margin: 20px 20px 10px 20px; /* Вернули нормальные ровные отступы */
    font-size: 24px; 
}

.view-modal-date { 
    margin: 0 20px 20px 20px; 
    color: #e67e22; 
    font-size: 14px; 
    font-weight: bold; 
    text-transform: uppercase; 
}

.view-modal-text { 
    margin: 0 20px 20px 20px; 
    font-size: var(--dynamic-font-size); 
    line-height: 1.6; 
    white-space: pre-wrap; 
    color: var(--text-color); 
}

.view-modal-link { 
    margin: 0 20px 15px 20px; 
    width: calc(100% - 40px); 
    box-sizing: border-box; 
    text-align: center; 
    text-decoration: none; 
    display: block; 
}

.view-modal-controls { 
    margin: 0 20px 20px 20px; 
    gap: 10px; 
    border-top: 1px solid #eee; 
    padding-top: 15px; 
}
body.dark-theme .view-modal-controls { border-top: 1px solid rgba(255,255,255,0.1); }

.view-modal-edit-btn { flex: 1; background-color: #f39c12; }
.view-modal-delete-btn { flex: 1; }

/* =========================================
   ФИКС ДЛЯ ОКНА ДОБАВЛЕНИЯ (УМНЫЙ СКРОЛЛ)
========================================= */

#addModal.modal-overlay {
    align-items: center; 
    padding: 15px; 
    /* Заставляем оверлей жестко привязываться к динамической высоте экрана */
    height: 100dvh; 
    box-sizing: border-box;
}

#addModal .modal-content {
    margin: 0 auto;
    width: 100%;
    max-width: 500px; 
    
    /* 🔥 НОВАЯ МАГИЯ ЗДЕСЬ 🔥 */
    /* Окно занимает максимум 100% динамической высоты МИНУС отступы (padding) */
    max-height: calc(100dvh - 30px); 
    
    /* Скролл появится только тогда, когда контент физически перестанет влезать в эти рамки */
    overflow-y: auto; 
    
    border-radius: 12px; 
    
    /* Добавляем flex, чтобы внутренние элементы вели себя предсказуемо при сжатии */
    display: flex;
    flex-direction: column;
}