:root {
  --bg: #eef1f6; --card: #fff; --text: #0f172a; --muted: #4b5563; --line: #cfd6e4;
  --accent: #1d4ed8; --accent-text: #fff; --ok: #15803d; --warn: #b45309; --danger: #b91c1c;
  --code-bg: #fde68a; --code-text: #451a03; --shadow: 0 -6px 24px rgba(15, 23, 42, .22);
  --tag: #7c3aed;
}
:root[data-theme="dark"] {
  --bg: #0a0f1c; --card: #151e33; --text: #f8fafc; --muted: #b6c0d4; --line: #2b3857;
  --accent: #60a5fa; --accent-text: #0a0f1c; --ok: #4ade80; --warn: #fbbf24; --danger: #f87171;
  --code-bg: #422006; --code-text: #fde68a; --shadow: 0 -6px 24px rgba(0, 0, 0, .6);
  --tag: #c4b5fd;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { font-size: 18px; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body {
  background: var(--bg); color: var(--text);
  font-family: Heebo, Assistant, system-ui, -apple-system, "Segoe UI", Arial, sans-serif; line-height: 1.35;
}
button, .btn, input, select, textarea { font: inherit; color: inherit; }
#stage { position: relative; height: 100dvh; overflow: hidden; }
#map { position: absolute; inset: 0; background: var(--bg); z-index: 0; }
#nomap { padding: 70px 24px 0; text-align: center; color: var(--muted); font-size: 1rem; }
#map.leaflet-container #nomap { display: none; }
.tiles-dark { filter: invert(1) hue-rotate(180deg) brightness(.85) contrast(.9); } /* גיבוי רסטר בלילה */
#layer-menu { display: flex; flex-direction: column; gap: 6px; padding: 8px; background: var(--card); border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 4px 14px rgba(0,0,0,.35); }
#layer-menu[hidden] { display: none; }
#pickbar {
  position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 76px; left: 10px; z-index: 650; display: flex; gap: 8px;
  align-items: center; justify-content: space-between; background: var(--accent); color: var(--accent-text);
  padding: 6px 12px; border-radius: 14px; font-weight: 700; min-height: 52px;
}
#pickbar .btn { color: var(--text); }
#pickbar[hidden], #banner[hidden], #ovbar[hidden], #toast[hidden], #why-box[hidden], #loc-sbox[hidden], #toast-b[hidden] { display: none; }
#banner {
  position: absolute; top: calc(76px + env(safe-area-inset-top)); right: 10px; left: 10px; z-index: 640; padding: 8px 12px;
  background: var(--code-bg); color: var(--code-text); display: flex; gap: 8px; align-items: center; justify-content: space-between;
  border-radius: 12px; font-size: 1rem;
}
#ovbar {
  position: absolute; top: calc(76px + env(safe-area-inset-top)); right: 10px; left: 10px; z-index: 645; padding: 8px 12px;
  background: #fff8e1; color: #3a2e00; display: flex; gap: 8px; align-items: center; justify-content: space-between;
  border-radius: 12px; font-size: .95rem; font-weight: 700; box-shadow: 0 2px 8px rgba(0,0,0,.25);
}
#toast {
  position: absolute; bottom: 14px; right: 12px; left: 12px; z-index: 900; display: flex; gap: 10px; align-items: center;
  justify-content: space-between; background: #111827; color: #fff; padding: 6px 8px 6px 14px; border-radius: 14px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,.5);
}
#toast .btn { background: #fff; color: #111827; }

