/* ============================================
   Design System — Dark Theme (default)
   ============================================ */
:root,
[data-theme="dark"] {
  --bg-primary: #0F0F1A;
  --bg-secondary: #1A1A2E;
  --bg-tertiary: #16213E;
  --bg-card: rgba(26, 26, 46, 0.75);
  --bg-glass: rgba(255, 255, 255, 0.04);
  --bg-glass-hover: rgba(255, 255, 255, 0.08);
  --bg-input: rgba(255, 255, 255, 0.05);

  --text-primary: #E8E8F0;
  --text-secondary: #A0A0BC;
  --text-muted: #6C6C8A;
  --text-accent: #818CF8;

  --border-color: rgba(255, 255, 255, 0.07);
  --border-focus: rgba(129, 140, 248, 0.5);

  --accent-primary: #818CF8;
  --accent-secondary: #6C5CE7;
  --accent-gradient: linear-gradient(135deg, #818CF8, #6C5CE7);

  --danger: #FF6B6B;
  --danger-bg: rgba(255, 107, 107, 0.12);
  --success: #00B894;
  --warning: #FDCB6E;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.45);
  --shadow-glow: 0 0 30px rgba(129, 140, 248, 0.12);

  --header-bg: rgba(15, 15, 26, 0.88);
  --glow-1: rgba(129, 140, 248, 0.08);
  --glow-2: rgba(108, 92, 231, 0.06);
  --lunch-bg: rgba(253, 203, 110, 0.06);
  --current-bg: rgba(129, 140, 248, 0.1);
}

/* ============================================
   Light Theme
   ============================================ */
[data-theme="light"] {
  --bg-primary: #F0F2F8;
  --bg-secondary: #FFFFFF;
  --bg-tertiary: #E8ECF4;
  --bg-card: rgba(255, 255, 255, 0.92);
  --bg-glass: rgba(0, 0, 0, 0.03);
  --bg-glass-hover: rgba(0, 0, 0, 0.06);
  --bg-input: rgba(0, 0, 0, 0.04);

  --text-primary: #1A1A2E;
  --text-secondary: #5A5A7A;
  --text-muted: #9090A8;
  --text-accent: #5B4BD4;

  --border-color: rgba(0, 0, 0, 0.08);
  --border-focus: rgba(91, 75, 212, 0.4);

  --accent-primary: #6C5CE7;
  --accent-secondary: #5B4BD4;
  --accent-gradient: linear-gradient(135deg, #6C5CE7, #5B4BD4);

  --danger: #E74C3C;
  --danger-bg: rgba(231, 76, 60, 0.08);
  --success: #00A884;
  --warning: #F39C12;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.1);
  --shadow-glow: 0 0 30px rgba(108, 92, 231, 0.08);

  --header-bg: rgba(255, 255, 255, 0.92);
  --glow-1: rgba(108, 92, 231, 0.05);
  --glow-2: rgba(91, 75, 212, 0.04);
  --lunch-bg: rgba(253, 203, 110, 0.12);
  --current-bg: rgba(108, 92, 231, 0.08);
}

/* Shared tokens */
:root {
  --header-height: 60px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============================================
   Reset & Base
   ============================================ */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'Noto Sans TC', 'Inter', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  transition: background var(--transition-normal), color var(--transition-normal);
}

body::before {
  content: '';
  position: fixed;
  top: -200px; left: -200px;
  width: 600px; height: 600px;
  background: radial-gradient(circle, var(--glow-1) 0%, transparent 70%);
  pointer-events: none; z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  bottom: -200px; right: -200px;
  width: 500px; height: 500px;
  background: radial-gradient(circle, var(--glow-2) 0%, transparent 70%);
  pointer-events: none; z-index: 0;
}

/* ============================================
   Header
   ============================================ */
.app-header {
  position: sticky; top: 0; z-index: 100;
  background: var(--header-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border-color);
  height: var(--header-height);
  display: flex; align-items: center;
  transition: background var(--transition-normal);
}

.header-content {
  width: 100%; max-width: 1200px;
  margin: 0 auto; padding: 0 20px;
  display: flex; align-items: center; justify-content: space-between;
}

.logo { display: flex; align-items: center; gap: 10px; }

.logo-icon { font-size: 1.5rem; }

.logo-text h1 {
  font-size: 1.15rem; font-weight: 700;
  background: var(--accent-gradient);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  background-clip: text; line-height: 1.2;
}

.logo-sub {
  font-size: 0.72rem; color: var(--text-muted); font-weight: 400;
}

.header-actions { display: flex; gap: 8px; align-items: center; }

/* ============================================
   Buttons
   ============================================ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border: none; border-radius: var(--radius-sm);
  font-family: inherit; font-size: 0.82rem; font-weight: 500;
  cursor: pointer; transition: all var(--transition-fast); outline: none;
  white-space: nowrap;
}

.btn-sm { padding: 6px 12px; font-size: 0.78rem; }

.btn-icon-only {
  padding: 8px 10px; background: var(--bg-glass);
  border: 1px solid var(--border-color); font-size: 1.1rem;
}

.btn-icon-only:hover { background: var(--bg-glass-hover); transform: scale(1.05); }

.btn-ghost {
  background: var(--bg-glass); color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

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

.btn-primary {
  background: var(--accent-gradient); color: white;
  box-shadow: 0 2px 10px rgba(108, 92, 231, 0.3);
}

.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(108, 92, 231, 0.4); }

.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-accent {
  background: var(--accent-gradient); color: white;
  box-shadow: 0 2px 8px rgba(108, 92, 231, 0.25);
}

.btn-accent:hover:not(:disabled) { transform: translateY(-1px); }

.btn-accent:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
  background: var(--bg-glass); color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

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

.btn-danger {
  background: var(--danger-bg); color: var(--danger);
  border: 1px solid rgba(255, 107, 107, 0.15);
}

.btn-danger:hover { background: rgba(255, 107, 107, 0.18); }

/* ============================================
   Info Bar
   ============================================ */
.info-bar {
  position: relative; z-index: 1;
  max-width: 1200px; margin: 0 auto;
  padding: 12px 20px;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}

.profile-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 14px; border-radius: 20px;
  background: var(--bg-glass); border: 1px solid var(--border-color);
  font-size: 0.82rem; color: var(--text-secondary);
}

.profile-icon { font-size: 1rem; }

.stats-group {
  display: flex; align-items: center; gap: 12px;
  margin-left: auto;
}

.stat-item { text-align: center; }

.stat-value {
  display: block; font-size: 1.2rem; font-weight: 700;
  color: var(--text-accent); line-height: 1.2;
}

.stat-label { font-size: 0.68rem; color: var(--text-muted); }

.stat-divider { width: 1px; height: 28px; background: var(--border-color); }

#btn-import { margin-left: 0; }

/* ============================================
   Day Tabs (Mobile)
   ============================================ */
.day-tabs {
  display: none;
  position: sticky; top: var(--header-height); z-index: 90;
  background: var(--header-bg);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border-color);
  padding: 8px 12px; gap: 6px;
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}

