/* --- CSS VARIABLES FOR THEME --- */
:root {
    --bg-main: #0a0a0a;
    --bg-container: #121212;
    --bg-panel: #1a1a1a;
    --bg-element: #181818;
    --bg-element-hover: #1f1f1f;
    --bg-break: #151515;
    --bg-empty: #0f0f0f;
    --text-primary: #ececec;
    --text-secondary: #999999;
    --border-color: #2a2a2a;
    --table-border: #222;
    --accent-color: #0066cc;
    --accent-hover: #0052a3;
    --modal-overlay: rgba(0, 0, 0, 0.85);
    --shadow-color: rgba(0, 0, 0, 0.5);
    --edit-pool-bg: #1c2b42;
    --edit-pool-border: #004c99;
    --preset-block-bg: #2a2010;
    --preset-block-border: #996500;
}

body.light-mode {
    --bg-main: #f0f2f5;
    --bg-container: #ffffff;
    --bg-panel: #ffffff;
    --bg-element: #f7f9fa;
    --bg-element-hover: #eef2f5;
    --bg-break: #f0f2f5;
    --bg-empty: #fafafa;
    --text-primary: #1a1a1a;
    --text-secondary: #5f6368;
    --border-color: #dadce0;
    --table-border: #dadce0;
    --accent-color: #1a73e8;
    --accent-hover: #1765cc;
    --modal-overlay: rgba(255, 255, 255, 0.9);
    --shadow-color: rgba(0, 0, 0, 0.15);
    --edit-pool-bg: #e8f0fe;
    --edit-pool-border: #1a73e8;
    --preset-block-bg: #fff8e1;
    --preset-block-border: #ffc107;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    scrollbar-width: none;
}

body {
    font-family: 'Montserrat', -apple-system, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: 0.3s ease;
}

/* HEADER & NEXT LESSON BOX */
.container {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: var(--bg-container);
}

