/* app.css - tokens first, both themes, mobile first */
:root {
  --bg: #f7f6f2; --surface: #ffffff; --fg: #1d2430; --muted: #5c6572; --line: #e1dfd7;
  --accent: #1f5f8b; --accent-soft: #e3eef6; --accent-fg: #ffffff;
  --exam: #c7483c; --exam-soft: #fbe6e3;
  --holiday: #2f8a5b; --holiday-soft: #e1f3e8;
  --changed: #2f8a5b; --changed-soft: #e1f3e8;
  --event: #2e6fb7; --event-soft: #e3ecf8;
  --shabbat: #f1efe8; --danger: #b3261e; --ok: #2f8a5b;
  --fact: #6a4fb3; --fact-soft: #efeafb;
  --display: "Heebo", system-ui, sans-serif; --body: "Assistant", system-ui, sans-serif;
  --radius: 10px; --shadow: 0 8px 28px rgba(0,0,0,.12);
  color-scheme: light;
}
/* dark only when the viewer chose it on this device (data-theme set by the inline head script and themeBtn) */
:root[data-theme="dark"] {
  --bg: #141820; --surface: #1c2230; --fg: #eef0f4; --muted: #a2abb8; --line: #2d3544;
  --accent: #6fb0dc; --accent-soft: #1d3144; --accent-fg: #0f1722;
  --exam: #f08b80; --exam-soft: #3a2321;
  --holiday: #6fcf97; --holiday-soft: #1d3327;
  --changed: #6fcf97; --changed-soft: #1d3327;
  --event: #7fb2ec; --event-soft: #1e2d44;
  --shabbat: #1a2029; --danger: #f28b82; --ok: #6fcf97;
  --fact: #b9a4f2; --fact-soft: #2a2440;
  --shadow: 0 8px 28px rgba(0,0,0,.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0; min-height: 100%; background: var(--bg); color: var(--fg);
  font-family: var(--body); font-size: 16px; line-height: 1.45;
  padding-inline: 12px; padding-block: 0 calc(24px + env(safe-area-inset-bottom, 0px));
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2 { font-family: var(--display); margin: 0; line-height: 1.2; text-wrap: balance; }
[hidden] { display: none !important; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: calc(14px + env(safe-area-inset-top, 0px)) 8px; }
.top h1 { font-size: 1.25rem; font-weight: 800; }
.cls { margin: 0; color: var(--muted); font-weight: 600; font-size: .95rem; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; color: var(--muted); flex: 0 0 auto; }
.icon-btn.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.top-actions { display: flex; gap: 8px; flex: 0 0 auto; }
#themeBtn .ic-sun { display: none; }
:root[data-theme="dark"] #themeBtn .ic-moon { display: none; }
:root[data-theme="dark"] #themeBtn .ic-sun { display: block; }
.icon-btn:focus-visible, .tab:focus-visible, .btn:focus-visible, .day:focus-visible, .seg:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.tabs { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg); display: flex; gap: 6px; overflow-x: auto; padding-block: 6px 8px; scrollbar-width: none; margin-inline: -12px; padding-inline: 12px; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: 0 0 auto; border: 1px solid var(--line); background: var(--surface); color: var(--muted); border-radius: 999px; padding: 6px 14px; font-weight: 600; font-size: .92rem; white-space: nowrap; }
.tab.on { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.tab small { font-weight: 400; opacity: .8; margin-inline-start: 4px; }

.legend-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; padding-block: 4px 10px; }
.legend { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.install { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .82rem; font-weight: 600; }
.chip i { width: 9px; height: 9px; border-radius: 50%; flex: 0 0 auto; }
.chip.exam { background: var(--exam-soft); color: var(--exam); } .chip.exam i, .dot.exam, .bar.exam { background: var(--exam); }
.chip.holiday { background: var(--holiday-soft); color: var(--holiday); } .chip.holiday i, .dot.holiday, .bar.holiday { background: var(--holiday); }
.chip.event { background: var(--event-soft); color: var(--event); } .chip.event i, .dot.event, .bar.event { background: var(--event); }

main { display: grid; gap: 16px; }
.grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; font-variant-numeric: tabular-nums; }
.dh { text-align: center; font-size: .75rem; font-weight: 700; color: var(--muted); padding-bottom: 2px; font-family: var(--display); }
.dh .long { display: none; }
.day { position: relative; min-height: 46px; border-radius: 8px; background: var(--surface); border: 1px solid var(--line); padding: 4px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 3px; font-weight: 600; font-size: .9rem; color: var(--fg); }
.day.empty { background: transparent; border-color: transparent; }
.day.shabbat { background: var(--shabbat); color: var(--muted); }
.day.today { outline: 2px solid var(--accent); outline-offset: -2px; }
.day.has { cursor: pointer; }
.dots { display: flex; gap: 3px; }
.dot { width: 6px; height: 6px; border-radius: 50%; }
.day .chips { display: none; }

.agenda { display: grid; gap: 6px; }
.agenda h2 { font-size: 1rem; color: var(--muted); font-weight: 700; margin-block: 6px 2px; }
.row { display: grid; grid-template-columns: 44px 4px 1fr; gap: 10px; align-items: stretch; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; scroll-margin-top: 90px; }
.row.flash { animation: flash 1.2s ease-out; }
.row.past { opacity: .55; }
.row.past .bar { opacity: .6; }
.agenda .divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .82rem; font-weight: 600; margin-block: 8px 2px; }
.agenda .divider::before, .agenda .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.steps { margin: 0; padding-inline-start: 22px; display: grid; gap: 8px; }
@keyframes flash { from { background: var(--accent-soft); } to { background: var(--surface); } }
.row .d { font-family: var(--display); font-weight: 700; color: var(--muted); font-size: .9rem; align-self: center; }
.row .bar { border-radius: 2px; }
.row .texts { display: grid; gap: 2px; min-width: 0; }
.row .t { font-weight: 600; overflow-wrap: anywhere; }
.row .t small { color: var(--muted); font-weight: 400; margin-inline-start: 6px; }
.empty-month { color: var(--muted); text-align: center; padding-block: 20px; margin: 0; }