/* מגירה */
#drawer {
  position: absolute; right: 0; left: 0; bottom: 0; z-index: 700; background: var(--bg); border-radius: 22px 22px 0 0;
  box-shadow: var(--shadow); display: flex; flex-direction: column; overflow: hidden; height: 300px;
}
#dhead { flex: none; touch-action: none; cursor: grab; background: var(--card); border-bottom: 1px solid var(--line); }
.grip { height: 22px; display: flex; align-items: center; justify-content: center; }
.grip span { width: 48px; height: 5px; border-radius: 3px; background: var(--line); }
.hrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 0 12px 8px; }
.title { display: flex; flex-direction: column; align-items: flex-start; min-width: 0; flex: 1; background: none; border: 0; padding: 0; text-align: right; cursor: pointer; min-height: 48px; justify-content: center; }
#rname::after { content: ' ▾'; color: var(--muted); }
.hrow .btn { padding: 0 10px; }
.title b { font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#count { font-size: 1.3rem; font-weight: 800; }
#dbody { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 10px 10px 40px; }
#dbody main { max-width: 640px; margin: 0 auto; }
#drawer[data-state="peek"] #dbody { display: none; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  min-height: 48px; min-width: 48px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--card); text-decoration: none; cursor: pointer; font-weight: 700;
}
.btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.btn.ok { background: var(--ok); color: #fff; border-color: transparent; }
:root[data-theme="dark"] .btn.ok { color: #052e16; }
.btn.danger { color: var(--danger); }
.btn.danger.armed { background: var(--danger); color: #fff; }
.btn.small { padding: 0 10px; font-weight: 600; }
.btn.big { min-height: 56px; font-size: 1.1rem; }

/* כרטיסים והחלקה */
.sw { position: relative; margin-bottom: 10px; border-radius: 16px; overflow: hidden; background: var(--line); }
.sw-bg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: flex-start; padding: 0 22px; font-size: 1.3rem; font-weight: 800; color: #fff; opacity: 0; transition: none; }
.sw-bg .a { display: none; }
.sw[data-dir="done"] .sw-bg { background: var(--ok); opacity: calc(.1 + .9 * var(--p, 0)); justify-content: flex-end; }
:root[data-theme="dark"] .sw[data-dir="done"] .sw-bg { color: #052e16; }
.sw[data-dir="done"] .sw-bg .a { display: none; }
.sw[data-dir="fail"] .sw-bg { background: #d64545; opacity: calc(.1 + .9 * var(--p, 0)); justify-content: flex-start; }
:root[data-theme="dark"] .sw[data-dir="fail"] .sw-bg { color: #fff; }
.sw[data-dir="fail"] .sw-bg .d { display: none; }
.sw[data-dir="fail"] .sw-bg .a { display: inline; }
.sw.armed .sw-bg { filter: brightness(1.15); font-size: 1.5rem; }
.sw .card, .sw .row-item { position: relative; touch-action: pan-y; user-select: none; -webkit-user-select: none; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 12px; }
.card.current { border: 3px solid var(--accent); padding: 14px; }
.card.hl { outline: 4px solid var(--tag); }
.hd { display: flex; align-items: center; gap: 8px; font-size: 1.25rem; }
.hd b { flex: 1; min-width: 0; }
.num { background: var(--accent); color: var(--accent-text); border-radius: 999px; min-width: 2.4em; text-align: center; padding: 2px 8px; font-weight: 800; font-size: 1.1rem; }
.current .num { font-size: 1.6rem; background: var(--ok); color: #fff; }
:root[data-theme="dark"] .current .num { color: #052e16; }
.tag { direction: ltr; unicode-bidi: isolate; background: var(--tag); color: #fff; border: 0; border-radius: 999px; min-width: 48px; min-height: 48px; font-weight: 800; font-size: 1.1rem; padding: 0 10px; cursor: pointer; }
:root[data-theme="dark"] .tag { color: #1e1b4b; }
.sens { color: var(--warn); font-size: 1.2rem; background: none; border: 0; min-width: 48px; min-height: 48px; cursor: pointer; opacity: .85; }
.addr { font-size: 1.2rem; margin: 4px 0; }
.current .addr { font-size: 1.35rem; font-weight: 600; }
.meta { color: var(--muted); font-size: 1.05rem; }
.code { margin: 6px 0; padding: 6px 10px; background: var(--code-bg); color: var(--code-text); border-radius: 10px; font-size: 1.7rem; font-weight: 800; letter-spacing: 1px; text-align: center; }
.code bdi { direction: ltr; unicode-bidi: isolate; }
.nopin { margin: 6px 0; padding: 6px 10px; border: 2px dashed var(--warn); border-radius: 10px; color: var(--warn); font-weight: 700; display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.extra, .hint { color: var(--muted); font-size: 1rem; margin: 4px 0; }
.warn { color: var(--warn); font-size: 1rem; font-weight: 600; }
.btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.btns .btn { flex: 1 1 0; padding: 0 4px; min-width: 0; font-size: .88rem; }
.btns .btn.ok { flex: 1.4 1 0; }
.btns .btn.more { flex: 0 0 48px; }
.btns .btn.nav { flex: 1 1 100%; min-height: 56px; font-size: 1.2rem; }
.row-item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; background: var(--card); min-height: 56px; cursor: pointer; }
.row-item.hl { outline: 4px solid var(--tag); outline-offset: -4px; }
.row-item .t { flex: 1; min-width: 0; }
.row-item .t b, .row-item .t span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-item .t span { color: var(--muted); font-size: 1rem; }
details.done { margin-top: 14px; }
details.done summary { min-height: 48px; display: flex; align-items: center; font-weight: 700; cursor: pointer; }
.done-item { opacity: .85; margin-bottom: 8px; }
.failtag { color: var(--danger); font-weight: 800; }
.tools { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }
.tools .btn { flex: 1 1 40%; }
.pending { font-size: 1rem; color: var(--muted); align-self: center; }
#msg { min-height: 1.4em; margin: 2px 2px 8px; color: var(--muted); font-size: 1rem; }
#msg.err { color: var(--danger); }
.empty { text-align: center; padding: 24px 10px; font-size: 1.1rem; }
.empty .btn { margin-top: 10px; }
.muted { color: var(--muted); font-size: 1rem; }

/* חלונות */
dialog { border: 1px solid var(--line); border-radius: 16px; background: var(--card); color: var(--text); width: min(92vw, 460px); padding: 14px; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog h2 { margin: 0 0 10px; font-size: 1.2rem; }
dialog label { display: block; margin-bottom: 12px; font-weight: 600; }
dialog input[type=password], dialog input[type=search], dialog input[type=text], dialog input[type=tel], dialog select {
  width: 100%; min-height: 48px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg);
}
dialog input[type=file] { display: block; margin-top: 6px; min-height: 48px; width: 100%; }
dialog textarea { width: 100%; font: inherit; padding: 8px; margin-bottom: 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); }
dialog.sheet { margin: auto auto 0; width: 100%; max-width: 560px; border-radius: 22px 22px 0 0; border-bottom: 0; padding-bottom: calc(14px + env(safe-area-inset-bottom)); animation: up .2s ease; }
@keyframes up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 10px; }
.grid.one { grid-template-columns: 1fr; }
dialog.sheet > .btn:last-child { width: 100%; }
.row { display: flex; gap: 8px; margin-top: 6px; }
.row input { flex: 1; min-width: 0; }
#loc-results .btn, #add-results .btn { width: 100%; margin: 4px 0; justify-content: flex-start; text-align: right; }

/* 1.3: מתקדם, מסלולים, נקודות, שינוי כתובת, כרטיס פתוח */
#adv { margin: 8px 0 12px; border: 1px solid var(--line); border-radius: 12px; padding: 0 10px; }
#adv summary { min-height: 48px; display: flex; align-items: center; font-weight: 700; cursor: pointer; }
.pts h3 { margin: 8px 0 6px; font-size: 1.05rem; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg .btn { flex: 1 1 0; padding: 0 6px; }
.sblock { margin: 8px 0; }
.sblock .results .btn { width: 100%; margin: 4px 0; justify-content: flex-start; text-align: right; }
#addr-search { margin-bottom: 8px; }
#addr-mode[hidden] { display: none; }
#addr-mode small { font-weight: 500; }
.hd.closable { cursor: pointer; }
.chev { color: var(--muted); font-size: 1rem; padding: 0 6px; }
.was { color: var(--muted); font-size: 1rem; display: flex; align-items: center; gap: 8px; justify-content: space-between; margin: 2px 0; }
#addr-mode .btn { flex-direction: column; gap: 0; }
#addr-mode small { font-size: .85rem; }
#rt-load, #set-routes { width: 100%; margin: 6px 0 8px; }

/* דיווח על הדרך */
.road-h { margin: 8px 0 6px; font-size: 1rem; }
#dlg-road .btn.sel { background: var(--accent); color: var(--accent-text); border-color: transparent; }
#dlg-road { max-height: 94vh; overflow-y: auto; }
#road-dir-l { margin: 4px 0 8px; }
#dlg-road [hidden] { display: none !important; }

/* 2.0: הרשאות ופרטי משפחה */
[data-feat][hidden] { display: none !important; }
#det-form { display: flex; flex-direction: column; gap: 8px; margin: 8px 0; }
#det-form label { display: flex; align-items: center; gap: 10px; font-size: 1.05rem; }
#det-form label > span { flex: 0 0 6.5em; color: var(--muted); }
#det-form input { flex: 1; min-width: 0; font-size: 1.1rem; padding: 10px; border-radius: 10px; border: 1px solid var(--sep, #ccc); background: var(--card, transparent); color: inherit; }
#det-form input[readonly] { opacity: .6; }
#det-diff .drow { display: flex; flex-direction: column; padding: 8px 0; border-bottom: 1px solid var(--sep, #ddd); }
#det-diff .drow b { font-size: 1rem; }
#det-diff .was-v { color: var(--muted); text-decoration: line-through; }
#det-diff .new-v { font-weight: 700; }
#det-btns { flex-wrap: wrap; }
#det-form[hidden], #det-btns[hidden], #det-confirm[hidden], #det-request[hidden], #det-revert[hidden] { display: none !important; }
#det-form input { padding: 7px 10px; }

/* כל שדה בתוך חלון (מספר, שעה, תאריך, טקסט, בחירה) לוקח את צבעי העיצוב - גם בלילה (היה לבן על לבן בשדות מספר) */
dialog input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=range]), dialog select, dialog textarea {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px; min-height: 44px; padding: 0 10px; caret-color: var(--text);
}
dialog textarea { padding: 8px; }
dialog input::placeholder, dialog textarea::placeholder { color: var(--muted); opacity: .8; }
:root[data-theme="dark"] dialog, :root[data-theme="dark"] input, :root[data-theme="dark"] select, :root[data-theme="dark"] textarea { color-scheme: dark; }
#round-body input[type=checkbox], dialog input[type=checkbox] { width: 24px; height: 24px; }

/* בועת הערות פיתוח (מנהל): מעל כרטיס העצירה (710), מתחת להודעה (900); חלונות dialog תמיד מעליה */
#dn-bubble { position: fixed; z-index: 850; width: 46px; height: 46px; border-radius: 50%; border: 0; padding: 0; font-size: 1.4rem; line-height: 1; background: var(--blue, #1d4ed8); color: #fff; box-shadow: 0 3px 12px rgba(0,0,0,.4); opacity: .85; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab; }
#dn-bubble[hidden] { display: none; }
#dn-bubble.dn-bl { left: 8px; bottom: calc(92px + env(safe-area-inset-bottom)); }
#dn-bubble.dn-br { right: 8px; bottom: calc(92px + env(safe-area-inset-bottom)); }
#dn-bubble.dn-tl { left: 8px; top: calc(130px + env(safe-area-inset-top)); }
#dn-bubble.dn-tr { right: 8px; top: calc(130px + env(safe-area-inset-top)); }
#dlg-devnote textarea { min-height: 38vh; }

/* העיפרון: ההערות שלי והמצב שלהן (22.11) */
#dlg-devnote { max-height: 92dvh; overflow-y: auto; }
.dn-mine-h { margin: 14px 0 6px; font-size: 1.05rem; }
.dn-mine { display: flex; flex-direction: column; gap: 8px; }
.dn-item { border: 1px solid var(--line); border-radius: 12px; padding: 8px 10px; border-inline-start: 5px solid #9ca3af; }
.dn-item.st-done { border-inline-start-color: #16a34a; }
.dn-item.st-working, .dn-item.st-new { border-inline-start-color: #f59e0b; }
.dn-item.st-asked { border-inline-start-color: #3b82f6; }
.dn-top { display: flex; justify-content: space-between; gap: 8px; font-size: .9rem; }
.dn-st { font-weight: 700; }
.dn-when { color: var(--muted, #6b7280); }
.dn-txt { margin-top: 4px; }
.dn-reply { margin-top: 4px; font-size: .92rem; color: var(--muted, #6b7280); }

/* 23.11: קלט קובץ מוסתר נשאר מוסתר גם בתוך חלון (היה מופיע "בחירת קובץ"), ובחירת הניווט קטנה ובצד */
dialog input[type=file][hidden] { display: none; }
.small-sec summary { font-size: .9rem; color: var(--muted, #6b7280); font-weight: 400; }
