:root {
  --bg: #f4f6f9; --card: #ffffff; --ink: #18202b; --muted: #5b6676; --line: #dfe4ec;
  --brand: #1f3a5f; --brand-ink: #ffffff; --accent: #2f6fd6; --accent-soft: #e6efff;
  --ok: #1e7a46; --ok-soft: #e3f4ea; --warn: #9a5b00; --warn-soft: #fff3dc;
  --bad: #b3261e; --bad-soft: #fde8e6; --violet: #6a3fb5; --violet-soft: #efe7fb;
  --me: #fff4c2; --radius: 14px; --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  --tabh: 62px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1720; --card: #17212d; --ink: #e7edf5; --muted: #9aa7b8; --line: #2a3747;
    --brand: #17212d; --brand-ink: #e7edf5; --accent: #6ea0ff; --accent-soft: #1c2c47;
    --ok: #5fd08f; --ok-soft: #173326; --warn: #f0b25a; --warn-soft: #3a2b12;
    --bad: #ff8a80; --bad-soft: #3b1c1a; --violet: #b99cf0; --violet-soft: #2a2140;
    --me: #3b3413; --shadow: none;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
/* Android/Chrome: no pull-to-refresh fighting the drawer/modals, no text inflation, no zoom on inputs (16px). */
html { overscroll-behavior-y: none; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
.drawer, .modal { overscroll-behavior: contain; }
/* The table scrolls sideways only. Containing the Y axis too made Android Chrome swallow vertical
   swipes that start on the table, so the page could not be scrolled down. */
.table-wrap { overscroll-behavior-x: contain; overscroll-behavior-y: auto; }
button, a, input, select, label { touch-action: manipulation; }
input[type=date], input[type=month] { -webkit-appearance: none; appearance: none; text-align: right; display: block; }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans Hebrew", "Rubik", "Arial Hebrew", Arial, sans-serif;
  font-size: 16px; line-height: 1.45;
  /* App shell: the body never scrolls; only <main> does. A position:fixed tab bar drifted
     up on iOS when Safari's toolbar collapsed / the page bounced (2026-11-21). */
  height: 100vh; height: 100dvh; overflow: hidden; display: flex; flex-direction: column;
}
.topbar, .tabbar { flex: none; }
button, input, select, textarea { font: inherit; font-size: 16px; color: inherit; }
a { color: var(--accent); }
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  gap: 8px; background: var(--brand); color: var(--brand-ink);
  padding: calc(6px + env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) 6px max(10px, env(safe-area-inset-left));
}
.brand { font-weight: 700; font-size: 19px; display: flex; gap: 6px; align-items: center; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.iconbtn { background: none; border: 0; color: inherit; width: 44px; height: 44px; display: grid; place-items: center; border-radius: 12px; cursor: pointer; }
.iconbtn:active { background: rgba(255,255,255,.15); }

/* drawer (right side in RTL) */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 40; }
.drawer {
  position: fixed; top: 0; bottom: 0; right: 0; width: min(300px, 84vw); z-index: 50; background: var(--card);
  padding: calc(14px + env(safe-area-inset-top)) 10px 20px; display: flex; flex-direction: column; gap: 2px;
  box-shadow: -6px 0 24px rgba(0,0,0,.2); overflow-y: auto;
}
.drawer-head { font-weight: 700; font-size: 20px; padding: 6px 10px 14px; display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.drawer-user { font-weight: 400; font-size: 14px; color: var(--muted); }
.drawer a, .drawer .linkbtn { display: block; padding: 12px; border-radius: 10px; text-decoration: none; color: var(--ink); font-size: 17px; text-align: right; }
.drawer a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.drawer hr { border: 0; border-top: 1px solid var(--line); margin: 6px 0; }
.linkbtn { background: none; border: 0; cursor: pointer; color: var(--bad) !important; }

/* tab bar */
.tabbar {
  position: relative; z-index: 30; display: grid; grid-template-columns: repeat(6, 1fr);
  background: var(--card); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a { display: flex; flex-direction: column; align-items: center; justify-content: center; height: var(--tabh); font-size: 11px; color: var(--muted); text-decoration: none; gap: 2px; white-space: nowrap; overflow: hidden; min-width: 0; }
.tabbar a span { font-size: 22px; line-height: 1; filter: grayscale(1); opacity: .7; }
.tabbar a.active { color: var(--accent); font-weight: 600; }
.tabbar a.active span { filter: none; opacity: 1; }

main { flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain;
  /* content column stays 820px wide (788 + 2x16) while the scrollbar sits at the window edge */
  padding: 12px max(16px, env(safe-area-inset-right), calc((100% - 788px) / 2)) 24px max(16px, env(safe-area-inset-left), calc((100% - 788px) / 2)); outline: none; }
h1 { font-size: 22px; margin: 6px 0 12px; }
h2 { font-size: 18px; margin: 18px 0 8px; }
h3 { font-size: 16px; margin: 12px 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); padding: 14px; margin: 10px 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.btn { border: 0; border-radius: 12px; padding: 11px 16px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; min-height: 44px; }
.btn.secondary { background: var(--accent-soft); color: var(--accent); }
.btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
.btn.danger { background: var(--bad-soft); color: var(--bad); }
.btn.small { padding: 6px 10px; min-height: 34px; font-size: 14px; }
.btn:disabled { opacity: .5; }
.btn.block { width: 100%; }
input[type=text], input[type=email], input[type=date], input[type=month], input[type=number], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
textarea { min-height: 80px; resize: vertical; }
label.field { display: block; margin: 10px 0; }
label.field > span { display: block; font-size: 14px; color: var(--muted); margin-bottom: 4px; }
.pill { display: inline-block; border-radius: 999px; padding: 2px 10px; font-size: 13px; background: var(--accent-soft); color: var(--accent); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.violet { background: var(--violet-soft); color: var(--violet); }
.notice { border-radius: 12px; padding: 10px 12px; margin: 10px 0; background: var(--accent-soft); font-size: 14px; }
.notice.warn { background: var(--warn-soft); }
.notice.bad { background: var(--bad-soft); }
.notice.ok { background: var(--ok-soft); }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tabh) + 16px + env(safe-area-inset-bottom)); background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 60; max-width: 90vw; }
.toast.show { opacity: .95; }

