:root {
  --bg: #f4f6f9;
  --panel: #ffffff;
  --ink: #16202c;
  --muted: #6a7684;
  --line: #dfe4ea;
  --line-strong: #c3cbd5;
  --brand: #1f6feb;
  --brand-dark: #1657bd;
  --ok: #1a7f4f;
  --ok-bg: #e6f5ed;
  --warn: #b26a00;
  --warn-bg: #fdf3e0;
  --bad: #c0392b;
  --bad-bg: #fdecea;
  --weekend: #f0f2f5;
  --holiday: #f6efff;
  --holiday-ink: #6b3fa0;
  --personal: #fff6e5;
  --sick: #fdeaf0;
  --sick-ink: #b23a63;
  --reserve: #eaf1e0;
  --reserve-ink: #5c7a29;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(16,32,48,.08), 0 6px 20px rgba(16,32,48,.05);
}

* { box-sizing: border-box; }
/* חייב לגבור על כללי display של רכיבים שמוסתרים עם התכונה hidden */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Heebo', 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}
h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 700; }
.muted { color: var(--muted); }
.error { color: var(--bad); background: var(--bad-bg); padding: .5rem .75rem; border-radius: 8px; font-size: 13px; }
a { color: var(--brand); }

/* ---------- כפתורים ---------- */
.btn {
  font: inherit; font-weight: 500;
  border: 1px solid var(--line-strong);
  background: #fff; color: var(--ink);
  padding: .45rem .9rem; border-radius: 8px; cursor: pointer;
  transition: background .12s, border-color .12s, box-shadow .12s;
  white-space: nowrap;
}
.btn:hover { background: #f7f9fb; border-color: var(--muted); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn.danger { color: var(--bad); border-color: #edc4bf; }
.btn.danger:hover { background: var(--bad-bg); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn.small { padding: .25rem .6rem; font-size: 13px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

input, select, textarea {
  font: inherit; color: inherit;
  border: 1px solid var(--line-strong); border-radius: 8px;
  padding: .45rem .6rem; background: #fff; width: 100%;
}
input:focus, select:focus { outline: 2px solid rgba(31,111,235,.35); outline-offset: 0; border-color: var(--brand); }
label { display: block; font-size: 13px; font-weight: 500; margin-bottom: .75rem; }
label > input, label > select { margin-top: .25rem; font-weight: 400; }

/* ---------- מסך התחברות ---------- */
.login-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 1rem;
  background: linear-gradient(160deg, #eef3fb, #f7f5fb);
}
.login-card {
  background: var(--panel); padding: 2rem; border-radius: 14px;
  box-shadow: var(--shadow); width: min(380px, 100%);
}
.login-card h1 { font-size: 1.35rem; }
.login-card .muted { margin: 0 0 1.25rem; font-size: 13px; }

/* ---------- סרגל עליון ---------- */
.topbar {
  display: flex; align-items: center; gap: 1rem;
  background: var(--panel); border-bottom: 1px solid var(--line);
  padding: .5rem 1rem; position: sticky; top: 0; z-index: 40;
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; }
.logo {
  display: grid; place-items: center; width: 28px; height: 28px;
  background: var(--brand); color: #fff; border-radius: 8px; font-size: 15px;
}
.nav { display: flex; gap: .15rem; flex: 1; flex-wrap: wrap; }
.nav button {
  font: inherit; font-weight: 500; border: 0; background: transparent;
  padding: .4rem .8rem; border-radius: 8px; cursor: pointer; color: var(--muted);
}
.nav button:hover { background: rgba(0,0,0,.05); color: var(--ink); }
.nav button.active { background: rgba(31,111,235,.1); color: var(--brand); }
.topbar-left { display: flex; align-items: center; gap: .35rem; }
.whoami { font-size: 13px; color: var(--muted); }

.view { padding: 1.25rem; max-width: 1600px; margin: 0 auto; }

/* ---------- פאנלים ---------- */
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 1rem;
}
.panel-head {
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
  padding: .75rem 1rem; border-bottom: 1px solid var(--line);
}
.panel-head h2 { font-size: 1rem; margin: 0; }
.panel-body { padding: 1rem; }
.spacer { flex: 1; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }

/* ---------- כרטיסי סיכום ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: .75rem; }
.stat {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .75rem .9rem;
}
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-size: 1.5rem; font-weight: 700; line-height: 1.2; }
.stat.ok .v { color: var(--ok); }
.stat.bad .v { color: var(--bad); }
.stat.warn .v { color: var(--warn); }

/* ---------- טבלאות ---------- */
.table-wrap { overflow: auto; max-width: 100%; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
th, td { border-bottom: 1px solid var(--line); padding: .45rem .6rem; text-align: right; }
thead th {
  background: #f7f9fb; font-weight: 700; position: sticky; top: 0; z-index: 5;
  border-bottom: 1px solid var(--line-strong); white-space: nowrap;
}
tbody tr:hover { background: #fafbfc; }

/* ---------- גרירה לסידור מחדש ---------- */
tr.draggable-row .drag-handle {
  cursor: grab; color: var(--muted); text-align: center; width: 28px;
  font-size: 15px; user-select: none;
}
tr.draggable-row.dragging { opacity: .4; }
tr.draggable-row.drag-over { box-shadow: inset 0 2px 0 var(--brand); }

.num { text-align: center; font-variant-numeric: tabular-nums; }
.pill {
  display: inline-block; padding: .1rem .5rem; border-radius: 99px;
  font-size: 12px; font-weight: 500; background: #eef1f4; color: var(--muted);
}
.pill.ok { background: var(--ok-bg); color: var(--ok); }
.pill.bad { background: var(--bad-bg); color: var(--bad); }
.pill.warn { background: var(--warn-bg); color: var(--warn); }
.pill.brand { background: rgba(31,111,235,.1); color: var(--brand); }
.pill.sick { background: var(--sick); color: var(--sick-ink); }
.pill.reserve { background: var(--reserve); color: var(--reserve-ink); }

/* ---------- גיליון ההזנה ---------- */
.sheet-wrap { overflow: auto; max-height: calc(100vh - 260px); }
table.sheet { border-collapse: separate; border-spacing: 0; font-size: 13px; width: auto; min-width: 100%; }
table.sheet th, table.sheet td {
  border-bottom: 1px solid var(--line); border-left: 1px solid var(--line);
  padding: 0; text-align: center; white-space: nowrap;
}
table.sheet th { background: #f7f9fb; font-weight: 700; padding: .3rem .4rem; }

/* עמודות מוקפאות (RTL: right) */
.sheet .c-proj {
  position: sticky; right: 0; z-index: 6; background: var(--panel);
  width: 180px; min-width: 180px; max-width: 180px;
  text-align: right; padding: .3rem .55rem !important;
  border-left: 1px solid var(--line-strong) !important;
  overflow: hidden; text-overflow: ellipsis;
}
.sheet .c-pct {
  position: sticky; right: 180px; z-index: 6; background: var(--panel);
  width: 76px; min-width: 76px; max-width: 76px;
  font-variant-numeric: tabular-nums; padding: .3rem .4rem !important;
  border-left: 1px solid var(--line-strong) !important; font-weight: 500;
}
.sheet .c-days {
  position: sticky; right: 256px; z-index: 6; background: var(--panel);
  width: 58px; min-width: 58px; max-width: 58px;
  font-variant-numeric: tabular-nums; padding: .3rem .4rem !important;
  border-left: 2px solid var(--line-strong) !important;
}
.sheet thead .c-proj, .sheet thead .c-pct, .sheet thead .c-days { z-index: 8; background: #f7f9fb; }
.sheet tfoot .c-proj, .sheet tfoot .c-pct, .sheet tfoot .c-days { background: #f7f9fb; }

.sheet td.day { min-width: 40px; width: 40px; }
.sheet td.day input {
  width: 100%; height: 30px; border: 0; border-radius: 0; padding: 0 2px;
  text-align: center; background: transparent; font-variant-numeric: tabular-nums;
}
.sheet td.day input:focus { outline: 2px solid var(--brand); outline-offset: -2px; background: #fff; z-index: 3; position: relative; }
.sheet td.day input:disabled { color: var(--muted); }
.sheet td.day.has-val { background: rgba(31,111,235,.07); font-weight: 500; }
.sheet .off { background: var(--weekend); }
.sheet .off input { background: transparent; }
.sheet th.off { background: #e9ecf1; color: var(--muted); }
.sheet .hol { background: var(--holiday); }
.sheet th.hol { background: #ebe0fb; color: var(--holiday-ink); }
.sheet .pers, .sheet .pers-vacation { background: var(--personal); }
.sheet th.pers, .sheet th.pers-vacation { background: #ffeaba; color: var(--warn); }
.sheet .pers-sick { background: var(--sick); }
.sheet th.pers-sick { background: #fad7e3; color: var(--sick-ink); }
.sheet .pers-reserve { background: var(--reserve); }
.sheet th.pers-reserve { background: #d9e8c7; color: var(--reserve-ink); }
.sheet th.today { box-shadow: inset 0 -3px 0 var(--brand); }
.sheet .half::after { content: '½'; position: absolute; }
.sheet thead th.dcol { cursor: pointer; }
.sheet thead th.dcol:hover { filter: brightness(.95); }
.sheet tfoot td { font-weight: 700; background: #f7f9fb; padding: .3rem .3rem; }
.sheet tfoot td.s-ok { color: var(--ok); background: var(--ok-bg); }
.sheet tfoot td.s-under { color: var(--warn); background: var(--warn-bg); }
.sheet tfoot td.s-over { color: var(--bad); background: var(--bad-bg); }
.sheet tfoot td.s-empty { color: var(--muted); }
.sheet .dnum { font-size: 13px; }
.sheet .dlet { font-size: 11px; font-weight: 400; color: var(--muted); }
.sheet tr.total-row td { background: #eef1f4; font-weight: 700; }

.legend { display: flex; gap: .9rem; flex-wrap: wrap; font-size: 12px; color: var(--muted); align-items: center; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; border: 1px solid var(--line-strong); margin-left: .3rem; vertical-align: -2px; }

/* ---------- מודאל ---------- */
.modal { border: 0; border-radius: 12px; padding: 0; box-shadow: 0 20px 60px rgba(0,0,0,.25); width: min(440px, 92vw); }
.modal::backdrop { background: rgba(16,32,48,.4); }
.modal form { padding: 1.25rem; }
.modal h3 { font-size: 1.05rem; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-start; margin-top: 1rem; }

/* ---------- טוסט ---------- */
.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%);
  background: #16202c; color: #fff; padding: .6rem 1.1rem; border-radius: 99px;
  font-size: 13px; z-index: 100; box-shadow: 0 8px 30px rgba(0,0,0,.25);
}
.toast.bad { background: var(--bad); }

.bar { height: 8px; background: #eef1f4; border-radius: 99px; overflow: hidden; min-width: 90px; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; }

@media (max-width: 720px) {
  .view { padding: .75rem; }
  .nav { order: 3; width: 100%; }
  .sheet .c-proj { width: 120px; min-width: 120px; max-width: 120px; }
  .sheet .c-pct { right: 120px; }
  .sheet .c-days { display: none; }
}

@media print {
  .topbar, .btn, .legend { display: none !important; }
  .sheet-wrap { max-height: none; overflow: visible; }
  body { background: #fff; }
}