.header {
    background: var(--bg-panel);
    padding: 0 30px;
    height: 70px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-title {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.header-title h1 {
    font-size: 1.4em;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
}

.header-title h2 {
    font-size: 0.8em;
    color: var(--text-secondary);
    font-weight: 500;
    margin: 0;
    cursor: pointer;
    transition: 0.2s;
}

.header-title h2:hover {
    color: var(--accent-color);
}

.info-bar {
    display: flex;
    align-items: center;
    height: 100%;
    gap: 15px;
}

.lesson-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0 16px;
    border-radius: 8px;
    background: var(--bg-element);
    border: 1px solid var(--border-color);
    height: 42px;
    min-width: 130px;
}

.lesson-name {
    font-size: 0.9em;
    font-weight: 600;
    color: var(--text-primary);
    max-width: 180px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.lesson-countdown {
    font-size: 0.85em;
    color: var(--accent-color);
    font-family: monospace;
    font-weight: 600;
}

.action-buttons {
    display: flex;
    align-items: center;
    gap: 8px;
}

.compact-toggle {
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-secondary);
    width: 40px;
    height: 40px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.compact-toggle:hover {
    background: var(--bg-element-hover);
    color: var(--text-primary);
    transform: translateY(-1px);
}

.compact-toggle.active {
    background: var(--accent-color);
    color: #fff;
}

/* TIMETABLE & CELLS */
.dual-timetable-container {
    display: flex;
    padding: 20px;
    gap: 20px;
    flex: 1;
    overflow-x: auto;
}

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

.timetable {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    background: transparent;
    border-radius: 6px;
    table-layout: fixed;
    height: 100%;
    min-width: 700px;
}

.timetable th, .timetable td {
    padding: 12px 8px;
    text-align: center;
    border: 1px solid var(--table-border);
    border-top-width: 0;
    border-left-width: 0;
    vertical-align: middle;
    transition: 0.2s;
}

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

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

.timetable th {
    background: var(--bg-panel);
    color: var(--text-primary);
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.9em;
    position: sticky;
    top: 0;
    z-index: 10;
}

.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;
}

.period-time {
    background: var(--bg-panel);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.8em;
    width: 110px;
}

.lesson-cell {
    background: var(--bg-element);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}

.lesson-cell:hover {
    background: var(--bg-element-hover);
}

/* Edit Mode Styling */
body.edit-mode .lesson-cell {
    box-shadow: inset 0 0 0 1px var(--border-color);
}

body.edit-mode td[data-locked="true"] {
    opacity: 0.3;
    pointer-events: none;
    filter: grayscale(100%);
    background: #000 !important;
}

body.light-mode.edit-mode td[data-locked="true"] {
    background: #ddd !important;
}

body.edit-mode td[data-pool]:hover {
    background: var(--accent-color) !important;
    color: #fff;
    box-shadow: inset 0 0 0 2px #fff;
    z-index: 2;
}

body.edit-mode td.pool-hover {
    background: var(--edit-pool-bg) !important;
    box-shadow: inset 0 0 0 1px var(--edit-pool-border);
}

body.edit-mode td[data-pool]::after {
    content: '\e3c9';
    font-family: 'Material Symbols Outlined';
    position: absolute;
    top: 4px;
    right: 6px;
    font-size: 16px;
    color: var(--text-secondary);
    opacity: 0;
    transition: 0.2s;
}

body.edit-mode td[data-pool]:hover::after {
    opacity: 1;
    color: #fff;
}

.cell-content {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95em;
}

.cell-badge {
    font-size: 0.7em;
    background: var(--bg-panel);
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    padding: 2px 6px;
    border-radius: 4px;
    display: inline-block;
    margin-top: 4px;
}

.unmapped-block {
    font-style: italic;
    color: var(--accent-color);
    font-weight: 500;
}

/* Current/Next Lesson Highlights */
.highlight-current {
    outline: 2px solid #0a8f08;
    outline-offset: -2px;
    background: #111f11;
}

.highlight-next {
    outline: 2px solid var(--accent-color);
    outline-offset: -2px;
    background: #101924;
}

body.light-mode .highlight-current {
    outline: 2px solid #1e8e3e;
    background: #e6f4ea;
}

body.light-mode .highlight-next {
    outline: 2px solid var(--accent-color);
    background: #e8f0fe;
}

/* MODALS & INPUTS */
.modal {
    position: fixed;
    z-index: 1000;
    inset: 0;
    background-color: var(--modal-overlay);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.show {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.modal-content {
    background: var(--bg-panel);
    padding: 32px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    width: 450px;
    color: var(--text-primary);
    position: relative;
    text-align: center;
    box-shadow: 0 20px 60px var(--shadow-color);
    max-height: 90vh;
    overflow-y: auto;
}

.wide-modal {
    width: 850px;
}

.close-button {
    color: var(--text-secondary);
    position: absolute;
    top: 12px;
    right: 16px;
    font-size: 28px;
    cursor: pointer;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: 0.2s;
}

.close-button:hover {
    color: var(--text-primary);
    background: var(--bg-element);
}

.modal-btn {
    padding: 12px 20px;
    border-radius: 6px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: 0.2s;
    font-size: 0.95em;
    width: 100%;
    font-family: inherit;
}

.modal-btn:hover {
    transform: translateY(-1px);
}

.custom-btn {
    background: var(--bg-element);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.custom-btn:hover {
    background: var(--bg-element-hover);
}

.delete-btn {
    background: #1a0a0a;
    border: 1px solid #3a1a1a;
    color: #cc5555;
}

body.light-mode .delete-btn {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #991b1b;
}

.editor-section {
    margin-bottom: 20px;
    text-align: left;
}

.editor-section label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.9em;
}

.styled-input, .styled-select {
    width: 100%;
    padding: 10px;
    background: var(--bg-element);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 6px;
    outline: none;
    font-family: inherit;
}

.styled-input:focus, .styled-select:focus {
    border-color: var(--accent-color);
}

.desc-text {
    font-size: 0.85em;
    color: var(--text-secondary);
}

.dropdown-item {
    padding: 12px 16px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: 0.15s;
    color: var(--text-primary);
    background: var(--bg-element);
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background: var(--bg-element-hover);
    color: var(--accent-color);
}

/* TABS */
.week-tabs {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 15px;
}

.week-tab {
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    padding: 10px 20px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: 0.2s;
    font-family: inherit;
}

.week-tab:hover {
    color: var(--text-primary);
    background: var(--bg-element);
    border-radius: 4px 4px 0 0;
}

.week-tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent-color);
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 15px;
    text-align: left;
}

.template-card {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    background: var(--bg-element);
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: 0.2s;
}

.template-card:hover {
    border-color: var(--accent-color);
    transform: translateY(-2px);
}

.template-card h4 {
    margin-bottom: 5px;
    color: var(--text-primary);
}

.template-card p {
    font-size: 0.85em;
    color: var(--text-secondary);
    margin-bottom: 15px;
    flex: 1;
}

/* FULLSCREEN STUDIO */
.fullscreen-modal {
    position: fixed;
    inset: 0;
    background: var(--bg-container);
    z-index: 2000;
    display: none;
    flex-direction: column;
}

.fullscreen-modal.show {
    display: flex;
}

.studio-top-tabs {
    display: flex;
    height: 100%;
    align-items: flex-end;
    gap: 5px;
    margin-left: 20px;
}

.studio-tab {
    background: var(--bg-element);
    border: 1px solid var(--border-color);
    border-bottom: none;
    color: var(--text-secondary);
    padding: 10px 20px;
    border-radius: 8px 8px 0 0;
    cursor: pointer;
    font-weight: 600;
    transition: 0.2s;
}

.studio-tab.active {
    background: var(--bg-main);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.studio-body {
    flex: 1;
    display: flex;
    overflow: hidden;
    background: var(--bg-main);
    border-top: 1px solid var(--border-color);
    margin-top: -1px;
}

.studio-view {
    flex: 1;
    display: none;
}

.studio-view.active {
    display: flex;
}

.settings-sidebar {
    background: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 20px 10px;
    overflow-y: auto;
}

.sidebar-header {
    font-size: 1.1em;
    font-weight: 700;
    color: var(--text-primary);
    padding: 0 10px 15px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 10px;
}

.tab-btn {
    background: var(--bg-element);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    padding: 10px 15px;
    text-align: left;
    cursor: pointer;
    border-radius: 6px;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 10px;
    font-family: inherit;
}

.tab-btn:hover {
    background: var(--bg-element-hover);
    color: var(--text-primary);
}

.tab-btn.active {
    background: var(--accent-color);
    color: #fff;
    border-color: var(--accent-color);
}

.checkbox-group {
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    color: var(--text-primary);
    font-size: 0.9em;
}

/* Studio Paint FX */
#studioTimetable td.lesson-cell {
    user-select: none;
}

#studioTimetable td.lesson-cell.painting {
    background: var(--accent-color);
    transform: scale(0.95);
    z-index: 10;
    border-radius: 4px;
}

/* Sub-Preset Block Styling */
.preset-block {
    background: var(--preset-block-bg) !important;
    border: 1px dashed var(--preset-block-border) !important;
    color: var(--preset-block-border) !important;
}

#studioTimetable td.locked-cell {
    opacity: 0.3;
    filter: grayscale(100%);
    pointer-events: none;
}