/* ========================================= */
/* БАЗОВЫЕ СТИЛИ (ДЕСКТОП)                   */
/* ========================================= */
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; display: flex; height: 100%; width: 100%; overflow: hidden; background: #fff; font-family: -apple-system, sans-serif; }

#sidebar-container { height: 100%; display: flex; flex-shrink: 0; z-index: 100; }
.main-content { flex-grow: 1; display: flex; flex-direction: column; height: 100%; min-width: 0; position: relative; }

/* ДЕСКТОПНАЯ ШАПКА */
.topbar { height: 50px; border-bottom: 1px solid #ddd; display: flex; align-items: center; padding: 0 20px; font-weight: bold; font-size: 16px; flex-shrink: 0; background: #fff; }

/* СКРЫВАЕМ МОБИЛЬНЫЕ ЭЛЕМЕНТЫ НА КОМПЬЮТЕРЕ */
.mobile-app-bar, .mobile-bottom-nav { display: none !important; }

/* ========================================= */
/* СЕТКА РАСПИСАНИЯ                          */
/* ========================================= */
/* min-height: 0; - КРИТИЧЕСКИ ВАЖНО, чтобы сетка не выдавливала нижнее меню */
.schedule-scroll { flex-grow: 1; overflow: auto; display: flex; align-items: flex-start; min-height: 0; }

.time-col { width: 55px; flex-shrink: 0; background: #fff; border-right: 1px solid #ddd; position: sticky; left: 0; z-index: 30; }
.doc-col { flex: 1; min-width: 220px; border-right: 1px solid #eee; position: relative; background: #fff; }

.grid-header { height: 50px; display: flex; align-items: center; justify-content: center; background: #fff; border-bottom: 1px solid #ddd; position: sticky; top: 0; z-index: 31; font-size: 12px; font-weight: bold; text-align: center; }
.time-col .grid-header { z-index: 32; }

/* Ячейки времени (1 час = 100px, 15 мин = 25px) */
.time-cell-hour { height: 100px; display: flex; align-items: flex-start; justify-content: center; padding-top: 5px; font-size: 11px; color: #999; border-bottom: 1px solid #ddd; }
.cell-15min { height: 25px; border-bottom: 1px solid #f5f5f5; border-right: 1px solid #f9f9f9; cursor: pointer; }
.cell-15min.hour-mark { border-bottom: 1px solid #eee; }

/* === КАРТОЧКА ВИЗИТА === */
.appointment { 
    position: absolute; border-radius: 4px; padding: 6px; font-size: 11px; z-index: 10; 
    overflow: hidden; /* Скрываем то, что не влезло в высоту */
    box-shadow: 0 1px 2px rgba(0,0,0,0.15); border-left: 4px solid transparent; 
    cursor: pointer; transition: all 0.15s ease-in-out; display: flex; flex-direction: column; gap: 4px;
}
.appointment .time-range { font-weight: bold; font-size: 10px; opacity: 0.8; }
.appointment .patient-name { font-weight: bold; font-size: 12px; line-height: 1.2; display: inline-block; transition: 0.1s; }
.appointment .patient-name:hover { text-decoration: underline; color: #000; }

.appt-details { display: none; flex-direction: column; gap: 4px; padding-top: 4px; border-top: 1px solid rgba(0,0,0,0.1); margin-top: 2px; }
.appt-services { color: #333; line-height: 1.3; }
.appt-comment { font-style: italic; color: #555; background: rgba(0,0,0,0.03); padding: 4px; border-radius: 3px; }

/* Значок первички */
.primary-badge { position: absolute; top: 4px; right: 4px; font-size: 12px; color: #888; font-weight: bold; }

/* Корзина */
.delete-icon { align-self: flex-end; font-size: 14px; cursor: pointer; color: #999; margin-top: auto; padding-top: 5px; }
.delete-icon:hover { color: #cc0000; }

/* Эффект разворачивания (Раскрытие всех данных) */
.appointment:hover { z-index: 50 !important; height: auto !important; min-height: max-content; box-shadow: 0 8px 24px rgba(0,0,0,0.2); }
.appointment:hover .appt-details { display: flex; } /* Показываем скрытые детали */


/* Цвета статусов */
.status-scheduled { background: #ffe6e6; border-left-color: #ff4d4d; color: #cc0000; }
.status-confirmed { background: #e6e6fa; border-left-color: #9370db; color: #4b0082; }
.status-arrived   { background: #d4edda; border-left-color: #28a745; color: #155724; }
.status-cancelled { background: #ff4d4d; border-left-color: #cc0000; color: #fff; }

.ghost-appt { 
    position: absolute; left: 2px; right: 2px; height: 50px; 
    border: 1px solid #ff4d4d; background: rgba(255, 77, 77, 0.05); z-index: 5; 
    pointer-events: none; display: none; padding: 4px; font-size: 10px; font-weight: bold; color: #cc0000; border-radius: 3px; 
}

/* ========================================= */
/* МОБИЛЬНАЯ АДАПТАЦИЯ (Экраны до 768px)     */
/* ========================================= */
@media (max-width: 768px) {
    /* 1. Прячем десктопную шапку */
    .topbar { display: none !important; }
    
    /* 2. Показываем мобильные панели */
    .mobile-app-bar { display: flex !important; flex-direction: column; background: #2b2b2b; color: #fff; padding-top: 10px; flex-shrink: 0; width: 100%; }
    .mobile-bottom-nav { 
        display: flex !important; width: 100%; height: 65px; background: #fff; 
        border-top: 1px solid #eee; justify-content: space-around; align-items: center; 
        padding-bottom: env(safe-area-inset-bottom); flex-shrink: 0; z-index: 1000; 
    }

    /* 3. Левое меню (Бургер) */
    #sidebar-container { 
        position: fixed; left: -100%; top: 0; bottom: 0; z-index: 2000; 
        transition: left 0.3s ease; box-shadow: 5px 0 15px rgba(0,0,0,0.5); background: #222; 
    }
    #sidebar-container.mobile-open { left: 0; }

    /* 4. Адаптируем сетку расписания */
    .doc-col { min-width: 85vw !important; }
    .time-col { width: 50px !important; }

    /* Элементы мобильной шапки с датами */
    .mobile-title { text-align: center; font-weight: bold; font-size: 14px; margin-bottom: 10px; }
    .date-scroll-container { display: flex; overflow-x: auto; padding: 0 10px 10px; gap: 10px; scrollbar-width: none; }
    .date-scroll-container::-webkit-scrollbar { display: none; }
    .date-item { min-width: 45px; height: 55px; border-radius: 8px; display: flex; flex-direction: column; align-items: center; justify-content: center; background: #3d3d3d; cursor: pointer; flex-shrink: 0; }
    .date-item.active { background: #ff7a59; color: #fff; }
    .date-day-name { font-size: 10px; opacity: 0.7; text-transform: uppercase; }
    .date-day-num { font-size: 16px; font-weight: bold; }

    /* Кнопки нижнего меню */
    .nav-item { display: flex; flex-direction: column; align-items: center; justify-content: center; color: #888; font-size: 10px; cursor: pointer; flex: 1; height: 100%; }
    .nav-item i { font-size: 20px; margin-bottom: 3px; font-style: normal; }
    .nav-item.active { color: #ff7a59; }

    
    /* 5. Модалка превращается в страницу */
    #apptModal {
        align-items: flex-start !important; /* Прибиваем к верхнему краю */
        background: #fff !important; /* Убираем затемнение */
    }
    .sqns-modal { 
        width: 100vw !important; 
        height: 100vh !important; 
        max-height: 100vh !important;
        border-radius: 0 !important; 
        padding: 0 !important; /* Убираем отступы, чтобы шапка прилипла к краям */
        display: flex;
        flex-direction: column;
    }
    
    /* Мобильная шапка внутри модалки (заменяет крестик) */
    .sqns-header {
        background: #2b2b2b;
        color: #fff;
        padding: 15px;
        border-radius: 0;
        display: flex;
        align-items: center;
        flex-shrink: 0;
        padding-top: env(safe-area-inset-top); /* Учет челки iPhone */
    }
    .sqns-title { color: #fff; display: flex; flex-direction: column; align-items: flex-start; margin-left: 15px; }
    .sqns-title span { color: #fff !important; }
    
    /* Скрываем десктопный крестик закрытия */
    .sqns-close { display: none; }
    
    /* Добавляем кнопку Назад */
    .sqns-header::before {
        content: '‹ Назад';
        color: #ff7a59;
        font-weight: bold;
        font-size: 16px;
        cursor: pointer;
        margin-right: 15px;
    }

    /* Контент модалки скроллится отдельно */
    .sqns-row { flex-direction: column; gap: 10px; padding: 0 15px; }
    .patient-stats { display: none; }
    #modal-content-loader > div > div:not(.sqns-header) {
        padding: 15px;
        overflow-y: auto;
        flex-grow: 1;
    }

     /* 6. Карточка пациента */
    .pc-header-area, .pc-body { padding: 15px; }
    .pc-tabs { padding: 0 15px; }
    .pc-title-flex { flex-direction: column; }
    .pc-dob-block { text-align: left; margin-top: 10px; }
    .pc-data-row { flex-direction: column; }
    .pc-data-label { width: 100%; margin-bottom: 5px; font-size: 11px; }
}

/* ========================================= */
/* КАРТОЧКА ПАЦИЕНТА                         */
/* ========================================= */
.pc-container { display: flex; flex-direction: column; height: 100%; background: #f9f9fc; width: 100%; overflow: hidden; }

/* Шапка пациента */
.pc-header-area { padding: 20px 30px; background: #fff; }
.pc-back { color: #888; cursor: pointer; font-size: 12px; margin-bottom: 15px; display: inline-flex; align-items: center; gap: 5px; text-decoration: none; }
.pc-back:hover { color: #333; }
.pc-title-flex { display: flex; justify-content: space-between; align-items: flex-start; }
.pc-name { font-size: 22px; font-weight: bold; margin: 0 0 4px 0; color: #222; }
.pc-sub { font-size: 11px; color: #999; }
.pc-dob-block { text-align: right; }
.pc-dob { font-size: 18px; font-weight: bold; margin: 0 0 4px 0; color: #222; }

/* Вкладки */
.pc-tabs { display: flex; border-bottom: 1px solid #ddd; padding: 0 30px; background: #fff; overflow-x: auto; scrollbar-width: none; flex-shrink: 0; }
.pc-tabs::-webkit-scrollbar { display: none; }
.pc-tab { padding: 15px 20px; font-size: 13px; color: #777; cursor: pointer; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.pc-tab.active { color: #222; font-weight: bold; border-bottom-color: #222; }
.pc-tab:hover:not(.active) { color: #444; }

/* Основной контент (скролл) */
.pc-body { padding: 30px; flex-grow: 1; overflow-y: auto; }

/* Панель инструментов (Печать, Сохранить) */
.pc-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.pc-card-info { font-size: 16px; font-weight: bold; color: #333; }
.pc-actions { display: flex; gap: 10px; }
.pc-btn { padding: 8px 15px; border-radius: 4px; font-size: 12px; font-weight: bold; cursor: pointer; border: 1px solid #ddd; background: #fff; color: #333; }
.pc-btn.primary { background: #ff7a59; color: #fff; border-color: #ff7a59; }

/* Аккордеоны */
.pc-section { background: #fff; border: 1px solid #eaeaea; border-radius: 6px; margin-bottom: 12px; }
.pc-sec-header { padding: 15px 20px; display: flex; justify-content: space-between; align-items: center; font-weight: bold; cursor: pointer; font-size: 13px; color: #222; transition: background 0.2s; }
.pc-sec-header:hover { background: #fafafa; }
.pc-sec-content { padding: 0 20px 20px 20px; display: none; font-size: 13px; }
.pc-sec-content.open { display: block; }
.pc-sec-icon { color: #999; font-size: 10px; transition: transform 0.2s; }
.pc-sec-header.active .pc-sec-icon { transform: rotate(180deg); }

/* Внутренности аккордеона */
.pc-data-row { display: flex; margin-bottom: 15px; }
.pc-data-label { width: 200px; color: #777; flex-shrink: 0; }
.pc-data-value { color: #222; font-weight: 500; }