/* --- 1. База и Шрифты --- */
body {
    font-family: 'Inter', -apple-system, system-ui, sans-serif;
    background-color: #f8fafc;
    color: #334155;
    margin: 0;
    padding: 0px;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: #ffffff;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
    overflow-y: auto;
    max-height: 100%;
}

section { margin-bottom: 35px; }
h2 { font-size: 1.25rem; font-weight: 700; color: #1e293b; margin-bottom: 20px; }

/* --- 2. Инструкция (Шаг 1) --- */
.info-box {
    background: #f0f7ff;
    border: 1px solid #cce3ff;
    border-left: 5px solid #007bff;
    padding: 20px;
    border-radius: 8px;
    margin-bottom: 25px;
}
.info-box strong { display: block; color: #0056b3; margin-bottom: 10px; font-size: 1.1em; }
.info-box ul { margin: 0 0 15px 20px; padding: 0; }
.info-box ul li { margin-bottom: 5px; color: #444; }
.info-hint { display: block; font-style: italic; color: #64748b; font-size: 0.95em; line-height: 1.4; }

/* --- 3. Загрузка файла --- */
.upload-container { display: flex; gap: 15px; align-items: center; flex-wrap: wrap; }
.file-upload-wrapper { position: relative; flex-grow: 1; min-width: 250px; }
.file-input { width: 0.1px; height: 0.1px; opacity: 0; position: absolute; z-index: -1; }
.file-label {
    display: flex;
    align-items: center;
    padding: 0 20px;
    background: #fff;
    border: 2px dashed #cbd5e1;
    border-radius: 8px;
    cursor: pointer;
    transition: 0.2s;
    height: 50px;
    box-sizing: border-box;
}
.file-label:hover { border-color: #3b82f6; background: #f8fafc; }
.file-icon { margin-right: 10px; font-size: 1.2rem; }

/* --- 4. Кнопки --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 25px;
    font-weight: 600;
    font-size: 14px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    transition: 0.2s;
    height: 50px;
    box-sizing: border-box;
}
.btn-primary { background: #3b82f6; color: white; }
.btn-primary:hover { background: #2563eb; }
.btn-success { background: #10b981; color: white; }
.btn-success:hover { background: #059669; }
.btn-lg { padding: 0 40px; font-size: 1.1rem; box-shadow: 0 10px 15px -3px rgba(16, 185, 129, 0.3); }

/* --- 5. Таблица и Фильтры --- */
.filter-bar { display: flex; gap: 8px; margin: 25px 0 10px; }
.f-btn {
    background: #fff;
    border: 1px solid #e2e8f0;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
    color: #64748b;
    transition: 0.2s;
}
.f-btn.active { background: #3b82f6; color: white; border-color: #3b82f6; }

.table-wrapper { border: 1px solid #e2e8f0; border-radius: 8px; overflow: hidden; background: #fff; }
.preview-table { width: 100%; border-collapse: collapse; }
.preview-table th { background: #f1f5f9; color: #475569; font-size: 0.75rem; text-transform: uppercase; padding: 15px 20px; text-align: left; border-bottom: 2px solid #e2e8f0; }
.preview-table td { padding: 15px 20px; border-bottom: 1px solid #f1f5f9; vertical-align: middle; }

/* Валидация */
.row-error { background-color: #fef2f2 !important; border-left: 4px solid #ef4444; }
.row-warning { background-color: #fffbeb !important; border-left: 4px solid #f59e0b; }
.msg-err, .msg-warn { display: block; font-size: 0.75rem; font-weight: 600; padding: 2px 6px; border-radius: 4px; margin-top: 5px; user-select: none; pointer-events: none; }
.msg-err { color: #b91c1c; background: #fee2e2; }
.msg-warn { color: #92400e; background: #fef3c7; }

/* Интерактив */
[contenteditable="true"]:focus { outline: 2px solid #3b82f6; border-radius: 4px; background: #fff; }
.cell-date { color: #2563eb; font-weight: 600; text-decoration: underline dotted; cursor: pointer; }

/* Управление таблицей */
.table-controls { padding: 20px; background: #f8fafc; border-top: 1px solid #e2e8f0; text-align: center; }
.btn-toggle { background: #fff; border: 1px solid #cbd5e1; padding: 10px 25px; border-radius: 25px; font-weight: 600; cursor: pointer; color: #475569; }

/* --- 6. Шаг 3 (Финальный блок) --- */
.step-3-container {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-top: 5px solid #10b981;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.05);
    text-align: center;
}
.save-controls-wrapper {
    display: flex;
    justify-content: center;
    gap: 30px;
    margin: 25px 0;
    padding: 20px;
    background: #f8fafc;
    border-radius: 8px;
    align-items: flex-end;
}
.control-item { text-align: left; }
.control-item label { display: block; font-size: 0.8rem; font-weight: 700; color: #64748b; margin-bottom: 8px; text-transform: uppercase; }

.custom-select { height: 50px; min-width: 200px; border: 1px solid #cbd5e1; border-radius: 8px; padding: 0 15px; font-size: 1rem; font-weight: 600; background: #fff; }
.mode-status-badge { height: 50px; display: flex; align-items: center; padding: 0 20px; background: #fff; border: 1px solid #e2e8f0; border-radius: 8px; font-weight: 600; }
.warning-alert { background: #fff3cd; border: 1px solid #ffe69c; color: #856404; padding: 15px; border-radius: 8px; margin-bottom: 20px; font-size: 0.9em; text-align: left; display: none; }

/* --- 7. Мобильность --- */
@media (max-width: 768px) {
    .container { padding: 15px; }
    .upload-container, .save-controls-wrapper { flex-direction: column; align-items: stretch; gap: 15px; }
    .preview-table { font-size: 0.85rem; }
    .preview-table th, .preview-table td { padding: 10px; }
}


/* --- Единый стиль для всех выпадающих списков --- */
select[name="sheet_index"], 
.custom-select, 
#finalCityId {
    height: 50px;
    min-width: 220px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 0 15px;
    font-size: 1rem;
    font-weight: 600;
    color: #1e293b;
    background-color: #fff;
    cursor: pointer;
    transition: all 0.2s;
    background-size: 1.2em;
}

/* Эффект при наведении и фокусе */
select:hover, .custom-select:hover {
    border-color: #3b82f6;
}

select:focus, .custom-select:focus {
    outline: none;
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}



.login-wrapper { display:flex; justify-content:center; align-items:center; height:100vh; background:#f4f4f4; }
.login-box { 
    background:white; 
    padding:40px; 
    border-radius:8px; 
    box-shadow:0 2px 10px rgba(0,0,0,0.1); 
    width:100%; max-width:350px; 
    box-sizing: border-box;
}
.form-group { margin-bottom:15px; }
.form-group label { display:block; margin-bottom:5px; }
.form-group input { width:100%; padding:10px; border:1px solid #ddd; border-radius:4px; box-sizing:border-box;}
.btn-login { 
    width:100%; 
    padding:10px; 
    background:#007bff; 
    color:white; 
    border:none; 
    border-radius:4px; 
    cursor:pointer; 
    height: 50px;
    font-size: 1.1em;
    margin-top: 20px;
}
.btn-login:hover { background:#0056b3; }
.error { color:red; margin-bottom:15px; text-align:center; }








:root {
    --bg: #f5f7fa;
    --white: #ffffff;
    --text: #1e293b;
    --text-light: #64748b;
    --primary: #3b82f6;
    --border: #cbd5e1; /* Цвет линий сетки */
    --radius: 12px;
}

/* LAYOUT */
.layout {
    display: grid;
    grid-template-columns: 350px 1fr;
    height: 100vh;
    height: 100svh;
}

/* --- SIDEBAR --- */
.sidebar {
    background: var(--white);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    border-right: 1px solid #e2e8f0;
    overflow-y: auto;
}


/* --- КАСТОМНЫЙ СКРОЛЛ ДЛЯ SIDEBAR --- */

/* 1. Для Firefox */
.sidebar {
    scrollbar-width: thin; /* Тонкий скролл */
    scrollbar-color: #cbd5e1 transparent; /* Цвет ползунка и фон трека */
}

/* 2. Для Chrome, Safari, Edge (Webkit) */
.sidebar::-webkit-scrollbar {
    width: 5px; /* Ширина скролла */
}

.sidebar::-webkit-scrollbar-track {
    background: transparent; /* Фон дорожки прозрачный */
}

.sidebar::-webkit-scrollbar-thumb {
    background-color: #cbd5e1; /* Цвет ползунка (под цвет границ) */
    border-radius: 10px;       /* Закругление */
}

.sidebar::-webkit-scrollbar-thumb:hover {
    background-color: #94a3b8; /* При наведении чуть темнее */
}


/* Виджет Даты (Лого) */
.brand-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.date-widget {
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    width: 48px;
    height: 48px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}
.dw-month { font-size: 10px; font-weight: 700; text-transform: uppercase; color: #ef4444; line-height: 1; margin-bottom: 2px; }
.dw-day { font-size: 18px; font-weight: 800; color: #1e293b; line-height: 1; }

.logout-btn { font-size: 13px; color: #94a3b8; text-decoration: none; font-weight: 500; }
.logout-btn:hover { color: #ef4444; }

.select-city {
    padding: 10px; border: 1px solid #e2e8f0; border-radius: 8px;
    background: #f8fafc; width: 100%; cursor: pointer; color: var(--text);
}

.block-header {
    font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.5px;
    padding: 6px 10px; border-radius: 6px; margin-bottom: 10px; display: inline-block;
}
.cards-container { display: flex; flex-direction: column; gap: 8px; }

/* Карточка в сайдбаре */
.person-card {
    background: var(--white);
    border: 1px solid #e2e8f0;
    border-radius: 10px;
    padding: 10px;
    display: flex; align-items: center; gap: 12px;
    transition: 0.2s;
}
.person-card:hover { border-color: var(--primary); transform: translateY(-1px); box-shadow: 0 4px 6px -1px rgba(0,0,0,0.05); }
.person-card.is-top { background: #fffbeb; border-color: #fcd34d; }

/* Кружок возраста (для Сегодня) */
.age-circle {
    width: 42px; height: 42px; border-radius: 50%;
    background: #fee2e2; color: #ef4444;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    line-height: 1; flex-shrink: 0;
}
.age-num { font-size: 14px; font-weight: 800; }
.age-txt { font-size: 8px; font-weight: 600; text-transform: lowercase; margin-top: 1px;}

/* Квадратик даты (для Ближайших) */
.date-box {
    width: 42px; height: 42px; border-radius: 8px;
    background: #eff6ff; color: #3b82f6; border: 1px solid #dbeafe;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    line-height: 1; flex-shrink: 0;
}
.db-month { font-size: 9px; font-weight: 700; text-transform: uppercase; margin-bottom: 2px; }
.db-day { font-size: 16px; font-weight: 800; }

.info { flex: 1; min-width: 0; }
.name { font-weight: 600; font-size: 14px; margin-bottom: 2px; line-height: 1.2; }

.manager-lbl { 
    font-size: 11px; 
    color: #64748b; 
    margin-top: 2px; 
    display: flex; 
    align-items: center; 
    flex-wrap: wrap;

}

.manager-lbl>span{
    width: 100%;
}


.agentNM{
    font-weight: 600;
    color: var(--primary);
}

.btn-upload {
    margin-top: auto; text-align: center; padding: 12px;
    background: #f1f5f9; border-radius: 8px; text-decoration: none; color: var(--text);
    font-size: 13px; font-weight: 600;
}

/* --- MAIN CALENDAR --- */
.main { padding: 20px; display: flex; flex-direction: column; height: 100vh; box-sizing: border-box; }

.header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 15px; }
.header h2 { margin: 0; font-size: 24px; font-weight: 800; }

.controls button {
    background: var(--white); border: 1px solid #cbd5e1;
    padding: 6px 12px; border-radius: 6px; cursor: pointer;
    font-weight: 600; color: var(--text);
}
.controls button:hover { background: #f1f5f9; }

/* ОБНОВЛЕННАЯ СЕТКА КАЛЕНДАРЯ */
.calendar-wrapper {
    background: var(--white);
    border-radius: 12px;
    border: 1px solid #cbd5e1; /* Общая рамка */
    flex: 1; display: flex; flex-direction: column;
    overflow: hidden; position: relative;
}

.week-days {
    display: grid; grid-template-columns: repeat(7, 1fr);
    background: #f8fafc; border-bottom: 1px solid #cbd5e1;
    text-align: left; padding: 10px;
}
.w-day { color: #64748b; font-size: 12px; font-weight: 700; text-transform: uppercase; }

/* Сама сетка */
.days-grid {
    display: grid; grid-template-columns: repeat(7, 1fr);
    grid-auto-rows: 1fr;
        /*background: #f5f6f7;*/
    /*gap: 1px;*/
    flex: 1; overflow-y: auto;
}

/* ЯЧЕЙКА */
.day-cell {
    background: var(--white); /* Белые ячейки на сером фоне создают границы */
    padding: 8px;
    display: flex; flex-direction: column; gap: 4px;
    cursor: pointer; position: relative;
    border-bottom: 1px solid #cecece;
    border-right: 1px solid #cecece;

}

.day-cell.no-border-bottom{
    border-bottom: none;
}

.day-cel.no-border-right{
    border-right: none; 
}



.day-cell:hover { background: #f8fafc; }
.day-cell.empty { background: #f9fbfc; }

/* Сегодняшний день в календаре */
.day-cell.today { background: #dde8f5; }
.today .day-num { 
    background: #3fb2f4; color: white; 
    width: 24px; height: 24px; border-radius: 50%; 
    display: flex; align-items: center; justify-content: center;
}

.day-num { font-weight: 600; font-size: 14px; color: #334155; margin-bottom: 4px; }

/* Точки событий */
.event-dot {
    font-size: 12px; padding: 2px 6px; border-radius: 4px;
    background: #eff5fc; color: #334155; border-left: 3px solid #3fb2f4;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    font-weight: 500;
}
.event-dot.top-client { background: #fffbeb; color: #b45309; border-left-color: #f59e0b; }

.more-events {
    font-size: 10px; color: #3b82f6; font-weight: 700; 
    text-align: center; margin-top: auto; padding-top: 2px;
}

/* МОДАЛКА */
.modal-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    display: none; justify-content: center; align-items: center; z-index: 100;
}
.modal-content {
    background: var(--white); width: 400px; max-width: 90%;
    border-radius: 12px; overflow: hidden; box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
}
.modal-header { padding: 15px; border-bottom: 1px solid #e2e8f0; display: flex; justify-content: space-between; align-items: center;}
.modal-body { padding: 15px; max-height: 60vh; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; }
.loading-overlay { display: none; position: absolute; inset: 0; background: rgba(255,255,255,0.8); justify-content: center; align-items: center; z-index: 50; }
.spinner { width: 30px; height: 30px; border: 3px solid #e2e8f0; border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }


.day-cell.past {
    background: #f8fafc; /* Очень светлый серый, почти сливается с фоном заголовков */
    opacity: 0.85; /* Чуть прозрачнее */
}

/* Номер дня в прошлом делаем бледным */
.day-cell.past .day-num {
    color: #cbd5e1; 
}

/* События в прошлом обесцвечиваем */
.day-cell.past .event-dot {
    filter: grayscale(100%); /* ЧБ режим */
    opacity: 0.6;

}

/* Даже ТОП клиенты в прошлом становятся серыми */
.day-cell.past .event-dot.top-client {
    background: #f6f7f8; 

}

/* При наведении чуть "оживляем" ячейку, чтобы можно было посмотреть историю */
.day-cell.past:hover {
    opacity: 1;
    background: #fff;
}

#agentSelect{
    width: auto;
    height: 28px;
    padding: 0px 6px;
}


.modal-close{
    background: none;
    border: none;
    font-size: 1.9em;
    border: 1px solid #d5d5d5;
    border-radius: 50px;
    height: 30px;
    width: 30px;
    line-height: 0;
    padding: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-top: 5px;
    color: var(--primary);
    cursor: pointer;
}



/*АДАПТИВ*/

/* Скрытые элементы по умолчанию (для десктопа) */
.burger-btn, .mobile-close-btn, .sidebar-overlay {
    display: none;
}

/* Header layout tweaks for Desktop too */
.header-left { display: flex; align-items: center; gap: 10px; }
.scroll-container { display: flex; flex-direction: column; flex: 1; height: 100%; }


@media (max-width: 900px) {
    .layout {
        display: block; /* Убираем Grid */
        position: relative;
    }

    /* --- SIDEBAR (OFF-CANVAS) --- */
    .sidebar {
        position: fixed;
        top: 0; left: -100%; /* Скрыт слева */
        width: 280px;
        height: 100svh;
        z-index: 1000;
        transition: left 0.3s ease;
        box-shadow: 4px 0 15px rgba(0,0,0,0.1);
        box-sizing: border-box;
    }
    .sidebar.active {
        left: 0; /* Выезжает */
    }

    .sidebar-overlay {
        position: fixed; inset: 0;
        background: rgba(0,0,0,0.5);
        z-index: 999;
        display: none; /* JS покажет это */
    }

    .mobile-close-btn {
        display: block;
        background: none; border: none; font-size: 24px; color: #64748b; cursor: pointer;
        margin-left: auto; /* Прижать вправо */
    }
    .logout-btn { display: none; } /* В меню кнопку "выйти" убираем из хедера сайдбара, чтобы не мешала крестику, либо переверстать */
    /* Лучше добавим "Выйти" вниз сайдбара отдельной кнопкой, но пока просто скроем лишнее */

    /* --- MAIN CONTENT --- */
    .main {
        padding: 10px;
        height: 100vh;
        height: 100svh;
    }

    /* --- HEADER --- */
    .header {
        flex-wrap: wrap;
        gap: 10px;
    }
    .header h2 { font-size: 18px; }
    
    .burger-btn {
        display: flex; align-items: center; justify-content: center;
        background: #fff; border: 1px solid #cbd5e1;
        width: 36px; height: 36px; border-radius: 6px;
        font-size: 20px; cursor: pointer;
    }

    .agent-wrapper {
        order: 3; width: 100%; /* Перенос на новую строку */
    }
    #agentSelect { width: 100%; height: 36px; }

    .controls {
        margin-left: auto; /* Прижать вправо */
    }

    /* --- CALENDAR HORIZONTAL SCROLL --- */
    /* Самое важное: разрешаем скроллить календарь, чтобы ячейки не сплющивались */
    .calendar-wrapper {
        overflow-x: auto; /* Горизонтальный скролл */
        -webkit-overflow-scrolling: touch; /* Плавность на iOS */
    }
    
    .scroll-container {
        min-width: 700px; /* Минимальная ширина календаря, чтобы он выглядел нормально */
        height: 100%;
        overflow: hidden;
    }
    
    /* Делаем заголовки дней фиксированными при вертикальном скролле (если нужно) */
    .week-days {
        min-width: 700px;
        overflow: hidden;
    }

    .days-grid{
        min-width: 700px;
        overflow: hidden; 

    }

    .day-cell, .w-day {
        min-width: 100px;
        max-width: 100px;  
        box-sizing: border-box;
    }
}