/* calculators list */
.search { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: 4px 0 8px; }
.calc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.calc-tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 12px; text-decoration: none; color: var(--ink); display: flex; flex-direction: column; gap: 4px; min-height: 92px; }
.calc-tile b { font-size: 17px; }
.calc-tile .muted { font-size: 13px; }
.calc-tile .ico { font-size: 22px; }
.edit-list { list-style: none; margin: 0; padding: 0; }
.edit-list li { display: flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; margin: 6px 0; }
.edit-list li .name { flex: 1; font-weight: 600; }
.sq { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-size: 18px; cursor: pointer; display: grid; place-items: center; }
.sq.del { color: var(--bad); }
.sq.add { color: var(--ok); }
.newbadge { font-size: 11px; background: var(--ok-soft); color: var(--ok); border-radius: 6px; padding: 1px 6px; margin-inline-start: 6px; }

/* calculator page */
.calc-head { display: flex; align-items: center; gap: 8px; }
.result { position: sticky; top: 0; z-index: 6; background: var(--card); border: 2px solid var(--accent); border-radius: var(--radius); padding: 10px 14px; margin: 8px 0 12px; }
.result .score { font-size: 28px; font-weight: 800; }
.result .interp { font-size: 15px; }
.result.ok { border-color: var(--ok); } .result.warn { border-color: var(--warn); } .result.bad { border-color: var(--bad); }
.q { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 8px 0; }
.q-title { font-weight: 700; margin-bottom: 6px; }
.q-hint { font-size: 13px; color: var(--muted); margin: -2px 0 6px; }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 9px 8px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; }
.opt input { margin-top: 3px; width: 20px; height: 20px; flex: none; accent-color: var(--accent); }
.opt.sel { background: var(--accent-soft); border-color: var(--accent); }
.opt .pts { margin-inline-start: auto; font-weight: 700; color: var(--muted); white-space: nowrap; padding-inline-start: 8px; }
.check.flag-abs.sel { background: var(--bad-soft); border-color: var(--bad); }
.check.flag-rel.sel { background: var(--warn-soft); border-color: var(--warn); }
.ref { font-size: 12px; color: var(--muted); margin-top: 16px; border-top: 1px solid var(--line); padding-top: 8px; }
.ref p { margin: 4px 0; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: 15px; }
.numrow { display: flex; gap: 8px; align-items: center; }
.numrow input { max-width: 140px; }

