:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --text: #17312e;
  --muted: #5d716e;
  --line: #dde6e4;
  --primary: #1f6f68;
  --primary-soft: #e3f2ef;
  --paid: #1d7a46;
  --paid-soft: #e2f4e9;
  --due: #b4541a;
  --due-soft: #fbeadf;
  --sent: #8a6d00;
  --sent-soft: #fbf3d3;
  --danger: #b3261e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(23, 49, 46, .06), 0 4px 16px rgba(23, 49, 46, .06);
  font-family: "Rubik", system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
  color: var(--text);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1a19; --surface: #172624; --text: #e5efed; --muted: #9ab0ac; --line: #26403c;
    --primary: #4fb3a8; --primary-soft: #1d3a37;
    --paid: #6fcf97; --paid-soft: #183427; --due: #f0a06a; --due-soft: #3a2619;
    --sent: #e6c75a; --sent-soft: #36301a; --danger: #f2827a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); min-height: 100dvh; font-size: 16px; line-height: 1.45; }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.muted { color: var(--muted); }
a { color: var(--primary); }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }

/* כפתורים וטפסים */
.btn {
  font: inherit; font-weight: 500; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  border-radius: 10px; padding: 10px 14px; cursor: pointer; min-height: 44px; white-space: nowrap;
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
}
.btn:hover { border-color: var(--primary); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { color: var(--danger); }
.btn.link { border: none; background: none; color: var(--primary); }
.btn.small { min-height: 36px; padding: 6px 10px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
label { display: grid; gap: 6px; font-size: 14px; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; width: 100%; min-height: 44px;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.form { display: grid; gap: 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.actions.end { justify-content: flex-start; margin-top: 4px; }
.heb-hint { font-size: 13px; color: var(--primary); min-height: 1.2em; }
.msg { min-height: 1.2em; color: var(--danger); margin: 0; font-size: 14px; }

/* כניסה */
.login { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.login-card { width: min(400px, 100%); display: grid; gap: 14px; padding: 28px 22px; }
.login-card h1 { color: var(--primary); }

/* מבנה */
.app { min-height: 100dvh; }
.nav {
  position: fixed; inset: auto 0 0 0; z-index: 10; display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom);
}
.brand { display: none; }
.nav-item {
  font: inherit; font-size: 12px; border: none; background: none; color: var(--muted); padding: 8px 4px 10px;
  display: grid; justify-items: center; gap: 2px; cursor: pointer; min-height: 56px;
}
.nav-item .ico { font-size: 20px; line-height: 1; }
.nav-item.active { color: var(--primary); font-weight: 700; }
main { padding: 0 16px calc(84px + env(safe-area-inset-bottom)); max-width: 1100px; margin: 0 auto; }
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--bg); display: flex; align-items: center;
  justify-content: space-between; gap: 12px; padding: 14px 0 12px;
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.sync { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.sync.live { background: var(--paid); }

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 220px 1fr; }
  .nav {
    position: sticky; top: 0; height: 100dvh; inset: auto; display: flex; flex-direction: column; gap: 4px;
    border-top: none; border-inline-start: 1px solid var(--line); padding: 20px 12px;
  }
  .brand { display: block; font-weight: 700; font-size: 20px; color: var(--primary); padding: 0 12px 16px; }
  .nav-item { display: flex; gap: 10px; font-size: 16px; padding: 12px; border-radius: 10px; min-height: 0; }
  .nav-item.active { background: var(--primary-soft); }
  main { padding: 8px 32px 40px; width: 100%; }
}

/* כרטיסים */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { padding: 14px 16px; }
.stat .label { font-size: 14px; color: var(--muted); }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 4px; }
.stat.due .value { color: var(--due); }
.stat.paid .value { color: var(--paid); }
.section { margin-bottom: 24px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.section-head h3 { font-size: 17px; }
.list { display: grid; gap: 10px; }
.empty { padding: 20px; text-align: center; color: var(--muted); }

.item { padding: 12px 14px; display: grid; gap: 10px; }
.item-main { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.item-title { font-weight: 700; }
.item-sub { font-size: 14px; color: var(--muted); }
.item-amount { font-weight: 700; font-size: 18px; text-align: left; }
.clickable { cursor: pointer; }
.clickable:hover { border-color: var(--primary); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13px; padding: 3px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); white-space: nowrap; }
.chip.paid { background: var(--paid-soft); color: var(--paid); }
.chip.due { background: var(--due-soft); color: var(--due); }
.chip.sent { background: var(--sent-soft); color: var(--sent); }
.chip.muted { background: var(--line); color: var(--muted); }

.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 14px; }
.filter { font: inherit; font-size: 14px; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 999px; padding: 6px 14px; cursor: pointer; white-space: nowrap; min-height: 36px; }
.filter.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.search { margin-bottom: 12px; }

/* לוח שנה */
.cal-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.cal-title { text-align: center; flex: 1; }
.cal-title .greg { font-weight: 700; font-size: 18px; }
.cal-title .heb { font-size: 14px; color: var(--muted); }
.cal-nav { font-size: 20px; min-width: 44px; padding: 6px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.cal-dow { text-align: center; font-size: 12px; color: var(--muted); padding: 4px 0; }
.cal-day {
  font: inherit; color: var(--text); text-align: start; background: var(--surface); border: 1px solid var(--line);
  border-radius: 8px; min-height: 64px; padding: 4px; cursor: pointer; display: flex; flex-direction: column; gap: 2px; overflow: hidden;
}
.cal-day.other { opacity: .45; }
.cal-day.shabbat { background: var(--primary-soft); }
.cal-day.chag { background: var(--sent-soft); }
.cal-day.today .cal-num { background: var(--primary); color: #fff; border-radius: 999px; padding: 0 6px; }
.cal-day.selected { outline: 2px solid var(--primary); outline-offset: -1px; }
.cal-top { display: flex; justify-content: space-between; align-items: baseline; gap: 2px; }
.cal-num { font-weight: 700; font-size: 14px; }
.cal-heb { font-size: 11px; color: var(--muted); white-space: nowrap; }
.cal-hol { font-size: 10px; line-height: 1.2; color: var(--sent); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-hol.fast { color: var(--due); }
.cal-hol.parasha { color: var(--muted); }
.cal-dots { display: flex; flex-wrap: wrap; gap: 3px; margin-top: auto; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--primary); }
.dot.paid { background: var(--paid); } .dot.due { background: var(--due); } .dot.muted { background: var(--line); }
.cal-ses { display: none; }
.day-panel { margin-top: 16px; }
.day-panel .hols { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 10px; }
@media (min-width: 900px) {
  .cal-day { min-height: 118px; padding: 6px; }
  .cal-heb { font-size: 12px; }
  .cal-hol { font-size: 11px; }
  .cal-dots { display: none; }
  .cal-ses { display: flex; flex-direction: column; gap: 2px; }
  .cal-chip {
    font: inherit; font-size: 12px; border: none; border-radius: 6px; padding: 2px 5px; cursor: pointer; text-align: start;
    background: var(--surface); color: var(--primary); box-shadow: inset 0 0 0 1px var(--line); line-height: 1.25;
    /* שם ארוך עובר לשורה שנייה במקום להיחתך */
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word;
  }
  .cal-chip.paid { background: var(--paid-soft); color: var(--paid); }
  .cal-chip.due { background: var(--due-soft); color: var(--due); }
  .cal-chip.muted { background: var(--line); color: var(--muted); text-decoration: line-through; }
}

/* חלון */
dialog {
  border: none; padding: 0; border-radius: 18px; background: var(--surface); color: var(--text);
  width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
dialog::backdrop { background: rgba(10, 25, 23, .45); }
#dialog-body { padding: 20px; display: grid; gap: 14px; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.close { font-size: 22px; line-height: 1; border: none; background: none; color: var(--muted); cursor: pointer; padding: 4px 8px; }
.preview { background: var(--bg); border-radius: 10px; padding: 12px; white-space: pre-wrap; font-size: 15px; word-break: break-word; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.toast {
  position: fixed; inset-inline: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); z-index: 50; margin: 0 auto; max-width: 420px;
  background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 12px; text-align: center; box-shadow: var(--shadow);
}
@media (min-width: 900px) { .toast { bottom: 24px; } }
