:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #1a1f26;
  --muted: #5d6673;
  --line: #d9dee5;
  --brand: #0b3a6e;
  --brand-ink: #ffffff;
  --accent: #1f6fd1;
  --ok: #1d7a3d;
  --ok-bg: #e5f4ea;
  --bad: #b3261e;
  --bad-bg: #fbe9e7;
  --warn: #8a5a00;
  --warn-bg: #fff4d6;
  --pending: #4a5a8c;
  --pending-bg: #e9edf8;
  --plan: #4a8edb;
  --exec: #1f5aa3;
  --radius: 10px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418;
    --surface: #1a1f25;
    --surface-2: #232a32;
    --text: #e7eaee;
    --muted: #9aa4b1;
    --line: #333c47;
    --brand: #16345a;
    --accent: #6aa8f0;
    --ok: #6fcf8e;
    --ok-bg: #173022;
    --bad: #ff8a80;
    --bad-bg: #3a1c1a;
    --warn: #f0c060;
    --warn-bg: #3a2f14;
    --pending: #a9b8ea;
    --pending-bg: #252c44;
    --plan: #a9cdf7;
    --exec: #5b93dc;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Arial, sans-serif;
}
h1, h2, h3 { line-height: 1.25; margin: 0; }
h2 { font-size: 1.15rem; margin-bottom: .6rem; }
h3 { font-size: 1rem; margin-bottom: .4rem; }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: isolate; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
/* בשינויים בין תכנון לביצוע כל צד בצבע משלו (בעל המוצר, 29/09/2026). */
.side-plan { color: var(--plan); }
.side-exec { color: var(--exec); }

/* ---------- מבנה ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1.25rem;
  padding: .6rem max(16px, env(safe-area-inset-right)) .6rem max(16px, env(safe-area-inset-left));
  padding-top: max(.6rem, env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-ink);
}
.topbar h1 { font-size: 1.15rem; }
.tabs { display: flex; gap: .25rem; }
.tabs button {
  border: 0; background: transparent; color: inherit; opacity: .75;
  padding: .35rem .8rem; border-radius: 999px; cursor: pointer;
}
.tabs button[aria-selected="true"] { opacity: 1; background: rgba(255,255,255,.18); font-weight: 600; }
.topbar .credit { flex-basis: 100%; margin: 0; text-align: right; color: #fff; font-size: .8rem; opacity: .85;
  display: flex; flex-wrap: wrap; justify-content: space-between; gap: 0 1rem; }
/* מספר הגרסה בקצה השמאלי, גם כשבמסך צר הוא יורד לשורה משלו. לידו הכפתור לגרסה חדשה שהותקנה. */
.topbar .version { margin-inline-start: auto; display: flex; align-items: center; gap: .5rem; }
#app-update { background: var(--brand-ink); color: var(--brand); border: 0; border-radius: 999px;
  padding: .1rem .7rem; font-size: .8rem; font-weight: 600; cursor: pointer; }
#app-update[hidden] { display: none; }
main { max-width: 1100px; margin: 0 auto; padding: 1rem 16px 3rem; }

