@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

:root {
  --primary-color: #60a5fa; --primary-hover: #3b82f6; --success-color: #22c55e;
  --warning-color: #f59e0b; --danger-color: #ef4444; --background: #0b1120;
  --surface: #0f172a; --surface-elevated: #111827; --border: #1f2937;
  --text-primary: #e5e7eb; --text-secondary: #cbd5e1; --text-muted: #94a3b8;
  --slot-bg: #0e192b; --slot-empty-bg: #0c1528; --tooltip-bg: #0f1b2f;
  --tooltip-text: #ffffff; --radius-sm: 6px; --radius: 10px; --radius-lg: 14px;
  --shadow: 0 4px 12px rgba(0,0,0,0.35); --shadow-md: 0 10px 20px rgba(0,0,0,0.4);
  --c1: 210, 100%, 68%; --c2: 265, 86%, 76%; --c3: 160, 65%, 62%; --c4: 18, 92%, 62%;
  --c5: 340, 80%, 70%; --c6: 30, 85%, 60%; --c7: 195, 80%, 70%; --c8: 130, 60%, 55%;
}

:root[data-theme="light"] {
  --background: #f7fafc; --surface: #ffffff; --surface-elevated: #f1f5f9;
  --border: #e2e8f0; --text-primary: #0f172a; --text-secondary: #334155; --text-muted: #64748b;
  --slot-bg: #f8fafc; --slot-empty-bg: #f1f5f9; --tooltip-bg: #ffffff; --tooltip-text: #0f172a;
}

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

body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--background); color: var(--text-primary); padding: 20px;
  transition: background 0.2s ease, color 0.2s ease;
}

.container { max-width: 1400px; margin: 0 auto; }
h1 { font-size: 22px; font-weight: 800; margin-bottom: 14px; }
h2 { font-size: 1.25rem; font-weight: 700; margin-bottom: 0.75rem; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 1.5rem; margin-bottom: 1.5rem;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

/* ========== Professional Login Gate (replaces blur approach) ========== */

.gate.card { border-radius: 16px; box-shadow: var(--shadow); }
.pro-gate {
  max-width: 680px;
  margin: 20px auto 16px;
  padding: 24px 20px;
  background: linear-gradient(180deg, rgba(255,255,255,0.02), rgba(255,255,255,0.01));
  border: 1px solid var(--border);
  border-radius: 16px;
}

.gate-header { text-align: center; margin-bottom: 14px; }
.gate-logo {
  width: 56px; height: 56px; margin: 0 auto 10px;
  display: grid; place-items: center;
  font-weight: 800; letter-spacing: 0.5px;
  border-radius: 12px;
  color: #0ea5e9;
  background: radial-gradient(120% 120% at 50% 0%, rgba(14,165,233,.18) 0%, rgba(14,165,233,.06) 60%, transparent 100%);
  border: 1px solid rgba(14,165,233,.25);
}
.gate-title { margin: 0; font-size: 1.2rem; line-height: 1.25; }
.gate-subtitle { margin: 6px 0 0; color: var(--text-secondary); font-size: 0.95rem; }

.gate-actions { display: grid; place-items: center; gap: 12px; padding: 6px 0 2px; }
.gate-msg { margin-top: 6px; font-size: 0.9rem; color: var(--text-secondary); text-align: center; }
.gate-msg.error { color: var(--danger-color); font-weight: 800; }
.gate-foot { margin-top: 10px; text-align: center; color: var(--text-muted); }

/* App lock state */
.app-locked {
  opacity: 0.35;
  pointer-events: none;
  user-select: none;
  transform: scale(0.985);
  filter: saturate(0.9);
}
#appShell { transition: opacity .2s ease, transform .2s ease, filter .2s ease; }

/* ========== Control Panel ========== */

.control-panel-header {
  display: flex; align-items: center; justify-content: space-between; margin-bottom: .5rem;
}
.cp-title { font-weight: 900; font-size: 1rem; color: var(--text-secondary); }

.cp-toggle {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--surface-elevated); border: 1px solid var(--border);
  color: var(--text-secondary); padding: 6px 10px; border-radius: 999px;
  cursor: pointer; font-weight: 800;
}
.cp-toggle:hover { background: color-mix(in oklab, var(--surface-elevated) 70%, transparent); }
.cp-toggle .chev { transition: transform 180ms ease; }
.cp-toggle[aria-expanded="false"] .chev { transform: rotate(-90deg); }

