/* 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: grid; grid-template-columns: 1fr auto 1fr; 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); }
.bar-left { display: flex; align-items: center; gap: 6px; min-width: 0; }
.bar-mid { display: flex; align-items: center; justify-content: center; min-width: 0; }
.bar-right { display: flex; align-items: center; justify-content: flex-end; gap: 6px; min-width: 0; }
.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; }
/* notes: a scratchpad pinned to the far side of the app, collapsed by default */
.notes-panel { width: var(--notes-w, 300px); flex: none; display: flex; flex-direction: column; gap: 6px; background: var(--surface); padding: 10px 12px; position: sticky; top: var(--topbar-h); height: calc(100vh - var(--topbar-h)); }
/* always pinned to the physical left of the window, whichever way the interface reads */
[dir="rtl"] .notes-panel { border-left: 0; border-right: 1px solid var(--border); }
[dir="ltr"] .notes-panel { order: -1; border-right: 0; border-left: 1px solid var(--border); }
.notes-head { display: flex; align-items: center; gap: 8px; }
.notes-area { flex: 1; width: 100%; resize: none; border: 1px solid var(--border); border-radius: 10px; padding: 10px; font: inherit; font-size: 14px; line-height: 1.6; background: #fffef7; color: var(--text); }
.notes-area:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.notes-foot { line-height: 1.4; }
.notes-saved { color: var(--ok); }
.notes-grip { position: absolute; top: 0; bottom: 0; width: 6px; cursor: col-resize; z-index: 2; }
[dir="rtl"] .notes-grip { right: auto; left: -3px; }
[dir="ltr"] .notes-grip { left: auto; right: -3px; }
.notes-grip:hover { background: var(--primary-soft); }
.notes-btn.on { color: var(--primary); background: var(--primary-soft); }
.notes-close { width: 28px; height: 28px; font-size: 14px; }
.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 { width: auto; min-height: 36px; padding-block: 4px; padding-inline: 10px 28px; font-weight: 700; max-width: 46vw; }
/* page navigation in the middle of the bar; JS hides whichever of the two does not fit (see fitNav) */
.nav-seg { display: flex; align-items: center; gap: 2px; min-width: 0; max-width: 100%; overflow: hidden; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.nav-seg .seg { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; border: 0; background: transparent; color: var(--text); font: inherit; font-size: 13.5px; font-weight: 600; padding: 5px 12px; border-radius: 8px; cursor: pointer; }
.nav-seg .seg:hover { background: var(--surface); }
.nav-seg .seg.active { background: var(--surface); color: var(--primary); box-shadow: var(--shadow); }
.nav-seg .seg-icon { font-size: 15px; line-height: 1; }
.nav-seg.compact .seg-label { display: none; }
.nav-seg.compact .seg { padding: 5px 10px; }
[data-theme="dark"] .nav-seg .seg:hover, [data-theme="dark"] .nav-seg .seg.active { background: #232b3a; }
.page { display: flex; flex-direction: column; gap: 14px; width: 100%; max-width: 1100px; margin-inline: auto; }   /* centred, not hugging the start edge on a wide screen */
.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; }
.toolbar .subj-filter { max-width: 200px; }
.picker { display: inline-flex; align-items: center; gap: 2px; }
.picker select { min-width: 140px; }
.checklist { display: flex; flex-direction: column; gap: 6px; max-height: 210px; overflow: auto; padding: 6px; border: 1px solid var(--border); border-radius: 10px; background: #fafafa; }
.checklist .check-items { display: flex; flex-wrap: wrap; gap: 6px; }
.check-bar { display: flex; align-items: center; gap: 6px; padding: 0 2px 4px; border-bottom: 1px solid var(--border); position: sticky; top: -6px; background: #fafafa; z-index: 1; }
.check-bar .link { font-size: 12.5px; }
.check-bar .link:disabled { color: var(--muted); cursor: default; text-decoration: none; }
.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; }
.check-note { font-size: 11.5px; color: var(--muted); }
.check.check-free { background: #f0fdf4; border-color: #bbf7d0; }
.check.check-free .check-note { color: #047857; }
.check.check-mine { background: var(--primary-soft); border-color: rgba(79, 70, 229, .35); }
.check.check-mine .check-note { color: var(--primary); }
.check.check-shared { background: #fde68a; border-color: #d97706; }
.check.check-shared .check-note { color: #78350f; font-weight: 700; }
.share-row { margin-bottom: 6px; font-size: 13px; }
.check.check-taken { background: #fff7ed; border-color: #fed7aa; }
.check.check-taken .check-note { color: #b45309; font-weight: 600; }
.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; }
/* the subject picture: a preview beside the buttons that change it, and the gallery it can be picked from */
.subj-thumb { width: 20px; height: 20px; object-fit: contain; vertical-align: middle; }
.pic-field { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.pic-box { width: 64px; height: 64px; flex: none; display: grid; place-items: center; padding: 4px; border: 1px solid var(--border-strong); border-radius: 10px; background: #fff; }
.pic-preview { max-width: 100%; max-height: 100%; object-fit: contain; }
.pic-actions { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.row-btns { display: flex; gap: 6px; flex-wrap: wrap; }
.art-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(88px, 1fr)); gap: 8px; }
.art-tile { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 4px; border: 1px solid var(--border); border-radius: 10px; background: #fff; cursor: pointer; font-size: 12px; color: #334155; }
.art-tile img { width: 44px; height: 44px; object-fit: contain; }
.art-tile:hover { border-color: var(--primary); }
.art-tile.active { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(37, 99, 235, .2); }
.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); }
/* the count under a table */
.row-count { padding: 6px 2px 0; text-align: start; }
.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); }
/* the filters are only set aside while a goal is on show: the badge still counts them, dimmed */
.filter-btn.paused { opacity: .6; }
.filter-btn.paused .filter-badge { background: var(--muted); }
.filters-paused { margin: 0; }
.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; }
.rules-preview .panel-head { gap: 12px; flex-wrap: wrap; }
.av-box { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; margin-bottom: 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); }
.av-stats { display: flex; flex-wrap: wrap; gap: 8px; }
.av-stat { flex: 1 1 130px; padding: 8px 10px; border-radius: 8px; background: var(--surface); border: 1px solid var(--border); }
.av-stat .av-value { font-size: 18px; font-weight: 800; line-height: 1.2; font-variant-numeric: tabular-nums; }
.av-stat .av-label { font-size: 12px; color: var(--muted); }
.av-stat.ok .av-value { color: var(--ok); } .av-stat.warn .av-value { color: var(--warn); } .av-stat.bad .av-value { color: var(--danger); }
.preview-teacher { width: 280px; max-width: 100%; }
.preview-who { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.rules-preview tr.row-bad td { background: #fef2f2; }
.combo { position: relative; display: inline-block; min-width: 0; }
.combo .combo-input { width: 100%; padding-inline-end: 26px; }
.combo-caret { position: absolute; inset-inline-end: 8px; top: 50%; transform: translateY(-60%); color: var(--muted); pointer-events: auto; cursor: pointer; font-size: 13px; }
.combo-list { position: absolute; z-index: 60; inset-inline: 0; top: calc(100% + 2px); max-height: 260px; overflow: auto; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: 0 10px 26px rgba(0, 0, 0, .16); padding: 4px; }
.combo-item { padding: 7px 10px; border-radius: 7px; cursor: pointer; font-size: 13.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.combo-item:hover, .combo-item.active { background: var(--primary-soft); }
.combo-item.chosen { font-weight: 700; color: var(--primary); }
.combo-empty { padding: 8px 10px; }
.target-box { display: flex; flex-direction: column; gap: 8px; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--bg); }
.target-chips { display: flex; flex-wrap: wrap; gap: 6px; min-height: 26px; align-items: center; }
.target-chip { gap: 6px; background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.target-chip .target-kind { font-size: 10px; font-weight: 800; color: var(--muted); background: var(--bg); padding: 0 5px; border-radius: 999px; }
.target-chip.k-teacher { border-inline-start: 3px solid var(--primary); }
.target-chip.k-subject { border-inline-start: 3px solid var(--ok); }
.target-chip.k-tag { border-inline-start: 3px solid var(--warn); }
.target-adds { display: flex; flex-wrap: wrap; gap: 6px; }
.target-add { width: 190px; max-width: 100%; }
.target-add .combo-input { min-height: 34px; font-size: 13px; }
.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; }
.class-chips { display: inline-flex; flex-wrap: wrap; gap: 3px; max-width: 260px; }
.class-chip { padding: 0 6px; border-radius: 5px; background: var(--bg); border: 1px solid var(--border); font-size: 11.5px; font-weight: 600; white-space: nowrap; }
.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-xl { width: min(1200px, 100%); }
.overlay-grid .tt-wrap { --z: var(--tt-zoom, 1); }
.overlay-grid .hint { margin: 6px 0 0; }
.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; }
/* a slot may hold several lessons at once (a subject across its classes, a room, parallel groups): they share
   the cell instead of each demanding its full height, which used to make them overlap */
.tt-grid td.slot .card:not(:only-child) { min-height: 0; }
.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; }
/* the second half of a double lesson is drawn a touch lighter, but that rule is more specific than .dim was:
   a dimmed continuation has to fade like everything else */
.overview .card.cont.dim { opacity: .28; }
/* a dimmed card recedes altogether: the lock's dark outline and corner mark would otherwise still stand out */
.card.dim.locked { outline-color: transparent; }
.overview .card.dim.locked::before { display: none; }
.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)); --grid-line: #d9dce3; --head-bg: #f1f3f7; --head-hov: color-mix(in srgb, var(--primary) 11%, var(--head-bg)); --row-hov: color-mix(in srgb, var(--primary) 11%, var(--surface)); font-size: calc(11.5px * var(--z)); }
.overview th, .overview td.slot { border: 1px solid var(--grid-line); border-radius: 0; padding: 0; }
.overview thead th { background: var(--head-bg); 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: var(--head-bg); 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)); }
/* a class's row names the subject and the teacher under it: the second line reads as a caption */
.overview .card .l-teach { font-size: .82em; font-weight: 600; opacity: .85; }
.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; }
.rh-in { display: flex; align-items: center; gap: 2px; min-width: 0; }
.overview th.rh .rh-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* the tags a teacher carries, beside their name in the overview: a tap filters the rows by one */
/* the name in a subject's table is a button: it picks that teacher's cards out of the tray below */
.rh-name-btn { border: 0; background: transparent; color: inherit; font: inherit; padding: 0; text-align: start; cursor: pointer; }
.rh-name-btn:hover { color: var(--primary); }
.rh-name-btn.on { color: var(--primary); font-weight: 800; }
.rh-tags { display: flex; gap: 2px; flex: 0 1 auto; min-width: 0; overflow: hidden; }
.rh-tag { max-width: 66px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 5px; border: 0; border-radius: 999px; font: inherit; font-size: 9.5px; font-weight: 700; line-height: 15px; cursor: pointer; background: var(--primary-soft); color: var(--primary); }
.rh-tag.smart { background: color-mix(in srgb, var(--tg, var(--primary)) 22%, transparent); color: var(--tg, var(--primary)); }
.rh-tag:hover { filter: brightness(.94); }
.rh-tag.on { background: var(--tg, var(--primary)); color: #fff; }
.overview.has-tags col.col-rh { width: 218px; }
/* the same chips beside a single teacher's own timetable, in the toolbar and over the dialog */
.tt-tags { gap: 4px; }
.tt-tags .rh-tag { max-width: 160px; font-size: 11px; line-height: 20px; padding: 0 9px; }
/* the tags ride beside the name in the dialog's heading */
.overlay-title { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.overlay-title .tt-tags { display: inline-flex; }
.overview th.rh .open-btn, .overview th.rh .note-btn { flex: none; }
.overview th.sel-head { cursor: pointer; user-select: none; -webkit-user-select: none; }
.overview thead th.sel-head:hover { background: var(--head-hov); }
.overview th.rh:hover { background: var(--row-hov); }
.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.band { background: #e0e7ff !important; box-shadow: inset 0 0 0 1px var(--primary); }
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(--row-hov); }
.tt-grid tbody tr:hover > th { background: var(--primary-soft); }
.overview tbody tr:hover > th.strip:not(.active) { background: color-mix(in srgb, var(--primary) 11%, var(--strip-bg)); }
.tt-grid thead th.hov { background: var(--primary-soft); color: var(--primary); }
.overview thead th.hov { background: var(--head-hov); color: var(--primary); }
.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; }
/* a note button that is still empty keeps its place, faded: hiding it made the icons jump as rows gained notes */
.overview th.rh .note-btn.empty { opacity: .28; }
.overview tbody tr:hover .note-btn.empty { opacity: .7; }
.overview tbody tr:hover th.rh .note-btn.empty { display: inline-flex; }
.tt-toolbar .note-btn { width: 38px; height: 38px; font-size: 17px; }
/* frozen name column: opaque, and always under the frozen header rows (see the z-index ladder below) */
.overview .sticky-col { position: sticky; inset-inline-start: -1px; z-index: 20; 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: 164px; }
.overview th.strip { --strip-w: 16px; --strip-bg: color-mix(in srgb, var(--subj, var(--border)) 25%, var(--surface)); width: var(--strip-w); min-width: var(--strip-w); max-width: var(--strip-w); padding: 0; background: var(--strip-bg); 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: 9px; }
.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: 10.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); }
/* z-index ladder for the frozen edges: cards (auto..2) < name column (20) < header rows (30) < corner (40),
   so nothing scrolling underneath can surface through them */
