/* ==========================================================================
 *   ЧАСТЬ 1: Навигационная панель, кнопки экспорта и сетка фильтров
 *   ========================================================================== */
* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    padding: 12px 16px;
    background-color: #eef2f6;
    color: #1f2328;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.container {
    max-width: 100%;
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Верхняя шапка сайта с кнопками "Главная", "Новости", датами и экспортом */
.top-navbar {
    background: #1e293b;
    color: #ffffff;
    padding: 12px 18px;
    border-radius: 12px;
    margin-bottom: 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.1);
}

.nav-links {
    display: flex;
    gap: 8px;
    align-items: center;
}

.nav-btn {
    text-decoration: none;
    background-color: #334155;
    color: #f8fafc;
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 13.5px;
    font-weight: 500;
    border: 1px solid #475569;
    transition: background-color 0.15s ease;
}

.nav-btn:hover {
    background-color: #475569;
    color: #ffffff;
}

.period-title {
    font-size: 15px;
    font-weight: 600;
    text-align: center;
    color: #f8fafc;
    flex-grow: 1;
}

.export-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.btn-export {
    background-color: #16a34a;
    color: #ffffff;
}

.btn-export:hover:not(:disabled) {
    background-color: #15803d;
}

.btn-export-alt {
    background-color: #0284c7;
    color: #ffffff;
}

.btn-export-alt:hover:not(:disabled) {
    background-color: #0369a1;
}

/* Панель фильтров */
.controls {
    background: #ffffff;
    padding: 14px 18px;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.06);
    margin-bottom: 14px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    border: 1px solid #e2e8f0;
}

.control-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

.top-bar {
    justify-content: space-between;
}

.right-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.filters-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
    gap: 10px;
    padding-top: 10px;
    border-top: 1px solid #f1f5f9;
}

.bottom-bar {
    padding-top: 10px;
    border-top: 1px solid #f1f5f9;
    justify-content: space-between;
}

.file-label {
    font-weight: 600;
    font-size: 14px;
    color: #0f172a;
}

input[type="text"],
select {
    padding: 8px 12px;
    font-size: 13.5px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background-color: #f8fafc;
    color: #0f172a;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

.filters-grid select {
    width: 100%;
    text-overflow: ellipsis;
}

input[type="text"]:focus,
select:focus {
    outline: none;
    border-color: #2563eb;
    background-color: #ffffff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

input[type="text"] {
    min-width: 240px;
    flex-grow: 1;
    max-width: 420px;
}

.btn {
    padding: 8px 14px;
    font-size: 13px;
    font-weight: 500;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    color: #ffffff;
    transition: all 0.15s ease;
}

.btn:disabled,
input:disabled,
select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background-color: #475569;
}

.btn-secondary:hover:not(:disabled) {
    background-color: #334155;
}

.btn-outline {
    background-color: #ffffff;
    color: #0f172a;
    border: 1px solid #cbd5e1;
}

.btn-outline:hover:not(:disabled) {
    background-color: #f1f5f9;
}

.btn-outline.active {
    background-color: #fff7ed;
    border-color: #f97316;
    color: #c2410c;
    font-weight: 600;
}

.history-panel {
    background-color: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 8px;
    padding: 12px 16px;
    font-size: 13px;
    color: #78350f;
}

.history-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid #fde68a;
}

.close-btn {
    background: none;
    border: none;
    font-size: 18px;
    line-height: 1;
    color: #92400e;
    cursor: pointer;
    padding: 0 4px;
}

.history-list {
    margin: 0;
    padding-left: 18px;
    max-height: 150px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.status-bar {
    font-size: 13px;
    color: #475569;
}

.status-error {
    color: #dc2626;
    font-weight: 600;
}
/* ==========================================================================
 *   ЧАСТЬ 2: Таблица, время в 2 строки, фиксация и горизонтальный киоск
 *   ========================================================================== */
.table-wrapper {
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.07);
    border: 1px solid #cbd5e1;
    overflow: auto;
    flex: 1;
    min-height: 320px;
    position: relative;
}