/* schedule */
.daynav { display: flex; align-items: center; gap: 6px; justify-content: space-between; }
.daynav .title { text-align: center; flex: 1; }
.daynav .title b { font-size: 19px; display: block; }
.mybox { background: var(--me); border-radius: var(--radius); padding: 10px 14px; margin: 10px 0; }
.station { display: flex; justify-content: space-between; gap: 12px; padding: 9px 2px; border-bottom: 1px solid var(--line); }
.station:last-child { border-bottom: 0; }
.station .lab { color: var(--muted); flex: none; max-width: 45%; }
.station .who { text-align: left; font-weight: 600; }
.station .who .me { background: var(--me); border-radius: 6px; padding: 0 4px; }
.oncall .station .lab { color: var(--bad); font-weight: 600; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .dow { text-align: center; font-size: 12px; color: var(--muted); padding: 2px 0; }
.cal .d { background: var(--card); border: 1px solid var(--line); border-radius: 10px; min-height: 64px; padding: 4px; font-size: 11px; display: flex; flex-direction: column; gap: 2px; cursor: pointer; text-align: center; overflow: hidden; color: var(--ink); text-decoration: none; }
.cal .d .n { font-weight: 700; font-size: 14px; }
.cal .d.today { outline: 2px solid var(--accent); }
.cal .d.weekend { background: color-mix(in srgb, var(--card) 85%, var(--muted)); }
.cal .d.call { background: var(--bad-soft); border-color: var(--bad); }
.cal .d.off { background: var(--ok-soft); }
.cal .d .tag { line-height: 1.15; font-size: 10.5px; overflow-wrap: anywhere; }
.cal .d.blank { visibility: hidden; }
.legend { display: flex; gap: 10px; flex-wrap: wrap; font-size: 13px; margin: 8px 0; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: middle; margin-inline-end: 4px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: 12px; background: var(--card); }
table.grid { border-collapse: collapse; font-size: 13px; white-space: nowrap; }
table.grid th, table.grid td { border: 1px solid var(--line); padding: 4px 6px; text-align: center; }
table.grid th { background: var(--accent-soft); position: sticky; top: 0; }
table.grid td.sticky, table.grid th.sticky { position: sticky; right: 0; background: var(--card); z-index: 1; }
table.grid td.mine { background: var(--me); font-weight: 700; }
.segmented { display: flex; background: var(--accent-soft); border-radius: 12px; padding: 3px; gap: 3px; margin: 8px 0; }
.segmented button { flex: 1; border: 0; border-radius: 10px; padding: 8px 4px; background: transparent; color: var(--accent); font-weight: 600; min-height: 40px; cursor: pointer; font-size: 14px; }
.segmented button.on { background: var(--card); box-shadow: var(--shadow); }

/* blocks */
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 8px 0; }
.mode { border: 2px solid var(--line); border-radius: 12px; padding: 8px; background: var(--card); text-align: right; cursor: pointer; min-height: 48px; }
.mode.on { border-color: var(--accent); background: var(--accent-soft); }
.mode small { display: block; color: var(--muted); font-size: 12px; }
.cal .d.m-block { background: var(--bad-soft); border-color: var(--bad); }
.cal .d.m-extra { background: var(--warn-soft); border-color: var(--warn); }
.cal .d.m-positive { background: var(--violet-soft); border-color: var(--violet); }
.cal .d.m-off { background: var(--ok-soft); border-color: var(--ok); }
.counters { display: flex; flex-wrap: wrap; gap: 6px; }

