/* ============ Time Table Management System — UI theme ============ */
:root {
  --primary: #2563eb;
  --primary-dark: color-mix(in srgb, var(--primary) 80%, black);
  --primary-soft: color-mix(in srgb, var(--primary) 12%, transparent);
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 14px rgba(0,0,0,.04);
  --radius: 10px;
  --lecture: #2563eb;
  --practical: #059669;
  --written: #d97706;
  --lunch: #94a3b8;
  --danger: #dc2626;
  --ok: #16a34a;
}
[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #131c2e;
  --surface-2: #1a2438;
  --text: #e2e8f0;
  --text-muted: #94a3b8;
  --border: #263349;
  --shadow: 0 1px 3px rgba(0,0,0,.4);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: 'Inter', 'Segoe UI', system-ui, -apple-system, Roboto, sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { letter-spacing: -0.01em; }
.hidden { display: none !important; }
.muted { color: var(--text-muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 13px; }
code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* ---------- login ---------- */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(1100px 700px at 12% -10%, color-mix(in srgb, var(--primary) 35%, transparent), transparent 60%),
    radial-gradient(900px 600px at 100% 110%, color-mix(in srgb, var(--primary-dark) 45%, transparent), transparent 60%),
    linear-gradient(160deg, #0b1220 0%, #111a2e 55%, var(--primary-dark) 100%);
  padding: 20px;
}
.login-panel { display: flex; flex-direction: column; align-items: center; gap: 16px; width: 100%; max-width: 400px; }
.login-card {
  background: var(--surface); padding: 44px 44px 36px; border-radius: 18px; box-shadow: 0 30px 80px rgba(0,0,0,.35);
  width: 100%; text-align: center; border: 1px solid rgba(255,255,255,.08);
}
.login-card h1 { font-size: 21px; margin: 14px 0 4px; font-weight: 800; }
.login-logo { max-height: 64px; max-width: 200px; object-fit: contain; }
.login-badge {
  width: 56px; height: 56px; border-radius: 14px; margin: 0 auto; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; font-weight: 800; font-size: 18px;
  letter-spacing: .02em; box-shadow: 0 8px 20px color-mix(in srgb, var(--primary) 45%, transparent);
}
.login-card form { text-align: left; margin-top: 22px; }
.fld-login { margin-bottom: 14px; }
.fld-login input { width: 100%; }
.login-footnote { color: rgba(255,255,255,.75); font-size: 12.5px; text-align: center; }

/* ---------- layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 250px; flex-shrink: 0; background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 16px; border-bottom: 1px solid var(--border); }
.brand-logo { width: 40px; height: 40px; object-fit: contain; border-radius: 8px; }
.brand-badge {
  width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; font-weight: 800; font-size: 13px;
}
.brand-name { font-weight: 800; font-size: 15px; line-height: 1.25; }
.brand-tagline { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
nav { padding: 8px; flex: 1; }
.nav-section {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted);
  padding: 14px 10px 4px;
}
.nav-item {
  display: block; padding: 8px 10px; border-radius: 8px; cursor: pointer; color: var(--text);
  text-decoration: none; margin: 1px 0; font-size: 13.5px;
}
.nav-item:hover { background: var(--surface-2); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 26px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20; gap: 10px;
}
.topbar-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.topbar h2 { margin: 0; font-size: 18px; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.content { padding: 24px 26px 60px; max-width: 1280px; }
.nav-toggle { display: none; font-size: 19px; line-height: 1; padding: 6px 10px; flex-shrink: 0; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 29; }

.user-chip { display: flex; align-items: center; gap: 8px; padding: 4px 10px 4px 4px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); margin-left: 4px; }
.user-avatar { width: 28px; height: 28px; border-radius: 999px; background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff; font-weight: 700; font-size: 11.5px; display: flex; align-items: center; justify-content: center; }
.user-meta { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { font-size: 12.5px; font-weight: 700; }
.user-role { font-size: 11px; color: var(--text-muted); }

/* ---------- components ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px;
}
.card h3 { margin: 0 0 12px; font-size: 15px; }
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid-5 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }

.dash-hero {
  background: linear-gradient(120deg, color-mix(in srgb, var(--primary) 10%, var(--surface)), var(--surface));
  border-left: 4px solid var(--primary);
}
.dash-hello { font-size: 19px; font-weight: 800; display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.kpi-row .stat .num { font-size: 24px; }

.quick-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.qa-btn {
  display: flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; font-family: inherit;
}
.qa-btn:hover { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 40%, var(--border)); color: var(--primary); }
.qa-icon { font-size: 16px; }

.activity-row { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.activity-row:last-child { border-bottom: none; }
.activity-dot { width: 8px; height: 8px; border-radius: 999px; background: var(--primary); margin-top: 6px; flex-shrink: 0; }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px; margin-top: 10px; }

.tt-grid.readonly .tt-cell { cursor: default; }
.tt-grid.readonly .tt-cell:hover { background: none; }
.tt-grid.readonly .add-hint { display: none; }

.stat { display: flex; flex-direction: column; gap: 4px; }
.stat .num { font-size: 26px; font-weight: 700; color: var(--primary); }
.stat .lbl { font-size: 12.5px; color: var(--text-muted); }

.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px;
  background: var(--primary-soft); color: var(--primary); font-weight: 600;
}
.badge.red { background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); }
.badge.green { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); }
.badge.amber { background: color-mix(in srgb, var(--written) 14%, transparent); color: var(--written); }

button, .btn {
  font-family: inherit; font-size: 13.5px; border: 1px solid var(--border); background: var(--surface);
  color: var(--text); padding: 8px 14px; border-radius: 8px; cursor: pointer;
}
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, transparent); background: transparent; }
.btn-danger:hover { background: color-mix(in srgb, var(--danger) 8%, transparent); }
.btn-ghost { border: none; background: transparent; font-size: 16px; }
.btn-sm { padding: 4px 9px; font-size: 12px; }
.btn-block { width: 100%; }

input, select, textarea {
  font-family: inherit; font-size: 13.5px; padding: 8px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--surface); color: var(--text); outline: none; max-width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
input[type="color"] { padding: 2px; height: 38px; width: 60px; }
label.fld { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-muted); font-weight: 600; min-width: 0; }
label.fld > input, label.fld > select, label.fld > textarea { font-weight: 400; color: var(--text); width: 100%; min-width: 0; }
label.fld > input[type="color"] { width: 60px; }
.form-row { display: flex; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.form-row > label.fld { flex: 1; min-width: 140px; }
.toolbar > label.fld { min-width: 140px; }
label.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 400; color: var(--text); padding: 5px 9px; border: 1px solid var(--border); border-radius: 7px; cursor: pointer; }
label.chk input { width: auto; padding: 0; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 16px; }

table.tbl { width: 100%; border-collapse: collapse; }
.tbl th, .tbl td { text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--border); font-size: 13px; }
.tbl th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.tbl tr:hover td { background: var(--surface-2); }
/* a data table wider than its card scrolls sideways inside the card instead of the whole page */
.card:has(table.tbl) { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* ---------- timetable grid ---------- */
.tt-wrap { overflow-x: auto; }
.tt-grid { border-collapse: collapse; width: 100%; min-width: 860px; }
.tt-grid th, .tt-grid td { border: 1px solid var(--border); padding: 5px; vertical-align: top; }
.tt-grid th { background: var(--surface-2); font-size: 12px; padding: 8px; }
.tt-grid .time-col { width: 110px; font-size: 11.5px; color: var(--text-muted); background: var(--surface-2); text-align: center; }
.tt-cell { min-height: 56px; min-width: 118px; cursor: pointer; position: relative; }
.tt-cell:hover { background: var(--primary-soft); }
.tt-cell.break-cell { background: repeating-linear-gradient(45deg, var(--surface-2), var(--surface-2) 8px, var(--surface) 8px, var(--surface) 16px); cursor: default; text-align: center; color: var(--text-muted); font-size: 11px; }
.tt-cell.off-cell { background: var(--surface-2); cursor: default; text-align: center; color: var(--text-muted); font-size: 11px; }
.lesson {
  border-radius: 7px; padding: 5px 7px; font-size: 11.5px; line-height: 1.35; color: #fff; margin-bottom: 3px;
  position: relative;
}
.lesson .sub { font-weight: 700; }
.lesson .tch { opacity: .92; }
.lesson .rm { opacity: .8; font-size: 10px; text-transform: uppercase; letter-spacing: .03em; margin-top: 1px; }
.lesson .typ { position: absolute; top: 3px; right: 5px; font-size: 9px; text-transform: uppercase; letter-spacing: .05em; background: rgba(255,255,255,.25); border-radius: 4px; padding: 1px 4px; }
.lesson.type-lecture { background: var(--lecture); }
.lesson.type-practical { background: var(--practical); }
.lesson.type-written { background: var(--written); }
.add-hint { color: var(--text-muted); font-size: 18px; text-align: center; opacity: 0; }
.tt-cell:hover .add-hint { opacity: .6; }

/* ---------- master timetable (bird's-eye view) ---------- */
.mt-grid { min-width: 0; }
.mt-grid th, .mt-grid .tt-cell { min-width: 92px; max-width: 150px; }
.mt-grid th { position: sticky; top: 0; z-index: 1; }
.mt-grid .time-col { position: sticky; left: 0; z-index: 2; }
.mt-grid th.time-col { z-index: 3; }
.mt-grid .lesson { font-size: 10.5px; padding: 4px 5px; }
.mt-teacher-row td { background: var(--surface-2); font-weight: 600; text-align: center; font-size: 12px; }

/* ---------- progress bars ---------- */
.pbar { height: 9px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.pbar > div { height: 100%; border-radius: 999px; background: var(--primary); transition: width .3s; }
.pbar.lec > div { background: var(--lecture); }
.pbar.prac > div { background: var(--practical); }
.pbar.writ > div { background: var(--written); }
.prog-row { display: grid; grid-template-columns: 130px 1fr 150px; align-items: center; gap: 12px; margin: 7px 0; font-size: 12.5px; }

.legend { display: flex; gap: 14px; font-size: 12px; color: var(--text-muted); margin: 8px 0; flex-wrap: wrap; }
.legend .dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex;
  align-items: center; justify-content: center; z-index: 100; padding: 20px;
}
.modal {
  background: var(--surface); border-radius: 14px; padding: 22px 24px; width: 100%; max-width: 560px;
  box-shadow: 0 24px 80px rgba(0,0,0,.35); max-height: 90vh; overflow-y: auto;
}
.modal h3 { margin: 0 0 16px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

/* ---------- toast ---------- */
#toastRoot { position: fixed; bottom: 22px; right: 22px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 10px; font-size: 13.5px;
  box-shadow: var(--shadow); animation: slideIn .25s ease;
}
.toast.err { background: var(--danger); color: #fff; }
@keyframes slideIn { from { transform: translateY(12px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; border-bottom: 1px solid var(--border); }
.tab { padding: 8px 16px; cursor: pointer; border: none; background: none; color: var(--text-muted); font-weight: 600; font-size: 13.5px; border-bottom: 2px solid transparent; border-radius: 0; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.day-row { display: flex; align-items: center; gap: 10px; padding: 8px 4px; border-bottom: 1px solid var(--border); font-size: 13px; flex-wrap: wrap; }
.day-row:last-child { border-bottom: none; }

/* ---------- v2 additions ---------- */
/* pagination */
.pager { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.pager-btns { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; }
.pager .btn.active { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 600; }
.pager .btn:disabled { opacity: .45; cursor: default; }
.pager-gap { color: var(--text-muted); padding: 0 4px; }
/* busy / disabled buttons */
.btn:disabled, button:disabled { opacity: .6; cursor: not-allowed; }
.btn.busy { position: relative; }
.btn.busy::after { content: ''; display: inline-block; width: 10px; height: 10px; margin-left: 6px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; vertical-align: -1px; }
@keyframes spin { to { transform: rotate(360deg); } }
/* inactive faculty */
.row-inactive td { color: var(--text-muted); }
.row-inactive td b { font-weight: 600; }
.badge.muted-badge { background: color-mix(in srgb, var(--text-muted) 16%, transparent); color: var(--text-muted); }
/* lunch + session-log indicator on the grid */
.lesson.type-lunch { background: var(--lunch); }
.lesson .log-ind { position: absolute; right: 3px; bottom: 3px; border: none; background: rgba(255,255,255,.28); border-radius: 5px; font-size: 11px; line-height: 1; padding: 3px 4px; cursor: pointer; opacity: .8; }
.lesson .log-ind:hover { opacity: 1; background: rgba(255,255,255,.5); }
.lesson .log-ind.logged { background: #fff; opacity: 1; box-shadow: 0 0 0 2px var(--ok); }
.btn-logged { border-color: color-mix(in srgb, var(--ok) 50%, var(--border)); color: var(--ok); }
.log-row td { padding-top: 0; background: var(--surface-2); }
.log-row summary { cursor: pointer; font-size: 12.5px; padding: 6px 0; }
.log-body { font-size: 13px; padding: 2px 0 8px 18px; display: flex; flex-direction: column; gap: 4px; white-space: pre-wrap; }
textarea { resize: vertical; width: 100%; line-height: 1.45; }
/* completion checkboxes */
label.chk.chk-sm { font-size: 11.5px; padding: 2px 7px; margin: 1px 0; }
label.chk.chk-on { border-color: color-mix(in srgb, var(--ok) 55%, var(--border)); background: color-mix(in srgb, var(--ok) 10%, transparent); }
/* settings */
.logo-slots { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.logo-slot { border: 1px solid var(--border); border-radius: 9px; padding: 10px; display: flex; flex-direction: column; gap: 7px; background: var(--surface-2); }
.logo-slot-title { font-weight: 700; font-size: 12.5px; }
.logo-preview { height: 64px; border: 1px dashed var(--border); border-radius: 7px; display: flex; align-items: center; justify-content: center; background: var(--surface); text-align: center; padding: 4px; }
.logo-preview img { max-height: 56px; max-width: 100%; object-fit: contain; }
.logo-preview.fav img { width: 32px; height: 32px; }
.logo-slot-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.logo-slot-actions label.btn { display: inline-block; }
.sub-h { margin: 18px 0 6px; font-size: 13.5px; }
.settings-footer { text-align: center; margin-top: 4px; }
.login-logo.login-logo-rect { max-width: 300px; max-height: 80px; }
/* empty states */
.empty-state { text-align: center; padding: 28px 20px; }
.empty-state p { margin: 4px 0; }
/* faculty overview */
.fo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.fo-card { margin-bottom: 0; display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.fo-card.inactive { opacity: .62; filter: grayscale(.6); }
.fo-head { display: flex; align-items: center; gap: 10px; }
.fo-id { flex: 1; min-width: 0; }
.fo-name { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fo-avatar { width: 38px; height: 38px; border-radius: 10px; color: #fff; font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.fo-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.fo-stats > div { background: var(--surface-2); border: 1px solid var(--border); border-radius: 8px; padding: 7px 9px; display: flex; flex-direction: column; }
.fo-stats .num { font-weight: 700; font-size: 16px; color: var(--primary); }
.fo-stats .lbl { font-size: 11px; color: var(--text-muted); }
.fo-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; border-top: 1px solid var(--border); padding-top: 10px; }

@media (max-width: 860px) {
  .sidebar { width: 200px; }
  .content { padding: 16px; }
}

/* ---------- mobile (phones / narrow tablets): off-canvas sidebar + compact layout ---------- */
@media (max-width: 760px) {
  .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100vh; width: 260px; max-width: 82vw;
    transform: translateX(-100%); transition: transform .22s ease; z-index: 30; box-shadow: none;
  }
  .app.sidebar-open .sidebar { transform: translateX(0); box-shadow: 12px 0 34px rgba(0,0,0,.28); }
  .app.sidebar-open .sidebar-backdrop { display: block; }
  .topbar { padding: 10px 14px; }
  .topbar-left { min-width: 0; flex: 1; }
  .topbar h2 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .topbar-right { flex-shrink: 0; }
  .content { padding: 14px 14px 50px; }
  .user-chip .user-meta { display: none; }
  .nav-item { padding: 10px 10px; font-size: 14px; }
  button, .btn { padding: 9px 13px; }
  .modal-backdrop { padding: 12px; }
  .modal { padding: 18px 18px; }
  .grid-4, .grid-5 { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .grid-2 { grid-template-columns: 1fr; }
  .fo-grid { grid-template-columns: 1fr; }
  .prog-row { grid-template-columns: 1fr; row-gap: 4px; margin: 10px 0; }
  .login-card { padding: 32px 26px 28px; }
}
@media (max-width: 420px) {
  #todayBadge { display: none; }
  .grid-4, .grid-5 { grid-template-columns: 1fr 1fr; }
}
@media print {
  .sidebar, .topbar { display: none; }
  .toolbar, .add-hint { display: none !important; }
  .mt-grid th, .mt-grid .tt-cell { max-width: none; }
}