.placeholder-text {
    color: #64748b;
    text-align: center;
    padding: 50px 20px;
    font-size: 15px;
}

table {
    border-collapse: separate;
    border-spacing: 0;
    width: max-content;
    font-size: 12.5px;
}

td {
    border-right: 1px solid #e2e8f0;
    border-bottom: 1px solid #e2e8f0;
    padding: 7px 10px;
    text-align: left;
    vertical-align: middle;
    white-space: pre-wrap;
    line-height: 1.35;
    transition: background-color 0.15s ease, color 0.15s ease;
}

/* Монолитная фиксация верхней шапки */
thead {
    position: sticky;
    top: 0;
    z-index: 20;
}

/* Фиксация левого блока (День недели, Занятие, Урок, Время) */
td.sticky-left {
    position: sticky;
    z-index: 10;
}

thead td.sticky-left {
    z-index: 30;
}

td.sticky-edge {
    border-right: 2px solid #94a3b8 !important;
    box-shadow: 4px 0 8px -2px rgba(15, 23, 42, 0.08);
}

/* Ячейка времени (вывод 1-го и 2-го урока строго в две компактные строки) */
td.time-cell {
    white-space: pre-line;
    line-height: 1.45;
    font-variant-numeric: tabular-nums;
    min-width: 86px;
}

td.header-cell {
    background-color: #f1f5f9;
    color: #0f172a;
    font-weight: 600;
    text-align: center;
    border-bottom: 1px solid #cbd5e1;
}

td.header-cell.sticky-left {
    background-color: #e2e8f0;
}

td.group-title-cell {
    font-size: 14px;
    font-weight: 700;
    padding: 9px 10px;
    letter-spacing: 0.3px;
}

td.group-even.header-cell {
    background-color: #e0f2fe;
    color: #0369a1;
}

td.group-odd.header-cell {
    background-color: #ede9fe;
    color: #5b21b6;
}

td.group-even:not(.header-cell):not(.highlighted):not(.dimmed):not(.change-highlighted):not(.current-pair-cell) {
    background-color: #ffffff;
}

td.group-odd:not(.header-cell):not(.highlighted):not(.dimmed):not(.change-highlighted):not(.current-pair-cell) {
    background-color: #fafaff;
}

td.group-border-left {
    border-left: 2px solid #94a3b8 !important;
}

td.group-border-right {
    border-right: 2px solid #94a3b8 !important;
}

td.pair-bottom-border {
    border-bottom: 2px solid #cbd5e1 !important;
}

td.day-bottom-border {
    border-bottom: 4px solid #475569 !important;
}

td.day-even.day-name-cell {
    background-color: #e2e8f0;
}

td.day-odd.day-name-cell {
    background-color: #f1f5f9;
}

td.service-col {
    background-color: #f8fafc;
    font-weight: 500;
    color: #334155;
    text-align: center;
    width: 44px;
    min-width: 44px;
    max-width: 44px;
}

td.time-cell {
    white-space: pre-line;
    line-height: 1.45;
    font-variant-numeric: tabular-nums;
    width: 92px;
    min-width: 92px;
    max-width: 92px;
}

td.day-name-cell {
    font-weight: 700;
    color: #0f172a;
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    text-align: center;
    letter-spacing: 1px;
    padding: 12px 6px;
    border-right: 2px solid #94a3b8;
    width: 36px;
    min-width: 36px;
    max-width: 36px;
}

/* Оптимальная ширина ячеек группы, чтобы одна группа не выглядела слишком узкой или гигантской */
td.group-even,
td.group-odd {
    min-width: 65px;
    max-width: 260px;
}

td.teacher-row-cell {
    color: #475569;
    font-style: italic;
    font-size: 12px;
    padding-top: 4px;
    padding-bottom: 6px;
}

td.current-day-cell {
    background-color: #bae6fd !important;
    color: #0369a1 !important;
    box-shadow: inset 0 -4px 0 #0284c7;
}

