:root {
  --primary: #2563eb;
  --primary-light: #3b82f6;
  --primary-dark: #1d4ed8;
  --success: #10b981;
  --success-light: #d1fae5;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --gray-50: #f8fafc;
  --gray-100: #f1f5f9;
  --gray-200: #e2e8f0;
  --gray-300: #cbd5e1;
  --gray-400: #94a3b8;
  --gray-500: #64748b;
  --gray-600: #475569;
  --gray-700: #334155;
  --gray-800: #1e293b;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
  --transition: all 0.2s ease;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ========= LAYOUT ========= */
#setup-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #eff6ff 0%, #f0fdf4 100%);
}

.setup-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 40px;
  max-width: 520px;
  width: 100%;
}

.setup-card h1 {
  font-size: 24px;
  margin-bottom: 8px;
  color: var(--gray-800);
}

.setup-card .subtitle {
  color: var(--gray-500);
  margin-bottom: 32px;
  font-size: 14px;
}

#app-screen {
  display: none;
  min-height: 100vh;
}

.app-header {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.app-header .logo {
  font-size: 20px;
  font-weight: 700;
  color: var(--primary);
  white-space: nowrap;
}

.app-header .logo span { font-size: 24px; margin-right: 6px; }

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

.header-right .date-display {
  font-size: 13px;
  color: var(--gray-500);
}

.app-body {
  display: flex;
  min-height: calc(100vh - 57px);
}

.sidebar {
  width: 240px;
  background: white;
  border-right: 1px solid var(--gray-200);
  padding: 16px 12px;
  overflow-y: auto;
  flex-shrink: 0;
}

.sidebar h3 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-400);
  padding: 8px 12px 4px;
  margin-top: 8px;
}

.sidebar h3:first-child { margin-top: 0; }

.class-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--transition);
  font-size: 14px;
  color: var(--gray-600);
}

.class-item:hover {
  background: var(--gray-100);
  color: var(--gray-800);
}

.class-item.active {
  background: #eff6ff;
  color: var(--primary);
  font-weight: 600;
}

.class-item .badge {
  margin-left: auto;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 10px;
  font-weight: 500;
}

.badge-ok { background: var(--success-light); color: #065f46; }
.badge-behind { background: var(--danger-light); color: #991b1b; }
.badge-ahead { background: #dbeafe; color: #1e40af; }

.main-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  min-width: 0;
}

/* ========= NAV TABS ========= */
.nav-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 24px;
  background: white;
  border-radius: var(--radius);
  padding: 4px;
  box-shadow: var(--shadow);
}

.nav-tab {
  flex: 1;
  padding: 10px 16px;
  border: none;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  color: var(--gray-500);
  transition: var(--transition);
  white-space: nowrap;
}

.nav-tab:hover { color: var(--gray-700); background: var(--gray-100); }
.nav-tab.active { background: var(--primary); color: white; }

/* ========= CARDS ========= */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--gray-800);
}

/* ========= LESSON CARDS ========= */
.lesson-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  margin-bottom: 12px;
  border-left: 4px solid var(--gray-300);
  transition: var(--transition);
}

.lesson-card:hover { box-shadow: var(--shadow-md); }
.lesson-card.completed { border-left-color: var(--success); }
.lesson-card.today { border-left-color: var(--primary); }
.lesson-card.overdue { border-left-color: var(--danger); }
.lesson-card.shifted { border-left-color: var(--warning); opacity: 0.7; }

.lesson-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.lesson-class {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-800);
}

.lesson-meta {
  display: flex;
  gap: 12px;
  font-size: 12px;
  color: var(--gray-500);
  margin-top: 4px;
}

.lesson-topic {
  font-size: 14px;
  color: var(--gray-700);
  margin-top: 8px;
  line-height: 1.5;
}

.lesson-topic input {
  width: 100%;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  padding: 6px 10px;
  font-size: 14px;
  font-family: inherit;
}

.lesson-note {
  font-size: 13px;
  color: var(--gray-500);
  margin-top: 8px;
  padding: 8px 12px;
  background: var(--gray-50);
  border-radius: 8px;
  cursor: pointer;
}

.lesson-note:hover { background: var(--gray-100); }

.lesson-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.lesson-hw {
  margin-top: 8px;
  padding: 8px 12px;
  background: #fffbeb;
  border-radius: 8px;
  font-size: 13px;
  color: #92400e;
}

/* ========= BUTTONS ========= */
.btn {
  padding: 8px 16px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: inherit;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover { background: var(--primary-dark); }

.btn-success {
  background: var(--success);
  color: white;
}

.btn-success:hover { background: #059669; }

.btn-outline {
  background: transparent;
  border: 1px solid var(--gray-300);
  color: var(--gray-600);
}

.btn-outline:hover {
  background: var(--gray-100);
  border-color: var(--gray-400);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover { background: #dc2626; }

.btn-warning {
  background: var(--warning);
  color: white;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 16px;
}

.btn-block {
  width: 100%;
  justify-content: center;
}

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

.check-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 2px solid var(--gray-300);
  background: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: var(--transition);
  flex-shrink: 0;
}

.check-btn:hover { border-color: var(--success); }
.check-btn.checked {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

/* ========= FORMS ========= */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--gray-700);
  margin-bottom: 6px;
}

.form-group input,
.form-group textarea,
.form-group select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--gray-300);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  transition: var(--transition);
  background: white;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group .hint {
  font-size: 12px;
  color: var(--gray-400);
  margin-top: 4px;
}

.form-group .hint a {
  color: var(--primary);
  text-decoration: none;
}

textarea { resize: vertical; min-height: 80px; }

/* ========= MODALS ========= */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 20px;
  backdrop-filter: blur(4px);
}