.toast { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); inset-inline: 16px; margin: 0 auto; max-width: 420px; background: var(--fg); color: var(--bg); padding: 12px 16px; border-radius: var(--radius); box-shadow: var(--shadow); font-weight: 600; z-index: 50; text-align: center; }
.toast.err { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

@media (min-width: 768px) {
  body { padding-inline: 24px; max-width: 1100px; margin: 0 auto; }
  .tabs { margin-inline: -24px; padding-inline: 24px; }
  .top h1 { font-size: 1.6rem; }
  .dh .short { display: none; } .dh .long { display: inline; }
  .day { min-height: 92px; align-items: stretch; text-align: start; padding: 6px 8px; }
  .day .num { align-self: flex-start; }
  .dots { display: none; }
  .day .chips { display: grid; gap: 3px; width: 100%; }
  .day .chips .chip { font-size: .78rem; padding: 2px 8px; justify-content: flex-start; overflow: hidden; }
  .day .chips .chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* editor */
body.editing .day { cursor: pointer; }
body.editing .day.empty { cursor: default; }
body.editing .top h1 { text-decoration: underline dotted var(--muted); cursor: pointer; }
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 40; display: grid; align-items: end; justify-items: center; }
.backdrop.center { align-items: center; padding: 16px; }
.sheet { width: 100%; max-width: 560px; background: var(--surface); color: var(--fg); border-radius: 18px 18px 0 0; padding: 14px 16px calc(16px + env(safe-area-inset-bottom, 0px)); display: grid; gap: 12px; max-height: 88vh; overflow-y: auto; box-shadow: var(--shadow); margin: 0; }
.backdrop.center .sheet { border-radius: 16px; }
.sheet h2 { font-size: 1.1rem; }
.sheet .hint { color: var(--muted); font-size: .9rem; margin: 0; }
.ev { display: grid; gap: 8px; padding: 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.ev.bad { border-color: var(--danger); }
.ev input, .sheet input { width: 100%; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--fg); }
.ev .types, .sheet .types { display: flex; gap: 6px; }
.seg { flex: 1; padding: 6px 0; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); font-weight: 600; font-size: .9rem; color: var(--muted); }
.seg.exam.on { background: var(--exam-soft); color: var(--exam); border-color: var(--exam); }
.seg.holiday.on { background: var(--holiday-soft); color: var(--holiday); border-color: var(--holiday); }
.seg.event.on { background: var(--event-soft); color: var(--event); border-color: var(--event); }
.ev .foot { display: flex; justify-content: flex-end; }
.btn { padding: 10px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; }
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.small { padding: 6px 10px; font-size: .88rem; }
.btn[disabled] { opacity: .5; cursor: default; }
.actions { display: flex; gap: 8px; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.actions .grow { flex: 1; }
.field { display: grid; gap: 4px; }
.field label { font-size: .88rem; color: var(--muted); font-weight: 600; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.unsaved { display: grid; gap: 8px; padding: 10px 12px; border-radius: var(--radius); background: var(--exam-soft); color: var(--fg); }
.unsaved p { margin: 0; font-weight: 700; color: var(--exam); }
.err-text { color: var(--danger); font-size: .88rem; margin: 0; min-height: 1.2em; }

/* ---- week view ---- */
.install-row { display: flex; justify-content: flex-start; padding-block: 0 6px; }
.install-row .btn.install[hidden] { display: none; }
.view[hidden] { display: none !important; }
body { padding-bottom: calc(80px + env(safe-area-inset-bottom, 0px)); }
.wk-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.icon-btn.small { width: 36px; height: 36px; font-size: 1.3rem; line-height: 1; font-family: var(--display); font-weight: 700; color: var(--fg); }
.wk-title { display: flex; flex-direction: column; align-items: center; gap: 2px; font-family: var(--display); font-weight: 700; }
.wk-status:empty { display: none; }
.wk-status { font-size: .75rem; padding: 1px 10px; border-radius: 999px; font-weight: 700; }
.wk-status.draft { background: var(--exam-soft); color: var(--exam); }
.wk-status.published { background: var(--holiday-soft); color: var(--holiday); }
.wk-tools { display: flex; justify-content: space-between; align-items: center; gap: 8px; min-height: 8px; padding-block: 6px; }
.chip-btn { border: 1px solid var(--accent); background: transparent; color: var(--accent); border-radius: 999px; padding: 3px 12px; font-weight: 700; font-size: .85rem; }
.chip-btn[hidden] { display: none; }
.day-strip { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--bg); padding-block: 4px 8px; }
.day-pill { position: relative; display: grid; justify-items: center; gap: 0; padding: 6px 0; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--muted); font-weight: 600; }
.day-pill .dl { font-size: .8rem; }
.day-pill b { font-family: var(--display); font-size: 1.05rem; color: var(--fg); line-height: 1.2; }
.day-pill.today { border-color: var(--accent); }
.day-pill.holiday { background: var(--holiday-soft); }
.day-pill.on { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.day-pill.on b { color: var(--accent-fg); }
.pill-dot { position: absolute; top: 5px; inset-inline-start: 7px; width: 6px; height: 6px; border-radius: 50%; background: var(--exam); }
.day-body { display: grid; gap: 10px; touch-action: pan-y; }
.day-title { font-size: 1.15rem; display: flex; align-items: baseline; gap: 8px; }
.day-title span { color: var(--muted); font-size: .9rem; font-weight: 600; }
.day-events { display: flex; gap: 6px; flex-wrap: wrap; }
.day-events .chip small { font-weight: 400; opacity: .8; }
.holiday-banner { display: grid; gap: 2px; text-align: center; padding: 22px 12px; border-radius: var(--radius); background: var(--holiday-soft); color: var(--holiday); }
.holiday-banner b { font-family: var(--display); font-size: 1.2rem; }
.lessons { display: grid; gap: 6px; }
.lesson { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 8px; align-items: stretch; }
.lesson .t { display: grid; align-content: start; justify-items: center; font-variant-numeric: tabular-nums; font-size: .78rem; color: var(--muted); padding-top: 6px; line-height: 1.25; }
.lesson .t b { font-family: var(--display); font-size: 1rem; color: var(--fg); }
.lesson .t .end { opacity: .7; }
.lesson .cell { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; font-weight: 600; display: grid; align-content: start; gap: 2px; min-width: 0; overflow-wrap: anywhere; }
.lesson.other .cell { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.lesson .cell.empty { color: var(--muted); font-weight: 400; border-style: dashed; background: transparent; }
.lesson .cell .note { font-weight: 400; color: var(--muted); font-size: .85rem; }
.lesson.changed .cell { border-color: var(--changed); background: var(--changed-soft); }
.lesson .split { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
.lesson .split .cell { position: relative; padding-top: 20px; }
.lesson .split em { position: absolute; top: 4px; inset-inline-start: 10px; font-style: normal; font-size: .72rem; color: var(--accent); font-weight: 700; }
.lesson .split-note { grid-column: 1 / -1; padding-inline: 4px; }
.brk { text-align: center; font-size: .78rem; color: var(--muted); background: var(--shabbat); border-radius: 8px; padding: 3px 0; font-variant-numeric: tabular-nums; }
body.editing .lesson { cursor: pointer; }
/* Opus credit: the text-cut wordmark, one colour (the brand never tints the mark) */
.powered { display: flex; justify-content: center; padding: 28px 0 8px; }
.powered a { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); text-decoration: none; font-size: .78rem; opacity: .85; }
.powered a:hover, .powered a:focus-visible { opacity: 1; color: var(--fg); }
.powered svg { display: block; }
.bottom-nav { position: fixed; inset-inline: 0; bottom: 0; z-index: 30; display: grid; grid-template-columns: 1fr 1fr; background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom, 0px); }
.bottom-nav button { display: grid; justify-items: center; gap: 2px; padding: 8px 0 10px; border: 0; background: transparent; color: var(--muted); font-family: var(--display); font-weight: 700; font-size: .82rem; }
.bottom-nav button.on { color: var(--accent); }
.toast { bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
@media (min-width: 768px) {
  .bottom-nav { max-width: 1100px; margin: 0 auto; border-inline: 1px solid var(--line); border-radius: 14px 14px 0 0; }
  .day-body, .day-strip, .wk-head, .wk-tools { max-width: 640px; margin-inline: auto; width: 100%; }
}

/* ---- week editor ---- */
.wk-tools .btn.small { padding: 6px 12px; }
#weekEditorSlot { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.sheet h2 .sub { color: var(--muted); font-size: .9rem; font-weight: 600; }
.slot-row { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 6px; padding: 8px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
.slot-row.break { background: var(--shabbat); }
.slot-row select, .slot-row input { font: inherit; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--fg); min-width: 0; width: 100%; }
.slot-row .times { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 6px; align-items: center; color: var(--muted); font-size: .85rem; }
.slot-row .row-tools { grid-column: 1 / -1; display: flex; gap: 6px; justify-content: flex-end; }

/* ---- week header v2: prev | today | next, then dates + which-week tag ---- */
.wk-head { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; }
.wk-nav { display: inline-flex; align-items: center; gap: 4px; min-height: 44px; padding: 0 8px; border: 1px solid var(--line); background: var(--surface); color: var(--fg); border-radius: 12px; font-weight: 700; font-size: .9rem; font-family: var(--display); }
#weekPrev { justify-self: start; }
#weekNext { justify-self: end; }
.today-btn { min-height: 48px; min-width: 104px; padding: 0 22px; border-radius: 999px; border: 2px solid var(--accent); background: var(--surface); color: var(--accent); font-family: var(--display); font-weight: 800; font-size: 1.15rem; }
.today-btn.on { background: var(--accent); color: var(--accent-fg); }
.wk-title { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 10px; padding-block: 10px 2px; font-family: var(--display); font-weight: 700; font-variant-numeric: tabular-nums; }
.wk-rel { font-size: .8rem; padding: 2px 10px; border-radius: 999px; font-weight: 700; }
.wk-rel.current { background: var(--accent); color: var(--accent-fg); }
.wk-rel.future { background: var(--accent-soft); color: var(--accent); }
.wk-rel.past { background: var(--shabbat); color: var(--muted); border: 1px solid var(--line); }
.wk-tools:has(#weekEditorSlot:empty) { display: none; }
.day-pill b { font-size: .95rem; font-variant-numeric: tabular-nums; }
.day-pill.past:not(.on) { opacity: .45; background: var(--shabbat); }
.day-pill.past.on { opacity: .7; }
.past-banner { text-align: center; padding: 8px 12px; border-radius: var(--radius); background: var(--shabbat); color: var(--muted); font-weight: 700; border: 1px dashed var(--line); }
.day-body.past .lessons, .day-body.past .day-events { opacity: .45; filter: grayscale(1); }
.day-body.past .day-title { color: var(--muted); }
#weekView.past-week .wk-title #weekLabel { color: var(--muted); text-decoration: line-through; text-decoration-thickness: 1px; }
@media (max-width: 360px) { .wk-nav span { display: none; } }

/* ---- editor tools: versions, logout-all ---- */
.tool-list { display: grid; gap: 8px; }
.version-list { display: grid; gap: 6px; max-height: 50vh; overflow-y: auto; }
.version-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); font-variant-numeric: tabular-nums; }
.restore-confirm { flex-basis: 100%; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--exam); font-weight: 600; font-size: .9rem; }