.day-tab {
  flex-shrink: 0;
  padding: 6px 14px; border: 1px solid var(--border-color);
  border-radius: 20px; background: var(--bg-glass);
  color: var(--text-secondary); font-family: inherit;
  font-size: 0.82rem; font-weight: 500; cursor: pointer;
  transition: all var(--transition-fast);
}

.day-tab.active {
  background: var(--accent-gradient); color: white;
  border-color: transparent; box-shadow: 0 2px 8px rgba(108, 92, 231, 0.3);
}

.day-tab:hover:not(.active) { background: var(--bg-glass-hover); color: var(--text-primary); }

/* ============================================
   Main & Grid
   ============================================ */
.main-content {
  position: relative; z-index: 1;
  padding: 0 20px 40px;
  max-width: 1200px; margin: 0 auto;
}

.schedule-container {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  background: var(--bg-card);
  box-shadow: var(--shadow-lg);
  backdrop-filter: blur(10px);
  transition: background var(--transition-normal);
}

.schedule-grid {
  display: grid;
  grid-template-columns: 120px repeat(5, 1fr);
  min-width: 720px;
}

.grid-cell {
  border-right: 1px solid var(--border-color);
  border-bottom: 1px solid var(--border-color);
  min-height: 50px;
  display: flex; align-items: center; justify-content: center;
}

.grid-header {
  background: var(--bg-glass);
  font-weight: 600; font-size: 0.85rem;
  color: var(--text-accent);
  padding: 12px 6px;
  position: sticky; top: 0; z-index: 2;
}

.grid-corner { font-size: 0.72rem; color: var(--text-muted); font-weight: 500; }

.day-header.day-hidden,
.course-cell.day-hidden { display: none; }

.time-cell {
  flex-direction: column; gap: 2px;
  padding: 4px 8px;
  background: var(--bg-glass);
}

.time-cell .period-label { font-weight: 700; font-size: 0.85rem; }

.time-cell .time-range { font-size: 0.65rem; color: var(--text-muted); }

.time-cell.lunch-break { background: var(--lunch-bg); }

.time-cell.lunch-break .period-label { color: var(--warning); }