td.current-pair-cell:not(.dimmed):not(.highlighted):not(.change-highlighted) {
    background-color: #f0f9ff !important;
}

td.service-col.current-pair-cell {
    background-color: #e0f2fe !important;
    color: #0369a1 !important;
    font-weight: 700;
}

td.dimmed {
    color: transparent !important;
    background-color: #f8fafc !important;
    user-select: none;
}

td.highlighted {
    background-color: #fef08a !important;
    font-weight: 600;
    color: #0f172a !important;
}

td.change-highlighted:not(.dimmed) {
    background-color: #ffedd5 !important;
    box-shadow: inset 0 0 0 1.5px #f97316;
    color: #7c2d12 !important;
}

.col-hidden {
    display: none;
}

.hidden {
    display: none !important;
}

/* ==========================================================================
 *   Горизонтальный режим киоска и адаптация под смартфоны
 *   ========================================================================== */
body.kiosk-mode {
    padding: 6px;
    background-color: #ffffff;
}

body.kiosk-mode .top-navbar,
body.kiosk-mode .controls {
    display: none !important;
}

body.kiosk-mode .table-wrapper {
    max-height: calc(100vh - 12px);
    height: calc(100vh - 12px);
    border-radius: 6px;
    box-shadow: none;
}

td.kiosk-course-banner {
    background-color: #0f172a !important;
    color: #ffffff !important;
    font-size: 14px;
    font-weight: 700;
    text-align: center;
    padding: 6px 10px;
    border-left: 3px solid #f97316 !important;
    border-right: 3px solid #1e293b !important;
}

td.kiosk-course-divider-left {
    border-left: 3px solid #0f172a !important;
}

/* Скрываем дублирующиеся 4 левых столбца у 2, 3 и 4 курсов в режиме киоска */
.kiosk-course-block.kiosk-no-service-cols td[data-col-start="0"],
.kiosk-course-block.kiosk-no-service-cols td[data-col-start="1"],
.kiosk-course-block.kiosk-no-service-cols td[data-col-start="2"],
.kiosk-course-block.kiosk-no-service-cols td[data-col-start="3"] {
    display: none !important;
}

body.kiosk-mode tr.past-day-row {
    display: none !important;
}

body.kiosk-mode td.col-hidden {
    display: table-cell !important;
}

.kiosk-exit-btn {
    position: fixed;
    bottom: 18px;
    right: 18px;
    z-index: 9999;
    background-color: rgba(15, 23, 42, 0.85);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 10px 18px;
    border-radius: 30px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

@media (max-width: 768px) {
    html, body {
        height: auto;
        overflow: auto;
    }
    .container {
        height: auto;
        overflow: visible;
    }
    .table-wrapper {
        height: 75vh;
        max-height: 75vh;
    }
    body {
        padding: 8px;
    }
    .top-navbar {
        flex-direction: column;
        align-items: stretch;
        text-align: center;
    }
    .nav-links, .export-controls {
        justify-content: center;
    }
    .filters-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    /* На телефонах фиксируем только самый компактный левый край (день и время), если экран >= 360px */
    table {
        font-size: 11px;
    }
    td {
        padding: 4px 6px;
    }
    td.time-cell {
        min-width: 72px;
        font-size: 10.5px;
    }
}

@media (max-width: 480px) {
    .filters-grid {
        grid-template-columns: 1fr;
    }
}

/* ==========================================================================
 *  Логотип в верхней панели и выравнивание высоты строк для режима киоска
 *  ========================================================================== */
.logo-link {
    display: flex;
    align-items: center;
    margin-right: 4px;
    text-decoration: none;
}

.site-logo {
    height: 34px;
    width: auto;
    border-radius: 6px;
    object-fit: contain;
}

/* Фиксированная минимальная высота строк в режиме киоска, чтобы все 4 курса стыковались ровно */
body.kiosk-mode tbody tr {
    height: 28px;
}

body.kiosk-mode thead tr {
    height: 34px;
}