/* ---- seven-day strip, weekend and fact cards ---- */
.day-strip { grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.day-pill { padding: 5px 0; border-radius: 10px; }
.day-pill .dl { font-size: .74rem; }
.day-pill b { font-size: .74rem; letter-spacing: -.02em; }
.day-pill.weekend:not(.on) { background: var(--fact-soft); border-color: transparent; }
.weekend-banner { display: grid; gap: 2px; text-align: center; padding: 18px 12px; border-radius: var(--radius); background: var(--fact-soft); color: var(--fact); }
.weekend-banner b { font-family: var(--display); font-size: 1.15rem; }
.fact-card { display: grid; gap: 6px; padding: 12px 14px; border-radius: 14px; background: var(--fact-soft); color: var(--fg); border: 1px solid transparent; margin-top: 4px; text-align: start; font: inherit; }
.fact-card .fact-title { font-family: var(--display); font-weight: 800; font-size: .85rem; color: var(--fact); }
.fact-card p { margin: 0; font-weight: 600; line-height: 1.5; }
.fact-card a { font-size: .8rem; color: var(--muted); text-decoration: underline; text-underline-offset: 2px; justify-self: start; }
.fact-card.muted { opacity: .65; border: 1px dashed var(--fact); }
.fact-card.add { color: var(--fact); font-weight: 700; border: 1px dashed var(--fact); cursor: pointer; text-align: center; }
.fact-flag { color: var(--exam); font-weight: 700; }
body.editing .fact-card { cursor: pointer; }
.day-body.past .fact-card { opacity: .55; }
.sheet textarea, .sheet select { width: 100%; font: inherit; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); color: var(--fg); resize: vertical; }
.check-row { display: flex; align-items: center; gap: 8px; font-weight: 600; }
/* quoted English inside Hebrew facts: keep the phrase on one line so its quote marks stay in place */
.fact-card bdi { unicode-bidi: isolate; white-space: nowrap; }
