:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f0f3f8;
  --text: #172033;
  --muted: #637089;
  --border: #dde3ec;
  --primary: #1d4ed8;
  --primary-soft: #e3ebff;
  --ok: #15803d;
  --ok-soft: #dcf5e4;
  --warn: #a15c00;
  --warn-soft: #fff1d6;
  --bad: #b42318;
  --bad-soft: #fde4e1;
  --holiday: #7c3aed;
  --holiday-soft: #f1eaff;
  --weekend: #f7f8fb;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141d; --surface: #171e2a; --surface-2: #1e2734; --text: #e7ecf4; --muted: #95a1b5;
    --border: #2b3546; --primary: #6c9bff; --primary-soft: #1f2d4d; --ok: #4ade80; --ok-soft: #173325;
    --warn: #fbbf24; --warn-soft: #3a2d10; --bad: #f87171; --bad-soft: #3d1b1b;
    --holiday: #c4a5ff; --holiday-soft: #2c2346; --weekend: #141a25;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Assistant", "Rubik", "Segoe UI", "Arial Hebrew", Arial, system-ui, sans-serif;
  font-size: 16px; line-height: 1.45;
}
a { color: var(--primary); text-decoration: none; }
h1 { font-size: 1.35rem; margin: .2rem 0; }
h2 { font-size: 1.15rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
h4 { font-size: .95rem; margin: 0 0 .4rem; }
code { background: var(--surface-2); padding: 0 .3em; border-radius: 4px; direction: ltr; unicode-bidi: embed; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; flex-wrap: wrap; align-items: center; gap: .3rem .8rem;
  padding: .5rem 1rem calc(.5rem) 1rem; padding-top: max(.5rem, env(safe-area-inset-top));
  background: var(--primary); color: #fff;
}
.topbar.admin { background: #0f2a5f; }
.topbar .brand { font-weight: 700; }
.topbar .tag { background: rgba(255,255,255,.2); border-radius: 6px; padding: 0 .4em; font-size: .8rem; }
.topbar nav { order: 3; width: 100%; display: flex; gap: .2rem; overflow-x: auto; scrollbar-width: none; }
.topbar nav a { color: #fff; padding: .35rem .7rem; border-radius: 999px; white-space: nowrap; background: rgba(255,255,255,.12); font-size: .92rem; }
.topbar .who { margin-inline-start: auto; display: flex; align-items: center; gap: .5rem; font-size: .9rem; }
.topbar .btn.ghost { color: #fff; border-color: rgba(255,255,255,.4); }
@media (min-width: 900px) {
  .topbar nav { order: 0; width: auto; }
}

.container { max-width: 1400px; margin: 0 auto; padding: 1rem; padding-bottom: 4rem; }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .3rem;
  min-height: 44px; padding: .45rem .95rem; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; touch-action: manipulation;
}
.btn.small { min-height: 36px; padding: .3rem .7rem; font-size: .88rem; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); border-color: var(--bad); background: transparent; }
.btn.ghost { background: transparent; }
.btn.wide { width: 100%; }
.btn:active { transform: translateY(1px); }
form.inline { display: inline; margin: 0; }

label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; color: var(--muted); margin-bottom: .6rem; }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: .55rem .7rem; min-height: 44px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
input[type=checkbox] { width: 20px; height: 20px; min-height: 0; accent-color: var(--primary); }
label.check { flex-direction: row; align-items: center; gap: .4rem; color: var(--text); margin: 0; }
fieldset { border: 1px solid var(--border); border-radius: 10px; margin: 0 0 .8rem; padding: .6rem .8rem; }
legend { color: var(--muted); font-size: .9rem; padding: 0 .3rem; }
.checks { display: flex; flex-wrap: wrap; gap: .6rem 1.2rem; }
.two { display: grid; grid-template-columns: 1fr; gap: 0 .8rem; }
@media (min-width: 600px) { .two { grid-template-columns: 1fr 1fr; } }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }

.flash { padding: .6rem .8rem; border-radius: 10px; margin: .5rem 0; font-weight: 600; }
.flash.ok { background: var(--ok-soft); color: var(--ok); }
.flash.warn { background: var(--warn-soft); color: var(--warn); }
.flash.err { background: var(--bad-soft); color: var(--bad); }

.chip { display: inline-flex; align-items: center; gap: .2rem; padding: .15rem .6rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); font-size: .82rem; white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.chip.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }

/* ---------- Login ---------- */
.login-wrap { min-height: 80vh; display: grid; place-items: center; }
.card.login { width: 100%; max-width: 400px; }
.demo { background: var(--warn-soft); color: var(--warn); padding: .5rem .7rem; border-radius: 8px; font-size: .88rem; }

/* ---------- Month calendar ---------- */
.month-nav { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; margin-bottom: .6rem; }
.month-nav h1 { min-width: 8.5rem; text-align: center; }
.status-line, .toolbar { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-bottom: .6rem; }

.layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (min-width: 1000px) {
  .layout { grid-template-columns: minmax(0, 1.7fr) minmax(340px, 1fr); }
  .panel { position: sticky; top: 4.5rem; max-height: calc(100vh - 5.5rem); overflow-y: auto; }
}

.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.cal-h { text-align: center; font-size: .8rem; color: var(--muted); padding: .2rem 0; font-weight: 600; }
.cell {
  position: relative; display: flex; flex-direction: column; align-items: stretch; gap: 2px;
  min-height: 72px; padding: 4px; text-align: start; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  font: inherit; color: inherit; cursor: pointer; touch-action: manipulation;
}
.cell:hover { border-color: var(--primary); }
.cell.weekend { background: var(--weekend); }
.cell.holiday { background: var(--holiday-soft); }
.cell.past { opacity: .62; }
.cell.today { outline: 2px solid var(--primary); outline-offset: -1px; }
.cell.htmx-request { opacity: .5; }
.dnum { font-weight: 700; font-size: .9rem; }
.today .dnum { color: var(--primary); }
.hol { font-size: .66rem; color: var(--holiday); line-height: 1.15; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.badge { display: block; font-size: .66rem; line-height: 1.2; padding: 1px 4px; border-radius: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge.shift { background: var(--primary); color: #fff; }
.badge.req { background: var(--warn-soft); color: var(--warn); }
.badge.closed { background: var(--bad-soft); color: var(--bad); }
.flags { font-size: .7rem; position: absolute; top: 3px; inset-inline-end: 4px; }
.cov-wrap { display: flex; flex-direction: column; gap: 1px; }
.cov { font-size: .64rem; padding: 0 3px; border-radius: 4px; white-space: nowrap; display: inline-block; }
.cov.full { background: var(--ok-soft); color: var(--ok); }
.cov.miss { background: var(--bad-soft); color: var(--bad); }
.cov.off { background: var(--surface-2); color: var(--muted); text-decoration: line-through; }
@media (min-width: 700px) {
  .cell { min-height: 96px; padding: 6px; }
  .hol, .badge, .cov { font-size: .74rem; }
  .cov-wrap { flex-direction: row; flex-wrap: wrap; gap: 2px; }
}

.legend { display: flex; flex-wrap: wrap; gap: .4rem 1rem; margin-top: .6rem; font-size: .8rem; color: var(--muted); align-items: center; }
.legend .badge, .legend .cov { display: inline-block; }

/* ---------- Day panel ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow); scroll-margin-top: 4.5rem; }
.panel-empty { color: var(--muted); text-align: center; padding: 2rem .5rem; }
.panel section { border-top: 1px solid var(--border); margin-top: .8rem; }
.hol-line { color: var(--holiday); font-weight: 600; margin: .2rem 0; }
.cross-block { background: var(--surface-2); border-radius: 10px; padding: .6rem .7rem; margin-bottom: .6rem; }
.slot-line { display: flex; flex-wrap: wrap; justify-content: space-between; gap: .3rem; padding: .25rem 0; border-bottom: 1px dashed var(--border); }
.slot-line:last-child { border-bottom: 0; }
.slot-name { font-weight: 600; font-size: .9rem; }
.person { display: inline-block; margin-inline-start: .4rem; }
.person.me { font-weight: 800; color: var(--primary); }
.slot { padding: .45rem 0; border-bottom: 1px dashed var(--border); }
.slot:last-child { border-bottom: 0; }
.slot-head { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.count { margin-inline-start: auto; font-weight: 700; font-size: .85rem; padding: 0 .45rem; border-radius: 6px; }
.count.full { background: var(--ok-soft); color: var(--ok); }
.count.miss { background: var(--bad-soft); color: var(--bad); }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; margin: .35rem 0; }
.chip.person { background: var(--surface); padding-inline-end: .2rem; margin: 0; }
.chip .x { border: 0; background: transparent; color: var(--bad); font-size: 1.15rem; line-height: 1; min-width: 32px; min-height: 32px; cursor: pointer; }
form.add select { min-height: 40px; font-size: 15px; background: var(--surface); }
.req-list { padding-inline-start: 1.1rem; margin: .3rem 0; }
.req-list li { margin-bottom: .2rem; }
details.controls { background: var(--surface-2); border-radius: 10px; padding: .5rem .7rem; margin: .6rem 0; }
details.controls summary { cursor: pointer; display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; font-weight: 700; }
.ctrl-row { padding: .5rem 0; border-bottom: 1px dashed var(--border); }
.ctrl-label { font-weight: 600; font-size: .9rem; margin-bottom: .3rem; }
.ctrl-btns { display: flex; flex-wrap: wrap; gap: .3rem; }
details.more summary { cursor: pointer; color: var(--primary); font-size: .9rem; padding: .3rem 0; }

/* ---------- Year view ---------- */
.year-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr)); gap: .8rem; }
.mini { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .7rem; color: var(--text); box-shadow: var(--shadow); }
.mini:hover { border-color: var(--primary); }
.mini h3 { margin: 0 0 .4rem; color: var(--primary); }
.mini-cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; text-align: center; font-size: .78rem; }
.mini-cal .mh { color: var(--muted); font-weight: 600; }
.mini-cal .md { padding: 2px 0; border-radius: 5px; }
.mini-cal .md.h { background: var(--holiday-soft); color: var(--holiday); }
.mini-cal .md.hm { background: var(--holiday); color: #fff; font-weight: 700; }
.mini-cal .md.t { outline: 2px solid var(--primary); }
.hol-list { list-style: none; padding: 0; margin: .5rem 0 0; font-size: .8rem; }
.hol-list .hd { display: inline-block; min-width: 2.6rem; color: var(--holiday); font-weight: 700; }

/* ---------- Tables ---------- */
table.data { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
table.data th, table.data td { padding: .55rem .7rem; text-align: start; border-bottom: 1px solid var(--border); }
table.data th { background: var(--surface-2); font-size: .85rem; color: var(--muted); }
.tagc { display: inline-block; background: var(--primary-soft); color: var(--primary); border-radius: 5px; padding: 0 .35rem; margin: 1px; font-size: .8rem; }
@media (max-width: 760px) {
  table.data thead { display: none; }
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data tr { border-bottom: 1px solid var(--border); padding: .5rem .2rem; }
  table.data td { border: 0; padding: .15rem .6rem; display: flex; gap: .5rem; }
  table.data td[data-label]::before { content: attr(data-label); color: var(--muted); min-width: 5.5rem; font-size: .85rem; }
}
.table-scroll { overflow-x: auto; margin-bottom: .8rem; }
table.matrix { border-collapse: collapse; min-width: 100%; }
table.matrix th, table.matrix td { padding: .3rem; text-align: start; }
table.matrix th { font-size: .85rem; white-space: nowrap; }
table.matrix input { width: 4.5rem; text-align: center; }

.row-form { display: flex; flex-wrap: wrap; gap: .5rem; align-items: flex-end; padding: .4rem 0; border-bottom: 1px dashed var(--border); }
.row-form label { margin: 0; }
.row-form .grow { flex: 1 1 10rem; }
.row-form.grow { border: 0; padding: 0; flex: 1 1 auto; }
.row-form.add-row { border: 0; margin-top: .6rem; background: var(--surface-2); padding: .6rem; border-radius: 10px; }
.row-actions { display: flex; flex-wrap: wrap; gap: .6rem; }
details.add-card > summary { list-style: none; display: inline-flex; }
details.add-card[open] > summary { margin-bottom: .8rem; }
details.mail summary { cursor: pointer; }
details.mail pre { white-space: pre-wrap; font-family: inherit; background: var(--surface-2); padding: .7rem; border-radius: 8px; }

/* ---------- Feedback (הערות לשיפור) ---------- */
.fab {
  position: fixed; z-index: 25; inset-inline-end: 16px; bottom: max(16px, env(safe-area-inset-bottom));
  width: 56px; height: 56px; border-radius: 50%; border: 0; cursor: pointer;
  background: var(--primary); color: #fff; font-size: 1.5rem; box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
#fb-drawer { display: none; position: fixed; z-index: 30; inset: 0; background: var(--surface); }
#fb-drawer.open { display: block; }
@media (min-width: 700px) {
  #fb-drawer { inset: 0 auto 0 0; width: 440px; border-inline-start: 1px solid var(--border); box-shadow: 0 0 30px rgba(0,0,0,.18); }
}
#fb-drawer #fb-panel { height: 100%; padding: 1rem; padding-bottom: max(1rem, env(safe-area-inset-bottom)); }
#fb-panel { display: flex; flex-direction: column; gap: .4rem; }
.fb-page #fb-panel { height: calc(100dvh - 140px); min-height: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem; }
.fb-head { display: flex; align-items: center; gap: .4rem; }
.fb-head h2 { margin: 0; margin-inline-end: auto; }
#fb-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: .55rem; padding: .3rem 0; }
.fb-empty { text-align: center; margin: auto; }
.msg { max-width: 88%; align-self: flex-end; background: var(--surface-2); border-radius: 14px; padding: .5rem .75rem; }
.msg.mine { align-self: flex-start; background: var(--primary-soft); }
.msg.editing { width: 88%; }
.msg-meta { display: flex; flex-wrap: wrap; gap: .4rem; align-items: baseline; font-size: .82rem; }
.msg-meta .role { background: var(--surface); border-radius: 5px; padding: 0 .35rem; font-size: .72rem; }
.msg-loc { font-size: .74rem; color: var(--muted); margin: .15rem 0; word-break: break-word; }
.msg-body { white-space: pre-wrap; word-break: break-word; }
.linkbtn { background: none; border: 0; padding: .2rem 0 0; color: var(--primary); font: inherit; font-size: .8rem; cursor: pointer; }
.fb-where { word-break: break-word; }
.fb-compose { display: flex; gap: .4rem; align-items: flex-end; }
.fb-compose textarea { flex: 1; min-height: 44px; resize: vertical; }
