:root {
  --bg: #f5f4fb;
  --card: #fff;
  --text: #1f1b2e;
  --muted: #6b6780;
  --line: #e4e1f0;
  --brand: #5b3fd1;
  --brand-soft: #ece8fd;
  --ok: #17865a;
  --ok-soft: #e3f6ed;
  --warn: #b7650a;
  --warn-soft: #fdf0dc;
  --bad: #c22d3d;
  --bad-soft: #fde6e8;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(30 20 80 / 6%), 0 4px 14px rgb(30 20 80 / 5%);
  font-family: system-ui, "Segoe UI", "Heebo", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; font-size: 15px; line-height: 1.45; }
a { color: var(--brand); text-decoration: none; }
h1 { font-size: 1.35rem; margin: 0; }
h2 { font-size: 1.1rem; margin: 0 0 .6rem; }
h3 { font-size: 1rem; margin: 0 0 .4rem; }
[hidden] { display: none !important; }

/* ----- top bar ----- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem;
  padding: .55rem 1rem; background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); white-space: nowrap; }
.brand small { display: block; font-weight: 400; color: var(--muted); font-size: .72rem; margin-top: -3px; }
.logo {
  width: 34px; height: 34px; border-radius: 10px; background: var(--brand); color: #fff;
  display: grid; place-items: center; font-size: 1.2rem;
}
.nav { display: flex; gap: .25rem; flex: 1; }
.nav a {
  padding: .45rem .8rem; border-radius: 10px; color: var(--muted); font-weight: 500;
  display: flex; align-items: center; gap: .35rem; white-space: nowrap;
}
.nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav .ico { font-size: 1.05rem; }
.user { display: flex; align-items: center; gap: .5rem; color: var(--muted); font-size: .9rem; white-space: nowrap; }

main { max-width: 1100px; margin: 0 auto; padding: 1rem; padding-bottom: 6rem; }
.loading { text-align: center; color: var(--muted); padding: 3rem; }

/* ----- mobile: bottom tab bar ----- */
@media (max-width: 760px) {
  .topbar { padding: .5rem .75rem; }
  .user .who { display: none; }
  .nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
    background: var(--card); border-top: 1px solid var(--line);
    justify-content: space-around; padding: .3rem .25rem calc(.3rem + env(safe-area-inset-bottom));
  }
  .nav a { flex-direction: column; gap: 0; font-size: .7rem; padding: .3rem .4rem; }
  .nav .ico { font-size: 1.25rem; }
  main { padding: .75rem; padding-bottom: 6rem; }
}

/* ----- generic ----- */
.page-head { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.page-head .spacer { flex: 1; }
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1rem; }
.card + .card, .section + .section { margin-top: 1rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  border: 1px solid var(--line); background: var(--card); color: var(--text);
  padding: .5rem .9rem; border-radius: 10px; font: inherit; font-weight: 500; cursor: pointer;
  min-height: 40px;
}
.btn:hover { border-color: #cdc7e6; }
.btn.primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: .25rem .6rem; min-height: 32px; font-size: .88rem; }
.btn:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  font: inherit; color: inherit; width: 100%;
  padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 10px; background: #fff;
  min-height: 42px;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
label { display: block; font-size: .85rem; color: var(--muted); margin-bottom: .25rem; font-weight: 500; }
.field { margin-bottom: .85rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .9rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 .9rem; }
@media (max-width: 560px) { .grid2, .grid3 { grid-template-columns: 1fr; } }
.check { display: flex; align-items: center; gap: .4rem; color: var(--text); font-size: .95rem; cursor: pointer; }
.check input { width: auto; min-height: 0; }

