:root {
  --bg: #eef1f8;
  --bg-grad-1: #6366f1;
  --bg-grad-2: #8b5cf6;
  --panel: #ffffff;
  --ink: #1e293b;
  --muted: #64748b;
  --line: #e6e9f0;
  --brand: #6366f1;
  --brand-dark: #4f46e5;
  --ok: #16a34a;
  --ok-bg: #dcfce7;
  --warn: #b45309;
  --warn-bg: #fef3c7;
  --err: #dc2626;
  --err-bg: #fee2e2;
  --break: #f1f5f9;
  --shadow: 0 1px 3px rgba(15,23,42,.06), 0 8px 24px rgba(15,23,42,.06);
  --radius: 14px;
}

* { box-sizing: border-box; }
html { -webkit-font-smoothing: antialiased; }
body {
  margin: 0;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 16px 26px;
  background: linear-gradient(120deg, var(--bg-grad-1), var(--bg-grad-2));
  color: #fff; box-shadow: var(--shadow);
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  font-size: 26px; width: 46px; height: 46px; border-radius: 12px;
  background: rgba(255,255,255,.18); display: grid; place-items: center;
  backdrop-filter: blur(4px);
}
.topbar h1 { font-size: 19px; margin: 0; font-weight: 700; letter-spacing: -.2px; }
.brand-sub { margin: 2px 0 0; font-size: 12.5px; color: rgba(255,255,255,.82); }
.topbar-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.topbar .btn { background: rgba(255,255,255,.16); color: #fff; border-color: rgba(255,255,255,.28); }
.topbar .btn:hover { background: rgba(255,255,255,.28); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; gap: 6px; padding: 14px 26px; background: transparent;
  flex-wrap: wrap; max-width: 1120px; margin: 0 auto;
}
.tab {
  border: 1px solid transparent; background: #fff; padding: 9px 15px; cursor: pointer;
  color: var(--muted); font-size: 13.5px; border-radius: 999px; box-shadow: var(--shadow);
  transition: all .15s;
}
.tab:hover { color: var(--ink); }
.tab.active { color: #fff; background: var(--brand); font-weight: 600; box-shadow: 0 6px 16px rgba(99,102,241,.35); }

main { max-width: 1120px; margin: 0 auto; padding: 6px 26px 90px; }
.tabpane { display: none; background: var(--panel); border-radius: var(--radius);
  padding: 26px; box-shadow: var(--shadow); }
.tabpane.active { display: block; animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
h2 { margin: 0 0 6px; font-size: 21px; letter-spacing: -.3px; }
.hint { color: var(--muted); margin: 4px 0 18px; max-width: 720px; }
small.hint { display: block; margin-top: 4px; }
.opt { color: var(--muted); font-weight: 400; font-size: 12px; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; max-width: 460px; }
.field-row { display: flex; gap: 18px; flex-wrap: wrap; }
.field-row .field { flex: 1; min-width: 220px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
input[type=text], input[type=number], input[type=password], select {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font-size: 14px; background: #fff; color: var(--ink); transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(99,102,241,.15); }
input[type=number] { width: 130px; }
select:disabled { background: #f8fafc; color: var(--muted); }

/* ---------- Buttons ---------- */
.btn {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: 9px 15px; border-radius: 10px; cursor: pointer; font-size: 13.5px; font-weight: 500;
  transition: all .15s;
}
.btn:hover { background: #f8fafc; transform: translateY(-1px); }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand);
  box-shadow: 0 6px 16px rgba(99,102,241,.32); }
.btn-primary:hover { background: var(--brand-dark); }
.btn-lg { padding: 13px 24px; font-size: 15.5px; }
.btn-ghost { color: var(--muted); }

.inline-add { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 16px 0; }
.inline-add input[type=text] { width: auto; min-width: 190px; }
.checkbox { display: flex; align-items: center; gap: 6px; white-space: nowrap; font-weight: 500; }

/* ---------- Chips ---------- */
.chip-list { list-style: none; padding: 0; display: flex; flex-wrap: wrap; gap: 9px; }
.chip-list li {
  background: #eef2ff; border: 1px solid #e0e7ff; color: var(--brand-dark);
  padding: 7px 12px; border-radius: 999px; display: flex; align-items: center; gap: 9px;
  font-weight: 600; font-size: 13px;
}
.chip-list li button { border: none; background: none; cursor: pointer; color: var(--err);
  font-size: 17px; line-height: 1; padding: 0; }

/* ---------- Tables ---------- */
.grid-table { width: 100%; border-collapse: separate; border-spacing: 0; margin: 12px 0;
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.grid-table th, .grid-table td { border-bottom: 1px solid var(--line); padding: 10px 12px; text-align: left; }
.grid-table thead th { background: #f8fafc; font-size: 12.5px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px; }
.grid-table tbody tr:last-child td { border-bottom: none; }
.grid-table tbody tr:hover { background: #fafbff; }
.grid-table td button { border: none; background: none; color: var(--err); cursor: pointer; font-size: 16px; }

.capacity { font-weight: 600; margin: 10px 0; padding: 8px 12px; border-radius: 10px;
  display: inline-block; background: #f1f5f9; }
.capacity.over { color: var(--err); background: var(--err-bg); }
.capacity.under { color: var(--warn); background: var(--warn-bg); }
.capacity.exact { color: var(--ok); background: var(--ok-bg); }

/* ---------- Teachers ---------- */
.teacher-list { display: flex; flex-direction: column; gap: 12px; margin-top: 14px; }
.teacher-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  transition: box-shadow .15s; }
.teacher-card.open { box-shadow: var(--shadow); }
.teacher-card .tc-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.teacher-card .tc-head strong { font-size: 15px; }
.teacher-card .tc-head .btn { margin-left: auto; }
.teacher-card .tc-head .btn + .btn { margin-left: 0; }
.badge { font-size: 11px; padding: 3px 9px; border-radius: 999px; background: #eef2ff;
  color: var(--brand-dark); font-weight: 600; }
.badge.pt { background: var(--warn-bg); color: var(--warn); }
.tc-body { margin-top: 14px; display: none; border-top: 1px dashed var(--line); padding-top: 12px; }
.teacher-card.open .tc-body { display: block; }
.tc-section { margin-top: 12px; }
.tc-section > label { font-weight: 600; display: block; margin-bottom: 8px; font-size: 13px; }

.avail-grid { border-collapse: collapse; border-radius: 8px; overflow: hidden; }
.avail-grid th, .avail-grid td { border: 1px solid var(--line); width: 36px; height: 30px;
  text-align: center; font-size: 11px; padding: 0; }
.avail-grid th { background: #f8fafc; color: var(--muted); }
.avail-cell { cursor: pointer; user-select: none; transition: background .1s; }
.avail-cell.ok { background: #dcfce7; }
.avail-cell.ok:hover { background: #bbf7d0; }
.avail-cell.blocked { background: #fecaca; }
.avail-cell.blocked:hover { background: #fca5a5; }
.avail-cell.brk { background: var(--break); cursor: not-allowed; color: var(--muted); }

/* ---------- Messages ---------- */
.warnbox { margin-top: 16px; }
.warnbox .msg { padding: 10px 14px; border-radius: 10px; margin-bottom: 8px; font-weight: 500; }
.msg.warn { background: var(--warn-bg); color: var(--warn); }
.msg.err { background: var(--err-bg); color: var(--err); }
.msg.ok { background: var(--ok-bg); color: var(--ok); }

/* ---------- Results ---------- */
.gen-status { margin-left: 14px; color: var(--muted); font-weight: 500; }
.results { margin-top: 24px; }
.results-controls { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.results-controls .spacer { flex: 1; }
.toggle { display: flex; box-shadow: var(--shadow); border-radius: 10px; }
.toggle-btn { border-radius: 0; box-shadow: none; }
.toggle-btn:first-child { border-radius: 10px 0 0 10px; }
.toggle-btn:last-child { border-radius: 0 10px 10px 0; border-left: none; }
.toggle-btn.active { background: var(--brand); color: #fff; border-color: var(--brand); }
.toggle-btn.active:hover { background: var(--brand-dark); }

.tt { width: 100%; border-collapse: separate; border-spacing: 0; margin-top: 10px;
  border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.tt th, .tt td { border-bottom: 1px solid var(--line); border-right: 1px solid var(--line);
  padding: 8px 8px; text-align: center; vertical-align: middle; }
.tt tr td:last-child, .tt tr th:last-child { border-right: none; }
.tt tbody tr:last-child td { border-bottom: none; }
.tt thead th { background: #f8fafc; font-size: 12px; color: var(--muted);
  text-transform: uppercase; letter-spacing: .4px; }
.tt tbody th { background: #f8fafc; font-weight: 700; }
.tt td .subj { font-weight: 700; font-size: 13px; }
.tt td .sub { font-size: 11px; color: var(--muted); }
.tt td.empty { background: #fff; color: #cbd5e1; }
.tt td.brk { background: var(--break); color: var(--muted); font-size: 11px; font-style: italic; }
.tt-title { font-size: 17px; font-weight: 800; margin: 14px 0 4px; letter-spacing: -.2px; }
.tt-block { margin-bottom: 22px; }

/* ---------- Login ---------- */
.login-body { min-height: 100vh; margin: 0; display: grid; place-items: center;
  background: linear-gradient(140deg, var(--bg-grad-1), var(--bg-grad-2)); }
.login-card { background: #fff; padding: 38px 34px; border-radius: 18px; width: 340px;
  box-shadow: 0 20px 60px rgba(15,23,42,.3); text-align: center; display: flex;
  flex-direction: column; gap: 12px; }
.login-card h1 { margin: 4px 0 0; font-size: 22px; }
.login-card .muted { color: var(--muted); margin: 0 0 4px; }
.login-logo { font-size: 40px; }
.login-card input { text-align: center; }
.login-card .err { color: var(--err); background: var(--err-bg); padding: 8px; border-radius: 8px;
  margin: 0; font-size: 13px; }

/* ---------- Misc ---------- */
.hidden { display: none !important; }
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 20px; border-radius: 10px; z-index: 50;
  box-shadow: 0 10px 30px rgba(15,23,42,.3); font-weight: 500;
}

/* ---------- v2 Manager ---------- */
main.wide { max-width: none; padding: 6px 18px 90px; }
.pane-head { margin-bottom: 8px; }
.save-state { color: #fef3c7; font-size: 12.5px; align-self: center; }

.grid-scroll { overflow: auto; max-height: 72vh; border: 1px solid var(--line);
  border-radius: 12px; }
.school-grid { border-collapse: separate; border-spacing: 0; font-size: 11.5px; }
.school-grid th, .school-grid td { border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line); padding: 3px; text-align: center;
  min-width: 108px; vertical-align: top; background: #fff; }
.school-grid thead th { position: sticky; top: 0; z-index: 3; background: #eef2ff;
  font-size: 11px; padding: 6px 3px; }
.school-grid .sticky-col { position: sticky; left: 0; z-index: 2; background: #f8fafc;
  min-width: 54px; font-weight: 700; }
.school-grid thead .sticky-col { z-index: 4; }
.school-grid th .ct { font-size: 9.5px; color: var(--brand-dark); font-weight: 500; }
.school-grid td { cursor: pointer; }
.school-grid td:hover { outline: 2px solid var(--brand); outline-offset: -2px; }
.sg-entry { border-radius: 6px; padding: 2px 3px; margin: 1px 0; line-height: 1.25; }
.sg-entry b { display: block; font-size: 11px; }
.sg-entry span { font-size: 10px; color: var(--muted); }
.sg-sub { outline: 1.5px dashed var(--warn); }
.sg-free { color: #cbd5e1; }
td.sg-clash { outline: 2.5px solid var(--err) !important; outline-offset: -2px;
  background: var(--err-bg) !important; }

.cell-editor { position: fixed; right: 18px; top: 130px; width: 340px; background: #fff;
  border: 1px solid var(--line); border-radius: 14px; padding: 18px; z-index: 40;
  box-shadow: 0 20px 60px rgba(15,23,42,.25); }
.cell-editor h3 { margin: 0 0 12px; }
.ce-row { display: flex; gap: 6px; margin-bottom: 8px; }
.ce-row input { flex: 1; min-width: 0; }
.ce-actions { display: flex; gap: 6px; margin-top: 12px; align-items: center; }
.ce-actions .spacer { flex: 1; }

.ov-card { border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px;
  margin-bottom: 12px; }
.ov-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ov-head .btn { margin-left: auto; }
.ov-head .btn + .btn { margin-left: 0; }
.ov-body { display: none; margin-top: 12px; border-top: 1px dashed var(--line); padding-top: 12px; }
.ov-card.open .ov-body { display: block; }

.issue-badge { background: var(--err); color: #fff; border-radius: 999px; font-size: 10.5px;
  padding: 1px 7px; margin-left: 5px; }
.pending-card { border: 1px solid var(--line); border-left: 4px solid var(--warn);
  border-radius: 10px; padding: 12px 14px; margin-bottom: 10px; }
.pending-card p { margin: 6px 0 10px; color: var(--muted); }
td.wed-activity { background: repeating-linear-gradient(45deg, #f1f5f9, #f1f5f9 6px,
  #e2e8f0 6px, #e2e8f0 12px) !important; }

@media print {
  .topbar, .tabs, .results-controls, .btn, .gen-status, #gen-diagnostics { display: none !important; }
  body { background: #fff; }
  .tabpane { box-shadow: none; padding: 0; }
  #timetable-render { display: block; }
  .tt-block { page-break-inside: avoid; margin-bottom: 24px; }
  .tt td .subj { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
