/* app.css — layout, components and the timetable grid. Logical properties keep RTL and LTR identical. */
:root {
  --bg: #f3f4f6; --surface: #ffffff; --text: #111827; --muted: #6b7280; --border: #e5e7eb; --border-strong: #d1d5db;
  --primary: #4f46e5; --primary-600: #4338ca; --primary-soft: rgba(79, 70, 229, .10);
  --danger: #dc2626; --ok: #16a34a; --warn: #d97706;
  --radius: 12px; --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .04);
  --topbar-h: 56px; --side-w: 220px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Arabic", "Noto Naskh Arabic", "Geeza Pro", Tahoma, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; touch-action: pan-x pan-y; } /* no pinch-zoom on touch devices; the app has its own zoom control */
body { font-family: var(--font); font-size: 15px; line-height: 1.5; background: var(--bg); color: var(--text); -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
body.is-dragging { cursor: grabbing; user-select: none; -webkit-user-select: none; }
a { color: var(--primary); }
h1, h2, h3 { margin: 0; font-weight: 700; }
p { margin: 0 0 8px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.spacer { flex: 1; }
.grow { flex: 1; min-width: 0; }
.warn-text { color: var(--warn); font-weight: 600; }
.ok-text { color: var(--ok); font-weight: 600; }
.center { justify-content: center; }
.req { color: var(--danger); }
hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }

/* ---------- shell ---------- */
#app { display: flex; flex-direction: column; min-height: 100vh; }
.topbar { position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 6px; height: var(--topbar-h); padding: 0 10px; background: var(--surface); border-bottom: 1px solid var(--border); padding-top: env(safe-area-inset-top); }
.brand { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; flex: 0 1 auto; }
.brand-name { font-weight: 800; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.body { display: flex; flex: 1; align-items: stretch; }
.sidenav { width: var(--side-w); flex: none; background: var(--surface); border-inline-end: 1px solid var(--border); padding: 12px 8px; position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); display: flex; flex-direction: column; gap: 4px; }
.side-foot { margin-top: auto; padding: 8px; }
body.side-hidden .sidenav { display: none; }
.side-btn { font-size: 19px; }
[dir="rtl"] .side-btn { transform: scaleX(-1); }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px; color: var(--text); text-decoration: none; font-weight: 500; }
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 700; }
.nav-icon { font-size: 18px; line-height: 1; }
.view { flex: 1; min-width: 0; padding: 16px; }
.nav-select { display: none; width: auto; min-height: 36px; padding-block: 4px; padding-inline: 10px 28px; font-weight: 700; max-width: 46vw; }
body.side-hidden .nav-select { display: inline-block; }
.page { display: flex; flex-direction: column; gap: 14px; max-width: 1100px; }
.data-view .page { max-width: none; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 8px 14px; min-height: 40px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--bg); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.95); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--primary); }
.btn-ghost:hover { background: var(--primary-soft); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 38px; border-radius: 10px; border: 1px solid transparent; background: transparent; color: var(--text); font: inherit; font-size: 17px; cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--bg); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.undo-redo { display: none; } /* hidden for now; keyboard shortcuts still work */
.cloud-btn { position: relative; }
.role-chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--bg); }
.role-chip.role-admin { background: #fee2e2; color: #991b1b; } .role-chip.role-editor { background: #dbeafe; color: #1e40af; } .role-chip.role-viewer { background: var(--bg); color: var(--muted); }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 6px; }
.perm-item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); cursor: pointer; font-size: 13.5px; }
.perm-item input { width: 16px; height: 16px; accent-color: var(--primary); }
.perm-item.overridden { border-color: var(--primary); background: var(--primary-soft); }
.perm-note { margin-inline-start: auto; font-size: 11px; color: var(--primary); font-weight: 700; }
.page-title { font-size: 18px; }
.hist-list { display: flex; flex-direction: column; gap: 8px; }
.hist-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); flex-wrap: wrap; }
.hist-item.current { border-color: #a7f3d0; background: #f0fdf4; }
.hist-item.previewed { border-color: var(--primary); background: var(--primary-soft); }
.hist-ver { font-weight: 800; color: var(--muted); min-width: 44px; font-variant-numeric: tabular-nums; }
.hist-main { flex: 1 1 260px; min-width: 0; }
.hist-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.hist-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.diff { display: flex; flex-direction: column; gap: 10px; }
.diff.compact { max-height: 40vh; overflow: auto; font-size: 13px; }
.diff-coll { padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.diff-title { font-weight: 700; margin-bottom: 4px; }
.diff-line { padding: 2px 0; } .diff-line.add b { color: var(--ok); } .diff-line.del b { color: var(--danger); } .diff-line.chg b { color: var(--warn); }
.signin-banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 14px; margin-bottom: 12px; border-radius: 10px; background: var(--primary-soft); border: 1px solid rgba(79, 70, 229, .25); font-size: 13.5px; }
.preview-banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 14px; margin-bottom: 12px; border-radius: 10px; background: #fef3c7; border: 1px solid #fcd34d; color: #92400e; font-weight: 600; }
body.previewing .tt-toolbar .saved-btn, body.previewing .batch-bar, body.previewing .drag-handle, body.previewing .sel-box { display: none !important; }
.tt-wrap.read-only .card { cursor: default; }
body.cloud-signed-in:not(.can-editData) .note-btn.empty { display: none; }
body.cloud-signed-in:not(.can-editSchool) .school-view .btn-primary, body.cloud-signed-in:not(.can-editSchool) .school-view .icon-btn.danger { display: none; }
.cloud-dot { position: absolute; bottom: 6px; inset-inline-end: 6px; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); border: 2px solid var(--surface); }
.cloud-btn.st-synced .cloud-dot { background: var(--ok); }
.cloud-btn.st-syncing .cloud-dot { background: var(--primary); animation: pulse 1s ease-in-out infinite; }
.cloud-btn.st-pending .cloud-dot { background: var(--warn); }
.cloud-btn.st-conflict .cloud-dot, .cloud-btn.st-error .cloud-dot { background: var(--danger); }
.cloud-btn.st-signedOut { opacity: .6; }
@keyframes pulse { 50% { opacity: .3; } }
.cloud-who { padding: 6px 10px 10px; }
.cloud-state { padding: 6px 10px; margin-bottom: 6px; border-radius: 8px; background: var(--bg); font-size: 13px; }
.cloud-state.synced { color: #047857; } .cloud-state.pending { color: #92400e; } .cloud-state.conflict, .cloud-state.error { color: var(--danger); }
.icon-btn.danger { color: var(--danger); }
.icon-btn.has-timeoff { color: var(--warn); }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.btn-col { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.btn-col .btn { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--primary); font: inherit; cursor: pointer; text-align: start; }
.link:hover { text-decoration: underline; }

/* ---------- panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.panel-title { font-size: 16px; }
.panel-body { padding: 14px 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.stat { display: block; text-decoration: none; color: var(--text); background: var(--bg); border-radius: 10px; padding: 10px 12px; border: 1px solid var(--border); }
.stat:hover { border-color: var(--primary); }
.stat.warn { background: #fffbeb; border-color: #fcd34d; }
.stat-value { font-size: 22px; font-weight: 800; line-height: 1.2; }
.stat-label { font-size: 12.5px; color: var(--muted); }
.steps { padding-inline-start: 22px; margin: 0 0 8px; }
.steps li { margin: 4px 0; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--border-strong); border-radius: var(--radius); }
.empty-text { margin-bottom: 8px; }
.summary-line { padding: 8px 12px; border-radius: 10px; background: var(--primary-soft); font-weight: 600; }
.summary-line.warn { background: #fef3c7; color: #92400e; }
.warn-list { margin: 0; padding-inline-start: 20px; color: #92400e; }
.warn-list li { margin: 3px 0; }
.kv { border-collapse: collapse; width: 100%; }
.kv th { text-align: start; color: var(--muted); font-weight: 500; padding: 4px 0; width: 30%; vertical-align: top; }
.kv td { padding: 4px 0; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field.inline { flex-direction: row; align-items: center; gap: 10px; margin-bottom: 8px; }
.field-label { font-size: 13px; font-weight: 600; color: #374151; }
.field-hint { font-size: 12px; color: var(--muted); }
.input { width: 100%; min-height: 40px; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 10px; background: #fff; font: inherit; color: var(--text); }
.input:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.input.short { width: 110px; min-width: 80px; }
select.input { appearance: auto; }
textarea.input { min-height: 90px; resize: vertical; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.tt-toolbar { margin-bottom: 10px; gap: 6px; }
.tt-toolbar .input { min-height: 36px; padding-block: 4px; }
.toolbar .search { max-width: 260px; }
.toolbar .picker { min-width: 200px; }
.picker { display: inline-flex; align-items: center; gap: 2px; }
.picker select { min-width: 140px; }
.checklist { display: flex; flex-wrap: wrap; gap: 6px; max-height: 190px; overflow: auto; padding: 6px; border: 1px solid var(--border); border-radius: 10px; background: #fafafa; }
.check { display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border-radius: 8px; background: #fff; border: 1px solid var(--border); cursor: pointer; font-size: 14px; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--primary); }
.check.inline { border: 0; background: transparent; padding: 4px 0; }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: middle; border: 1px solid rgba(0, 0, 0, .15); }
.color-picker { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.color-input { width: 44px; height: 36px; border: 1px solid var(--border-strong); border-radius: 8px; padding: 2px; background: #fff; }
.swatches { display: flex; flex-wrap: wrap; gap: 4px; }
.swatch-btn { width: 24px; height: 24px; border-radius: 6px; border: 1px solid rgba(0, 0, 0, .15); cursor: pointer; padding: 0; }
.details { border: 1px solid var(--border); border-radius: 10px; padding: 8px 12px; background: #fafafa; }
.details summary { cursor: pointer; font-weight: 600; }
.range-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.range-row input[type=range] { width: 160px; accent-color: var(--primary); }
.range-val { width: 20px; text-align: center; font-weight: 700; }
.segmented { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font: inherit; font-weight: 600; color: var(--muted); cursor: pointer; min-height: 32px; }
.seg.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
.subtabs { display: flex; gap: 4px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; scrollbar-width: none; }
.subtabs::-webkit-scrollbar { display: none; }
.subtab { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 10px; text-decoration: none; color: var(--muted); font-weight: 600; white-space: nowrap; border: 1px solid transparent; }
.subtab.active { background: var(--surface); color: var(--primary); border-color: var(--border); box-shadow: var(--shadow); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--bg); color: var(--muted); font-size: 11.5px; font-weight: 700; text-align: center; line-height: 20px; }
.subtab.active .badge { background: var(--primary-soft); color: var(--primary); }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-family: inherit; }
.chip.ok { background: #ecfdf5; color: #047857; border-color: #a7f3d0; }
.chip.warn { background: #fffbeb; color: #92400e; border-color: #fcd34d; }
.chip.bad { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.chip.clickable { cursor: pointer; }
.chip.mini { padding: 3px 9px; font-size: 12px; font-variant-numeric: tabular-nums; }
.filter-panel { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; padding: 8px 12px; margin: -4px 0 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); }
.filter-extra { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.filter-btn { position: relative; }
.filter-btn.open, .filter-btn.has-filters { color: var(--primary); background: var(--primary-soft); }
.filter-badge { position: absolute; top: 2px; inset-inline-end: 2px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 999px; background: var(--primary); color: #fff; font-size: 10px; font-weight: 700; line-height: 16px; text-align: center; }
.filter-bars { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.day-bar { display: flex; gap: 4px; flex-wrap: wrap; }
.day-bar.periods .day-tab { min-width: 34px; padding-inline: 8px; }
.overview .card.cont { opacity: .85; }
.overview .card.cont .line { font-weight: 500; }
.day-tab { border: 1px solid var(--border); background: var(--surface); border-radius: 999px; padding: 3px 12px; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--muted); cursor: pointer; }
.day-tab.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.day-tab:hover:not(.active) { background: var(--bg); }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; max-width: 100%; }
.table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.table th, .table td { padding: 9px 10px; text-align: start; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { font-size: 12.5px; color: var(--muted); font-weight: 600; background: #fafafa; white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafaff; }
.table tbody tr.row-link { cursor: pointer; }
.table tbody tr.row-link:hover { background: var(--primary-soft); }
.table td.num { text-align: center; font-variant-numeric: tabular-nums; }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
.table td.actions { white-space: nowrap; text-align: end; }
.tag { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; line-height: 1.5; background: var(--primary-soft); color: var(--primary); border: 1px solid transparent; font-family: inherit; white-space: nowrap; }
.tag.clickable { cursor: pointer; }
.tag.clickable:hover { border-color: var(--primary); }
.tag.active { background: var(--primary); color: #fff; }
.tag-x { border: 0; background: transparent; color: inherit; font: inherit; font-size: 13px; line-height: 1; padding: 0 0 0 2px; cursor: pointer; opacity: .7; }
.tag-x:hover { opacity: 1; }
.tags { display: inline-flex; flex-wrap: wrap; gap: 4px; margin-inline-start: 6px; vertical-align: middle; }
.tag-input { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; min-height: 40px; padding: 5px 8px; cursor: text; }
.tag-entry { flex: 1 1 120px; min-width: 100px; border: 0; outline: 0; background: transparent; font: inherit; color: var(--text); padding: 2px 0; }
.filters { display: inline-flex; gap: 6px; flex-wrap: wrap; }
.tt-toolbar .tag-select { max-width: 180px; }
.table .drag-cell { width: 28px; padding-inline: 6px 0; }
.table .sel-cell { width: 30px; padding-inline: 4px; text-align: center; }
.sel-box { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; vertical-align: middle; }
.table tbody tr.selected { background: var(--primary-soft); }
.batch-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 12px; margin-bottom: 10px; border-radius: 10px; background: var(--primary-soft); border: 1px solid rgba(79, 70, 229, .25); }
.opt-field { padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.opt-label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.opt-box { width: 16px; height: 16px; accent-color: var(--primary); }
.opt-off { opacity: .45; pointer-events: none; }
.drag-handle { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 28px; border-radius: 6px; color: var(--muted); cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; font-size: 15px; opacity: .55; }
.drag-handle:hover { opacity: 1; background: var(--bg); }
tbody.sorting .drag-handle { cursor: grabbing; }
tr.row-dragging { opacity: .4; }
tr.drop-before td { box-shadow: inset 0 3px 0 var(--primary); }
tr.drop-after td { box-shadow: inset 0 -3px 0 var(--primary); }
tr.drop-no td { background: #fef2f2; }
.snap-actions { justify-content: space-between; margin: 0 0 12px; }
.snap-list { display: flex; flex-direction: column; gap: 8px; }
.snap-item { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); flex-wrap: wrap; }
.snap-main { flex: 1 1 220px; min-width: 0; }
.snap-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; }
.snap-meta { line-height: 1.4; }
.snap-btns { display: flex; align-items: center; gap: 2px; flex-wrap: wrap; }
.table.compact th, .table.compact td { padding: 5px 8px; }
.table.compact .input { min-height: 34px; padding: 4px 8px; }

/* ---------- modal ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(17, 24, 39, .45); display: flex; align-items: center; justify-content: center; padding: 16px; opacity: 0; transition: opacity .18s; }
.modal-backdrop.open { opacity: 1; }
.modal { background: var(--surface); border-radius: 16px; width: min(640px, 100%); max-height: calc(100vh - 32px); display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); transform: translateY(10px); transition: transform .18s; }
.modal-backdrop.open .modal { transform: none; }
.modal-sm { width: min(420px, 100%); }
.modal-lg { width: min(860px, 100%); }
.modal-head { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-title { font-weight: 700; font-size: 16px; flex: 1; }
.modal-body { padding: 16px; overflow: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.confirm-text { font-size: 15px; }
.menu-list { display: flex; flex-direction: column; gap: 2px; }
.menu-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 10px; border: 0; background: transparent; font: inherit; font-size: 15px; text-align: start; border-radius: 10px; cursor: pointer; color: var(--text); }
.menu-item:hover { background: var(--bg); }
.menu-item.danger { color: var(--danger); }
.menu-item .ico { width: 24px; text-align: center; }
.welcome p { font-size: 15px; }
.toasts { position: fixed; bottom: calc(16px + env(safe-area-inset-bottom)); inset-inline: 0; display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 200; pointer-events: none; }
.toast { background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; opacity: 0; transform: translateY(8px); transition: all .25s; max-width: 90vw; box-shadow: 0 8px 20px rgba(0, 0, 0, .2); }
.toast.show { opacity: 1; transform: none; }
.toast.success { background: #065f46; }
.toast.error { background: #991b1b; }

/* ---------- time-off editor ---------- */
.timeoff { border-collapse: separate; border-spacing: 3px; }
.timeoff th { font-size: 12px; color: var(--muted); padding: 2px 4px; white-space: nowrap; }
.timeoff th.clickable { cursor: pointer; }
.timeoff th.clickable:hover { color: var(--primary); }
.to-cell { display: inline-block; min-width: 34px; height: 30px; line-height: 30px; text-align: center; border-radius: 6px; background: #ecfdf5; color: #047857; cursor: pointer; font-weight: 700; user-select: none; padding: 0 6px; }
td.to-cell { display: table-cell; }
.to-cell.soft { background: #fef3c7; color: #92400e; }
.to-cell.hard { background: #fee2e2; color: #b91c1c; }
.to-legend { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 8px; font-size: 13px; }
.to-legend .to-cell { cursor: default; min-width: 0; }

/* ---------- timetable ---------- */
.tt-toolbar .kind-select { max-width: 190px; }
.tt-toolbar .entity-select { max-width: 200px; }
.tt-toolbar .hl-select { max-width: 200px; }
.tt-wrap { --z: var(--tt-zoom, 1); }
.tt-scroll { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 6px; }
.tt-grid { border-collapse: separate; border-spacing: 3px; width: 100%; table-layout: fixed; }
.tt-grid th { font-weight: 700; font-size: calc(12.5px * var(--z)); color: #374151; padding: 4px; background: var(--bg); border-radius: 8px; text-align: center; }
.tt-grid th.corner { width: 64px; background: transparent; }
.tt-grid th.dh { white-space: nowrap; }
.tt-grid .ph-time { font-size: calc(10.5px * var(--z)); color: var(--muted); font-weight: 500; white-space: nowrap; direction: ltr; unicode-bidi: isolate; }
.tt-grid td.slot { vertical-align: top; background: #fff; border: 1px dashed var(--border-strong); border-radius: 8px; height: calc(66px * var(--z)); padding: 3px; position: relative; transition: background .12s; }
.tt-grid td.slot:hover { border-color: var(--primary); }
.tt-grid td.slot.off-hard { background: repeating-linear-gradient(45deg, #f3f4f6 0 6px, #e5e7eb 6px 12px); }
.tt-grid td.slot.off-soft { background: #fef9c3; }
.tt-grid.flip th.corner { width: 64px; }
.tt-grid.flip td.slot { height: calc(60px * var(--z)); }
.card { position: relative; border-radius: 7px; padding: 4px 6px; font-size: calc(12px * var(--z)); line-height: 1.3; cursor: grab; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: manipulation; min-height: 100%; display: flex; flex-direction: column; justify-content: center; text-align: center; }
.card + .card { margin-top: 3px; }
.card .line { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .l-subj { font-weight: 800; }
.card .l-group { font-size: .85em; opacity: .9; }
.card.locked { outline: 2px solid rgba(0, 0, 0, .45); outline-offset: -2px; }
.card .lock { position: absolute; top: 1px; inset-inline-end: 3px; font-size: 10px; line-height: 1; }
.card.conflict { box-shadow: 0 0 0 3px var(--danger); }
.card.overlapping::after { content: attr(data-multi) '×'; position: absolute; bottom: 1px; inset-inline-end: 4px; font-size: 10px; opacity: .8; }
.card.dragging { opacity: .35; }
.card.ghost { position: fixed; z-index: 1000; pointer-events: none; opacity: .92; box-shadow: 0 10px 28px rgba(0, 0, 0, .35); transform: scale(1.04); cursor: grabbing; min-height: 0; max-height: none; margin: 0; }
.card.flash { animation: flash 1s ease-in-out 3; }
.card.dim { opacity: .28; }
.card.hl { box-shadow: 0 0 0 3px #f59e0b; }
.card .count, .card .len { position: absolute; top: 2px; inset-inline-start: 4px; font-size: 10px; background: rgba(0, 0, 0, .25); color: #fff; padding: 0 5px; border-radius: 999px; }
.card .len { inset-inline-start: auto; inset-inline-end: 4px; }
@keyframes flash { 0%, 100% { box-shadow: 0 0 0 0 rgba(245, 158, 11, 0); } 50% { box-shadow: 0 0 0 5px rgba(245, 158, 11, .9); } }
td.slot.drop-ok { background: rgba(22, 163, 74, .16) !important; border: 2px solid var(--ok) !important; }
td.slot.drop-bad { background: rgba(220, 38, 38, .12) !important; border: 2px solid var(--danger) !important; }
td.slot.drop-swap { background: rgba(217, 119, 6, .18) !important; border: 2px solid var(--warn) !important; }
td.slot.drop-origin { border: 2px dashed var(--primary) !important; }
td.slot.drop-hover { box-shadow: inset 0 0 0 3px var(--primary); }
.card.selected { box-shadow: 0 0 0 3px var(--primary), 0 4px 14px rgba(0, 0, 0, .3); z-index: 2; }
.overview .card.selected { box-shadow: inset 0 0 0 2px #fff, 0 0 0 2px var(--primary); }
.tt-wrap.has-sel td.slot.drop-ok, .tt-wrap.has-sel td.slot.drop-swap { cursor: pointer; }
.tt-wrap.has-sel td.slot.drop-bad { cursor: not-allowed; }
/* ---------- overviews: dense grid (aSc-like) ---------- */
.tt-grid.overview { border-collapse: collapse; border-spacing: 0; table-layout: auto; width: auto; min-width: 100%; --cell-h: calc(26px * var(--z)); --cell-w: calc(38px * var(--z)); font-size: calc(11.5px * var(--z)); }
.overview th, .overview td.slot { border: 1px solid #d9dce3; border-radius: 0; padding: 0; }
.overview thead th { background: #f1f3f7; font-weight: 600; color: #374151; font-size: calc(11px * var(--z)); height: 22px; line-height: 22px; padding: 0 4px; }
.overview thead th.dh { font-size: calc(12px * var(--z)); font-weight: 700; }
.overview th.corner { width: auto; background: #f1f3f7; font-size: 11px; color: var(--muted); }
.overview td.slot { height: var(--cell-h); width: var(--cell-w); min-width: var(--cell-w); background: #fff; vertical-align: middle; transition: none; }
.overview td.slot:hover { border-color: #d9dce3; box-shadow: inset 0 0 0 2px var(--primary); }
.overview td.slot.off-hard { background: repeating-linear-gradient(45deg, #eef0f4 0 4px, #e2e5eb 4px 8px); }
.overview .card { border-radius: 0; padding: 0 2px; margin: 0; min-height: var(--cell-h); height: 100%; font-size: calc(11.5px * var(--z)); font-weight: 700; line-height: 1.1; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12); }
.overview .card + .card { margin-top: 0; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .12), 0 -1px 0 #fff; }
.overview td.slot.covered .card, .overview .card.overlapping { font-size: calc(10px * var(--z)); }
.overview .card .line { font-weight: 700; }
.overview .card.locked { outline-width: 1px; outline-offset: -1px; }
.overview .card .lock { display: none; }
.overview .card.locked::before { content: ''; position: absolute; top: 0; inset-inline-start: 0; border: 4px solid transparent; border-top-color: rgba(0, 0, 0, .6); border-inline-start-color: rgba(0, 0, 0, .6); }
.overview .card.conflict { box-shadow: inset 0 0 0 2px var(--danger); }
.overview .card.overlapping::after { font-size: 8px; bottom: 0; inset-inline-end: 1px; }
.overview .card .count, .overview .card .len { display: none; }
.overview th.rh { text-align: start; white-space: nowrap; max-width: 170px; overflow: hidden; text-overflow: ellipsis; padding: 0 8px; font-weight: 600; font-size: calc(12px * var(--z)); background: var(--surface); }
.overview th.rh .link { display: inline-block; max-width: 120px; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; color: var(--text); text-decoration: none; }
.overview th.rh .rh-name { display: inline-block; max-width: 112px; overflow: hidden; text-overflow: ellipsis; vertical-align: middle; }
.overview th.sel-head { cursor: pointer; user-select: none; -webkit-user-select: none; }
.overview thead th.sel-head:hover, .overview th.rh:hover { background: var(--primary-soft); }
.overview th.strip.sel-head:hover { filter: brightness(.95); }
.open-btn { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border: 0; border-radius: 6px; background: transparent; color: var(--primary); font: inherit; font-size: 12px; cursor: pointer; padding: 0; margin-inline-start: 2px; vertical-align: middle; opacity: 0; }
.overview tbody tr:hover .open-btn, .open-btn:focus-visible { opacity: 1; }
.open-btn:hover { background: var(--primary); color: #fff; }
.grid-tip { position: fixed; z-index: 1300; max-width: min(320px, calc(100vw - 16px)); background: #111827; color: #fff; font-size: 12px; line-height: 1.4; padding: 6px 10px; border-radius: 8px; box-shadow: 0 6px 18px rgba(0, 0, 0, .25); white-space: pre-line; pointer-events: none; }
.ctx-menu { position: fixed; z-index: 1200; width: min(280px, calc(100vw - 16px)); background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); padding: 4px 0; font-size: 13px; }
.ctx-title { font-weight: 700; font-size: 12.5px; color: var(--muted); padding: 4px 12px 2px; }
.ctx-line { display: flex; align-items: center; gap: 6px; padding: 5px 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; width: 100%; border: 0; background: transparent; font-family: inherit; font-size: 13px; color: var(--text); text-align: start; }
button.ctx-line { cursor: pointer; }
button.ctx-line:hover { background: var(--primary-soft); }
.ctx-hand { margin-inline-start: auto; color: var(--primary); font-size: 14px; }
[dir="rtl"] .ctx-hand { transform: scaleX(-1); }
.ctx-line .swatch { width: 12px; height: 12px; flex: none; }
.ctx-menu hr { margin: 4px 0; }
.ctx-menu .menu-item { padding: 6px 12px; font-size: 13px; border-radius: 0; gap: 8px; }
.ctx-menu .menu-item .ico { width: 18px; font-size: 13px; }
.ctx-menu .menu-item.ok .ico { color: var(--ok); font-weight: 800; }
.ctx-menu .menu-item:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.card.msel { box-shadow: inset 0 0 0 2px #111827, 0 0 0 2px #fbbf24; }
td.slot.in-sel { background: #fef3c7 !important; }
td.slot.cross-cell { box-shadow: inset 0 0 0 200px rgba(79, 70, 229, .07); }
.tt-grid th.cross, .overview th.rh.cross { background: var(--primary) !important; color: #fff !important; }
.overview th.rh.cross .open-btn, .overview th.rh.cross .note-btn { color: #fff; }
.overview td.slot.in-sel.off-hard { background: repeating-linear-gradient(45deg, #fde68a 0 4px, #fcd34d 4px 8px) !important; }
.overview th.sel-head.active, .tt-grid th.sel-head.active { background: #fbbf24 !important; color: #111827; }
.overview th.strip.sel-head.active { box-shadow: inset 0 0 0 2px #f59e0b; }
.tt-grid th.sel-head { cursor: pointer; }
.overview .card.msel { box-shadow: inset 0 0 0 2px #fbbf24, inset 0 0 0 3px #111827; }
.zoom-box { display: inline-flex; align-items: center; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); height: 36px; }
.zoom-box .zoom-btn { width: 30px; height: 34px; border-radius: 8px; font-size: 18px; }
.ico-svg { display: inline-flex; line-height: 0; }
.undo-box { padding: 0 2px; }
.undo-box .hist-btn { width: 32px; height: 34px; border-radius: 8px; color: #374151; }
.undo-box .hist-btn:hover:not(:disabled) { background: var(--primary-soft); color: var(--primary); }
.undo-box .hist-btn:disabled { opacity: .3; }
[dir="rtl"] .undo-box .ico-svg { transform: scaleX(-1); }
.zoom-val { border: 0; background: transparent; font: inherit; font-size: 12px; font-weight: 700; color: var(--muted); min-width: 44px; padding: 0 2px; cursor: pointer; font-variant-numeric: tabular-nums; }
.zoom-val:hover { color: var(--primary); }
.cards-bar { position: sticky; top: calc(var(--topbar-h) + 4px); z-index: 5; }
.overview tbody tr:hover th.rh { background: var(--primary-soft); }
.overview tbody tr:hover td.slot:not(.off-hard) { background: #fafbff; }
.note-btn { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border: 0; border-radius: 8px; background: transparent; font: inherit; font-size: 14px; line-height: 1; cursor: pointer; vertical-align: middle; padding: 0; }
.note-btn.empty { opacity: .3; filter: grayscale(1); }
.note-btn:hover, .note-btn.empty:hover { opacity: 1; filter: none; background: var(--bg); }
.note-btn.has-note { color: var(--warn); }
.overview th.rh .note-btn { width: 18px; height: 18px; font-size: 11px; margin-inline-start: 2px; }
.overview th.rh .note-btn.empty { display: none; }
.overview tbody tr:hover th.rh .note-btn.empty { display: inline-flex; }
.tt-toolbar .note-btn { width: 38px; height: 38px; font-size: 17px; }
.overview .sticky-col { position: sticky; inset-inline-start: 0; z-index: 3; background: var(--surface); }
/* subject strip before each teacher name in the all-teachers overview */
.overview col.col-strip { width: var(--strip-w, 10px); }
.overview col.col-rh { width: 150px; }
.overview th.strip { --strip-w: 10px; width: var(--strip-w); min-width: var(--strip-w); max-width: var(--strip-w); padding: 0; background: color-mix(in srgb, var(--subj, var(--border)) 25%, var(--surface)); border-inline-end: 2px solid var(--subj, var(--border)); overflow: hidden; position: sticky; }
.overview th.strip.active { background: var(--subj, var(--border)); }
.overview th.strip.active .strip-text { color: #fff; }
.overview.has-strips th.rh { inset-inline-start: 10px; }
.strip-btn { position: absolute; inset: 0; display: block; width: 100%; height: 100%; border: 0; padding: 0; background: transparent; cursor: pointer; font: inherit; pointer-events: none; }
.strip-btn:hover { background: color-mix(in srgb, var(--subj, var(--border)) 30%, transparent); }
.strip-text { position: absolute; top: 0; inset-inline: 0; display: flex; justify-content: center; font-size: 8.5px; font-weight: 700; line-height: 1; color: var(--text); letter-spacing: .03em; opacity: .9; will-change: transform; }
.strip-text::before { content: attr(data-label); writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; }
[dir="rtl"] .strip-text::before { transform: none; }
.subject-chip { gap: 6px; color: var(--text); border-color: var(--subj); }
.overview thead th { position: sticky; top: 0; z-index: 2; }
.overview thead tr:nth-child(2) th { top: 23px; }
.overview thead th.corner { z-index: 4; }
.overview td.day-start, .overview th.day-start { border-inline-start: 2px solid #9aa0ad; }
.overview-scroll { max-height: calc(100vh - 190px); overflow: auto; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); } /* max-height is refined by fitOverview() to the space actually left */
/* fit mode: the whole week in the available width */
.tt-grid.overview.fit { table-layout: fixed; width: 100%; min-width: 0; } /* min-width is set by fitOverview() so cells never shrink below readable */
.overview.fit td.slot { width: auto; min-width: 0; overflow: hidden; }
.overview.fit th.rh { max-width: 150px; }
.overview.fit th.rh .link { max-width: 112px; }
.overview.fit thead th.ph { padding: 0; overflow: hidden; font-size: min(11px, calc(var(--fit-font, 11px) + 1px)); }
.overview.fit .card { font-size: var(--fit-font, 11px); padding: 0 1px; }
.overview.fit .card .line { overflow: hidden; text-overflow: clip; }
.overview.fit.narrow thead th.dh { font-size: 10.5px; padding: 0 2px; overflow: hidden; }
.overview.fit.one-day { table-layout: fixed; }
.overview.fit.one-day .card { font-size: calc(12px * var(--z)); }
.tray { margin-top: 12px; padding: 10px 12px; background: var(--surface); border: 2px dashed var(--border-strong); border-radius: var(--radius); }
.tray.drop-ok { border-color: var(--ok); background: #ecfdf5; }
.tray-title { font-weight: 700; margin-bottom: 8px; font-size: 14px; }
.tray-list { display: flex; flex-wrap: wrap; gap: 8px; }
.tray-card { min-width: 120px; max-width: 170px; min-height: 48px; }
.hint { margin-top: 8px; }
.conflicts { margin-bottom: 12px; }
.conflict-list { margin: 0; padding: 8px 24px; max-height: 240px; overflow: auto; font-size: 13.5px; }
.conflict-list li { margin: 4px 0; }
.slot-picks { display: flex; flex-wrap: wrap; gap: 6px; }
.pick { border: 1px solid var(--border-strong); background: #fff; border-radius: 8px; padding: 6px 10px; font: inherit; font-size: 13px; cursor: pointer; }
.pick.ok { border-color: #a7f3d0; background: #ecfdf5; color: #047857; }
.pick:hover { filter: brightness(.96); }
.choose-list { display: flex; flex-direction: column; gap: 4px; }
.choose-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px; border: 1px solid var(--border); border-radius: 10px; background: #fff; font: inherit; text-align: start; cursor: pointer; }
.choose-item.ok { border-color: #a7f3d0; }
.choose-item.bad { opacity: .6; }
.choose-item .status { font-weight: 800; }
.choose-item.ok .status { color: var(--ok); }
.choose-item.bad .status { color: var(--danger); }
.progress { height: 12px; background: var(--bg); border-radius: 999px; overflow: hidden; margin-bottom: 8px; border: 1px solid var(--border); }
.progress-bar { height: 100%; background: var(--primary); transition: width .2s; }
.progress-bar.done { background: var(--ok); }
.progress-bar.partial { background: var(--warn); }
.status-line { font-weight: 700; margin-bottom: 4px; }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .sidenav { display: none; }
  .side-btn { display: none; }
  .nav-select { display: inline-block; max-width: 38vw; }
  .topbar .spacer { flex: 1 0 8px; }
  .view { padding: 12px; padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
  .brand-name { font-size: 15px; }
  .toolbar .search { max-width: none; flex: 1 1 160px; }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { width: 100% !important; max-height: 92vh; border-radius: 16px 16px 0 0; transform: translateY(30px); }
  .modal-body { padding: 14px; }
  .modal-foot { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .table th, .table td { padding: 8px 6px; font-size: 14px; }
  .tt-toolbar .kind-select, .tt-toolbar .entity-select, .tt-toolbar .hl-select { max-width: none; flex: 1 1 140px; }
  .tt-toolbar .picker { flex: 1 1 200px; }
  .tt-toolbar .picker select { flex: 1; }
}
@media (max-width: 720px) {
  .hide-sm { display: none !important; }
  .subtab { padding: 6px 8px; font-size: 13px; gap: 4px; }
  .subtab .badge { font-size: 10.5px; min-width: 16px; line-height: 17px; padding: 0 4px; }
  .tt-grid.flip .ph-end { display: none; }
  .tt-grid.flip th.ph { padding: 3px 2px; }
  .tt-scroll { padding: 3px; }
  .tt-grid { border-spacing: 2px; }
  .tt-grid th.corner { width: 44px; }
  .tt-grid.flip th.corner { width: 44px; }
  .tt-grid th { font-size: calc(11.5px * var(--z)); padding: 3px 1px; }
  .tt-grid .ph-time { font-size: calc(9.5px * var(--z)); }
  .tt-grid td.slot { padding: 2px; height: calc(56px * var(--z)); border-radius: 6px; }
  .card { font-size: calc(11px * var(--z)); padding: 3px 3px; border-radius: 5px; }
  .tray-card { min-width: 100px; max-width: 140px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .overview col.col-rh { width: 84px; }
  .overview.fit th.corner, .overview.fit th.rh { max-width: 84px; padding: 0 4px; font-size: 11px; }
  .overview.fit th.rh .link, .overview.fit th.rh .rh-name { max-width: 66px; }
  .open-btn { opacity: 1; }
  .overview col.col-strip { width: 8px; }
  .overview.fit th.strip { --strip-w: 8px; }
  .overview.fit.has-strips th.rh { inset-inline-start: 8px; }
  .overview.fit th.rh .note-btn { display: none; }
  .overview td.slot { height: calc(22px * var(--z)); }
  .filter-bars { gap: 4px 10px; }
  .filter-panel { padding: 6px 8px; margin-bottom: 8px; }
  body[data-route="timetable"] .view { padding: 6px 4px calc(12px + env(safe-area-inset-bottom)); }
  .tt-toolbar { margin-bottom: 6px; }
  .overview-scroll { border-radius: 6px; }
  .tt-toolbar .chips { order: 5; }
}
@media (min-width: 861px) {
  .view { padding: 20px 24px; }
}

/* ---------- print ---------- */
#print-all { display: none; }
@media print {
  @page { size: landscape; margin: 10mm; }
  body { background: #fff; }
  .topbar, .sidenav, .toolbar, .tray, .hint, .conflicts, .toasts, .modal-backdrop, .subtabs, .note-btn { display: none !important; }
  .view { padding: 0 !important; }
  .tt-scroll { border: 0; padding: 0; max-height: none !important; overflow: visible !important; }
  .tt-grid td.slot { border: 1px solid #999; border-radius: 0; break-inside: avoid; }
  .tt-grid th { border-radius: 0; background: #eee; color: #000; }
  .card { -webkit-print-color-adjust: exact; print-color-adjust: exact; cursor: default; }
  .overview .sticky-col, .overview thead th { position: static; }
  body.print-all #app { display: none !important; }
  body.print-all #print-all { display: block; }
  .print-page { break-after: page; page-break-after: always; }
  .print-page:last-child { break-after: auto; page-break-after: auto; }
  .print-title { font-size: 16px; margin: 0 0 6px; }
}