.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1rem; margin-bottom: 1rem;
}
.card > h2:first-child { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.count {
  display: inline-block; min-width: 1.6em; padding: 0 .45em; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: .8rem; text-align: center; font-weight: 600;
}
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.spacer { flex: 1; }

.btn {
  border: 1px solid var(--line); background: var(--surface); border-radius: 8px;
  padding: .4rem .9rem; cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.link { border: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline; }

.banner { border-radius: var(--radius); padding: .75rem 1rem; margin-bottom: 1rem; }
.notice { border-radius: 8px; padding: .6rem .8rem; margin: .5rem 0; }
.notice.warn, .banner.warn { background: var(--warn-bg); color: var(--warn); }
.notice.bad, .banner.bad { background: var(--bad-bg); color: var(--bad); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }
.notice.info, .banner.info { background: var(--pending-bg); color: var(--pending); }
.notice ul, .banner ul { margin: .3rem 0 0; padding-inline-start: 1.2rem; }
/* הערה מתחת לרשימה: צמודה אליה, ומתחילה בקו של הטקסט ולא של התבליט. */
.notice .list-note { margin: .15rem 0 0; padding-inline-start: 1.2rem; }
/* קוד לא מוכר: שורת הקוד, ותחתיה מה שהדוח רשם ותשובת המשתמש. */
.notice ul.codes li { margin-bottom: .4rem; }
.notice ul.codes .small { opacity: .85; }
.notice .copy-text { width: 100%; font: inherit; }

/* ---------- העלאה ---------- */
.uploads { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
/* תלוש האש"ל של אפריל: משבצת שלישית, רק בחודש מאי ולבעל המוצר (בעל המוצר, 18/10/2026). */
.uploads.three { grid-template-columns: 1fr 1fr 1fr; }
.drop[hidden] { display: none; }

/* יומן (רשות): שורת מצב מתחת לאזור ההעלאה, וחלון החיבור. */
.calendar-bar { margin: 0 0 1rem; font-size: .95rem; }
.calendar-bar .row { gap: .4rem .6rem; }
.cal-toggle { background: none; border: 0; padding: 0; font: inherit; color: inherit; cursor: pointer; }
.cal-label { color: var(--muted); font-size: .875rem; }
.cal-info { margin-top: .3rem; }
.dialog {
  max-width: min(36rem, calc(100vw - 2rem)); border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: inherit; padding: 1rem 1.2rem;
}
.dialog::backdrop { background: rgb(0 0 0 / .45); }
.dialog h2 { margin-top: 0; }
.dialog ol { padding-inline-start: 1.2rem; line-height: 1.5; }
.dialog label { display: block; margin: .6rem 0; }
.dialog input, .dialog select { width: 100%; box-sizing: border-box; font: inherit; padding: .35rem .5rem; margin-top: .25rem; }
.dialog .row { margin-top: .8rem; }
.drop {
  display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center;
  min-height: 130px; padding: 1rem; cursor: pointer;
  border: 2px dashed var(--line); border-radius: var(--radius); background: var(--surface);
  transition: border-color .15s, background .15s;
}
.drop:hover, .drop.over { border-color: var(--accent); }
.drop.loaded { border-style: solid; border-color: var(--ok); }
.drop.busy { opacity: .6; pointer-events: none; }
.drop-title { font-weight: 700; font-size: 1.05rem; }
.drop-sub { color: var(--muted); font-size: .85rem; line-height: 1.2; }
.drop-state { margin-top: .5rem; font-size: .9rem; word-break: break-word; }
/* קובץ טעון (בעל המוצר, 29/09/2026): לחיצה על הקובץ פותחת אותו, ו"בחר חודש אחר" הוא הדרך היחידה
   לבחור קובץ חדש, חוץ מגרירה. בלי קובץ – כל האזור בוחר קובץ, כמו קודם. */
.drop.loaded { cursor: default; }
.drop.loaded:hover { border-color: var(--ok); }
.drop.loaded.over { border-color: var(--accent); }
.drop.loaded:not(.busy) .drop-state { display: none; }
/* אחרי שנבחר קובץ ההסבר מה להעלות מיותר; רווח קטן בין הכותרת לקובץ (בעל המוצר, 29/09/2026). */
.drop.loaded .drop-sub { display: none; }
.drop.loaded .drop-file { margin-top: .15rem; }
.drop:not(.loaded) .drop-file, .drop:not(.loaded) .drop-pick,
.drop.busy .drop-file, .drop.busy .drop-pick { display: none; }
.drop-file {
  display: flex; align-items: center; gap: .6rem; margin-top: 0; padding: 0 .75rem .25rem; line-height: 1.2;
  font: inherit; color: var(--ok); background: none; text-align: start;
  border: 1px solid transparent; border-radius: var(--radius); cursor: pointer;
}
.drop-file:hover:not(:disabled) { border-color: var(--ok); }
.drop-file:disabled { cursor: default; }
.drop-file > svg { width: 1.6rem; height: 1.6rem; flex: none; }
/* מקום ריק ברוחב הסמל בצד השני, כדי שהחודש ושם הקובץ יהיו בדיוק מתחת לכותרת (בעל המוצר, 29/09/2026). */
.drop-file::after { content: ''; width: 1.6rem; flex: none; }
/* בלי קובץ שמור אין מה לפתוח, ולכן גם אין סמל מסמך (בעל המוצר, 29/09/2026). */
.drop-file:disabled > svg, .drop-file:disabled::after { display: none; }
.drop-file-text { display: flex; flex-direction: column; align-items: center; text-align: center; }
.drop-month { font-weight: 700; font-size: .95rem; }
.drop-name { font-size: .8rem; color: var(--muted); direction: ltr; text-align: center; word-break: break-word; }
.drop-pick {
  display: inline-flex; align-items: center; gap: .35rem; margin-top: .6rem; padding: .3rem .75rem;
  font: inherit; font-size: .85rem; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
}
.drop-pick:hover { border-color: var(--accent); }
.drop svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.drop-pick svg { width: 1em; height: 1em; }
.hint { color: var(--muted); font-size: .875rem; margin: .5rem 0 1rem; }

/* ---------- תוצאות ---------- */
.result-head { display: flex; flex-wrap: wrap; gap: .5rem 1rem; align-items: baseline; }
.result-head h2 { margin: 0; font-size: 1.35rem; }
.result-head .cal-toggle { font-weight: inherit; }
.head-meta { display: none; }
.cal-inline { display: contents; }
.head-name { font-weight: 600; }
.card > h2 .btn { font-size: 1rem; font-weight: normal; }
.meta { color: var(--muted); font-size: .9rem; }

.totals { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: .6rem; }
.total { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .7rem; }
.total .label { font-size: .8rem; color: var(--muted); direction: ltr; text-align: right; }
.total .val { font-size: 1.2rem; font-weight: 700; }
.total .rep { font-size: .85rem; color: var(--muted); }
.total.ok { border-color: var(--ok); }
.total.bad { border-color: var(--bad); background: var(--bad-bg); }
.total.free.bad .val { color: var(--bad); }
.total.warn { border-color: var(--warn); background: var(--warn-bg); }
.total.free.warn .val { color: var(--warn); }
.total.gain { border-color: var(--ok); background: var(--ok-bg); }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .4rem .5rem; border-bottom: 1px solid var(--line); text-align: right; vertical-align: top; }
th { font-weight: 600; color: var(--muted); font-size: .82rem; white-space: nowrap; }
td.col { direction: ltr; text-align: right; white-space: nowrap; }
/* ההסבר מתחת לטיסה בטבלת הפירוט (ואחריו שם החוק בתגית, כמו בהערות), ומתחת לשינוי בטבלת השינויים. */
.chain > summary { cursor: pointer; }
.chain > .explain { border-inline-start: 2px solid var(--line); padding-inline-start: .5rem; margin-inline-start: .3rem; }
.explain { margin-top: .2rem; font-size: .85rem; color: var(--muted); }
tr.bad td { background: var(--bad-bg); }
tr.gain td { background: var(--ok-bg); }
tr.pending td { background: var(--pending-bg); }
tr.detail td { background: var(--surface-2); font-size: .85rem; color: var(--muted); }
.status { font-weight: 700; white-space: nowrap; }
.status.ok { color: var(--ok); }
.status.bad { color: var(--bad); }
.status.gain { color: var(--ok); }
.status.pending { color: var(--pending); }

.filters { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .6rem; }
.chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 999px;
  padding: .2rem .75rem; cursor: pointer; font-size: .875rem;
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }

.list { margin: 0; padding: 0; list-style: none; }
.list > li { padding: .5rem 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list > li.bad { color: var(--bad); }
.list > li.warn { color: var(--warn); background: var(--warn-bg); border-radius: 8px; padding-inline: .6rem; margin: .25rem 0; }
.tag {
  display: inline-block; font-size: .75rem; padding: .05rem .5rem; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.bad { background: var(--bad-bg); color: var(--bad); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.info { background: var(--pending-bg); color: var(--pending); }
/* שם החוק, כשלוחצים על שורה (`setupRuleTips` ב-js/app.js) */
[data-rule] { cursor: pointer; }
.rule-tip {
  position: fixed; z-index: 50; max-width: min(22rem, calc(100vw - 16px));
  padding: .3rem .6rem; border-radius: 6px; font-size: .8rem; white-space: pre-line; pointer-events: none;
  background: var(--text); color: var(--surface); box-shadow: 0 2px 8px rgba(0, 0, 0, .2);
}

/* ---------- שאלות ---------- */
.question { border: 1px solid var(--line); border-radius: 8px; padding: .8rem; margin-bottom: .7rem; }
.question h3 { font-size: .98rem; white-space: pre-line; }
.question h3 .mixed { font-weight: normal; }
.question h3 .mixed b { font-weight: 700; }
.question p { margin: .3rem 0 .6rem; color: var(--muted); font-size: .9rem; }
.option { display: flex; gap: .5rem; align-items: flex-start; padding: .25rem 0; cursor: pointer; }
.option input { margin-top: .3rem; }
.option .hint-inline { color: var(--muted); font-size: .85rem; }
.date-pick { display: flex; gap: .5rem; align-items: center; padding: .25rem 0; }
.date-pick input { font: inherit; padding: .35rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.extra { margin: .3rem 1.6rem .3rem 0; }
.extra select, .extra textarea { width: 100%; max-width: 32rem; padding: .35rem; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.extra textarea { min-height: 3.5em; }
.credit-pick { display: flex; flex-wrap: wrap; gap: .5rem 1rem; margin-top: .4rem; }
.credit-pick label { display: flex; align-items: center; gap: .4rem; }
.credit-pick label[hidden] { display: none; }
.credit-pick select { width: auto; }

/* ---------- היסטוריה וחוקים ---------- */
.month-item { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; }
.month-item .name { font-weight: 700; min-width: 6rem; }
.rules-tools { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin-bottom: 1rem; }
.rules-tools input[type="search"], .rules-tools select {
  padding: .4rem .6rem; border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
}
.rules-tools .search-box { position: relative; flex: 1 1 14rem; min-width: 0; display: flex; }
.rules-tools input[type="search"] { flex: 1; min-width: 0; padding-inline-end: 2rem; }
.rules-tools input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
.search-clear {
  position: absolute; inset-block: 0; inset-inline-end: .2rem; width: 1.8rem; border: 0; background: none;
  color: var(--muted); font-size: 1.3rem; line-height: 1; cursor: pointer;
}
.search-clear[hidden] { display: none; }
.rule { border: 1px solid var(--line); border-radius: 8px; padding: .7rem .8rem; margin-bottom: .6rem; background: var(--surface); }
.rule.inactive { opacity: .65; }
.rule-head { display: flex; flex-wrap: wrap; gap: .35rem .6rem; align-items: center; }
.rule-head h3 { margin: 0; font-size: 1rem; }
.rule dl { display: grid; grid-template-columns: max-content 1fr; gap: .2rem .8rem; margin: .5rem 0 0; font-size: .9rem; }
.rule dt { color: var(--muted); }
.rule dd { margin: 0; white-space: pre-line; }
.rule code { font-size: .8rem; direction: ltr; unicode-bidi: isolate; }

@media (max-width: 600px) {
  .uploads, .uploads.three { grid-template-columns: 1fr; }
  .drop { min-height: 96px; }
  .rule dl { grid-template-columns: 1fr; }
  .rule dt { margin-top: .3rem; }
}

/* ---------- הדפסה / ייצוא PDF ---------- */
@media print {
  :root { --bg: #fff; --surface: #fff; }
  body { background: #fff; font-size: 11pt; }
  .topbar, .no-print, .btn, .filters, .question form { display: none !important; }
  main { max-width: none; padding: 0; }
  .card { border: 0; padding: 0; margin-bottom: 1rem; break-inside: auto; }
  .rule, .question, tr { break-inside: avoid; }
  .table-wrap { overflow: visible; }
  .print-only { display: block !important; }
  .head-meta { display: inline; }
  tr.bad td, tr.gain td, .total.bad, .total.warn, .total.gain, .list > li.bad, .list > li.warn { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.print-only { display: none; }