.course-cell {
  cursor: pointer; transition: all var(--transition-fast);
  position: relative; overflow: hidden; padding: 4px 6px;
}

.course-cell:hover { background: var(--bg-glass-hover); z-index: 1; }

.course-cell.has-course { padding: 6px 8px; align-items: flex-start; }

.course-cell.has-course::before {
  content: ''; position: absolute;
  left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--course-color, var(--accent-primary));
  border-radius: 0 2px 2px 0;
}

.course-info {
  display: flex; flex-direction: column; gap: 1px;
  width: 100%; padding-left: 5px;
}

.course-name {
  font-weight: 600; font-size: 0.78rem; line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap;
}

.course-cell.is-merged .course-name { white-space: normal; font-size: 0.85rem; }

.course-teacher { font-size: 0.68rem; color: var(--text-secondary); }

.course-room { font-size: 0.65rem; color: var(--text-muted); }

.course-time-range { font-size: 0.62rem; color: var(--text-muted); margin-top: 2px; }

.course-span-badge {
  display: inline-block; margin-top: 3px; padding: 1px 6px;
  font-size: 0.6rem; font-weight: 600; border-radius: 8px;
  background: var(--bg-glass); color: var(--text-muted); width: fit-content;
}

.empty-hint {
  font-size: 1.1rem; opacity: 0; transition: opacity var(--transition-fast);
  color: var(--text-muted);
}

.course-cell:hover .empty-hint { opacity: 0.4; }

.time-cell.current-period { background: var(--current-bg); }

.time-cell.current-period .period-label { color: var(--accent-primary); }

.course-cell.current-period { background: var(--current-bg); }

/* ============================================
   Mobile Schedule Cards
   ============================================ */
.mobile-schedule {
  display: none;
  flex-direction: column; gap: 10px;
  margin-top: 12px;
}

.mobile-card {
  display: flex; gap: 14px;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  border-left: 4px solid var(--course-color, var(--accent-primary));
  cursor: pointer;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
  box-shadow: var(--shadow-sm);
}

.mobile-card:active { transform: scale(0.98); }

.mobile-card-time {
  display: flex; flex-direction: column; align-items: center;
  min-width: 52px; gap: 2px;
}

.mobile-period { font-size: 1.1rem; font-weight: 700; color: var(--text-accent); }

.mobile-time { font-size: 0.62rem; color: var(--text-muted); text-align: center; }

.mobile-span {
  font-size: 0.6rem; padding: 1px 6px; border-radius: 6px;
  background: var(--bg-glass); color: var(--text-muted);
}

.mobile-day { font-size: 0.72rem; color: var(--text-accent); font-weight: 600; }

.mobile-name { font-size: 0.95rem; font-weight: 600; margin: 2px 0; }

.mobile-teacher { font-size: 0.78rem; color: var(--text-secondary); }

.mobile-room { font-size: 0.72rem; color: var(--text-muted); margin-top: 2px; }

.mobile-empty {
  text-align: center; padding: 40px 20px;
  color: var(--text-muted); font-size: 0.9rem;
}

/* ============================================
   Modals
   ============================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden;
  transition: all var(--transition-normal);
  padding: 16px;
}

.modal-overlay.active { opacity: 1; visibility: visible; }

.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  width: 100%; max-width: 440px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
  transform: translateY(16px) scale(0.97);
  transition: transform var(--transition-normal), background var(--transition-normal);
}

.modal-lg { max-width: 520px; }

.modal-overlay.active .modal { transform: translateY(0) scale(1); }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 8px;
}

.modal-header h2 { font-size: 1.05rem; font-weight: 600; }

.modal-desc {
  font-size: 0.82rem; color: var(--text-secondary);
  margin-bottom: 4px; line-height: 1.5;
}

.modal-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 1.4rem; cursor: pointer; padding: 4px 8px;
  border-radius: var(--radius-sm); line-height: 1;
  transition: all var(--transition-fast);
}

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

.modal-body {
  padding: 12px 24px 16px;
  display: flex; flex-direction: column; gap: 14px;
}

.modal-footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 8px 24px 20px;
}

/* Forms */
.form-group label {
  display: block; font-size: 0.78rem; font-weight: 500;
  color: var(--text-secondary); margin-bottom: 6px;
}

.form-group input,
.form-select {
  width: 100%; padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary); font-family: inherit; font-size: 0.88rem;
  outline: none; transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  appearance: none;
}

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%239090A8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  cursor: pointer;
}

.form-group input:focus,
.form-select:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.1);
}

.form-group input::placeholder { color: var(--text-muted); }

