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

:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--gray-50);
  color: var(--gray-900);
  line-height: 1.5;
}

/* Navbar */
.navbar {
  background: white;
  border-bottom: 1px solid var(--gray-200);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.nav-brand a {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--gray-900);
  text-decoration: none;
}

.nav-school {
  color: var(--gray-500);
  font-size: 0.85rem;
  margin-left: 0.75rem;
}

.nav-links {
  display: flex;
  gap: 0.25rem;
}

.nav-links a {
  padding: 0.5rem 1rem;
  text-decoration: none;
  color: var(--gray-700);
  border-radius: var(--radius);
  font-size: 0.9rem;
  transition: background 0.15s;
}

.nav-links a:hover { background: var(--gray-100); }
.nav-links a.active { background: var(--primary); color: white; }
.nav-logout { color: var(--danger) !important; }

/* Container */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Cards */
.card {
  background: white;
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
}

.card h3 { margin-bottom: 0.75rem; font-size: 1rem; }

/* Forms */
.form-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
}

input[type="text"], input[type="number"], input[type="password"],
select, textarea {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

input:focus, select:focus { border-color: var(--primary); }

input[type="color"] {
  width: 40px;
  height: 38px;
  padding: 2px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  cursor: pointer;
}

.subject-checks {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.85rem;
  cursor: pointer;
}

/* Buttons */
.btn {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
  background: var(--primary);
  color: white;
  transition: background 0.15s;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

.btn:hover { background: var(--primary-dark); }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.8rem; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-outline { background: white; color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-outline:hover { background: var(--gray-100); }
.btn-outline.active { background: var(--danger); color: white; border-color: var(--danger); }

/* Tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
}

.data-table th {
  background: var(--gray-50);
  text-align: left;
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  color: var(--gray-500);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  border-bottom: 1px solid var(--gray-200);
}

.data-table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--gray-100);
  font-size: 0.9rem;
}

.data-table tr:last-child td { border-bottom: none; }

/* Color dot */
.color-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 0.5rem;
  vertical-align: middle;
}

/* Timetable */
.timetable-header {
  margin-bottom: 1rem;
}

.view-tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 0.75rem;
}

.tab {
  padding: 0.5rem 1.25rem;
  text-decoration: none;
  color: var(--gray-700);
  border-radius: var(--radius);
  font-size: 0.9rem;
  background: white;
  border: 1px solid var(--gray-200);
}

.tab.active { background: var(--primary); color: white; border-color: var(--primary); }

.class-selector {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.class-btn {
  padding: 0.4rem 0.75rem;
  text-decoration: none;
  color: var(--gray-700);
  border-radius: var(--radius);
  font-size: 0.85rem;
  background: white;
  border: 1px solid var(--gray-200);
  font-weight: 600;
}

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

.timetable-wrapper {
  display: flex;
  gap: 1.5rem;
}

.timetable-main { flex: 1; min-width: 0; }

.timetable {
  width: 100%;
  border-collapse: collapse;
  background: white;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  table-layout: fixed;
}

.timetable th {
  background: var(--gray-50);
  padding: 0.6rem 0.5rem;
  font-size: 0.85rem;
  color: var(--gray-500);
  font-weight: 600;
  text-align: center;
  border-bottom: 1px solid var(--gray-200);
}

.timetable .period-col { width: 45px; }
.timetable .time-col { width: 100px; font-size: 0.75rem; }

.timetable td {
  padding: 0;
  border: 1px solid var(--gray-200);
  text-align: center;
  font-size: 0.8rem;
  vertical-align: middle;
}

.timetable .period-col,
.timetable .time-col {
  padding: 0.5rem;
  color: var(--gray-500);
  font-size: 0.8rem;
  background: var(--gray-50);
}

.slot {
  height: 60px;
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}

.slot:hover { background: var(--gray-100); }
.slot.selected { outline: 2px solid var(--primary); outline-offset: -2px; }
.slot.delete-mode:hover { background: #fee2e2; }

.slot-content {
  padding: 4px;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
}

.slot-content .subject-tag {
  font-weight: 700;
  font-size: 0.85rem;
  color: white;
  padding: 2px 8px;
  border-radius: 4px;
  line-height: 1.2;
}

.slot-content .teacher-tag {
  font-size: 0.7rem;
  color: var(--gray-500);
}

.slot-content .class-tag {
  font-size: 0.7rem;
  color: var(--gray-700);
  font-weight: 600;
}

.break-row td {
  background: var(--gray-50);
  padding: 0.25rem;
  font-size: 0.75rem;
  color: var(--gray-500);
  font-style: italic;
  border: none;
  text-align: center;
}

/* Sidebar */
.sidebar {
  width: 260px;
  flex-shrink: 0;
}

.sidebar h3 {
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
}

.sidebar-form {
  background: white;
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
}

.sidebar-form label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-500);
  margin: 0.5rem 0 0.25rem;
}

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

.sidebar-form select {
  width: 100%;
}

.sidebar-form .hint {
  font-size: 0.75rem;
  color: var(--gray-500);
  margin: 0.75rem 0;
}

.sidebar-form .btn { width: 100%; margin-top: 0.5rem; }

.conflict-info {
  margin-top: 1rem;
  padding: 0.75rem;
  border-radius: var(--radius);
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--danger);
  font-size: 0.85rem;
}

