:root {
  --bg: #f5f6f8; --panel: #fff; --text: #1d2330; --muted: #6b7280; --line: #e3e6eb;
  --accent: #2563eb; --on: #16a34a; --off: #dc2626; --bar: #f59e0b; --lock: #7c3aed;
  --odd: #fafbfc; --radius: 8px;
  font-family: "Segoe UI", Arial, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); direction: rtl; }
button, input, select { font: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: 6px; padding: 6px 12px; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button:disabled { opacity: .5; cursor: default; }
input, select { border: 1px solid var(--line); border-radius: 6px; padding: 6px 8px; background: #fff; }

header.top { display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
header.top h1 { font-size: 20px; margin: 0; }
header.top .spacer { flex: 1; }
nav.tabs { display: flex; gap: 4px; }
nav.tabs button { border: 0; background: none; padding: 8px 12px; border-bottom: 2px solid transparent; border-radius: 0; }
nav.tabs button.active { border-bottom-color: var(--accent); color: var(--accent); font-weight: 600; }
main { padding: 16px; }
.muted { color: var(--muted); font-size: 13px; }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.groups { display: flex; gap: 4px; }
.groups button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.week-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
table.week { border-collapse: collapse; width: 100%; min-width: 900px; table-layout: fixed; }
table.week th, table.week td { border-bottom: 1px solid var(--line); padding: 4px 6px; vertical-align: top; }
table.week thead th { position: sticky; top: 0; background: var(--panel); z-index: 5; font-weight: normal; text-align: center; }
table.week th.sw, table.week td.sw { width: 220px; text-align: right; position: sticky; right: 0; background: var(--panel); z-index: 4; }
table.week td.day:nth-child(even) { background: var(--odd); }
.dayhead .wd { font-weight: 700; font-size: 15px; }
.dayhead .hd { font-size: 13px; }
.dayhead .gd { font-size: 11px; color: var(--muted); }
.dayhead.today { outline: 2px solid var(--accent); outline-offset: -2px; border-radius: 6px; }
.recipe { display: inline-block; margin-top: 4px; padding: 1px 6px; border-radius: 10px; font-size: 11px; border: 1px solid var(--line); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.recipe .dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-left: 4px; vertical-align: middle; }
.recipe.manual { border-color: var(--accent); }

.swname { font-size: 13px; line-height: 1.3; }
.swname .out { color: var(--muted); font-size: 11px; margin-left: 4px; }
.state { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-left: 6px; background: var(--off); vertical-align: middle; }
.state.on { background: var(--on); }
.lockbadge { color: var(--lock); font-size: 11px; margin-right: 4px; }

.bar { position: relative; height: 10px; background: #eef0f3; border-radius: 3px; margin-top: 4px; }
.seg { position: absolute; top: 0; bottom: 0; background: var(--bar); border-radius: 2px; min-width: 2px; }
.seg.locked { background: var(--lock); }
.times { font-size: 10.5px; color: #444; margin-top: 3px; direction: ltr; text-align: right; line-height: 1.35; }
.nowline { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--accent); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; max-width: 760px; }
table.list { border-collapse: collapse; width: 100%; }
table.list th, table.list td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.list th { color: var(--muted); font-weight: normal; font-size: 13px; }
td.ltr { direction: ltr; text-align: right; }

.login { max-width: 340px; margin: 12vh auto; }
.login h1 { margin-top: 0; }
.login label { display: block; margin: 10px 0 4px; }
.login input { width: 100%; }
.login .err { color: var(--off); min-height: 20px; margin-top: 8px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }

@media print {
  header.top, .toolbar, nav.tabs { display: none; }
  main { padding: 0; }
  .week-wrap { border: 0; overflow: visible; }
  table.week { min-width: 0; font-size: 10px; }
  table.week th.sw, table.week td.sw { position: static; }
}
@media (max-width: 700px) {
  main { padding: 8px; }
  table.week th.sw, table.week td.sw { width: 140px; }
}

/* times under the bars: same direction as the bar (earliest on the right) */
.times { display: flex; flex-wrap: wrap; gap: 1px 8px; direction: rtl; text-align: right; }
.tseg { display: inline-flex; direction: rtl; gap: 2px; white-space: nowrap; }

.card.wide { max-width: 1100px; }
.scroll-x { overflow-x: auto; }
table.zmanim { min-width: 900px; }
table.zmanim input.zname { width: 150px; }
table.zmanim select.zbase { width: 260px; }
table.zmanim select.zround { width: 115px; }
table.zmanim input.zadd { width: 70px; }
.toast { position: fixed; bottom: 20px; left: 20px; background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 8px; z-index: 100; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.toast.bad { background: var(--off); }
.spacer { flex: 1; }

dialog#caldlg { box-sizing: border-box; max-width: 96vw; border: 0; border-radius: 12px; padding: 16px; width: min(760px, 96vw); box-shadow: 0 10px 40px rgba(0,0,0,.3); }
dialog#caldlg::backdrop { background: rgba(0,0,0,.35); }
.calhead { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.calhead b { font-size: 18px; min-width: 120px; text-align: center; }
table.calgrid { width: 100%; border-collapse: collapse; table-layout: fixed; }
table.calgrid th { color: var(--muted); font-weight: normal; padding: 4px; }
table.calgrid td { padding: 2px; }
.cday { width: 100%; min-height: 96px; display: flex; flex-direction: column; align-items: stretch; gap: 2px; padding: 4px 6px; text-align: start; }
.ctop { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; flex: 1; }
.ctag { font-size: 10.5px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.cday .crec { border-top: 1px dashed #ccd; padding-top: 3px; margin-top: 2px; text-align: start; min-height: 15px; }
.cday:hover { background: #eef4ff; }
.cday.today { outline: 2px solid var(--accent); }
.cmain { font-size: 17px; font-weight: 700; }
.csub { font-size: 11px; color: var(--muted); }
.crec { font-size: 10.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

/* phone: one day at a time, switches as a list */
.daylist .dayhdr { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 8px; }
.daylist .swrow { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px; margin-bottom: 6px; }
@media (max-width: 700px) {
  header.top { gap: 8px; padding: 8px; }
  header.top h1 { font-size: 17px; }
  nav.tabs { order: 10; width: 100%; overflow-x: auto; }
  #who { display: none; }
  .cday { min-height: 58px; padding: 2px 3px; }
  .ctag { font-size: 9px; padding: 0 3px; }
  .cmain { font-size: 14px; }
  .crec { display: none; }
}

/* ---- switch panel */
table.week td.day, table.week td.sw { cursor: pointer; }
table.week td.day:hover { background: #eef4ff; }
dialog#panel { box-sizing: border-box; border: 0; margin: 0 auto 0 0; height: 100vh; max-height: 100vh; width: min(1080px, 100vw); max-width: 100vw; padding: 0; box-shadow: 0 0 40px rgba(0,0,0,.3); }
dialog#panel::backdrop, dialog#sharedlg::backdrop { background: rgba(0,0,0,.3); }
dialog#panel section { padding: 12px 16px; border-bottom: 1px solid var(--line); }
dialog#panel h4 { margin: 0 0 8px; }
.phead { display: flex; align-items: center; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; flex-wrap: wrap; }
.pday { text-align: center; min-width: 150px; }
.row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.seg3 { display: inline-flex; }
.seg3 button { border-radius: 0; margin-left: -1px; }
.okbtn { color: var(--on); border-color: var(--on); }
.badbtn { color: var(--off); border-color: var(--off); }
button.primary.okbtn, button.primary.badbtn { color: #fff; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.chip { border: 1px solid var(--line); border-radius: 14px; padding: 2px 4px 2px 10px; font-size: 13px; }
.chip.on { color: var(--on); border-color: var(--on); }
.chip.off { color: var(--off); border-color: var(--off); }
.chip .x { border: 0; background: none; padding: 0 4px; color: inherit; }
.form { display: grid; gap: 8px; margin-top: 8px; }
.form label { display: flex; gap: 8px; align-items: center; }
.ltrin { direction: ltr; text-align: left; }
.swpick { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 2px 12px; max-height: 180px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 6px; font-size: 13px; }
table.cmds td { vertical-align: middle; }
table.cmds tr.dim { opacity: .55; }
.days { white-space: nowrap; }
.wdb { padding: 1px 5px; margin: 0 1px; font-size: 12px; border-radius: 4px; }
.wdb.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.formula { white-space: nowrap; }
.formula select, .formula input { margin-left: 4px; }
.czman { max-width: 190px; }
.nowrap { white-space: nowrap; }
button.shared { border-color: #9c27b0; }
.quick { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 10px; }
#qtext { width: 170px; }
dialog#sharedlg { border: 0; border-radius: 12px; padding: 16px; width: min(640px, 96vw); box-sizing: border-box; }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 700px) {
  dialog#panel { width: 100vw; }
  .cols { grid-template-columns: 1fr; }
  .formula { white-space: normal; }
}
dialog#panel { overflow-x: hidden; overflow-y: auto; }
dialog#panel select, dialog#panel input { max-width: 100%; }
.ctime { width: 64px; }
.ckind { width: auto; }
dialog#panel .row > select { max-width: 260px; }
dialog#histdlg { border: 0; border-radius: 12px; padding: 16px; width: min(820px, 96vw); box-sizing: border-box; }
dialog#histdlg::backdrop { background: rgba(0,0,0,.35); }
.histlist { max-height: 65vh; overflow: auto; }
nav.tabs.sub { flex-wrap: wrap; }
table.rules select { max-width: 150px; }
.form label input:not([type=checkbox]) { flex: 1; min-width: 0; }
[hidden] { display: none !important; }
.ochips { display: flex; flex-direction: column; align-items: center; gap: 2px; margin-top: 4px; }
.ochip { font-size: 10.5px; border: 1px solid; border-right-width: 4px; border-radius: 4px; padding: 0 4px; cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; background: #fff; }
button.oadd { font-size: 10px; padding: 0 6px; color: var(--muted); border-style: dashed; }
.card.addon { margin-bottom: 12px; }
.point { display: inline-flex; gap: 3px; flex-wrap: wrap; }
.point select { max-width: 150px; }
dialog#odlg { border: 0; border-radius: 12px; padding: 16px; width: min(520px, 96vw); box-sizing: border-box; }
dialog#odlg::backdrop { background: rgba(0,0,0,.35); }
.opick { display: block; width: 100%; text-align: right; margin-bottom: 6px; padding: 8px 10px; }
dialog.choose { border: 0; border-radius: 12px; padding: 18px; width: min(460px, 94vw); box-sizing: border-box; }
dialog.choose::backdrop { background: rgba(0,0,0,.35); }
dialog.choose .row { justify-content: flex-end; }

.setrow { border-top: 1px solid var(--line); padding-top: 10px; margin-top: 10px; }
.setbanner { border: 1px solid #c4b5fd; background: #f5f3ff; border-radius: 8px; padding: 8px 10px; margin: 8px 0; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.setbanner .muted { width: 100%; }
dialog.sidepanel { box-sizing: border-box; border: 0; margin: 0 auto 0 0; height: 100vh; max-height: 100vh; width: min(860px, 100vw); max-width: 100vw; padding: 0; overflow-x: hidden; }
dialog.sidepanel::backdrop { background: rgba(0,0,0,.3); }
dialog.sidepanel section { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.nextcol { font-size: 12px; }
.warn { color: #b45309; font-weight: 600; }

.step { display: flex; gap: 10px; border-top: 1px solid var(--line); padding: 10px 0; }
.step > div { flex: 1; min-width: 0; }
.step .num { flex: none; width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 700; }
.step .summary { margin-top: 4px; font-weight: 600; color: #5b21b6; }

table.rules { width: 100%; table-layout: auto; }
table.rules td { vertical-align: top; }
table.rules .rname { width: 100%; min-width: 110px; box-sizing: border-box; }
table.rules .lvl { font-size: 12px; color: var(--muted); margin-top: 4px; }
table.rules .rlevel { width: 48px; }
table.rules .rrec { max-width: 170px; }
table.rules .range div { white-space: nowrap; margin-bottom: 3px; }
table.rules .range select { max-width: 95px; }
table.rules .rlen { width: 50px; }
table.rules .nextcol { font-size: 12px; min-width: 110px; }
@media (max-width: 900px) {
  table.rules thead { display: none; }
  table.rules tr { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; border-bottom: 2px solid var(--line); padding: 6px 0; }
  table.rules td { border: 0; }
}

table.modes td { vertical-align: middle; }
table.modes .mtext { width: 150px; }

.kicon { display: inline-block; width: 1.3em; text-align: center; }
tr.areahead td { background: #eef2ff; border-top: 2px solid #c7d2fe; }
tr.sethead td { background: #faf5ff; }
tr.sethead .setcell { cursor: pointer; }
tr.sethead .setnote { font-size: 11px; }
tr.member td.sw .swname { padding-right: 14px; border-right: 3px solid #c4b5fd; }
.ochip.cont { border-style: dashed; }
.areasub { font-size: 12px; color: var(--muted); margin: 6px 0 2px; }
.help { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e3a8a; border-radius: 8px; padding: 6px 10px; margin: 6px 0; font-size: 13px; position: relative; }
.help .helpx { position: absolute; left: 6px; top: 4px; border: 0; background: none; color: #64748b; padding: 0 4px; }

dialog.choose.wide { width: min(760px, 96vw); }
.okmsg { color: var(--on); font-weight: 600; margin: 6px 0; }
/* English (left-to-right) */
html[dir=ltr] body { direction: ltr; }
html[dir=ltr] .bar { transform: scaleX(-1); }
html[dir=ltr] .times, html[dir=ltr] .tseg { direction: ltr; }
html[dir=ltr] table.week th.sw, html[dir=ltr] table.week td.sw { text-align: left; right: auto; left: 0; }
html[dir=ltr] table.list th, html[dir=ltr] table.list td { text-align: left; }
html[dir=ltr] .help .helpx { left: auto; right: 6px; }
html[dir=ltr] tr.member td.sw .swname { padding-right: 0; padding-left: 14px; border-right: 0; border-left: 3px solid #c4b5fd; }
html[dir=ltr] .ltrin { text-align: left; }

/* switch search on the weekly board */
.swsearch{width:230px;max-width:100%}
@media (max-width:700px){.swsearch{width:100%}}

/* parsha / holidays under the date */
.dtags{display:flex;flex-wrap:wrap;gap:2px;justify-content:center;margin:2px 0}
.dtag{font-size:11px;line-height:1.3;padding:0 5px;border-radius:8px;background:#eef2f7;color:#334;white-space:nowrap}
.dtag.parsha{background:#e8eefc;color:#1d3f8f;font-weight:600}
.dtag.special{background:#f3e8fc;color:#5b2a86}
.dtag.holiday,.dtag.chanukah{background:#fff4d6;color:#7a5200}
.dtag.fast{background:#fde8e8;color:#8f1d1d}
.dtag.rosh_chodesh{background:#e6f6ec;color:#1d6b3a}
.dtag.omer{background:transparent;color:#778;font-weight:400}

/* "not earlier / not later than" on zman commands */
.cbounds{font-size:12px;color:#667;margin-top:3px;white-space:nowrap}
.cbounds input{width:52px;padding:1px 3px;font-size:12px}
.clamp{display:inline-block;margin-top:3px;font-size:12px;font-weight:600;color:#7a4a00;background:#ffe9b3;border:1px solid #f0c36d;border-radius:10px;padding:0 7px;white-space:nowrap}
.cbounds input:not(:placeholder-shown){background:#fff4d6;border-color:#f0c36d;font-weight:600}
.warnbox .fixgap{margin-inline-start:8px}
.warnbox{background:#fff4d6;border:1px solid #f0c36d;color:#6b4a00;border-radius:6px;padding:6px 10px;margin:6px 0;font-size:13px}

/* "only on / except on" event condition on a command */
.ccond{margin-top:4px;display:flex;gap:4px;align-items:center;flex-wrap:wrap}
.ccondbtn{font-size:12px;padding:1px 8px;max-width:240px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
.ccondbtn.set{background:#eef2ff;border-color:#9fb1ea;font-weight:600;color:#1d3f8f}
#conddlg{width:min(560px,92vw)}
#conddlg section{margin:10px 0}
#conddlg h4{margin:0 0 2px}
.condline{display:flex;gap:6px;align-items:center;margin:5px 0}
.condline .cev{flex:1;min-width:0}

.shiftb{display:inline-block;margin-top:3px;font-size:12px;font-weight:600;color:#1d3f8f;background:#e8eefc;border:1px solid #9fb1ea;border-radius:10px;padding:0 7px;white-space:nowrap}
.condline .cmin{width:60px}

/* controllers ("בקרים") */
.dvgrid{display:grid;grid-template-columns:repeat(auto-fill,minmax(260px,1fr));gap:10px;margin:10px 0}
.dvcard{background:#fff;border:1px solid #dde;border-radius:10px;padding:10px 12px;display:flex;flex-direction:column;gap:5px}
.dvcard.stuck{border-color:#e5a3a3;background:#fff8f8}
.dvcard.ok{border-color:#a9d8b8}
.dvhead{display:flex;justify-content:space-between;gap:8px}
.dvst{font-weight:700;font-size:15px}
.dvst.ok{color:#1d7a3e}.dvst.bad{color:#b3261e}.dvst.none{color:#888}
.dvsw{font-size:12px}
.dvcard button{align-self:flex-start}
.filebtn{cursor:pointer;border:1px solid #ccd;border-radius:6px;padding:5px 10px;background:#fff}
.dvsum{display:flex;flex-wrap:wrap;gap:6px;margin:6px 0}
.dvchk{display:inline-block;font-size:12px;border-radius:10px;padding:1px 8px;margin:2px;white-space:nowrap;border:1px solid #ccd;background:#f6f7fa}
.dvchk.ok{background:#e9f7ee;border-color:#a9d8b8;color:#1d6b3a}
.dvchk.late{background:#fff4d6;border-color:#f0c36d;color:#7a4a00}
.dvchk.missing{background:#fde8e8;border-color:#e5a3a3;color:#8f1d1d;font-weight:600}
.dvchk.nodata,.dvchk.already{color:#667}
.dvchk.unexp{background:#f3e8fc;border-color:#c9a6e6;color:#5b2a86}
.dvtable td{vertical-align:top;padding:6px}
.dvname{width:220px}
.dvbars{width:40%;min-width:180px}
.dvbar{height:9px;margin:2px 0}
.seg.act{background:#2e9d5b}
.dvlegend{font-size:12px;color:#667;margin:4px 0}
.dvlegend .seg{display:inline-block;position:static;width:18px;height:8px;vertical-align:middle;margin:0 3px}
@media (max-width:700px){.dvname{width:auto}.dvtable tr{display:flex;flex-direction:column}}

.agentbar{background:#e8eefc;color:#1d3f8f;border-bottom:1px solid #9fb1ea;padding:6px 14px;font-size:13px;text-align:center}

/* does the change reach the site? – a bar under the header on every screen */
#linkbar{padding:7px 14px;font-size:14px;border-bottom:1px solid transparent}
#linkbar.ok{background:#e9f7ee;color:#1d6b3a;border-color:#a9d8b8;font-size:12px;padding:3px 14px}
#linkbar.wait{background:#e8eefc;color:#1d3f8f;border-color:#9fb1ea}
#linkbar.warn{background:#fff4d6;color:#6b4a00;border-color:#f0c36d}
#linkbar.bad{background:#fde8e8;color:#8f1d1d;border-color:#e5a3a3;font-weight:500}

.condline.isdate select{max-width:110px}
.cdate{display:inline-flex;gap:4px;align-items:center;flex-wrap:wrap}
.crange{font-size:12px;white-space:nowrap}
#conddlg .caddline{margin-inline-end:6px}

/* commands table in the switch / set panel: wrap instead of scrolling sideways, and if it is still wider,
   scroll inside a box whose sideways scrollbar is always on screen (not only at the very bottom) */
dialog#panel .formula, dialog#setpanel .formula { white-space: normal; }
dialog#panel .scroll-x, dialog#setpanel .scroll-x { max-height: 70vh; overflow: auto; }
dialog#panel table.cmds thead th, dialog#setpanel table.cmds thead th { position: sticky; top: 0; background: var(--card, #fff); z-index: 1; }
table.cmds td { padding: 6px 5px; }

.recipe.clickable{cursor:pointer}
.recipe.clickable:hover{outline:1px solid var(--accent, #2563eb);border-radius:10px}
#dprogdlg{width:min(420px,92vw)}

.okc{color:#1d7a3e}
.badc{color:#b3261e}
table.phones td{vertical-align:top}
table.phones .pacts{font-size:12px;white-space:nowrap}

#pickdlg{width:min(480px,94vw)}
.pklist{max-height:55vh;overflow:auto;display:flex;flex-direction:column;gap:3px;margin-top:8px}
.pksum{font-size:12px;max-width:260px}
