/* ============ БАЗОВЫЕ СТИЛИ ============ */
* { box-sizing: border-box; margin: 0; }
body { font-family: 'Segoe UI', Arial, sans-serif; background: #f0f2f5; color: #222; }

/* ============ ТОПБАР ============ */
.topbar {
    display: flex;
    align-items: center;
    gap: 20px;
    background: linear-gradient(135deg, #1a365d, #2d4a7a);
    color: #fff;
    padding: 0 24px;
    height: 64px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-left {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-shrink: 0;
}
.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 18px;
    color: #fff;
    text-decoration: none;
    user-select: none;
}
.brand-svg { color: #60a5fa; flex-shrink: 0; }
.brand-text { letter-spacing: 0.3px; white-space: nowrap; }

/* ============ НАВИГАЦИЯ ============ */
.nav-menu {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    overflow-x: auto;
    padding: 4px 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,0.2) transparent;
}
.nav-menu::-webkit-scrollbar { height: 3px; }
.nav-menu::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.3); border-radius: 2px; }

.nav-link {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.2s ease;
    white-space: nowrap;
    position: relative;
    background: transparent;
    border: none;
    cursor: pointer;
}
.nav-link:hover { color: #fff; background: rgba(255,255,255,0.1); }
.nav-link.active { color: #fff; background: rgba(255,255,255,0.15); }
.nav-link.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 20px;
    height: 3px;
    background: #60a5fa;
    border-radius: 2px;
}
.nav-icon { opacity: 0.7; transition: opacity 0.2s; display: flex; align-items: center; }
.nav-link:hover .nav-icon,
.nav-link.active .nav-icon { opacity: 1; }

.menu-toggle {
    display: none;
    flex-direction: column;
    gap: 4px;
    background: none;
    border: none;
    padding: 6px;
    cursor: pointer;
    border-radius: 4px;
}
.menu-toggle:hover { background: rgba(255,255,255,0.1); }
.menu-toggle span {
    display: block;
    width: 22px;
    height: 2px;
    background: #fff;
    border-radius: 2px;
    transition: all 0.3s ease;
}
.menu-toggle.active span:nth-child(1) { transform: rotate(45deg) translate(4px, 4px); }
.menu-toggle.active span:nth-child(2) { opacity: 0; }
.menu-toggle.active span:nth-child(3) { transform: rotate(-45deg) translate(4px, -4px); }

/* ============ ОСНОВНОЙ КОНТЕНТ ============ */
main { padding: 20px; margin: 0 auto; }
h2 { margin: 10px 0 14px; font-size: 22px; }
h3 { margin: 14px 0 8px; font-size: 18px; }

/* ============ ТАБЛИЦЫ ============ */
.tbl { border-collapse: collapse; width: 100%; background: #fff; margin: 8px 0 20px; box-shadow: 0 1px 3px rgba(0,0,0,.1); }
.tbl th, .tbl td { border: 1px solid #dde3ea; padding: 6px 10px; font-size: 14px; text-align: left; vertical-align: top; }
.tbl th { background: #eef3f9; font-weight: 600; }

/* ============ ФОРМЫ ============ */
.row-form {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
    background: #fff;
    padding: 12px 16px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
    margin-bottom: 12px;
}
.row-form label { display: flex; flex-direction: column; font-size: 13px; gap: 3px; }
input, select { padding: 6px 10px; border: 1px solid #bbb; border-radius: 5px; font-size: 14px; background: #fff; }
select { cursor: pointer; }

/* ============ КНОПКИ ============ */
button {
    padding: 7px 16px;
    border: none;
    border-radius: 6px;
    background: #2563eb;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}
button:hover { background: #1d4ed8; }
button.gray { background: #64748b; }
button.gray:hover { background: #475569; }
button.small { padding: 4px 10px; font-size: 12px; }

/* ============ СЕТКА РАСПИСАНИЯ ============ */
.table-wrapper { overflow-x: auto; margin: 12px 0; }

.grid {
    border-collapse: collapse;
    width: 100%;
    background: #fff;
    font-size: 13px;
    min-width: 700px;
}
.grid th, .grid td {
    border: 1px solid #ccd4dd;
    padding: 4px 6px;
    vertical-align: top;
    min-height: 50px;
}
.grid th {
    background: #1e3a5f;
    color: #fff;
    padding: 8px 6px;
    font-weight: 600;
    text-align: center;
}
.grid .pairnum {
    background: #eef3f9;
    font-weight: bold;
    text-align: center;
    min-width: 70px;
}
.grid .pairnum small { font-weight: normal; font-size: 10px; color: #666; }

/* ============ ЭЛЕМЕНТЫ ЗАНЯТИЙ ============ */
.lesson-item {
    background: #fff;
    border: 1px solid #c9d4e0;
    border-radius: 4px;
    padding: 3px 5px;
    margin: 2px 0;
    font-size: 12px;
    border-left: 3px solid #94a3b8;
}
.lesson-discipline { font-weight: 600; }
.lesson-teacher { font-size: 11px; color: #333; }
.lesson-room { font-size: 11px; color: #475569; }
.lesson-periods { font-size: 10px; color: #94a3b8; margin-top: 1px; }

/* Типы недель */
.lesson-item.week-every { border-left-color: #2563eb; }
.lesson-item.week-odd { border-left-color: #16a34a; }
.lesson-item.week-even { border-left-color: #f59e0b; }
.lesson-item.week-custom { border-left-color: #8b5cf6; }

.week-label {
    display: inline-block;
    padding: 1px 8px;
    border-radius: 3px;
    font-size: 10px;
    font-weight: bold;
}
.week-every .week-label { background: #dbeafe; color: #1e40af; }
.week-odd .week-label { background: #dcfce7; color: #166534; }
.week-even .week-label { background: #fef3c7; color: #92400e; }
.week-custom .week-label { background: #ede9fe; color: #5b21b6; }

/* ============ ЯЧЕЙКИ ДНЕЙ ============ */
.day-cell {
    background: #f8fafc;
    font-weight: 600;
    text-align: center;
    vertical-align: middle;
    min-width: 80px;
}
.pair-cell {
    background: #f8fafc;
    text-align: center;
    font-weight: 600;
}
.time-cell {
    background: #f8fafc;
    text-align: center;
    font-size: 10px;
    color: #64748b;
    min-width: 65px;
}
.empty-day {
    text-align: center;
    color: #94a3b8;
    padding: 12px 6px;
    background: #fafbfc;
    font-style: italic;
}

/* ============ ПРАЗДНИКИ ============ */
.holiday-notice {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 20px;
    background: linear-gradient(135deg, #fef3c7, #fde68a);
    border-radius: 12px;
    border: 2px solid #f59e0b;
    margin: 10px 0;
}
.holiday-icon { font-size: 48px; animation: holidayBounce 2s infinite; }
.holiday-content h3 { margin: 0; color: #92400e; font-size: 20px; }
.holiday-content p { margin: 5px 0; color: #78350f; }
.holiday-content .hint { color: #92400e; font-style: italic; }
@keyframes holidayBounce { 0%,100% { transform: scale(1); } 50% { transform: scale(1.1); } }

/* ============ ИНФО КАРТОЧКИ ============ */
.group-info-card {
    background: #fff;
    border-radius: 8px;
    padding: 16px 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,.1);
    border-left: 4px solid #2563eb;
    margin-bottom: 12px;
}
.group-info-header {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}
.group-info-header h3 { margin: 0; font-size: 18px; color: #1e293b; }
.group-badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}
.group-badge.бакалавриат { background: #dbeafe; color: #1e40af; }
.group-badge.СПО { background: #fce7f3; color: #9d174d; }
.group-badge.form { background: #f1f5f9; color: #475569; }

/* ============ НАВИГАЦИЯ ПО НЕДЕЛЯМ ============ */
.week-navigation {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #f8fafc;
    padding: 8px 16px;
    border-radius: 8px;
    margin: 8px 0 12px 0;
    border: 1px solid #e2e8f0;
    flex-wrap: wrap;
}
.week-navigation button {
    padding: 4px 12px;
    font-size: 16px;
    background: #e2e8f0;
    color: #1e293b;
    border-radius: 4px;
    min-width: 36px;
}
.week-navigation button:hover { background: #cbd5e1; }
#weekDisplay {
    font-weight: 600;
    font-size: 15px;
    color: #1e293b;
    min-width: 150px;
    text-align: center;
}

/* ============ СТАТИСТИКА ============ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.stat-card {
    background: #f8fafc;
    border-radius: 8px;
    padding: 12px;
    text-align: center;
    border-left: 4px solid #2563eb;
}
.stat-number { font-size: 28px; font-weight: 700; color: #1e3a5f; }
.stat-label { font-size: 12px; color: #64748b; margin-top: 4px; }

.week-stats { background: #f8fafc; border-radius: 8px; padding: 16px; }
.week-stats h4 { margin: 0 0 12px 0; font-size: 15px; color: #1e293b; }
.week-chart {
    display: flex;
    gap: 6px;
    align-items: flex-end;
    height: 150px;
    padding: 10px 8px;
    background: #fff;
    border-radius: 6px;
    overflow-x: auto;
    border: 1px solid #e2e8f0;
}
.week-bar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 36px;
    position: relative;
    flex-shrink: 0;
}
.week-bar-item .bar-tooltip {
    display: none;
    position: absolute;
    top: -24px;
    background: #1e293b;
    color: #fff;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    white-space: nowrap;
    z-index: 10;
}
.week-bar-item:hover .bar-tooltip { display: block; }
.bar-container {
    width: 20px;
    height: 100px;
    background: #f1f5f9;
    border-radius: 4px 4px 0 0;
    position: relative;
    overflow: hidden;
    flex-shrink: 0;
}
.bar {
    position: absolute;
    bottom: 0;
    width: 100%;
    border-radius: 4px 4px 0 0;
    transition: height 0.5s ease;
    min-height: 4px;
}
.week-label { font-size: 9px; color: #475569; margin-top: 6px; font-weight: 600; text-align: center; }
.week-type { font-size: 7px; color: #94a3b8; margin-top: 1px; text-align: center; }

.stats-types {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin: 12px 0;
}
.type-item { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #475569; }
.type-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
}
.type-dot.odd { background: #16a34a; }
.type-dot.even { background: #f59e0b; }
.type-dot.every { background: #2563eb; }
.type-dot.custom { background: #8b5cf6; }

/* ============ СООБЩЕНИЯ ============ */
.err { background: #fee2e2; color: #991b1b; padding: 8px 12px; border-radius: 6px; margin: 8px 0; }
.hint { color: #64748b; font-size: 13px; margin-top: 6px; }

/* ============ ЛЕГЕНДА ============ */
.legend {
    margin: 12px 0;
    padding: 10px 16px;
    background: #f8fafc;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
}
.legend-items { display: flex; flex-wrap: wrap; gap: 16px; align-items: center; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #475569; }
.legend-color {
    display: inline-block;
    width: 20px;
    height: 4px;
    border-radius: 2px;
}
.legend-color.week-every { background: #2563eb; }
.legend-color.week-odd { background: #16a34a; }
.legend-color.week-even { background: #f59e0b; }
.legend-color.week-custom { background: #8b5cf6; }

/* ============ СПЕЦИАЛЬНЫЕ СЕТКИ ============ */
/* Преподаватели */
.teacher-grid .teacher-header {
    background: #1e3a5f;
    color: #fff;
    padding: 8px 6px;
    text-align: center;
    font-size: 13px;
    min-width: 120px;
}
.teacher-grid .lesson-cell { padding: 3px 4px; min-height: 40px; }

/* Все группы */
.grid.all-groups {
    font-size: 12px;
    min-width: 800px;
}
.grid.all-groups .group-header {
    background: #1e3a5f;
    color: #fff;
    padding: 8px 6px;
    text-align: center;
    font-size: 13px;
    min-width: 100px;
}
.grid.all-groups .group-header.бакалавриат { background: #1a4a7a; }
.grid.all-groups .group-header.СПО { background: #2d4a6a; }
.grid.all-groups .group-subheader {
    background: #eef3f9;
    text-align: center;
    font-size: 10px;
    color: #475569;
    padding: 2px 4px;
}
.grid.all-groups .group-count {
    text-align: center;
    font-size: 11px;
    color: #64748b;
    background: #f8fafc;
    padding: 2px 4px;
}
.grid.all-groups .lesson-cell { padding: 3px 4px; min-height: 40px; }

/* Кабинеты */
.grid.all-rooms-grid {
    font-size: 12px;
    min-width: 800px;
}
.grid.all-rooms-grid .room-header {
    background: #1e3a5f;
    color: #fff;
    padding: 8px 6px;
    text-align: center;
    font-size: 12px;
    min-width: 120px;
}
.grid.all-rooms-grid .room-count {
    background: #eef3f9;
    text-align: center;
    font-size: 10px;
    color: #475569;
    padding: 2px 4px;
}
.grid.all-rooms-grid .lesson-cell { padding: 3px 4px; min-height: 40px; }

/* ============ АДАПТИВ ============ */
@media (max-width: 992px) {
    .topbar { padding: 0 16px; height: 56px; }
    .brand-text { font-size: 15px; }
    .nav-link { padding: 6px 10px; }
    .nav-label { font-size: 12px; }
}

@media (max-width: 768px) {
    .topbar {
        flex-wrap: wrap;
        height: auto;
        padding: 8px 12px;
        gap: 8px;
    }
    .topbar-left {
        width: 100%;
        justify-content: space-between;
    }
    .menu-toggle { display: flex; }
    
    .nav-menu {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: stretch;
        gap: 2px;
        padding: 8px 0;
        overflow-x: visible;
        max-height: 70vh;
        overflow-y: auto;
    }
    .nav-menu.open { display: flex; }
    .nav-link {
        padding: 10px 14px;
        border-radius: 6px;
        justify-content: flex-start;
    }
    .nav-link.active::after {
        left: 0;
        transform: none;
        width: 3px;
        height: 24px;
        top: 50%;
        transform: translateY(-50%);
    }
    
    main { padding: 12px; }
    h2 { font-size: 18px; }
    h3 { font-size: 16px; }
    
    .row-form {
        flex-direction: column;
        align-items: stretch;
        padding: 12px;
        gap: 8px;
    }
    .row-form label { width: 100%; }
    .row-form label select,
    .row-form label input { width: 100%; }
    .row-form button { align-self: flex-start; }
    
    .grid {
        font-size: 11px;
        min-width: 600px;
    }
    .grid th, .grid td { padding: 3px 4px; }
    .grid .pairnum { font-size: 11px; min-width: 50px; }
    .grid .pairnum small { font-size: 8px; }
    
    .lesson-item {
        font-size: 10px;
        padding: 2px 4px;
        margin: 1px 0;
    }
    .lesson-discipline { font-size: 11px; }
    .lesson-teacher { font-size: 9px; }
    .lesson-room { font-size: 9px; }
    .lesson-periods { font-size: 8px; }
    .week-label { font-size: 8px; padding: 1px 4px; }
    
    .day-cell { font-size: 11px; min-width: 60px; }
    .pair-cell { font-size: 11px; }
    .time-cell { font-size: 9px; min-width: 50px; }
    .empty-day { font-size: 11px; padding: 8px 4px; }
    
    .grid.all-groups,
    .grid.all-rooms-grid,
    .teacher-grid {
        font-size: 10px;
        min-width: 500px;
    }
    .grid.all-groups th,
    .grid.all-rooms-grid th,
    .teacher-grid th {
        font-size: 10px;
        padding: 4px 3px;
    }
    .grid.all-groups .group-header,
    .grid.all-rooms-grid .room-header,
    .teacher-grid .teacher-header {
        font-size: 10px;
        padding: 4px 3px;
        min-width: 80px;
    }
    .grid.all-groups .group-subheader { font-size: 8px; }
    .grid.all-groups .group-count { font-size: 9px; }
    .grid.all-groups .lesson-item,
    .grid.all-rooms-grid .lesson-item,
    .teacher-grid .lesson-item {
        font-size: 9px;
        padding: 2px 3px;
    }
    .grid.all-groups .lesson-discipline,
    .grid.all-rooms-grid .lesson-discipline {
        font-size: 10px;
    }
    .grid.all-groups .lesson-teacher,
    .grid.all-rooms-grid .lesson-teacher {
        font-size: 8px;
    }
    
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .stat-number { font-size: 22px; }
    
    .week-chart { height: 120px; gap: 4px; padding: 8px 4px; }
    .bar-container { height: 80px; width: 16px; }
    .week-bar-item { min-width: 28px; }
    .week-label { font-size: 8px; }
    
    .group-info-header { flex-direction: column; align-items: flex-start; }
    .group-info-header h3 { font-size: 16px; }
    .group-info-card { padding: 12px 16px; }
    
    .holiday-notice { flex-direction: column; text-align: center; padding: 16px; }
    .holiday-icon { font-size: 36px; }
    .holiday-content h3 { font-size: 17px; }
    
    .week-navigation { padding: 6px 12px; gap: 8px; justify-content: center; }
    #weekDisplay { font-size: 13px; min-width: 120px; }
    .week-navigation button { padding: 3px 10px; font-size: 14px; min-width: 30px; }
    
    .stats-types { gap: 8px; }
    .type-item { font-size: 12px; }
    .type-dot { width: 10px; height: 10px; }
    
    .tbl { font-size: 12px; }
    .tbl th, .tbl td { padding: 4px 6px; font-size: 12px; }
}

@media (max-width: 480px) {
    .topbar { padding: 6px 10px; }
    .brand-text { font-size: 13px; }
    .brand-svg { width: 22px; height: 22px; }
    
    main { padding: 8px; }
    h2 { font-size: 16px; margin: 6px 0 10px; }
    h3 { font-size: 14px; margin: 10px 0 6px; }
    
    .row-form { padding: 8px 10px; gap: 6px; }
    .row-form label { font-size: 12px; }
    input, select { font-size: 12px; padding: 4px 8px; }
    button { font-size: 12px; padding: 5px 12px; }
    button.small { font-size: 10px; padding: 2px 8px; }
    
    .grid { font-size: 9px; min-width: 400px; }
    .grid th, .grid td { padding: 2px 3px; }
    .grid .pairnum { font-size: 9px; min-width: 40px; }
    .grid .pairnum small { font-size: 7px; }
    
    .lesson-item { font-size: 8px; padding: 1px 3px; border-left-width: 2px; }
    .lesson-discipline { font-size: 9px; }
    .lesson-teacher { font-size: 8px; }
    .lesson-room { font-size: 8px; }
    .week-label { font-size: 7px; padding: 1px 3px; }
    
    .day-cell { font-size: 9px; min-width: 50px; }
    .pair-cell { font-size: 9px; }
    .time-cell { font-size: 8px; min-width: 40px; }
    .empty-day { font-size: 9px; padding: 6px 2px; }
    
    .grid.all-groups,
    .grid.all-rooms-grid,
    .teacher-grid {
        font-size: 8px;
        min-width: 350px;
    }
    .grid.all-groups th,
    .grid.all-rooms-grid th,
    .teacher-grid th {
        font-size: 8px;
        padding: 3px 2px;
    }
    .grid.all-groups .group-header,
    .grid.all-rooms-grid .room-header,
    .teacher-grid .teacher-header {
        font-size: 8px;
        padding: 3px 2px;
        min-width: 60px;
    }
    .grid.all-groups .group-subheader { font-size: 7px; }
    .grid.all-groups .group-count { font-size: 7px; }
    .grid.all-groups .lesson-item,
    .grid.all-rooms-grid .lesson-item,
    .teacher-grid .lesson-item {
        font-size: 7px;
        padding: 1px 2px;
    }
    
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .stat-card { padding: 8px; }
    .stat-number { font-size: 18px; }
    .stat-label { font-size: 10px; }
    
    .week-chart { height: 100px; gap: 3px; padding: 6px 2px; }
    .bar-container { height: 60px; width: 12px; }
    .week-bar-item { min-width: 22px; }
    .week-label { font-size: 7px; margin-top: 3px; }
    .week-type { font-size: 6px; }
    .week-bar-item .bar-tooltip { font-size: 8px; top: -20px; padding: 1px 5px; }
    
    .group-info-card { padding: 10px 12px; }
    .group-info-header h3 { font-size: 14px; }
    .group-badge { font-size: 10px; padding: 1px 8px; }
    
    .holiday-notice { padding: 12px; gap: 10px; }
    .holiday-icon { font-size: 28px; }
    .holiday-content h3 { font-size: 15px; }
    .holiday-content p { font-size: 13px; }
    
    .week-navigation { padding: 4px 8px; gap: 6px; }
    #weekDisplay { font-size: 11px; min-width: 80px; }
    .week-navigation button { padding: 2px 8px; font-size: 12px; min-width: 24px; }
    
    .stats-types { gap: 6px; }
    .type-item { font-size: 10px; }
    .type-dot { width: 8px; height: 8px; }
    
    .tbl { font-size: 10px; }
    .tbl th, .tbl td { padding: 3px 4px; font-size: 10px; }
}