/* --- GLOBAL & BODY STYLES --- */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    scrollbar-width: none;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Helvetica Neue', sans-serif;
    background: #0a0a0a;
    min-height: 100vh;
    padding: 0;
    color: #e8e8e8;
    user-select: none;
    overflow-x: hidden;
}

/* --- MAIN CONTAINER & HEADER --- */
.container {
    width: 100%;
    margin: 0;
    background: #121212;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.header {
    background: #1a1a1a;
    color: #ffffff;
    padding: 20px 40px;
    border-bottom: 1px solid #2a2a2a;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 20px;
}

.header-title h1 {
    font-size: 1.8em;
    margin-bottom: 4px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.header-title h2 {
    font-size: 0.95em;
    color: #888;
    font-weight: 400;
}

/* --- INFO BAR --- */
.info-bar {
    display: flex;
    align-items: center;
    gap: 12px;
}

.lesson-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-width: 140px;
    padding: 8px 16px;
    border-radius: 6px;
    background: #0f0f0f;
    border: 1px solid #2a2a2a;
    height: 50px;
}

.lesson-box.next-lesson {
    background: #141414;
    border-color: #333;
}

.lesson-name {
    font-size: 0.95em;
    font-weight: 600;
    text-align: center;
    color: #fff;
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lesson-countdown {
    font-size: 0.8em;
    color: #888;
    margin-top: 2px;
    font-family: monospace;
}

.compact-toggle {
    background: #0f0f0f;
    border-radius: 6px;
    border: 1px solid #2a2a2a;
    color: #aaa;
    font-size: 1.2em;
    height: 50px;
    width: 50px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.compact-toggle:hover {
    background: #1a1a1a;
    border-color: #333;
    color: #fff;
}

.compact-toggle.active {
    background: #0066cc;
    border-color: #0066cc;
    color: #fff;
}

/* --- DUAL TIMETABLE LAYOUT --- */
.dual-timetable-container {
    display: flex;
    flex-direction: row;
    padding: 20px;
    gap: 20px;
    flex: 1;
    overflow-x: auto;
}

.week-column {
    flex: 1;
    min-width: 600px;
    display: flex;
    flex-direction: column;
}

.week-title {
    text-align: center;
    color: #666;
    margin-bottom: 15px;
    font-size: 1.2em;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.week-content {
    flex: 1;
    display: block !important;
}

/* --- TABLE STYLES --- */
.timetable {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: transparent;
    border-radius: 6px;
    overflow: visible;
    table-layout: fixed;
    height: 100%;
}

.timetable th,
.timetable td {
    padding: 12px 8px;
    text-align: center;
    border: 1px solid #222;
    border-top-width: 0;
    border-left-width: 0;
    vertical-align: middle;
    transition: background-color 0.15s ease;
}

.timetable th:first-child, .timetable td:first-child { border-left-width: 1px; }
.timetable tr:first-child th { border-top-width: 1px; }

.timetable th {
    background: #1a1a1a;
    color: #fff;
    padding: 14px 8px;
    font-weight: 500;
    font-size: 0.9em;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.timetable thead tr:first-child th:first-child { border-top-left-radius: 6px; }
.timetable thead tr:first-child th:last-child { border-top-right-radius: 6px; }
.timetable tbody tr:last-child td:first-child { border-bottom-left-radius: 6px; }
.timetable tbody tr:last-child td:last-child { border-bottom-right-radius: 6px; }

.timetable th.day-header {
    cursor: pointer;
    transition: background-color 0.2s ease;
}
.timetable th.day-header:hover { background: #222; }

.period-time {
    background: #1a1a1a;
    color: #aaa;
    font-weight: 500;
    font-size: 0.8em;
    width: 80px;
}

.subject { font-weight: 500; color: #fff; font-size: 0.9em; }
.lesson { background: #181818; cursor: pointer; position: relative; transition: all 0.2s ease; }
.lesson:hover { background: #1f1f1f; }

/* FIX: Break looks exactly like lesson normally */
.break { 
    background: #181818; 
    color: #fff; 
    font-weight: 500; 
    font-size: 0.9em; 
    cursor: pointer;
    transition: all 0.2s ease;
}
.break:hover {
    background: #1f1f1f;
}

/* FIX: Break in edit mode is disabled/dimmed */
body.edit-mode .break { 
    opacity: 0.3;
    pointer-events: none;
    filter: grayscale(100%);
    background: #101010;
}

.empty { background: #0f0f0f; color: #444; font-style: italic; }

.highlight-current { outline: 2px solid #0a8f08; outline-offset: -2px; background: rgba(10, 143, 8, 0.1); }
.highlight-next { outline: 2px solid #0066cc; outline-offset: -2px; background: rgba(0, 102, 204, 0.1); }

/* --- LESSON POPUP --- */
.lesson-popup {
    position: fixed;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 24px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.8);
    z-index: 10000;
    min-width: 280px;
    opacity: 0;
    transform: scale(0.9);
    pointer-events: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.lesson-popup.show { opacity: 1; transform: scale(1); pointer-events: auto; }
.lesson-popup-header { margin-bottom: 20px; padding-bottom: 16px; border-bottom: 1px solid #2a2a2a; }
.lesson-popup-title { font-size: 1.4em; font-weight: 600; color: #fff; margin-bottom: 6px; }
.lesson-popup-time { font-size: 0.9em; color: #888; }
.lesson-popup-content { display: flex; flex-direction: column; gap: 12px; margin-bottom: 20px; }
.lesson-popup-info { display: flex; justify-content: space-between; align-items: center; padding: 10px 0; }
.lesson-popup-label { font-size: 0.9em; color: #888; }
.lesson-popup-value { font-size: 0.95em; color: #fff; font-weight: 500; }
.lesson-popup-actions { display: flex; gap: 10px; }
.lesson-popup-btn { flex: 1; padding: 10px 16px; border: none; border-radius: 6px; font-weight: 500; font-size: 0.9em; cursor: pointer; transition: all 0.2s ease; background: #2a2a2a; color: #fff; }
.lesson-popup-btn:hover { background: #333; }
.lesson-popup-btn.edit { background: #0066cc; color: #fff; }
.lesson-popup-btn.edit:hover { background: #0052a3; }
.lesson-popup-close { position: absolute; top: 12px; right: 12px; background: none; border: none; font-size: 24px; color: #666; cursor: pointer; width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 4px; transition: all 0.2s ease; }
.lesson-popup-close:hover { background: #222; color: #fff; }

/* --- MODAL STYLES --- */
.modal {
    position: fixed;
    z-index: 1000;
    left: 0; top: 0;
    width: 100%; height: 100%;
    background-color: rgba(0, 0, 0, 0.85);
    opacity: 0; visibility: hidden;
    pointer-events: none;
    transition: opacity 0.2s ease, visibility 0.2s ease;
    display: flex; align-items: center; justify-content: center;
}
.modal.show { opacity: 1; visibility: visible; pointer-events: auto; }
.modal-content {
    background: #1a1a1a;
    padding: 32px;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    width: 500px;
    max-height: 85vh;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.9);
    color: #e8e8e8;
    overflow-y: auto;
    position: relative;
    text-align: center;
}
.modal-content.wide-modal { width: 800px; }
.modal-content h3 { margin-bottom: 24px; font-size: 1.6em; color: #fff; font-weight: 600; }

.close-button {
    color: #666; position: absolute; top: 12px; right: 16px;
    font-size: 28px; font-weight: normal; cursor: pointer;
    width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
    border-radius: 4px; transition: color 0.2s ease;
}
.close-button:hover { color: #fff; background: #222; }

/* --- BOOKS DISPLAY STYLES --- */
.books-dual-container {
    display: flex;
    justify-content: space-between;
    text-align: left;
    gap: 20px;
}
.books-column { flex: 1; }
.books-column h4 { margin-bottom: 15px; color: #0066cc; font-size: 1.1em; text-transform: uppercase; letter-spacing: 0.5px; border-bottom: 1px solid #333; padding-bottom: 8px; }
.books-column-divider { width: 1px; background: #333; }
.books-list-display { list-style-type: none; padding: 0; }
.books-list-display li {
    background: #141414; margin-bottom: 8px; padding: 12px 14px;
    border-radius: 6px; font-size: 0.95em; border: 1px solid #222;
    transition: all 0.2s ease;
}
.books-list-display li:hover { background: #1a1a1a; border-color: #333; }
.no-books-msg { font-style: italic; color: #555; font-size: 0.9em; margin-top: 10px; }

/* --- BOOK EDITOR STYLES --- */
.large-content { width: 600px; text-align: left; }
.editor-section { margin-bottom: 24px; }
.editor-section label { display: block; margin-bottom: 8px; color: #aaa; font-weight: 500; font-size: 0.9em; }

.styled-select, .styled-input {
    width: 100%; padding: 12px; background: #0f0f0f; border: 1px solid #333;
    color: #fff; border-radius: 6px; font-size: 1em; outline: none;
    transition: border 0.2s; font-family: inherit;
}
.styled-select:focus, .styled-input:focus { border-color: #0066cc; background: #141414; }

.editor-book-list { list-style: none; padding: 0; border: 1px solid #222; border-radius: 6px; max-height: 200px; overflow-y: auto; background: #0f0f0f; }
.editor-book-list li {
    padding: 10px 14px; border-bottom: 1px solid #222; display: flex; justify-content: space-between; align-items: center;
}
.editor-book-list li:last-child { border-bottom: none; }
.remove-book-btn {
    background: none; border: none; color: #cc5555; font-size: 18px; cursor: pointer; padding: 0 8px;
}
.remove-book-btn:hover { color: #ff5555; }

.add-box { background: #161616; padding: 16px; border-radius: 8px; border: 1px solid #2a2a2a; }
.color-picker-label { margin-top: 12px; margin-bottom: 8px; font-size: 0.9em; color: #aaa; }
.color-picker { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.color-circle {
    width: 32px; height: 32px; border-radius: 50%; background: #1f1f1f;
    display: flex; align-items: center; justify-content: center; cursor: pointer;
    font-size: 14px; border: 2px solid transparent; transition: all 0.2s;
}
.color-circle:hover { background: #2a2a2a; transform: scale(1.1); }
.color-circle.selected { border-color: #0066cc; background: #2a2a2a; }

.add-btn { background: #0066cc; color: #fff; margin-top: 8px; }
.add-btn:hover { background: #0052a3; }

/* --- DROPDOWN & SELECTION --- */
.dropdown-wrapper label { display: block; margin-bottom: 8px; color: #aaa; font-size: 0.9em; font-weight: 500; }
.custom-dropdown { position: relative; width: 100%; }
#dropdownSearch, #bookSubjectSearch {
    width: 100%; padding: 12px 14px; border-radius: 6px; background: #0f0f0f;
    border: 1px solid #2a2a2a; color: white; font-size: 1em; outline: none;
    transition: all 0.2s ease; font-family: inherit;
}
#dropdownSearch:focus, #bookSubjectSearch:focus { background: #141414; border-color: #0066cc; }
.dropdown-options {
    position: absolute; top: 110%; left: 0; width: 100%; max-height: 240px;
    overflow-y: auto; background: #1a1a1a; border: 1px solid #2a2a2a;
    border-radius: 6px; z-index: 2000; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
    display: none;
}
.dropdown-options.show { display: block; }
.dropdown-options::-webkit-scrollbar { width: 8px; }
.dropdown-options::-webkit-scrollbar-track { background: #0f0f0f; }
.dropdown-options::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
.dropdown-item { padding: 12px 16px; cursor: pointer; border-bottom: 1px solid #222; transition: all 0.15s ease; color: #ccc; }
.dropdown-item:last-child { border-bottom: none; }
.dropdown-item:hover { background: #222; color: #fff; }
.separator { color: #555; font-weight: 500; font-size: 0.85em; margin: 8px 0; text-align: center; }
.modal-btn { padding: 12px 20px; border-radius: 6px; border: none; font-weight: 500; cursor: pointer; transition: all 0.2s ease; font-size: 0.95em; width: 100%; }
.modal-btn:hover { transform: translateY(-1px); }
.custom-btn { background: #0f0f0f; border: 1px solid #2a2a2a; color: #aaa; }
.custom-btn:hover { background: #1a1a1a; border-color: #333; color: #ccc; }
.delete-btn { background: #1a0a0a; border: 1px solid #3a1a1a; color: #cc5555; }
.delete-btn:hover { background: #2a1515; border-color: #4a2020; color: #dd6666; }

/* --- EDIT MODE VISUALS --- */
body.edit-mode .timetable .lesson { cursor: pointer; position: relative; background: #1a1a1a; box-shadow: inset 0 0 0 1px #333; }
body.edit-mode .timetable .lesson.pool-hover { background: #1c2b42 !important; box-shadow: inset 0 0 0 1px #004c99; }
body.edit-mode .timetable .lesson:hover { background: #0066cc !important; box-shadow: inset 0 0 0 2px #fff; z-index: 2; }

body.edit-mode td[data-pool="pool_gemoro"],
body.edit-mode td[data-pool="pool_english"],
body.edit-mode td[data-pool="pool_maths"] {
    opacity: 0.3;
    pointer-events: none;
    filter: grayscale(100%);
    box-shadow: none !important;
    background: #101010 !important;
}

body.edit-mode .timetable .lesson::after { content: '✎'; position: absolute; top: 4px; right: 6px; font-size: 12px; color: #666; opacity: 0; transition: opacity 0.2s ease; }
body.edit-mode .timetable .lesson:hover::after { opacity: 1; color: #fff; }

body.edit-mode td[data-pool="pool_gemoro"]::after,
body.edit-mode td[data-pool="pool_english"]::after,
body.edit-mode td[data-pool="pool_maths"]::after {
    display: none;
}

#editToggle.active { background: #0066cc; color: #fff; }

/* --- RESPONSIVE --- */
@media (max-width: 1250px) {
    .dual-timetable-container { flex-direction: column; overflow-x: hidden; }
    .week-column { min-width: 100%; margin-bottom: 30px; }
}
@media (max-width: 768px) {
    .timetable { font-size: 0.85em; }
    .timetable th, .timetable td { padding: 10px 4px; }
    .header h1 { font-size: 1.5em; }
    .modal-content { width: 95%; max-height: 80vh; }
    .period-time { width: 60px; font-size: 0.75em; }
    .books-dual-container { flex-direction: column; }
    .books-column-divider { width: 100%; height: 1px; margin: 15px 0; }
}