/* ─── Reset & Base ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: #f0f2f5;
  color: #1a1a2e;
  min-height: 100vh;
  padding-bottom: 80px;
}

/* ─── Header ───────────────────────────────────────────────────────── */
.app-header {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
  color: white;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,.4);
}
.header-inner {
  max-width: 1400px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; flex-wrap: wrap; padding: 12px 0;
}
.logo { display: flex; align-items: center; gap: 12px; }
.logo-icon { font-size: 2rem; }
.logo h1 { font-size: 1.25rem; font-weight: 700; line-height: 1.2; }
.logo p  { font-size: 0.75rem; opacity: .7; margin-top: 2px; }

/* ─── Tab Nav ──────────────────────────────────────────────────────── */
.tab-nav { display: flex; gap: 4px; }
.tab-btn {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.12);
  color: rgba(255,255,255,.75);
  border-radius: 8px; padding: 8px 16px;
  cursor: pointer; font-size: 0.85rem; font-weight: 500;
  transition: all .18s;
}
.tab-btn:hover:not(:disabled) { background: rgba(255,255,255,.18); color: white; }
.tab-btn.active { background: #e94560; border-color: #e94560; color: white; }
.tab-btn:disabled { opacity: .35; cursor: not-allowed; }

/* ─── Main ─────────────────────────────────────────────────────────── */
.app-main { max-width: 1400px; margin: 0 auto; padding: 24px; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.panel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 20px;
}

/* ─── Cards ────────────────────────────────────────────────────────── */
.card {
  background: white; border-radius: 12px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.04);
  padding: 20px; overflow: hidden;
}
.card.full-width { grid-column: 1 / -1; }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; gap: 8px; flex-wrap: wrap;
}
.card-header h2 { font-size: 1rem; font-weight: 600; }
.card-subtitle { color: #64748b; font-size: 0.8rem; margin-top: -8px; margin-bottom: 8px; }
.header-actions { display: flex; gap: 8px; }

/* ─── Forms ────────────────────────────────────────────────────────── */
.form-row { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.form-group { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 120px; }
.form-group label { font-size: 0.8rem; font-weight: 600; color: #475569; }
.hint { font-weight: 400; color: #94a3b8; }
input[type="number"], input[type="text"], select, .form-select {
  border: 1.5px solid #e2e8f0; border-radius: 8px;
  padding: 8px 12px; font-size: 0.9rem; outline: none;
  transition: border-color .18s, box-shadow .18s;
  background: white; color: #1a1a2e; width: 100%;
}
input:focus, select:focus, .form-select:focus {
  border-color: #e94560; box-shadow: 0 0 0 3px rgba(233,69,96,.12);
}

/* ─── Buttons ──────────────────────────────────────────────────────── */
.btn {
  border: none; border-radius: 8px; cursor: pointer;
  font-weight: 600; font-size: 0.85rem; padding: 9px 18px;
  transition: all .18s; display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary { background: #e94560; color: white; }
.btn-primary:hover { background: #c73652; transform: translateY(-1px); box-shadow: 0 4px 12px rgba(233,69,96,.3); }
.btn-secondary { background: #f1f5f9; color: #475569; border: 1.5px solid #e2e8f0; }
.btn-secondary:hover { background: #e2e8f0; }
.btn-ghost { background: transparent; color: #475569; border: 1.5px solid #e2e8f0; }
.btn-ghost:hover { background: #f8fafc; }
.btn-danger { background: #fff0f0; color: #dc2626; border: 1.5px solid #fecaca; }
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; border-radius: 6px; }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; box-shadow: none; }

/* ─── Chips ────────────────────────────────────────────────────────── */
.chip-list { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: #f1f5f9; border: 1.5px solid #e2e8f0;
  border-radius: 20px; padding: 4px 12px; font-size: 0.82rem; font-weight: 500;
}
.chip-remove {
  background: none; border: none; cursor: pointer; color: #94a3b8;
  font-size: 1rem; line-height: 1; padding: 0 1px;
  transition: color .15s;
}
.chip-remove:hover { color: #dc2626; }

/* ─── Matrix Table ─────────────────────────────────────────────────── */
.table-scroll { overflow-x: auto; }
.matrix-table { border-collapse: collapse; min-width: 100%; font-size: 0.8rem; }
.matrix-table th, .matrix-table td {
  border: 1px solid #e2e8f0; padding: 6px 10px; white-space: nowrap;
}
.matrix-table th { background: #f8fafc; font-weight: 600; position: sticky; top: 0; }
.matrix-table th:first-child { position: sticky; left: 0; z-index: 2; background: #f1f5f9; }
.matrix-table td:first-child { position: sticky; left: 0; background: white; font-weight: 500; z-index: 1; }
.matrix-table input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: #e94560; }

/* ─── Teacher Assignments ──────────────────────────────────────────── */
.teacher-card {
  border: 1.5px solid #e2e8f0; border-radius: 10px;
  margin-bottom: 12px; overflow: hidden;
}
.teacher-card-header {
  background: #f8fafc; padding: 10px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  cursor: pointer;
}
.teacher-card-header h3 { font-size: 0.9rem; font-weight: 600; }
.teacher-card-body { padding: 12px 16px; }
.assignment-row {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 8px; flex-wrap: wrap;
}
.assignment-row select { flex: 1; min-width: 120px; padding: 6px 10px; font-size: 0.82rem; }
.tag-badge {
  background: #eff6ff; color: #3b82f6; border: 1px solid #bfdbfe;
  border-radius: 4px; padding: 2px 8px; font-size: 0.75rem; font-weight: 600;
}

/* ─── Fixed First Period ───────────────────────────────────────────── */
.ffp-row {
  display: flex; align-items: center; gap: 10px; margin-bottom: 8px;
}
.ffp-row label { font-weight: 600; font-size: 0.85rem; min-width: 70px; }
.ffp-row select { flex: 1; padding: 7px 10px; font-size: 0.85rem; }

/* ─── Consecutive & Hours Rules ────────────────────────────────────── */
.rule-row {
  display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap;
}
.rule-row select, .rule-row input { flex: 1; min-width: 100px; padding: 7px 10px; font-size: 0.85rem; }
.rule-label { font-size: 0.8rem; color: #64748b; white-space: nowrap; }

/* ─── Solve Bar ────────────────────────────────────────────────────── */
.solve-bar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 200;
  background: white; border-top: 1.5px solid #e2e8f0;
  box-shadow: 0 -4px 16px rgba(0,0,0,.08);
}
.solve-bar-inner {
  max-width: 1400px; margin: 0 auto; padding: 12px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.solve-actions { display: flex; gap: 10px; }
#solve-status { font-size: 0.88rem; font-weight: 500; }
.status-idle    { color: #64748b; }
.status-running { color: #f59e0b; }
.status-done    { color: #10b981; }
.status-error   { color: #ef4444; }

/* ─── Results ──────────────────────────────────────────────────────── */
.results-header {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 20px;
}
.results-header h2 { font-size: 1.2rem; font-weight: 700; }
.view-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.timetable-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 20px; margin-bottom: 24px;
}
.timetable-card { background: white; border-radius: 12px; overflow: hidden; box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.timetable-card-header {
  padding: 12px 16px; font-weight: 700; font-size: 0.95rem;
  background: #1a1a2e; color: white;
  display: flex; justify-content: space-between; align-items: center;
}
.timetable-table { width: 100%; border-collapse: collapse; font-size: 0.75rem; }
.timetable-table th { background: #f8fafc; padding: 6px 8px; font-weight: 600; color: #475569; border-bottom: 1.5px solid #e2e8f0; }
.timetable-table td { padding: 5px 8px; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
.timetable-table tr:last-child td { border-bottom: none; }
.timetable-table .period-label { font-weight: 600; color: #64748b; white-space: nowrap; }

.cell-recess  { background: #fef3c7; color: #92400e; font-weight: 700; text-align: center; border-radius: 4px; padding: 3px 6px; }
.cell-free    { background: #f1f5f9; color: #94a3b8; text-align: center; border-radius: 4px; padding: 3px 6px; font-style: italic; }
.cell-subject { border-radius: 4px; padding: 3px 6px; font-weight: 600; }
.cell-teacher { font-size: 0.68rem; color: #64748b; margin-top: 1px; }

/* Subject colour palette */
.sub-English       { background:#dbeafe; color:#1d4ed8; }
.sub-Marathi       { background:#fce7f3; color:#9d174d; }
.sub-Hindi, .sub-Hindi-Sanskrit { background:#fef3c7; color:#92400e; }
.sub-Math          { background:#d1fae5; color:#065f46; }
.sub-Science       { background:#e0e7ff; color:#3730a3; }
.sub-History       { background:#fdf2f8; color:#701a75; }
.sub-Geography     { background:#ecfdf5; color:#064e3b; }
.sub-Drawing       { background:#fff7ed; color:#9a3412; }
.sub-Vocational    { background:#f0fdfa; color:#134e4a; }
.sub-PE            { background:#fff1f2; color:#881337; }
.sub-Computer      { background:#f0f9ff; color:#0c4a6e; }
.sub-Singing       { background:#fdf4ff; color:#581c87; }
.sub-Yoga          { background:#fffbeb; color:#78350f; }
.sub-Dance         { background:#fdf2f8; color:#831843; }

/* ─── Hours Summary ────────────────────────────────────────────────── */
.summary-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.summary-card { background: white; border-radius: 12px; padding: 16px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.summary-card h3 { font-size: 0.9rem; font-weight: 700; margin-bottom: 10px; }
.hours-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 0.8rem; }
.hours-row .subj-name { flex: 1; font-weight: 500; }
.dev-ok   { color: #10b981; font-weight: 700; }
.dev-warn { color: #f59e0b; font-weight: 700; }
.dev-bad  { color: #ef4444; font-weight: 700; }
.hours-bar { height: 4px; border-radius: 2px; background: #e2e8f0; flex: 1; overflow: hidden; }
.hours-fill { height: 100%; border-radius: 2px; background: #10b981; }
.hours-fill.over { background: #f59e0b; }
.hours-fill.under { background: #ef4444; }

/* ─── Modal ────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 500; display: flex; align-items: center; justify-content: center;
}
.modal-backdrop[hidden] { display: none; }
.modal { background: white; border-radius: 14px; width: 480px; max-width: 95vw; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal-header { padding: 18px 20px; border-bottom: 1px solid #e2e8f0; display: flex; justify-content: space-between; align-items: center; }
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-close { background: none; border: none; font-size: 1.2rem; cursor: pointer; color: #64748b; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid #e2e8f0; display: flex; justify-content: flex-end; gap: 10px; }

/* ─── Alert ────────────────────────────────────────────────────────── */
.alert { border-radius: 8px; padding: 12px 16px; margin-bottom: 16px; font-size: 0.85rem; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.alert-error   { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.alert-info    { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }

/* ─── Progress ─────────────────────────────────────────────────────── */
.progress-bar { height: 6px; background: #e2e8f0; border-radius: 3px; overflow: hidden; margin: 8px 0; }
.progress-fill { height: 100%; background: linear-gradient(90deg, #e94560, #f59e0b); border-radius: 3px;
  animation: progress-anim 1.5s ease-in-out infinite; }
@keyframes progress-anim { 0%{width:0%} 50%{width:80%} 100%{width:100%} }

/* ─── Spinner ──────────────────────────────────────────────────────── */
.spinner {
  width: 18px; height: 18px; border: 2.5px solid #e2e8f0;
  border-top-color: #e94560; border-radius: 50%;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Scrollbar ────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: #f1f5f9; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

/* ─── Utilities ────────────────────────────────────────────────────── */
.mt-8  { margin-top: 8px; }
.mb-8  { margin-bottom: 8px; }
.flex  { display: flex; }
.gap-8 { gap: 8px; }
.w100  { width: 100%; }
.text-small { font-size: 0.8rem; color: #64748b; }