.overview thead th { position: sticky; top: -1px; z-index: 30; }
/* Collapsed borders are painted by the table, not by the cell, so a frozen cell leaves its own seams
   behind as the grid scrolls under it. The frozen header and name column redraw the edges they lose. */
.overview thead th { box-shadow: inset 0 -1px 0 var(--grid-line); }
.overview th.rh { box-shadow: inset -1px 0 0 var(--grid-line); }
.overview thead th.corner { box-shadow: inset 0 -1px 0 var(--grid-line), inset -1px 0 0 var(--grid-line); }
.overview th.strip { box-shadow: inset -2px 0 0 var(--subj, var(--grid-line)); }
[dir="rtl"] .overview th.rh { box-shadow: inset 1px 0 0 var(--grid-line); }
[dir="rtl"] .overview thead th.corner { box-shadow: inset 0 -1px 0 var(--grid-line), inset 1px 0 0 var(--grid-line); }
[dir="rtl"] .overview th.strip { box-shadow: inset 2px 0 0 var(--subj, var(--grid-line)); }
.overview thead tr:nth-child(2) th { top: calc(var(--head1-h, 23px) - 2px); }   /* set by headOffset() from the day row's real height, which grows with the zoom */
.overview.measuring thead th, .overview.measuring .sticky-col { position: static; }   /* headOffset() reads where the rows really sit, not where they are stuck */
.overview thead th.corner { z-index: 40; }
.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); padding: 0; } /* no padding: it would sit outside the frozen header and name column, and rows would scroll through it. max-height is refined by fitOverview() */
/* 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: 164px; }
.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 { display: flex; align-items: center; gap: 10px; 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; }
.conflict-list .goal-fix { width: 24px; height: 24px; font-size: 13px; vertical-align: middle; margin-inline-start: 4px; }
.conflict-list li.ignored { opacity: .45; }
.conflict-list li.ignored .link { color: var(--muted); text-decoration: line-through; }
.conflict-list li.ignored .ignore-btn, .conflict-list li:hover .ignore-btn { opacity: 1; }
.conflict-list .ignore-btn { opacity: .5; }
.conflicts .panel-head .chip { margin-inline-end: auto; }
.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; }
  .notes-panel { position: fixed; inset-inline: 0; top: var(--topbar-h); bottom: 0; width: auto; height: auto; z-index: 40; border-inline-start: 0; box-shadow: 0 -8px 30px rgba(0, 0, 0, .2); }
  .notes-grip { display: none; }
  .nav-select { max-width: 38vw; }
  .nav-seg { padding: 2px; }
  .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-time { font-size: calc(9px * var(--z)); }
  .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.has-tags col.col-rh { width: 120px; }
  .rh-tag { max-width: 44px; }
  .overview.fit th.corner, .overview.fit th.rh { max-width: 84px; padding: 0 4px; font-size: 11px; }
  .overview.fit th.rh .link { 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: 7px; }   /* the strip pins a pixel out of view, so the name column follows it in */
  .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 preview ----------
   The pages themselves (.pp-sheet and what is inside) are styled by js/print.js, which shares that CSS with the
   printer and the HTML export. What follows is the window around them. */