/* Stats panel */
.stats-panel {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.stat-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.6rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  border: 1px solid var(--gray-200);
  background: white;
}

.stat-badge .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.stat-badge.ok { border-color: var(--success); color: var(--success); }
.stat-badge.under { border-color: var(--warning); color: var(--warning); }
.stat-badge.over { border-color: var(--danger); color: var(--danger); }

/* Class grid */
.class-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
}

.class-grade-group h3 {
  margin-bottom: 0.75rem;
  color: var(--gray-700);
}

.class-card {
  background: white;
  border-radius: var(--radius);
  padding: 1rem;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-200);
  margin-bottom: 0.75rem;
}

.class-card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.class-card-stats {
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  color: var(--gray-500);
}

.progress-bar {
  height: 6px;
  background: var(--gray-200);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.25rem;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s;
}

/* Alerts */
.alert { padding: 0.75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.9rem; }
.alert-error { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }

/* Info box */
.info-box {
  margin-top: 1.5rem;
  padding: 1rem;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius);
  color: #1e40af;
  font-size: 0.85rem;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal-content {
  background: white;
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 400px;
  max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.modal-content h3 { margin-bottom: 1rem; }
.modal-content input, .modal-content select { width: 100%; margin-bottom: 0.5rem; }
.modal-actions { display: flex; gap: 0.5rem; margin-top: 1rem; }

/* Login */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
}

.login-card {
  background: white;
  border-radius: 12px;
  padding: 2.5rem;
  width: 360px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}

.login-card h1 {
  font-size: 1.5rem;
  margin-bottom: 0.25rem;
}

.login-subtitle {
  color: var(--gray-500);
  margin-bottom: 1.5rem;
}

.login-card input {
  width: 100%;
  padding: 0.75rem 1rem;
  margin-bottom: 1rem;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 1rem;
  text-align: center;
}

.login-card button {
  width: 100%;
  padding: 0.75rem;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  cursor: pointer;
}

.login-card button:hover { background: var(--primary-dark); }

/* Utility */
.text-muted { color: var(--gray-500); }
.text-danger { color: var(--danger); font-weight: 600; }
h2 { margin-bottom: 1rem; }

/* Modal form grid */
.modal-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.form-group {
  display: flex;
  flex-direction: column;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--gray-500);
  margin-bottom: 0.3rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

/* Subject chips */
.subject-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.subject-chip {
  position: relative;
  cursor: pointer;
}

.subject-chip input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.subject-chip .chip-label {
  display: inline-block;
  padding: 0.4rem 0.85rem;
  border-radius: 20px;
  font-size: 0.82rem;
  font-weight: 600;
  background: var(--gray-100);
  color: var(--gray-500);
  border: 2px solid var(--gray-200);
  transition: all 0.15s;
  user-select: none;
}

.subject-chip input:checked + .chip-label {
  background: var(--chip-color, var(--primary));
  color: white;
  border-color: var(--chip-color, var(--primary));
}

.subject-chip:hover .chip-label {
  border-color: var(--chip-color, var(--primary));
}

/* Availability grid */
.avail-grid {
  width: 100%;
  border-collapse: collapse;
}

.avail-grid th, .avail-grid td {
  border: 1px solid var(--gray-200);
  padding: 0.5rem;
  text-align: center;
  font-size: 0.85rem;
}

.avail-grid th {
  background: var(--gray-50);
  font-weight: 600;
  color: var(--gray-500);
}

.avail-cell {
  width: 60px;
  height: 40px;
  cursor: pointer;
  transition: background 0.15s;
}

.avail-cell.available {
  background: #dcfce7;
}

.avail-cell.unavailable {
  background: #fee2e2;
}

.avail-cell:hover {
  opacity: 0.7;
}

/* Auto-generate result */
.generate-result {
  margin-top: 1rem;
  padding: 0.75rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
}

.generate-result.success {
  background: #dcfce7;
  border: 1px solid #86efac;
  color: #166534;
}

.generate-result.has-errors {
  background: #fef9c3;
  border: 1px solid #fde047;
  color: #854d0e;
}

/* Responsive */
@media (max-width: 900px) {
  .timetable-wrapper { flex-direction: column; }
  .sidebar { width: 100%; }
  .nav-school { display: none; }
}
