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

/* Restored Control Panel Styles */
.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;
}

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

/* Restored Status Bar */
.status-bar {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; margin-top: 0.5rem; padding-top: 1rem; border-top: 1px solid var(--border);
}
#weekRangeDisplay { font-size: 1.1rem; font-weight: 700; }
#status { color: var(--text-secondary); font-weight: 700; }
#status .btn.undo-btn { padding: 2px 8px; font-size: 12px; margin-left: 8px; }

/* Layout & Timetable */
.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; }

.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; }
.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;
}
.day-tab-btn.active { background: var(--primary-color); color: #0b1120; border-color: var(--primary-color); }
.note-day-date { color: var(--text-muted); font-size: 12px; }

.notes-panel { display: grid; gap: 8px; }
.note-item { background: var(--slot-empty-bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; }
.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); }

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

/* Modal */
.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-end; gap: 8px; margin-top: 16px; }
.modal-footer .btn.danger { margin-right: auto; }

/* 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; }

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

@media (max-width: 1100px) { .layout { grid-template-columns: 1fr; } }
@media (max-width: 768px) { .timetable-grid { grid-template-columns: 100px repeat(5, minmax(120px, 1fr)); } }