/* feedback */
.rate { display: flex; gap: 4px; }
.rate button { flex: 1; min-height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 700; cursor: pointer; }
.rate button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.scale-hint { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

/* cases */
.res-row { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 8px 0; }
.res-row.mine { border-color: var(--accent); }
.res-row .res-name { font-weight: 700; display: flex; align-items: center; gap: 8px; }
.case { display: flex; gap: 8px; align-items: flex-start; padding: 8px 0; border-top: 1px dashed var(--line); }
.case:first-of-type { border-top: 0; }
.case .body { flex: 1; min-width: 0; }
.case .pt { font-weight: 600; }
.case.presented .pt { text-decoration: line-through; color: var(--muted); }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 70; display: flex; align-items: flex-end; justify-content: center; }
.modal { background: var(--card); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom)); max-height: 90vh; overflow-y: auto; }
@media (min-width: 700px) { .modal-bg { align-items: center; } .modal { border-radius: 18px; } }

/* admin */
.admin-tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; }
.admin-tabs button { white-space: nowrap; }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list td, table.list th { border-bottom: 1px solid var(--line); padding: 8px 4px; text-align: right; vertical-align: top; }
pre.out { white-space: pre-wrap; direction: ltr; text-align: left; font-size: 12px; background: var(--bg); padding: 10px; border-radius: 10px; max-height: 300px; overflow: auto; }
.login { max-width: 420px; margin: 40px auto; text-align: center; }
.login .logo { font-size: 64px; }
.login input { text-align: center; letter-spacing: 3px; font-size: 20px; direction: ltr; text-transform: uppercase; }
table.list tr.mine td { background: var(--me); }
table.list tr.muted td { color: var(--muted); }

/* ---------------------------------------------------------------- desktop (2026-11-22)
   >=1024px: the drawer becomes a fixed right sidebar, no bottom tab bar, wider content.
   The drawer keeps its [hidden] attribute (mobile logic untouched); CSS overrides it here. */
@media (hover: hover) {
  .calc-tile:hover, .res-row:hover { border-color: var(--accent); }
  .drawer a:hover { background: var(--accent-soft); }
  .btn:hover:not(:disabled) { filter: brightness(1.07); }
  .iconbtn:hover { background: rgba(255,255,255,.12); }
  .opt:hover { background: var(--accent-soft); }
  .cal .d:hover { border-color: var(--accent); }
}
@media (min-width: 1024px) {
  body.authed {
    display: grid; grid-template-columns: 250px minmax(0, 1fr); grid-template-rows: auto minmax(0, 1fr);
    grid-template-areas: "top top" "nav main";
  }
  body.authed .topbar { grid-area: top; padding-inline: 20px; }
  body.authed #menuBtn { display: none; }
  body.authed .brand { font-size: 20px; }
  body.authed .drawer, body.authed .drawer[hidden] {
    display: flex !important; grid-area: nav; position: static; width: auto; z-index: auto;
    box-shadow: none; border-inline-end: 1px solid var(--line); padding: 14px 10px 20px;
  }
  body.authed .drawer-head { font-size: 15px; padding: 4px 12px 10px; }
  body.authed .drawer-head .brand-mark { display: none; }
  body.authed .drawer a, body.authed .drawer .linkbtn { font-size: 15.5px; padding: 10px 12px; }
  body.authed .scrim, body.authed .tabbar { display: none !important; }
  body.authed main { grid-area: main; min-width: 0;
    padding: 20px max(28px, calc((100% - 1080px) / 2)) 40px; }
  body.authed .toast { bottom: 28px; left: calc(50% - 125px); }
  h1 { font-size: 26px; }
  .calc-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
  .cal { gap: 6px; }
  .cal .d { min-height: 96px; font-size: 12.5px; padding: 6px; }
  .cal .d .n { font-size: 15px; }
  .cal .d .tag { font-size: 12px; }
  .cal .dow { font-size: 13px; }
  table.grid { font-size: 14px; }
  table.grid th, table.grid td { padding: 6px 8px; }
  .modal { max-width: 640px; }
  .login { margin-top: 10vh; }
}
@media (min-width: 1440px) {
  body.authed { grid-template-columns: 270px minmax(0, 1fr); }
  body.authed .toast { left: calc(50% - 135px); }
}