.cp-collapsible { display: grid; grid-template-rows: 1fr; transition: grid-template-rows 220ms ease; }
.cp-collapsible.collapsed { grid-template-rows: 0fr; }
.cp-inner { overflow: hidden; }

.control-panel { display: flex; flex-direction: column; gap: 1.25rem; }
.controls-row { display: flex; flex-wrap: wrap; gap: 1.5rem; align-items: flex-end; }
.input-group { flex: 1 1 250px; min-width: 200px; }
.input-group.button-group { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.quick-jump-group { flex-grow: 0.5; }
.help-text-group { flex-grow: 2; }
.help-text-group p { font-size: 0.8rem; color: var(--text-muted); padding-bottom: 0.5rem; }
.quick-jump-input { display: flex; gap: 0.5rem; }
.quick-jump-input input { max-width: 100px; }

label { display: block; font-weight: 700; margin-bottom: 6px; color: var(--text-secondary); font-size: 0.9rem; }
input[type="text"], input[type="date"], input[type="file"], input[type="number"], textarea, select, input[type="url"] {
  width: 100%; background: var(--slot-bg); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 10px 12px;
}

/* ========== Buttons ========== */

.btn {
  background: var(--primary-color); color: #071223; border: 1px solid var(--primary-color);
  padding: 9px 14px; border-radius: var(--radius); cursor: pointer; font-size: 14px; font-weight: 800;
}
.btn:hover { background: var(--primary-hover); }
.btn.warn { background: var(--warning-color); border-color: var(--warning-color); color: #0f172a; }
.btn.warn:hover { background: color-mix(in oklab, var(--warning-color) 85%, #000); }
.btn.info { background: #38bdf8; border-color: #38bdf8; color: #082f49; }
.btn.danger { background: var(--danger-color); border-color: var(--danger-color); color: #fff; }
.btn.success { background: var(--success-color); border-color: var(--success-color); color: #fff; }
.btn.success.active { background: #166534; border-color: #14532d; color: #dcfce7; }
.btn.theme-toggle { background: transparent; color: var(--text-primary); border-color: var(--border); }
.undo-btn { padding: 2px 8px; font-size: 12px; margin-left: 8px; }

/* ========== Status Bar (now with header action bar) ========== */

.status-bar {
  display: flex; flex-direction: column; gap: 10px;
  width: 100%; margin-top: 0.5rem; padding-top: 1rem; border-top: 1px solid var(--border);
}
.header-action-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }
.header-action-bar .spacer { flex: 1 1 auto; }
.header-actions-group { display: flex; flex-wrap: wrap; gap: 8px; }
.header-actions-group .btn { padding: 8px 12px; }

#weekRangeDisplay { font-size: 1.1rem; font-weight: 700; }
#status { color: var(--text-secondary); font-weight: 700; }

/* ========== Layout & Timetable Grid ========== */

.layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 1.5rem; }
.timetable-container { overflow-x: auto; }
.timetable-grid { display: grid; grid-template-columns: 110px repeat(5, minmax(160px, 1fr)); gap: 8px; }

.grid-header {
  position: sticky; top: 0; background: var(--surface-elevated); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 8px; font-weight: 800; text-align: center;
  z-index: 2; cursor: pointer; transition: all 0.2s ease; user-select: none;
}
.grid-header:hover { background: color-mix(in oklab, var(--surface-elevated) 70%, #0000); }
.grid-header.active {
  background: color-mix(in oklab, var(--primary-color) 20%, var(--surface-elevated));
  border-color: var(--primary-color); color: var(--primary-color);
}
.grid-header.corner { cursor: default; font-weight: 900; }

/* MODIFICATION: Style for the interactive week parity toggler */
.grid-header.corner-toggle {
    cursor: pointer;
}
.grid-header.corner-toggle:hover {
    background: color-mix(in oklab, var(--primary-color) 15%, var(--surface-elevated));
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.time-label {
  background: var(--surface-elevated); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 6px; display: flex; flex-direction: column; gap: 4px; justify-content: center;
  align-items: center; font-weight: 700; font-size: 12px;
}
.time-label .period-id { color: var(--text-muted); font-size: 11px; }

.lesson-slot {
  background: var(--slot-bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px; min-height: 72px; display: flex; align-items: stretch; position: relative;
  transition: all 0.2s ease;
}
.lesson-slot.empty {
  background: var(--slot-empty-bg); color: var(--text-muted); display: flex; align-items: center;
  justify-content: center; font-style: italic; font-size: 12px; cursor: pointer; border-style: dashed;
}

.lesson-card { display: flex; flex-direction: column; gap: 4px; width: 100%; cursor: pointer; }
.lesson-title { font-weight: 800; font-size: 13px; color: var(--text-primary); }
.lesson-meta { color: var(--text-secondary); font-size: 11px; }

.note-badge {
  position: absolute; top: 6px; right: 6px; background: #f59e0b; color: #0b1120;
  font-weight: 900; font-size: 10px; padding: 2px 6px; border-radius: 999px; border: 1px solid #f59e0b;
}
.order-badge {
  position: absolute; bottom: 6px; right: 6px; background: var(--success-color); color: #fff;
  font-weight: 900; font-size: 12px; width: 20px; height: 20px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center; border: 1px solid var(--success-color);
  box-shadow: 0 1px 3px rgba(0,0,0,0.3); user-select: none;
}
.lesson-class-link {
  position: absolute; bottom: 6px; right: 6px; width: 24px; height: 24px;
  background: var(--surface-elevated); border: 1px solid var(--border); border-radius: var(--radius-sm);
  color: var(--text-secondary); display: flex; align-items: center; justify-content: center;
  text-decoration: none; transition: all 0.2s ease;
}
.lesson-class-link:hover { background: var(--primary-color); color: #0b1120; border-color: var(--primary-color); }
.lesson-class-link svg { width: 14px; height: 14px; }

.lesson-slot[class*="cc-"] { border-width: 2px; }
.cc-1 { border-color: hsl(var(--c1)); background: color-mix(in oklab, hsl(var(--c1)) 14%, var(--slot-bg)); }
.cc-2 { border-color: hsl(var(--c2)); background: color-mix(in oklab, hsl(var(--c2)) 14%, var(--slot-bg)); }
.cc-3 { border-color: hsl(var(--c3)); background: color-mix(in oklab, hsl(var(--c3)) 14%, var(--slot-bg)); }
.cc-4 { border-color: hsl(var(--c4)); background: color-mix(in oklab, hsl(var(--c4)) 14%, var(--slot-bg)); }
.cc-5 { border-color: hsl(var(--c5)); background: color-mix(in oklab, hsl(var(--c5)) 14%, var(--slot-bg)); }
.cc-6 { border-color: hsl(var(--c6)); background: color-mix(in oklab, hsl(var(--c6)) 14%, var(--slot-bg)); }
.cc-7 { border-color: hsl(var(--c7)); background: color-mix(in oklab, hsl(var(--c7)) 14%, var(--slot-bg)); }
.cc-8 { border-color: hsl(var(--c8)); background: color-mix(in oklab, hsl(var(--c8)) 14%, var(--slot-bg)); }

.lesson-slot.current {
  outline: 2px solid #16a34a; outline-offset: 0;
  box-shadow: 0 0 0 2px color-mix(in oklab, #22c55e 35%, #0000) inset;
  background: color-mix(in oklab, #22c55e 16%, var(--slot-bg));
}
.lesson-slot.past { opacity: 0.6; filter: saturate(50%); }
.lesson-slot.past::after {
  content: ''; position: absolute; inset: 0; pointer-events: none; opacity: 0.9;
  background-image: linear-gradient(to top right, transparent calc(50% - .5px), color-mix(in srgb,var(--text-muted) 40%,transparent) calc(50% - .5px), color-mix(in srgb,var(--text-muted) 40%,transparent) calc(50% + .5px), transparent calc(50% + .5px)), linear-gradient(to top left, transparent calc(50% - .5px), color-mix(in srgb,var(--text-muted) 40%,transparent) calc(50% - .5px), color-mix(in srgb,var(--text-muted) 40%,transparent) calc(50% + .5px), transparent calc(50% + .5px));
}
.timetable-grid.focusing .lesson-slot.past:not(.dimmed) { opacity: 1; filter: none; }
.timetable-grid.focusing .lesson-slot.past:not(.dimmed)::after { opacity: 0.5; }

/* ========== Notes Sidebar ========== */

.notes-sidebar { 
  position: sticky; top: 1.5rem; height: fit-content; align-self: start;
  /* MODIFICATION: Allow the card to contain a scrolling panel */
  display: flex; flex-direction: column; max-height: calc(100vh - 3rem);
}
.notes-sidebar-head { display: grid; gap: 8px; margin-bottom: 8px; }
.note-day-selector { display: flex; justify-content: space-between; align-items: center; }
.day-header-tabs { display: flex; gap: 6px; }
.day-tab-btn {
  background: var(--slot-empty-bg); border: 1px solid var(--border); color: var(--text-secondary);
  padding: 6px 10px; border-radius: 999px; font-weight: 800; cursor: pointer; font-size: 12px;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.day-tab-btn.active { background: var(--primary-color); color: #0b1120; border-color: var(--primary-color); }
/* MODIFICATION: Style for the preview state on hover */
.day-tab-btn.preview {
    background: color-mix(in oklab, var(--primary-color) 25%, var(--slot-empty-bg));
    border-color: color-mix(in oklab, var(--primary-color) 50%, var(--border));
}
.note-day-date { color: var(--text-muted); font-size: 12px; }

/* MODIFICATION: Make the notes panel scrollable */
.notes-panel { 
  display: grid; gap: 8px; 
  overflow-y: auto;
  padding-right: 8px; /* Add some space for the scrollbar */
  margin-right: -8px;
}

.note-item { 
  background: var(--slot-empty-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; 
  /* MODIFICATION: Add left border for color coding */
  border-left: 4px solid transparent;
  transition: background-color 0.2s ease, border-color 0.2s ease;
}
.note-item.collapsed .note-body { grid-template-rows: 0fr; }
.note-body { display: grid; grid-template-rows: 1fr; transition: grid-template-rows 180ms ease; }
.note-body-inner { overflow: hidden; }
.note-item.current-note { outline: 2px solid #16a34a; outline-offset: 0; background: color-mix(in oklab, #22c55e 12%, transparent); }
.note-item-empty { color: var(--text-muted); }

/* MODIFICATION: Style for highlighted note on timetable hover */
.note-item.highlighted {
  background: color-mix(in oklab, var(--primary-color) 15%, var(--slot-empty-bg));
  border-color: var(--primary-color);
}

.note-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.note-head button.note-toggle { all: unset; display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 6px; border-radius: 8px; }
.note-head button.note-toggle:hover { background: color-mix(in oklab, var(--slot-empty-bg) 70%, transparent); }
.note-head .chevron { display: inline-block; transition: transform 180ms ease; }
.note-item.collapsed .note-head .chevron { transform: rotate(-90deg); }

.note-text { white-space: pre-wrap; overflow-wrap: anywhere; word-break: break-word; }
.note-text a { color: var(--primary-color); text-decoration: underline; word-break: break-all; }

/* ========== Modals ========== */

.modal { position: fixed; inset: 0; background: rgba(2,6,23,0.55); display: none; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
:root[data-theme="light"] .modal { background: rgba(15, 23, 42, 0.35); }
.modal.open { display: flex; }
.modal-content { width: 100%; max-width: 520px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: 16px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; }
.modal-close-btn { background: transparent; color: var(--text-primary); border: 1px solid var(--border); padding: 6px 10px; border-radius: 8px; cursor: pointer; }
#modalMeta, #reminderText { color: var(--text-secondary); margin: 6px 0 8px; }
#teacherNoteText, #technicianOrderText { min-height: 120px; }

.modal-form-group { margin-bottom: 12px; }
.modal-form-group label { display: block; font-weight: 700; margin-bottom: 6px; color: var(--text-secondary); font-size: 14px; }
.modal-input-group { display: flex; gap: 8px; }
.modal-input-group input { flex-grow: 1; }
.modal-input-group .btn { flex-shrink: 0; }
.modal-footer { display: flex; justify-content: flex-start; gap: 8px; margin-top: 16px; align-items: center; flex-wrap: wrap;}
.modal-footer .spacer { flex-grow: 1; }

/* ========== Export Modal ========== */

.export-modal-content { margin-top: 12px; background: var(--slot-empty-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; max-height: 60vh; overflow-y: auto; }
.export-group { margin-bottom: 16px; }
.export-group:last-child { margin-bottom: 0; }
.export-group h3 { font-size: 16px; font-weight: 800; color: var(--primary-color); margin-bottom: 8px; padding-bottom: 4px; border-bottom: 2px solid var(--border); }
.export-item { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.export-item:last-child { border-bottom: none; }
.export-item-meta { font-weight: 700; margin-bottom: 4px; }
.export-item-meta span { font-weight: 500; color: var(--text-secondary); margin-left: 8px; }
.export-item-note { white-space: pre-wrap; word-break: break-word; padding-left: 4px; }

/* ========== Tooltip ========== */

.note-tooltip { position: fixed; max-width: 360px; background: var(--tooltip-bg); color: var(--tooltip-text); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; font-size: 12px; box-shadow: var(--shadow); pointer-events: none; display: none; z-index: 1000; white-space: normal; }
.note-tooltip-caret { position: absolute; width: 10px; height: 10px; background: var(--tooltip-bg); border-left: 1px solid var(--border); border-top: 1px solid var(--border); transform: rotate(45deg); top: -6px; left: 12px; }
.note-tooltip-title { font-weight: 800; margin-bottom: 4px; }
.note-tooltip-meta { color: var(--text-secondary); margin-bottom: 6px; font-size: 11px; }
.note-tooltip-text { color: var(--text-primary); white-space: normal; overflow-wrap: anywhere; word-break: break-word; max-width: 320px; }

/* ========== Effects & Focus ========== */

@keyframes breathe-red { 50% { box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.25), 0 0 0 3px rgba(239, 68, 68, 0.25) inset; } }
.lesson-slot.scheduled.needs-note { animation: breathe-red 3s ease-in-out infinite; }
.timetable-grid.focusing .lesson-slot.dimmed { filter: grayscale(100%) saturate(40%); opacity: 0.45; }

/* ========== Responsive ========== */

@media (max-width: 1100px) { .layout { grid-template-columns: 1fr; } }
@media (max-width: 768px) {
  .timetable-grid { grid-template-columns: 100px repeat(5, minmax(120px, 1fr)); }
  .pro-gate { margin: 16px 12px; padding: 20px 16px; border-radius: 12px; }
  .gate-title { font-size: 1.1rem; }
  .gate-subtitle { font-size: 0.9rem; }
}
/* Add this at the end of your style.css file */

/* Style for the new color picker group in the modal */
.color-picker-group {
    align-items: center;
}
#classColorPicker {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    width: 50px;
    height: 38px;
    background-color: transparent;
    border: none;
    cursor: pointer;
    padding: 0;
}
#classColorPicker::-webkit-color-swatch {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}
#classColorPicker::-moz-color-swatch {
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

/* This class will be added to slots with a custom color */
.has-custom-color {
    border-width: 2px;
}

/* ========== Holiday and Special Event Styling ========== */
.day-badge {
    display: block;
    font-size: 10px;
    font-weight: 700;
    margin-top: 4px;
    padding: 2px 6px;
    border-radius: 6px;
    line-height: 1.2;
}
.holiday-badge {
    background-color: var(--success-color);
    color: #fff;
}
.event-badge {
    background-color: var(--warning-color);
    color: #0f172a;
}
.grid-header.holiday, .grid-header.special-event {
    padding-bottom: 8px;
    cursor: pointer; /* Allow double-clicking */
}
.lesson-slot.holiday, .lesson-slot.special-event {
    background: var(--surface-elevated);
    border-style: dashed;
    opacity: 0.7;
    filter: saturate(0.5);
    font-weight: 700;
    color: var(--text-secondary);
    cursor: not-allowed;
    display: flex;
    align-items: center;
    justify-content: center;
}
.note-item-empty.holiday-note, .note-item-empty.event-note {
    padding: 1rem;
    text-align: center;
    background: var(--surface-elevated);
    border-radius: var(--radius);
    line-height: 1.5;
}
.note-item-empty.holiday-note strong {
    color: var(--success-color);
}
.note-item-empty.event-note strong {
    color: var(--warning-color);
}