:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #16202b;
  --muted: #5b6876;
  --border: #d5dce4;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --ok: #16a34a;
  --shadow: 0 6px 24px rgba(15, 23, 42, 0.18);
  --bar-h: 56px;
  --panel-w: 390px;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #0f141a;
  --surface: #18202a;
  --surface-2: #212b37;
  --text: #e8edf3;
  --muted: #98a6b5;
  --border: #2d3846;
  --accent: #5b9bff;
  --accent-text: #08111f;
  --danger: #f87171;
  --ok: #4ade80;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans Hebrew", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
[hidden] { display: none !important; }
svg { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top bar ---------- */
#bar {
  height: var(--bar-h); flex: none; z-index: 1200;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 0 12px; padding-inline: max(12px, env(safe-area-inset-left)) max(12px, env(safe-area-inset-right));
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand svg { stroke: none; flex: none; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.brand-text strong { font-size: 16px; }
.brand-text span { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.actions { display: flex; align-items: center; gap: 6px; flex: none; }

button {
  font: inherit; color: inherit; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; min-width: 40px; padding: 0 10px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
}
button:hover { border-color: var(--accent); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
button svg { width: 20px; height: 20px; flex: none; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--danger); }
button.danger-fill { background: var(--danger); color: #fff; border-color: var(--danger); }
button.icon { padding: 0; }
.seg { display: flex; gap: 6px; }
.seg button { flex: 1; }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 600; }
#btn-user.signed-in { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
input[type="email"] { direction: ltr; }

/* ---------- map ---------- */
#stage { position: relative; flex: 1; min-height: 0; }
#map { position: absolute; inset: 0; background: var(--bg); }
:root[data-theme="dark"]:not([data-map="sat"]) .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(0.92) contrast(0.88) saturate(0.8); }
:root[data-theme="dark"] .leaflet-container { background: #0f141a; }
.leaflet-container { font: inherit; }
.leaflet-control-attribution { background: color-mix(in srgb, var(--surface) 85%, transparent) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--accent) !important; }
.leaflet-bar a { background: var(--surface); color: var(--text); border-color: var(--border); }
.leaflet-bar a:hover { background: var(--surface-2); color: var(--text); }

.cam-pin {
  width: 34px; height: 34px; border-radius: 50%;
  display: grid; place-items: center; color: #fff;
  border: 3px solid #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.45);
  transition: transform 0.12s;
}
:root[data-theme="dark"] .cam-pin { border-color: #18202a; }
.cam-pin svg { width: 18px; height: 18px; stroke: #fff; stroke-width: 2; }
.cam-pin.sel { transform: scale(1.25); }
.cam-pin.pending { opacity: 0.6; border-style: dashed; }
.cam-pin.stealth { opacity: 0.7; border-style: dotted; }
.cam-pin.mine::after { content: ""; position: absolute; inset: -7px; border-radius: 50%; border: 2px dashed currentColor; opacity: 0.8; }
.spot-pin { width: 18px; height: 18px; border-radius: 50%; background: var(--danger); border: 3px solid #fff; box-shadow: 0 0 0 4px rgba(220, 38, 38, 0.3); }
.me-pin { width: 16px; height: 16px; border-radius: 50%; background: #0ea5e9; border: 3px solid #fff; box-shadow: 0 0 0 5px rgba(14, 165, 233, 0.3); }

#banner {
  position: absolute; z-index: 1000; top: 10px; inset-inline: 10px; margin-inline: auto; width: fit-content; max-width: calc(100% - 20px);
  background: var(--accent); color: var(--accent-text); padding: 8px 14px; border-radius: 999px;
  font-weight: 600; box-shadow: var(--shadow); text-align: center;
}
.fab {
  position: absolute; z-index: 1000; inset-block-start: var(--fab-top, 12px); inset-inline-end: 12px;
  box-shadow: var(--shadow); background: var(--surface);
}
#banner:not([hidden]) ~ .fab { inset-block-start: calc(var(--fab-top, 12px) + 44px); }

/* ---------- panel ---------- */
#panel {
  position: absolute; z-index: 1100; display: flex; flex-direction: column;
  background: var(--surface); box-shadow: var(--shadow); border: 1px solid var(--border);
  inset-block: 10px; inset-inline-start: 10px; width: var(--panel-w); max-width: calc(100% - 20px);
  border-radius: 16px; overflow: hidden;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px 10px 16px; padding-inline: 16px 12px; border-bottom: 1px solid var(--border); flex: none; }
.panel-head h2 { margin: 0; font-size: 17px; }
#panel-body { overflow-y: auto; padding: 14px 16px 24px; flex: 1; -webkit-overflow-scrolling: touch; }

.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; color: #fff; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.row > * { flex: 1 1 0; }
.stack > * + * { margin-top: 12px; }

.item {
  display: block; width: 100%; text-align: start; padding: 10px 12px; margin: 0 0 8px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; min-height: 0;
}
.item .t { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.item .s { color: var(--muted); font-size: 13px; margin-top: 2px; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.card { background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 12px; }
a.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; color: inherit;
  min-height: 42px; padding: 0 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; font-weight: 600;
}
a.btn.call { background: var(--ok); border-color: var(--ok); color: #fff; }
:root[data-theme="dark"] a.btn.call { color: #052e14; }
a.btn.sos { background: var(--danger); border-color: var(--danger); color: #fff; font-size: 18px; }
a.btn svg { width: 18px; height: 18px; }

/* ---------- form ---------- */
label { display: block; font-weight: 600; margin-bottom: 4px; }
input[type="text"], input[type="tel"], input[type="number"], input[type="search"], input[type="password"], select, textarea {
  width: 100%; min-height: 42px; padding: 8px 10px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
}
input[type="tel"] { direction: ltr; text-align: start; }
html[dir="rtl"] input[type="tel"] { text-align: right; }
textarea { min-height: 70px; resize: vertical; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.hint { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; font-size: 13px; color: var(--muted); }
.err { color: var(--danger); font-weight: 600; margin: 0; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 400; font-size: 13.5px; }
.check input { margin-top: 3px; width: 20px; height: 20px; flex: none; }
.dial-wrap { display: flex; gap: 14px; align-items: center; }
.dial { width: 120px; height: 120px; flex: none; touch-action: none; cursor: grab; }
.dial circle.ring { fill: var(--surface-2); stroke: var(--border); }
.dial text { fill: var(--muted); font-size: 11px; stroke: none; text-anchor: middle; dominant-baseline: central; font-weight: 700; }
.dial .needle { stroke: var(--accent); stroke-width: 3; }
.dial .knob { fill: var(--accent); stroke: var(--surface); stroke-width: 2; }
.form-actions { position: sticky; bottom: -24px; padding: 12px 0 0; background: linear-gradient(transparent, var(--surface) 30%); display: flex; gap: 8px; }
.form-actions > * { flex: 1; }

/* ---------- toast / dialog ---------- */
#toast {
  position: fixed; z-index: 2000; bottom: 24px; inset-inline: 0; margin-inline: auto; width: fit-content; max-width: calc(100% - 32px);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 600;
}
dialog { border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); width: min(360px, calc(100% - 32px)); padding: 20px; }
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog h3 { margin: 0 0 6px; }
dialog form > * + * { margin-top: 10px; }
dialog button { width: 100%; }

/* ---------- mobile ---------- */
@media (max-width: 560px) { .brand-text { display: none; } }
@media (max-width: 720px) {
  .brand-text span, #btn-add span { display: none; }
  #bar { padding-inline: 8px; gap: 4px; }
  .actions { gap: 4px; }
  button { padding: 0 8px; }
  #panel {
    inset-block: auto 0; inset-inline: 0; width: auto; max-width: none; height: 52%;
    border-radius: 18px 18px 0 0; border-bottom: 0; padding-bottom: env(safe-area-inset-bottom);
  }
  #panel.tall { height: 78%; }
  .leaflet-bottom { bottom: 52%; }
  body.panel-closed .leaflet-bottom { bottom: 0; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