.modal-overlay.open { display: flex; }

.modal {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

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

.modal-header h2 {
  font-size: 18px;
  font-weight: 600;
}

.modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--gray-100);
  cursor: pointer;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--gray-500);
}

.modal-close:hover { background: var(--gray-200); }

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

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

.toast {
  padding: 12px 20px;
  border-radius: 8px;
  color: white;
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s;
  max-width: 360px;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }
.toast-warning { background: var(--warning); }

@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } }
@keyframes fadeOut { to { opacity: 0; transform: translateY(-10px); } }

/* ========= COMPARISON VIEW ========= */
.comparison-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.compare-card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.compare-card .class-name {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 4px;
}

.compare-card .class-level {
  font-size: 12px;
  color: var(--gray-500);
  margin-bottom: 16px;
}

.progress-bar {
  height: 8px;
  background: var(--gray-200);
  border-radius: 4px;
  overflow: hidden;
  margin: 8px 0;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width 0.5s ease;
}

.compare-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.stat-item {
  text-align: center;
  padding: 8px;
  background: var(--gray-50);
  border-radius: 8px;
}

.stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--gray-800);
}

.stat-label {
  font-size: 11px;
  color: var(--gray-500);
}

/* ========= CALENDAR VIEW ========= */
.cal-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  background: white;
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
}

.cal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  padding: 8px 12px;
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.cal-legend-item {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--gray-600);
}

.cal-legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
}

.cal-month-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
}

.cal-day {
  min-height: 120px;
  background: white;
  border-radius: 8px;
  padding: 8px;
  box-shadow: var(--shadow);
  transition: var(--transition);
}

.cal-day:hover { box-shadow: var(--shadow-md); }
.cal-day.today { border: 2px solid var(--primary); }
.cal-day.other-month { opacity: 0.4; }
.cal-day.holiday { background: #fef2f2; }

.cal-day-header {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-500);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.cal-day-num {
  font-size: 14px;
  font-weight: 700;
  color: var(--gray-700);
}

.cal-day.today .cal-day-num {
  color: var(--primary);
  background: #eff6ff;
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.cal-holiday-tag {
  font-size: 10px;
  color: var(--danger);
  background: var(--danger-light);
  padding: 1px 5px;
  border-radius: 4px;
}

.cal-lesson {
  font-size: 11px;
  padding: 3px 6px;
  border-radius: 4px;
  margin-bottom: 3px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: var(--transition);
  border-left: 3px solid transparent;
}

.cal-lesson:hover { filter: brightness(0.95); }
.cal-lesson.done { background: var(--success-light); color: #065f46; border-left-color: var(--success); }
.cal-lesson.pending { background: #eff6ff; color: #1e40af; border-left-color: var(--primary); }
.cal-lesson.overdue { background: var(--danger-light); color: #991b1b; border-left-color: var(--danger); }

.cal-lesson-class {
  font-size: 9px;
  font-weight: 600;
  opacity: 0.7;
  display: block;
}

/* ========= WEEK NAV ========= */
.week-nav {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  background: white;
  border-radius: var(--radius);
  padding: 10px 16px;
  box-shadow: var(--shadow);
}

/* ========= STATS BAR ========= */
.stats-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.stat-card {
  flex: 1;
  min-width: 140px;
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}

.stat-card .stat-icon { font-size: 24px; margin-bottom: 4px; }
.stat-card .stat-number {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-800);
}

.stat-card .stat-desc {
  font-size: 12px;
  color: var(--gray-500);
}

/* ========= EMPTY STATE ========= */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-400);
}

.empty-state .icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; color: var(--gray-600); margin-bottom: 8px; }
.empty-state p { font-size: 14px; }

/* ========= VISIBILITY ========= */
.hidden { display: none !important; }

/* ========= LOADING ========= */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--gray-400);
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--gray-200);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 12px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ========= SETTINGS ========= */
.settings-section {
  margin-bottom: 24px;
}

.settings-section h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--gray-200);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
}

.status-dot.green { background: var(--success); }
.status-dot.red { background: var(--danger); }
.status-dot.yellow { background: var(--warning); }

/* ========= RESPONSIVE ========= */
@media (max-width: 768px) {
  .app-body { flex-direction: column; }

  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--gray-200);
    padding: 8px;
    display: flex;
    gap: 4px;
    overflow-x: auto;
    flex-shrink: 0;
  }

  .sidebar h3 { display: none; }

  .class-item {
    flex-shrink: 0;
    padding: 8px 12px;
    font-size: 13px;
  }

  .class-item .badge { display: none; }

  .main-content { padding: 16px; }

  .nav-tabs { overflow-x: auto; }
  .nav-tab { font-size: 13px; padding: 8px 12px; }

  .stats-bar { gap: 8px; }
  .stat-card { min-width: 100px; padding: 12px; }
  .stat-card .stat-number { font-size: 22px; }

  .comparison-grid { grid-template-columns: 1fr; }
  .calendar-grid { grid-template-columns: 1fr; }

  .modal { max-width: 100%; margin: 10px; }

  .lesson-header { flex-direction: column; }

  .setup-card { padding: 24px; }
}

@media (max-width: 480px) {
  .app-header .logo { font-size: 16px; }
  .app-header .date-display { display: none; }

  .lesson-actions { flex-wrap: wrap; }
  .lesson-actions .btn { flex: 1; justify-content: center; }
}