.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .15rem .6rem; border-radius: 999px; background: var(--brand-soft); color: var(--brand);
  font-size: .82rem; font-weight: 500;
}
.chip.gray { background: #efeef4; color: var(--muted); }
.chip button { border: 0; background: none; color: inherit; cursor: pointer; padding: 0 .1rem; font-size: 1rem; line-height: 1; }
.toggle-chips label { margin: 0; }
.toggle-chips input { display: none; }
.toggle-chips span {
  display: inline-block; padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--line);
  cursor: pointer; color: var(--text); font-size: .9rem; background: #fff;
}
.toggle-chips input:checked + span { background: var(--brand); border-color: var(--brand); color: #fff; }

.badge { display: inline-flex; align-items: center; gap: .25rem; padding: .15rem .55rem; border-radius: 8px; font-size: .8rem; font-weight: 600; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.none { background: #efeef4; color: var(--muted); }

/* ----- activities ----- */
.month-nav { display: flex; align-items: center; gap: .25rem; }
.month-nav strong { min-width: 8.5rem; text-align: center; font-size: 1.1rem; }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-bottom: 1rem; }
.filters input[type=search] { max-width: 280px; }
.day { margin-bottom: 1.1rem; }
.day-head { font-weight: 700; margin: 0 .2rem .45rem; display: flex; gap: .5rem; align-items: baseline; }
.day-head.today { color: var(--brand); }
.day-head .muted { font-weight: 400; font-size: .85rem; }
.acts { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: .65rem; }
.act {
  display: block; color: inherit; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: .8rem .9rem; border-inline-start: 4px solid var(--brand); transition: transform .08s;
}
.act:hover { transform: translateY(-1px); }
.act.cancelled { opacity: .55; border-color: var(--muted); }
.act.cancelled .act-title { text-decoration: line-through; }
.act.past { border-color: #c9c4dd; }
.act-title { font-weight: 700; }
.act-sub { color: var(--muted); font-size: .88rem; margin-bottom: .45rem; }
.act-foot { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .5rem; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }

/* ----- detail ----- */
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.assign-list { list-style: none; margin: 0 0 .75rem; padding: 0; }
.assign-list li {
  display: flex; align-items: center; gap: .5rem; padding: .5rem .2rem; border-bottom: 1px solid var(--line);
}
.assign-list li:last-child { border-bottom: 0; }
.assign-list .name { flex: 1; font-weight: 500; }
.slot-empty { color: var(--muted); font-style: italic; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-top: 1rem; }
@media (max-width: 760px) { .detail-grid { grid-template-columns: 1fr; } }

/* ----- tables ----- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: start; padding: .55rem .6rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { color: var(--muted); font-weight: 600; font-size: .82rem; background: #faf9fe; position: sticky; top: 0; }
tr.inactive td { color: var(--muted); }
td.num, th.num { text-align: center; }
tr.group td { background: var(--brand-soft); font-weight: 700; color: var(--brand); }

.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--line); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .55rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 500; }
.tabs a.active { color: var(--brand); border-color: var(--brand); }

/* ----- modal / toast ----- */
dialog {
  border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100vw - 1.5rem));
  max-height: calc(100vh - 2rem); box-shadow: 0 20px 60px rgb(20 10 60 / 25%);
}
dialog::backdrop { background: rgb(20 15 40 / 45%); }
#modal-body { padding: 1.2rem; }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; flex-wrap: wrap; }
pre.message {
  white-space: pre-wrap; font-family: inherit; background: #faf9fe; border: 1px solid var(--line);
  border-radius: 10px; padding: .75rem; margin: 0; max-height: 260px; overflow: auto; font-size: .9rem;
}
.toast {
  position: fixed; bottom: 5.5rem; left: 50%; transform: translateX(-50%) translateY(20px);
  background: #2a2540; color: #fff; padding: .65rem 1.1rem; border-radius: 12px; opacity: 0;
  transition: .2s; pointer-events: none; z-index: 100; max-width: 90vw;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.error { background: var(--bad); }

/* ----- login ----- */
.login { max-width: 380px; margin: 8vh auto 0; }
.login .logo { width: 56px; height: 56px; font-size: 2rem; border-radius: 16px; margin: 0 auto .75rem; }
.login h1 { text-align: center; }
.login p { text-align: center; margin-top: .25rem; }
.err { color: var(--bad); font-size: .9rem; min-height: 1.2em; }

@media print {
  .topbar, .nav, .btn, .filters { display: none !important; }
  .card, .act { box-shadow: none; border: 1px solid #ddd; }
}

/* ===== צבע לכל תכנית ===== */
.p-race  { --pc: #0a74c2; --pcs: #e1f1fc; }
.p-hang  { --pc: #e8650a; --pcs: #fff0e1; }
.p-click { --pc: #6b4fd3; --pcs: #ece8fb; }
.p-meet  { --pc: #0e9384; --pcs: #dcf4f0; }
.p-other { --pc: #7a869c; --pcs: #eaeef3; }
.act[class*="p-"] { border-inline-start-color: var(--pc); }
.chip[class*="p-"] { background: var(--pcs); color: var(--pc); }

/* ===== סרגל כלים: תצוגה, מסננים, סטטיסטיקה ===== */
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--card); }
.seg button { border: 0; background: none; padding: .45rem .9rem; font: inherit; color: var(--muted); cursor: pointer; }
.seg button + button { border-inline-start: 1px solid var(--line); }
.seg button.on { background: var(--brand); color: #fff; font-weight: 600; }
.fchip {
  border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: .3rem .8rem;
  font: inherit; font-size: .88rem; cursor: pointer; display: inline-flex; gap: .35rem; align-items: center;
}
.fchip b { background: #efeef4; color: var(--muted); border-radius: 999px; padding: 0 .45rem; font-size: .78rem; }
.fchip.on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand); font-weight: 600; }
.fchip.on b { background: var(--brand); color: #fff; }
.stats { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: 1rem; font-size: .88rem; color: var(--muted); }
.stats span { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .25rem .7rem; }
.stats b { color: var(--text); font-size: 1.05rem; margin-inline-end: .2rem; }

/* ===== התראות ===== */
.alerts { background: var(--warn-soft); border: 1px solid #f3c98b; border-radius: 12px; padding: .6rem .9rem; margin-bottom: 1rem; }
.alerts summary { cursor: pointer; font-weight: 700; color: var(--warn); }
.alerts ul { margin: .4rem 0 0; padding-inline-start: 1.2rem; }
.alerts li { margin: .2rem 0; }
.alerts a { color: var(--text); }

/* ===== לוח שנה ===== */
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: .5rem; }
.cal .dh { text-align: center; font-weight: 700; font-size: .8rem; color: var(--muted); padding: .25rem; }
.cell { min-height: 96px; border: 1px solid var(--line); border-radius: 8px; padding: 4px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cell.blank { border: 0; }
.cell.none { background: #fbfbfd; }
.cell.today { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand-soft); }
.cell .num { font-weight: 800; font-size: .9rem; }
.cell .wd { display: none; color: var(--muted); font-size: .8rem; }
.pill {
  display: flex; flex-direction: column; gap: 1px; padding: 3px 6px; border-radius: 6px; font-size: .75rem; color: var(--text);
  background: var(--pcs, var(--brand-soft)); border-inline-start: 4px solid var(--pc, var(--brand)); overflow: hidden;
}
.pill b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill small { color: var(--muted); }
.pill .badge { font-size: .68rem; padding: 0 .35rem; align-self: flex-start; }
.pill.dead { opacity: .5; text-decoration: line-through; }
@media (max-width: 760px) {
  .cal { grid-template-columns: 1fr; }
  .cal .dh, .cell.blank, .cell.none { display: none; }
  .cell { min-height: 0; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .cell .wd { display: inline; }
  .pill { flex: 1 1 100%; font-size: .85rem; }
}

/* ===== הערות לפי קהל ===== */
.note { border-radius: 8px; padding: .45rem .7rem; margin-top: .6rem; font-size: .9rem; border-inline-start: 4px solid; white-space: pre-wrap; }
.note b { display: block; font-size: .78rem; margin-bottom: .1rem; }
.note.n-i { background: #e1f1fc; border-color: #0a74c2; }
.note.n-g { background: #fff0e1; border-color: #e8650a; }
.note.n-n { background: #efeef4; border-color: #8a8f98; }

/* ===== בקשות שיבוץ ===== */
.requests { background: var(--warn-soft); border-radius: 10px; padding: .5rem .7rem; margin-bottom: .75rem; }
.requests .req { display: flex; gap: .4rem; align-items: center; padding: .35rem 0; border-top: 1px solid #f3dcb8; }
.requests b { color: var(--warn); }
.nowrap { white-space: nowrap; }

/* ===== אזור אישי ===== */
.pdate { display: flex; flex-direction: column; align-items: center; min-width: 3.2rem; padding: .2rem .4rem;
  background: var(--brand-soft); color: var(--brand); border-radius: 10px; line-height: 1.15; }
.pdate b { font-size: 1.15rem; }
.pdate span { font-size: .72rem; }
div.act { cursor: default; }
div.act:hover { transform: none; }
