*, *::before, *::after {
    box-sizing: border-box;
}

body {
    font-family: system-ui, sans-serif;
    padding: 10px;
    margin: 0;
    background: #f0f2f5;
    color: #20252b;
}
@media (min-width: 900px) {
    body { padding: 18px clamp(28px, 5vw, 80px); }
}
.no-print {
    display: flex;
    flex-direction: column;
    gap: 15px;
    padding: 20px;
    margin-bottom: 20px;
    border-radius: 12px;
    background: #fff;
    box-shadow: 0 2px 10px rgba(0, 0, 0, .08);
}
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.timetable-source-row, #controls { width: min(100%, 1320px); margin-right: auto; margin-left: auto; }
.timetable-source-row > input,
.timetable-source-row > select,
.timetable-source-row > button { flex: 1 1 0 !important; min-width: 0 !important; }
input[type="text"], input[type="number"], select {
    min-width: 0;
    flex: 1;
    padding: 10px 12px;
    border: 1px solid #ced4da;
    border-radius: 6px;
    font-size: 14px;
    transition: border-color .2s, box-shadow .2s;
}
input:focus, select:focus { outline: none; border-color: #4472c4; box-shadow: 0 0 0 3px rgba(68, 114, 196, .14); }
button { padding: 10px 20px; border: 0; border-radius: 6px; color: #fff; background: #4472c4; cursor: pointer; font-weight: 700; }
button:hover { background: #355fa3; }
button.secondary { background: #6c757d; }
button.secondary:hover { background: #5a6268; }
.theme-toggle { display: inline-flex; align-items: center; gap: 9px; margin-left: auto; cursor: pointer; font-size: 13px; font-weight: 700; }
.theme-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.theme-toggle-track { position: relative; width: 42px; height: 24px; border-radius: 20px; background: #c8ced4; transition: background .2s; }
.theme-toggle-thumb { position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.theme-toggle input:checked + .theme-toggle-track { background: #4472c4; }
.theme-toggle input:checked + .theme-toggle-track .theme-toggle-thumb { transform: translateX(18px); }
.theme-toggle input:focus-visible + .theme-toggle-track { outline: 3px solid rgba(68,114,196,.3); }
.strict-filter-box { display: flex; align-items: center; min-width: 0; padding: 9px 10px; border: 1px solid #e9ecef; border-radius: 6px; background: #f8f9fa; }
.setting-toggle { display: flex; align-items: center; gap: 10px; cursor: pointer; }
.setting-toggle input { position: absolute; opacity: 0; pointer-events: none; }
.setting-toggle-track { position: relative; width: 38px; height: 22px; flex: 0 0 auto; border-radius: 20px; background: #c8ced4; transition: background .2s; }
.setting-toggle-thumb { position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.setting-toggle input:checked + .setting-toggle-track { background: #4472c4; }
.setting-toggle input:checked + .setting-toggle-track .setting-toggle-thumb { transform: translateX(16px); }
.setting-toggle input:focus-visible + .setting-toggle-track { outline: 3px solid rgba(68,114,196,.3); }
.strict-filter-copy { display: grid; gap: 2px; }
.strict-filter-copy strong { font-size: 13px; }
.strict-filter-copy small { color: #6c757d; font-size: 11px; font-weight: 400; line-height: 1.25; }
.filter-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 15px; margin-top: 5px; }
.custom-class-panel { grid-column: 1 / -1; }
.custom-class-row { justify-content: center; }
.custom-class-row > input,
.custom-class-row > select,
.custom-class-row > button { width: auto !important; min-width: 0 !important; flex: 1 1 0 !important; }
.filter-section { padding: 12px; border: 1px solid #e9ecef; border-radius: 8px; background: #f8f9fa; }
.filter-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; padding-bottom: 5px; border-bottom: 2px solid #e9ecef; }
.filter-section strong { color: #495057; font-size: 14px; }
.filter-actions { display: flex; gap: 4px; }
.filter-actions button { padding: 3px 7px; border: 1px solid #c9d0d6; border-radius: 4px; color: #495057; background: #fff; font-size: 11px; font-weight: 600; }
.filter-actions button:hover { color: #fff; background: #4472c4; border-color: #4472c4; }
.checkbox-group { max-height: 140px; overflow-y: auto; padding-right: 5px; font-size: 13px; }
.checkbox-group label { display: flex; align-items: flex-start; gap: 8px; padding: 4px 6px; margin-bottom: 2px; border-radius: 4px; cursor: pointer; }
.checkbox-group label:hover { background: #e2e6ea; }
#timetable-container { padding: 15px; border-radius: 12px; background: #fff; box-shadow: 0 2px 10px rgba(0,0,0,.08); overflow-x: auto; }
table { width: 100%; min-height: 600px; height: 75vh; --slot-height: 68px; border: 2px solid #000; border-collapse: collapse; table-layout: fixed; text-align: center; background: #fff; }
tr { height: var(--slot-height); }
th, td { padding: 0; border: 1px solid #000; vertical-align: middle; overflow: hidden; word-wrap: break-word; }
th { padding: 8px; color: #000; background: #8faadc !important; font-weight: 700; }
.time-col { width: 60px; border-right: 2px solid #000; background: #8faadc !important; font-size: 13px; font-weight: 700; white-space: nowrap; }
.cell-container { display: flex; flex-wrap: wrap; align-content: stretch; width: 100%; height: 100%; overflow-y: auto; }
.empty-cell { width: 100%; height: 100%; }
.cell-box { display: flex; flex: 1 1 45%; min-height: 60px; flex-direction: column; align-items: center; justify-content: center; box-sizing: border-box; margin: 4px; padding: 4px; border-radius: 4px; cursor: pointer; font-size: 11px; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: opacity .2s, filter .2s; }
.type-Curs { background: #f4b183 !important; }
.type-Seminar { background: #c5e0b4 !important; }
.type-Laborator { background: #ffe699 !important; }
.type-Custom { background: #e2d9f3 !important; }
.cell-box[data-selected="false"] { opacity: .35 !important; filter: grayscale(80%); }

/* Dark Theme */
body.dark-theme { color: #e0e0e0; background: #121212; }
body.dark-theme .no-print, body.dark-theme #timetable-container, body.dark-theme table { background: #1e1e1e; }
body.dark-theme .strict-filter-box, body.dark-theme .filter-section { border-color: #444; background: #2a2a2a; }
body.dark-theme .strict-filter-copy small, body.dark-theme .filter-actions button { color: #b9b9b9; }
body.dark-theme .filter-heading { border-color: #444; }
body.dark-theme .filter-section strong, body.dark-theme .theme-toggle { color: #e0e0e0; }
body.dark-theme .checkbox-group label { color: #e0e0e0; }
body.dark-theme .checkbox-group label:hover { background: #3a3a3a; }
body.dark-theme input[type="text"], body.dark-theme input[type="number"], body.dark-theme select { color: #e0e0e0; background: #2a2a2a; border-color: #444; }
body.dark-theme th, body.dark-theme .time-col { color: #e0e0e0; background: #2b3a55 !important; }
body.dark-theme table, body.dark-theme th, body.dark-theme td, body.dark-theme .time-col { border-color: #444; }
body.dark-theme .type-Curs { color: #fff; background: #9c6238 !important; }
body.dark-theme .type-Seminar { color: #fff; background: #587948 !important; }
body.dark-theme .type-Laborator { color: #121212; background: #a38a3d !important; }
body.dark-theme .type-Custom { color: #fff; background: #6a5a87 !important; }

/* Mobile Optimizations */
@media (max-width: 1100px) {
    .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 899px) {
    body { padding: 6px; overflow-x: hidden; }
    .no-print { padding: 14px; margin-bottom: 12px; gap: 12px; }
    body > .no-print > div:first-child { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 0 !important; }
    body > .no-print > div:first-child h2 { font-size: 20px; }
    .theme-toggle { margin-left: auto; }
    .timetable-source-row, #controls { width: 100%; }
    
    body > .no-print > .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    
    body > .no-print > .row input,
    body > .no-print > .row select { min-width: 0 !important; width: 100% !important; flex: none !important; }
    
    body > .no-print > .row #groupInput { grid-column: 1 / -1; }
    body > .no-print > .row button { width: 100%; padding: 10px 12px; }
    body > .no-print > .row #fetchBtn,
    body > .no-print > .row button.secondary { grid-column: 1 / -1; }
    
    .filter-grid { grid-template-columns: 1fr; gap: 10px; }
    .filter-section { padding: 10px; }
    #controls > .filter-grid .filter-section[style] { grid-column: auto !important; }
    
    #controls .row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
    #controls .row input,
    #controls .row select,
    #controls .row button { width: 100% !important; min-width: 0 !important; flex: none !important; padding: 9px !important; }
    #customDay { grid-column: 1 / -1; }
    #customSubject { grid-column: 1 / -1; }
    #customRoom { grid-column: 1 / -1; }
    
    #timetable-container { padding: 8px; border-radius: 8px; }
    #timetable { min-width: 700px; }
    table { min-width: 700px; min-height: 520px; height: 70vh; }
    th { padding: 7px 3px; font-size: 11px; }
    .time-col { width: 52px; font-size: 11px; }
    .cell-box { min-height: 48px; margin: 3px; padding: 3px; font-size: 10px; }
    .cell-box strong { font-size: 10px; }
}

/* Print Settings */
@media print {
    @page { 
        size: A4 landscape; 
        margin: 6mm; 
    }

    html, body, body.dark-theme {
        height: auto !important;
        overflow: visible !important;
        background: #fff !important;
        color: #000 !important;
        padding: 0 !important;
        margin: 0 !important;
    }

    .no-print, 
    .cell-box[data-selected="false"] { 
        display: none !important; 
    }

    #timetable-container,
    body.dark-theme #timetable-container {
        height: auto !important;
        padding: 0 !important;
        box-shadow: none !important;
        background: transparent !important;
        overflow: visible !important;
    }

    table,
    body.dark-theme table {
        width: 100% !important;
        height: auto !important;
        min-height: unset !important;
        --slot-height: 46px !important;
        border: 2px solid #000 !important;
        border-collapse: collapse !important;
        background: #fff !important;
        page-break-inside: avoid;
    }

    tr { 
        height: var(--slot-height) !important; 
    }

    th, td,
    body.dark-theme th,
    body.dark-theme td {
        border: 1px solid #000 !important;
        padding: 2px !important;
        color: #000 !important;
    }

    th, .time-col,
    body.dark-theme th,
    body.dark-theme .time-col {
        background: #8faadc !important;
        color: #000 !important;
    }

    body.dark-theme .type-Curs { background: #f4b183 !important; color: #000 !important; }
    body.dark-theme .type-Seminar { background: #c5e0b4 !important; color: #000 !important; }
    body.dark-theme .type-Laborator { background: #ffe699 !important; color: #000 !important; }
    body.dark-theme .type-Custom { background: #e2d9f3 !important; color: #000 !important; }

    .cell-container {
        min-height: unset !important;
        overflow: visible !important;
    }

    .cell-box {
        margin: 1px !important;
        padding: 3px !important;
        border: 1px solid rgba(0, 0, 0, 0.2) !important;
        box-shadow: none !important;
        font-size: 9.5px !important;
        line-height: 1.15 !important;
        break-inside: avoid;
    }

    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}