#pp-print { display: none; }
.pp-backdrop { padding: 0; }
.pp-backdrop .modal { width: 100%; height: 100%; max-height: none; border-radius: 0; }
.pp-backdrop .modal-body { flex: 1; min-height: 0; padding: 0; display: flex; flex-direction: column; overflow: hidden; }
.pp-root { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.pp-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; background: var(--surface); }
.pp-main { display: flex; flex: 1; min-height: 0; position: relative; }
.pp-panel { width: 320px; flex: none; overflow: auto; border-inline-end: 1px solid var(--border); background: var(--surface); }
.pp-panel-in { display: flex; flex-direction: column; padding: 4px 14px 20px; }
.pp-section { display: flex; flex-direction: column; gap: 8px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.pp-section:last-of-type { border-bottom: 0; }
.pp-section-title { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pp-section .segmented { width: 100%; }
.pp-section .segmented .seg { flex: 1; }
.pp-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pp-row.pp-lines { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.pp-checks { display: flex; flex-wrap: wrap; gap: 0 14px; }
.pp-check { margin: 0; }
.pp-list .check-items { flex-direction: column; gap: 2px; }
.pp-list .check { padding: 4px 8px; font-size: 13.5px; }
.pp-days { gap: 4px; }
.pp-panel-foot { padding-top: 12px; }
.pp-pages { flex: 1; overflow: auto; background: #525659; padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 16px; outline: none; }
.pp-page-wrap { position: relative; flex: none; background: #fff; box-shadow: 0 2px 12px rgba(0, 0, 0, .55); }
.pp-page-wrap .pp-sheet { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.pp-page-wrap.current { outline: 2px solid #93c5fd; }
.pp-empty { color: #fff; opacity: .85; padding: 40px 16px; text-align: center; }
.pp-nav { display: flex; align-items: center; gap: 2px; }
.pp-nav-label { min-width: 70px; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }
.pp-zoom .zoom-val { min-width: 48px; }
.pp-zoom .pp-zoom-sel { width: auto; min-height: 32px; padding: 2px 6px; border: 0; background: transparent; font-size: 12.5px; }
.pp-opts-btn { display: none; }
.pp-opts-btn.on { color: var(--primary); background: var(--primary-soft); }
@media (max-width: 860px) {
  .pp-opts-btn { display: inline-flex; order: -1; }
  .pp-panel { display: none; position: absolute; inset-block: 0; inset-inline-start: 0; z-index: 2; width: min(320px, 90%); box-shadow: 0 0 30px rgba(0, 0, 0, .4); }
  .pp-root.panel-open .pp-panel { display: block; }
  .pp-pages { padding: 8px; gap: 8px; }
  .pp-bar { padding: 6px 8px; gap: 6px; }
}

/* ---------- print ---------- */
@media print {
  :root, [data-theme="dark"] { color-scheme: light; }   /* always print on white, whatever the screen theme is */
  [data-theme="dark"] body, [data-theme="dark"] .tt-grid td.slot, [data-theme="dark"] .tt-grid th { background: #fff !important; color: #111827 !important; }
  [data-theme="dark"] .overview th, [data-theme="dark"] .overview td.slot { border-color: #999 !important; }
  @page { size: landscape; margin: 10mm; }
  body { background: #fff; }
  .topbar, .sidenav, .notes-panel, .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; }
  /* the print preview's pages: they are the only thing on paper, one sheet per page, at their real size */
  body.pp-printing > :not(#pp-print) { display: none !important; }
  #pp-print { display: block !important; }
  #pp-print .pp-sheet { break-after: page; page-break-after: always; }
  #pp-print .pp-sheet:last-child { break-after: auto; page-break-after: auto; }
}

/* ---------- advanced rules ---------- */
[hidden] { display: none !important; }
.rules-table td { vertical-align: top; }
.rules-table .chip { white-space: nowrap; }
.rules-table tr.rule-off td { opacity: .55; }
.rule-desc { font-weight: 600; }
.chip.hard { background: var(--primary-soft); color: var(--primary); border-color: transparent; }
.chip.soft { background: #f3f4f6; color: #4b5563; border-color: transparent; }
.rule-preview-box { padding: 10px 12px; border-radius: 10px; background: var(--primary-soft); display: flex; flex-direction: column; gap: 4px; }
.rule-preview { font-weight: 600; }
.rules-check { margin-top: 16px; }
.conflict-list.soft { color: #92400e; }
.rules-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

/* ---------- smart tags ---------- */
/* A smart tag is earned from the timetable, not typed in, so its chip carries the tag's own colour and a bolt. */
.tag-smart { background: color-mix(in srgb, var(--tag, var(--primary)) 14%, transparent); color: color-mix(in srgb, var(--tag, var(--primary)) 72%, var(--text)); border-color: color-mix(in srgb, var(--tag, var(--primary)) 35%, transparent); }
.tag-smart.clickable:hover { border-color: var(--tag, var(--primary)); }
.tag-smart.active { background: var(--tag, var(--primary)); color: #fff; border-color: transparent; }
.tag-smart.off { opacity: .5; }
.tag-bolt { font-size: 9px; line-height: 1; opacity: .85; }
.smart-panel { margin-top: 16px; }
.cond-box { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.cond-list { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.cond { display: flex; flex-direction: column; gap: 8px; padding: 8px 10px; border: 1px solid var(--border-strong); border-radius: 10px; background: var(--bg); }
.cond-main { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cond-main .input { min-width: 0; }
.cond-main select.input { flex: 1 1 160px; }
.cond .cmp-select { flex: 0 1 130px; min-width: 100px; }
.cond .n-input { flex: 0 0 72px; width: 72px; }
.cond .tag-input-one { flex: 1 1 140px; min-width: 120px; }
.cond-main .icon-btn { margin-inline-start: auto; }
.cond-pos { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 8px; }
/* the timetable's instant filter: the chip says what it is filtering by, however long the conditions are.
   Its body reopens the dialog and the ✕ drops the filter, so the chip is a span holding two buttons. */
.adv-chip { max-width: min(420px, 100%); gap: 4px; padding-inline-end: 6px; }
.adv-chip-main { display: inline-flex; align-items: center; gap: 4px; min-width: 0; padding: 0; border: 0; background: transparent; font: inherit; color: inherit; cursor: pointer; }
.adv-chip-main:hover { color: var(--primary); }
.adv-chip-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.adv-chip .tag-x { font-size: 15px; padding: 0 2px; }
/* saved views: opened from the grid dropdown; the chip is the one you have open, with ⟳ update, ↺ revert and ✕ delete */
.filter-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.view-chip { gap: 2px; padding-inline-end: 4px; max-width: min(320px, 100%); }
.view-chip.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.view-chip.dirty { border-style: dashed; }
.view-chip-main { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.view-chip .icon-btn.view-chip-btn { width: 20px; height: 20px; font-size: 12px; border-radius: 6px; color: inherit; }
.view-chip .tag-x { font-size: 15px; padding: 0 2px; }

/* ---------- goal: move a lesson into chosen slots ---------- */
.goal-btn.active { background: var(--primary); color: #fff; }
.goal-panel { margin-bottom: 12px; border-color: #f59e0b; }
.goal-body { display: flex; flex-direction: column; gap: 8px; }
.goal-step { display: flex; align-items: center; gap: 8px; margin: 0; font-weight: 600; }
.goal-num { display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px; border-radius: 50%; background: #f59e0b; color: #fff; font-size: 12px; font-weight: 800; flex: none; }
.goal-bar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.goal-label { font-size: 12.5px; font-weight: 700; color: var(--muted); }
.goal-chip { gap: 4px; padding-inline-end: 6px; }
.goal-chip-card { background: #fffbeb; border-color: #f59e0b; color: var(--text); }
.goal-chip-target { background: var(--surface); border-color: #f59e0b; color: var(--text); }
.goal-chip .tag-x { font-size: 15px; padding: 0 2px; }
.goal-max-wrap { display: inline-flex; align-items: center; gap: 6px; }
.goal-max { width: 64px; min-width: 0; padding: 4px 8px; }
.goal-summary { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 6px; }
.goal-stats { margin-inline-start: auto; }
.goal-pager { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.goal-page-no { min-width: 120px; text-align: center; font-variant-numeric: tabular-nums; }
.goal-focus { margin: 0; }
.kbd-hint { font-size: 11px; color: var(--muted); }
kbd { display: inline-block; min-width: 16px; padding: 0 4px; border: 1px solid var(--border-strong); border-bottom-width: 2px; border-radius: 4px; background: var(--bg); font: 700 11px/16px var(--font); color: var(--text); text-align: center; }
.goal-move-no { display: inline-flex; align-items: center; justify-content: center; width: 18px; height: 18px; border-radius: 50%; background: #111827; color: #fff; font-size: 11px; font-weight: 800; margin-inline-end: 4px; }
.goal-opt { border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; background: var(--bg); }
.goal-opt.active { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); background: var(--surface); }
.goal-opt-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.goal-moves { margin: 6px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px; font-size: 13.5px; }
.goal-move-card { font-weight: 600; }
.goal-move-slots { font-variant-numeric: tabular-nums; }
.goal-rules { margin-top: 6px; display: flex; flex-direction: column; gap: 3px; font-size: 12.5px; }
.goal-rule { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.goal-rule.bad { color: #b91c1c; }
.goal-rule.ok { color: #047857; }
/* on the grid: the lesson in hand, the slots it may go to, and a previewed chain (from → to, numbered) */
.goal-mode.goal-picking .card, .goal-mode.goal-picking td.slot { cursor: pointer; }
.goal-fill-lessons { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; }
.goal-fill-chip { gap: 4px; font-size: 12px; }
.goal-fill-chip.on { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.goal-in { gap: 4px; font-weight: 700; }
.card.goal-card { box-shadow: 0 0 0 3px #f59e0b, 0 4px 14px rgba(0, 0, 0, .3); }
.overview .card.goal-card { box-shadow: inset 0 0 0 2px #fff, 0 0 0 2px #f59e0b; }
td.slot.goal-target { background: #fef3c7 !important; box-shadow: inset 0 0 0 2px #f59e0b; cursor: pointer; }
/* the hole a fill is about: the same yellow, ringed so it is not mistaken for a slot the user chose */
td.slot.goal-hole { outline: 2px dashed #b45309; outline-offset: -5px; }
td.slot.goal-from { box-shadow: inset 0 0 0 2px #ef4444; background: #fee2e2 !important; }
td.slot.goal-to { box-shadow: inset 0 0 0 2px #16a34a; background: #dcfce7 !important; }
/* the move number sits in the very corner and stays small, so the card's own text stays readable */
td.slot[data-goal-n]::before { content: attr(data-goal-n); direction: ltr; unicode-bidi: isolate; position: absolute; top: 0; inset-inline-start: 0; z-index: 3; min-width: 10px; height: 10px; padding: 0 2px; border-radius: 0 0 5px 0; background: #111827; color: #fff; font-size: 7.5px; font-weight: 800; line-height: 10px; text-align: center; box-sizing: border-box; opacity: .92; }
[dir="rtl"] td.slot[data-goal-n]::before { border-radius: 0 0 0 5px; }
td.slot.goal-to[data-goal-n]::before { background: #16a34a; }
td.slot.goal-from[data-goal-n]::before { background: #ef4444; }
td.slot.goal-swap { box-shadow: inset 0 0 0 2px #f59e0b; background: #fef3c7 !important; }
td.slot.goal-swap[data-goal-n]::before { background: #b45309; }

/* ==========================================================================
   Dark theme. The light palette above is untouched: everything here either
   redefines a token or overrides the few rules that carry a literal light
   colour. Subject colours on cards stay as they are, with their text picked
   for contrast at render time.
   ========================================================================== */
:root[data-theme="dark"] {
  --bg: #0f131a; --surface: #171c26; --text: #e6e9ef; --muted: #96a0b5; --border: #2a3240; --border-strong: #3a4455;
  --primary: #8b95ff; --primary-600: #a3abff; --primary-soft: rgba(139, 149, 255, .16);
  --danger: #f87171; --ok: #4ade80; --warn: #fbbf24;
  --shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 1px 2px rgba(0, 0, 0, .4);
  color-scheme: dark;
}
[data-theme="dark"] .table th,
[data-theme="dark"] .checklist,
[data-theme="dark"] .check-bar { background: #1d2431; }
[data-theme="dark"] .input,
[data-theme="dark"] .check,
[data-theme="dark"] .btn,
[data-theme="dark"] .combo-list,
[data-theme="dark"] .ctx-menu,
[data-theme="dark"] .pick { background: var(--surface); color: var(--text); }
[data-theme="dark"] .table tbody tr:hover { background: #1d2431; }
[data-theme="dark"] .notes-area { background: #1b2130; }
[data-theme="dark"] .field-label { color: #c3cad8; }

/* status tints: dark, low-saturation beds with bright text */
[data-theme="dark"] .chip.ok, [data-theme="dark"] .pick.ok, [data-theme="dark"] .hist-item.current,
[data-theme="dark"] .check-free { background: #10291d; border-color: #1f5137; color: #6ee7a8; }
[data-theme="dark"] .check-free .check-note { color: #6ee7a8; }
[data-theme="dark"] .chip.warn, [data-theme="dark"] .stat.warn, [data-theme="dark"] .summary-line.warn,
[data-theme="dark"] .preview-banner { background: #2c220c; border-color: #6b5312; color: #fcd34d; }
[data-theme="dark"] .chip.bad, [data-theme="dark"] .ctx-card, [data-theme="dark"] .rules-preview tr.row-bad td,
[data-theme="dark"] .check.check-taken { background: #2c1517; border-color: #6b2b2f; color: #fca5a5; }
[data-theme="dark"] .check.check-taken .check-note { color: #fdba74; }
[data-theme="dark"] .check.check-shared { background: #3a2a08; border-color: #b45309; }
[data-theme="dark"] .check.check-shared .check-note { color: #fcd34d; }
[data-theme="dark"] .check.check-mine { background: var(--primary-soft); border-color: rgba(139, 149, 255, .45); }
[data-theme="dark"] .warn-list, [data-theme="dark"] .summary-line.warn { color: #fcd34d; }
[data-theme="dark"] .role-chip.role-admin { background: #3a1518; color: #fca5a5; }
[data-theme="dark"] .role-chip.role-editor { background: #16233f; color: #93c5fd; }
[data-theme="dark"] .cloud-state.synced { color: #6ee7a8; }
[data-theme="dark"] .cloud-state.pending { color: #fcd34d; }

/* the grid */
[data-theme="dark"] .tt-grid th { background: #1d2431; color: #c3cad8; }
[data-theme="dark"] .tt-grid td.slot { background: var(--surface); }
[data-theme="dark"] .tt-grid td.slot.off-soft { background: #33290b; }
[data-theme="dark"] .tt-grid.overview { --grid-line: #2f3847; --head-bg: #1d2431; }
[data-theme="dark"] .overview thead th { color: #c3cad8; }
[data-theme="dark"] .overview th.rh { background: var(--surface); }
[data-theme="dark"] .overview td.slot.off-hard,
[data-theme="dark"] .tt-grid td.slot.off-hard { background: repeating-linear-gradient(45deg, #202634 0 4px, #2a3140 4px 8px); }
[data-theme="dark"] .overview tbody tr:hover td.slot:not(.off-hard) { background: #1b2230; }
[data-theme="dark"] .overview td.day-start, [data-theme="dark"] .overview th.day-start { border-inline-start-color: #4a5566; }
[data-theme="dark"] td.slot.in-sel { background: #3a2f0d !important; }
[data-theme="dark"] .overview td.slot.in-sel.off-hard { background: repeating-linear-gradient(45deg, #4a3c10 0 4px, #5d4a12 4px 8px) !important; }
[data-theme="dark"] td.slot.band { background: #23305c !important; }
[data-theme="dark"] .tt-grid th.sel-head.active, [data-theme="dark"] .overview th.sel-head.active { background: #b45309 !important; color: #fff; }
[data-theme="dark"] .card.msel { box-shadow: inset 0 0 0 2px #fff, 0 0 0 2px #f59e0b; }
[data-theme="dark"] .tt-grid th.cross, [data-theme="dark"] .overview th.rh.cross { background: var(--primary) !important; color: #0f131a !important; }
[data-theme="dark"] .tt-grid thead th.hov { background: var(--primary-soft); color: var(--primary); }
[data-theme="dark"] .empty { border-color: var(--border-strong); }
[data-theme="dark"] .opt-field, [data-theme="dark"] .target-box, [data-theme="dark"] .av-box, [data-theme="dark"] .diff-coll { background: #1b2130; }
[data-theme="dark"] .av-stat, [data-theme="dark"] .snap-item, [data-theme="dark"] .hist-item { background: var(--surface); }
[data-theme="dark"] .details { background: #1b2130; }
[data-theme="dark"] .chip.soft { background: #232b3a; color: #a9b3c6; }
[data-theme="dark"] .tag-smart { background: color-mix(in srgb, var(--tag, var(--primary)) 26%, #171c26); color: color-mix(in srgb, var(--tag, var(--primary)) 45%, #e6e9ef); }
[data-theme="dark"] .cond { background: #1b2130; }
[data-theme="dark"] .view-chip.active { background: var(--primary-soft); border-color: var(--primary); }
[data-theme="dark"] .goal-chip-card { background: #2c220c; }
[data-theme="dark"] .goal-opt { background: #1b2130; }
[data-theme="dark"] .goal-opt.active { background: var(--surface); }
[data-theme="dark"] td.slot.goal-target { background: #3a2f0d !important; }
[data-theme="dark"] td.slot.goal-from { background: #3b1d1d !important; }
[data-theme="dark"] td.slot.goal-to { background: #12301f !important; }
[data-theme="dark"] .goal-rule.bad { color: #fca5a5; }
[data-theme="dark"] .goal-rule.ok { color: #6ee7a8; }
/* the strip is a thin sliver, so a 25% tint that reads on white disappears on a dark surface */
[data-theme="dark"] .overview th.strip { --strip-bg: color-mix(in srgb, var(--subj, var(--border)) 62%, #1a2130); background: var(--strip-bg); }
[data-theme="dark"] .overview th.strip .strip-text { color: #0b0f16; }
[data-theme="dark"] .overview th.strip.active { background: var(--subj, var(--border)); }
[data-theme="dark"] .overview th.strip.sel-head:hover { filter: brightness(1.18); }
[data-theme="dark"] .overview th.strip.sel-head.active { box-shadow: inset 0 0 0 2px #fff; }