.form-hint {
  display: block; margin-top: 4px;
  font-size: 0.7rem; color: var(--text-muted); min-height: 1em;
}

/* Grade Selector */
.grade-selector { display: flex; gap: 6px; flex-wrap: wrap; }

.grade-btn {
  flex: 1; min-width: 60px;
  padding: 10px 8px; border: 1px solid var(--border-color);
  border-radius: var(--radius-sm); background: var(--bg-glass);
  color: var(--text-secondary); font-family: inherit;
  font-size: 0.82rem; font-weight: 500; cursor: pointer;
  transition: all var(--transition-fast);
}

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

.grade-btn.active {
  background: var(--accent-gradient); color: white;
  border-color: transparent; box-shadow: 0 2px 8px rgba(108, 92, 231, 0.3);
}

/* Import Preview */
.import-preview {
  background: var(--bg-glass); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: 12px 14px;
  max-height: 220px; overflow-y: auto;
}

.preview-placeholder,
.preview-empty { font-size: 0.82rem; color: var(--text-muted); }

.preview-header {
  font-size: 0.82rem; font-weight: 600;
  color: var(--text-accent); margin-bottom: 8px;
}

.preview-list {
  list-style: none; display: flex; flex-direction: column; gap: 6px;
}

.preview-list li {
  padding: 6px 8px; border-radius: var(--radius-sm);
  background: var(--bg-glass); font-size: 0.78rem;
}

.preview-name { display: block; font-weight: 500; color: var(--text-primary); }

.preview-meta { display: block; color: var(--text-muted); font-size: 0.72rem; margin-top: 1px; }

/* Color & Span */
.color-picker { display: flex; flex-wrap: wrap; gap: 8px; }

.color-swatch {
  width: 30px; height: 30px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
  transition: all var(--transition-fast);
}

.color-swatch:hover { transform: scale(1.12); }

.color-swatch.active {
  border-color: var(--text-primary);
  box-shadow: 0 0 0 2px var(--bg-secondary);
  transform: scale(1.08);
}

.span-selector { display: flex; gap: 6px; }

.span-btn {
  flex: 1; padding: 8px 4px;
  border: 1px solid var(--border-color); border-radius: var(--radius-sm);
  background: var(--bg-glass); color: var(--text-secondary);
  font-family: inherit; font-size: 0.8rem; font-weight: 500;
  cursor: pointer; transition: all var(--transition-fast);
}

.span-btn.active {
  background: var(--accent-gradient); color: white;
  border-color: transparent;
}

.span-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ============================================
   Toast
   ============================================ */
.toast-container {
  position: fixed; bottom: 20px; right: 20px; z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
}

.toast {
  background: var(--bg-secondary); border: 1px solid var(--border-color);
  border-radius: var(--radius-md); padding: 12px 18px;
  font-size: 0.84rem; box-shadow: var(--shadow-md);
  animation: toast-in 0.3s ease forwards;
}

.toast.toast-out { animation: toast-out 0.3s ease forwards; }

.toast.success { border-left: 3px solid var(--success); }

.toast.info { border-left: 3px solid var(--accent-primary); }

.toast.warning { border-left: 3px solid var(--warning); }

@keyframes toast-in {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
  from { opacity: 1; transform: translateX(0); }
  to { opacity: 0; transform: translateX(30px); }
}

/* ============================================
   Scrollbar
   ============================================ */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 3px; }

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
  .header-content { padding: 0 14px; }
  .logo-text h1 { font-size: 1rem; }
  .logo-sub { display: none; }
  .btn-label { display: none; }
  .btn-ghost .btn-label { display: none; }

  .info-bar {
    padding: 10px 14px; gap: 10px;
  }

  .profile-chip { font-size: 0.78rem; padding: 5px 10px; }

  .stats-group { margin-left: auto; }

  .stat-value { font-size: 1rem; }

  #btn-import {
    width: 100%; justify-content: center;
    order: 10;
  }

  .day-tabs { display: flex; }

  .main-content { padding: 0 10px 32px; }

  .schedule-container { display: none; }

  .mobile-schedule { display: flex; }

  .toast-container { left: 14px; right: 14px; bottom: 14px; }

  .toast { text-align: center; }

  .modal { max-height: 85vh; }

  .grade-btn { min-width: 52px; padding: 8px 4px; font-size: 0.78rem; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .schedule-grid {
    grid-template-columns: 100px repeat(5, 1fr);
    min-width: 680px;
  }

  .course-name { font-size: 0.72rem; }
}

@media (min-width: 769px) {
  .day-tabs { display: none !important; }
  .mobile-schedule { display: none !important; }
  .schedule-container { display: block !important; }
}
