:root {
  --bg: #ffffff;
  --panel: #f6f6f8;
  --border: #e2e2e7;
  --border-strong: #cfcfd6;
  --text: #17171a;
  --muted: #6a6a73;
  --accent: #b3261e;
  --accent-dark: #8e1e17;
  --accent-weak: #fdecea;

  /* iOS reports a notch here; without it a fixed header hides under the
     status bar, which is what "cut off at the top" looked like. */
  --safe-top: env(safe-area-inset-top, 0px);
  --bar-h: 68px;
  --header-h: calc(var(--bar-h) + var(--safe-top));
  --sidebar-w: 318px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

/* ---------- top bar ---------- */

/* A working toolbar, not a banner: light surface, dark text, and the accent
   reserved for the one action worth taking. */
#topbar {
  height: var(--header-h);
  padding: var(--safe-top) 14px 0;
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  position: relative;
  z-index: 1200;
}

.brand { display: flex; align-items: baseline; gap: 9px; min-width: 0; }

#topbar h1 {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -.01em;
  margin: 0;
  color: var(--text);
  white-space: nowrap;
  /* Narrow screens: shorten with an ellipsis rather than run under the
     buttons -- the English title is longer than the Hebrew one. */
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

#result-count {
  font-size: 12.5px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

#filters-toggle {
  display: none;            /* only meaningful where the sidebar is a drawer */
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
}
#filters-toggle:hover { background: var(--panel); }
#filters-toggle svg { width: 16px; height: 16px; fill: none; flex: 0 0 auto; }

/* ---------- layout ---------- */

#shell {
  display: flex;
  height: calc(100% - var(--header-h));
}

#sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--panel);
  border-inline-start: 1px solid var(--border);
  overflow: hidden;
}

#sidebar-scroll {
  height: 100%;
  overflow-y: auto;
  padding: 14px;
}

#map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }

/* ---------- filters ---------- */

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 5px;
}

input[type="search"] {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-size: 14px;
  background: #fff;
}

input[type="search"]:focus-visible,
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.facet { margin-bottom: 18px; }

.facet h2 {
  font-size: 13px;
  font-weight: 700;
  margin: 0 0 7px;
  color: var(--text);
}

.facet-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.clear-facet {
  background: none;
  border: 0;
  color: var(--accent);
  font: inherit;
  font-size: 12px;
  cursor: pointer;
  padding: 0 0 7px;
}

.clear-facet[hidden] { display: none; }

#city-search { margin-bottom: 7px; }

.options.scroll {
  max-height: 210px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  padding: 5px;
}

.opt {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 5px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  line-height: 1.35;
}

.opt:hover { background: var(--accent-weak); }
.opt input { margin: 0; flex: 0 0 auto; accent-color: var(--accent); }
.opt .name { flex: 1; min-width: 0; }
.opt .count { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }

.opt.disabled { opacity: .4; cursor: default; }
.opt.disabled:hover { background: none; }

.city-group {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  padding: 7px 5px 2px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}
.city-group:first-child { border-top: 0; margin-top: 0; padding-top: 2px; }

.empty-note { font-size: 12px; color: var(--muted); padding: 6px 5px; margin: 0; }

#reset-all {
  width: 100%;
  padding: 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
}
#reset-all:hover { background: var(--accent-weak); border-color: var(--accent); }

#meta {
  font-size: 11px;
  color: var(--muted);
  line-height: 1.6;
  margin: 14px 0 0;
}
#meta a { color: var(--muted); }

/* ---------- map overlays ---------- */

#status {
  position: absolute;
  top: 14px;
  left: 50%;
  transform: translateX(-50%);
  background: #fff;
  padding: 9px 18px;
  border-radius: 20px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .2);
  z-index: 1000;
  font-size: 14px;
  font-weight: 600;
}
#status[hidden] { display: none; }

#unmapped {
  position: absolute;
  bottom: 22px;
  inset-inline-end: 12px;
  z-index: 1000;
  width: min(270px, calc(100% - 24px));
  background: rgba(255, 255, 255, .97);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .25);
  overflow: hidden;
}
#unmapped[hidden] { display: none; }

#unmapped-toggle {
  width: 100%;
  text-align: start;
  background: none;
  border: 0;
  padding: 10px 12px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
}

#unmapped-list {
  margin: 0;
  padding: 0 12px 10px;
  list-style: none;
  max-height: 190px;
  overflow-y: auto;
  font-size: 12px;
}
#unmapped-list[hidden] { display: none; }
#unmapped-list li { padding: 4px 0; border-top: 1px solid var(--border); }
#unmapped-list .n { font-weight: 600; display: block; }
#unmapped-list .a { color: var(--muted); }

/* ---------- popups ---------- */

.pop { text-align: start; min-width: 190px; }
.pop h3 { margin: 0 0 7px; font-size: 15px; color: var(--accent); }
.pop img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  border-radius: 5px;
  margin-bottom: 7px;
  display: block;
}
.pop dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: 2px 7px; font-size: 13px; }
.pop dt { color: var(--muted); }
.pop dd { margin: 0; }
.pop .approx {
  margin: 7px 0 0;
  font-size: 11px;
  color: #8a5a00;
  background: #fff6e0;
  padding: 4px 6px;
  border-radius: 4px;
}
.pop .links { margin-top: 9px; display: flex; flex-wrap: wrap; gap: 6px 10px; font-size: 13px; }
.pop .badge {
  display: inline-block;
  margin: -3px 0 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef4fd;
  color: #1d3f72;
  font-size: 11.5px;
  font-weight: 600;
}
.pop .desc { margin: 0 0 8px; font-size: 13px; color: var(--text); }
.pop .badge.updated { background: #fff4dd; color: #7a4b00; }
.pop .update-link {
  display: block;
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12.5px;
  color: var(--muted);
}
.pop .update-link:hover { color: var(--accent); }

/* "Is this correct?" on community listings */
.pop .confirm {
  margin-top: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #eef4fd;
  font-size: 12.5px;
}
.pop .confirm-ask { margin: 0 0 6px; font-weight: 600; color: #1d3f72; }
.pop .confirm-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pop .confirm-yes {
  height: 28px; padding: 0 12px; border: 0; border-radius: 6px;
  background: #1d3f72; color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}
.pop .confirm-yes:disabled { opacity: .6; cursor: default; }
.pop .confirm-no { color: #1d3f72; }
.pop .confirm-note { margin: 6px 0 0; color: var(--muted); font-size: 11.5px; }
.pop .confirm-note:empty { display: none; }
.pop .links a { color: var(--accent); }

.leaflet-popup-content { margin: 11px 13px; }

/* "Show all pins", under the zoom buttons. */
.pins-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  background: var(--bg);
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
  user-select: none;
}
.pins-toggle input { margin: 0; accent-color: var(--accent); }
.pins-toggle[hidden] { display: none; } /* only offered from city-level zoom */

/* ---------- mobile ---------- */

@media (max-width: 760px) {
  :root { --bar-h: 64px; }

  #filters-toggle { display: inline-flex; }
  #topbar h1 { font-size: 14.5px; }
  /* Not enough width for filter + title + count + action; the count is the
     least important of the four and the sidebar repeats the information. */
  #result-count { display: none; }
  #topbar { gap: 9px; padding-inline: 10px; }
  #add-restaurant { padding: 0 11px; font-size: 13px; }
  #filters-toggle { padding: 0 10px; }

  /* The sheet lives at the right edge, under the Filters button, and slides
     fully off to the right when closed. Physical left/right on purpose: the
     layout is the Hebrew one in both languages, and the earlier logical
     insets put it at the left edge with ~40px peeking in at the right. */
  #sidebar {
    position: fixed;
    top: var(--header-h);
    bottom: 0;
    right: 0;
    left: auto;
    width: min(88vw, 340px);
    flex: none;
    z-index: 1100;
    transform: translateX(102%);
    transition: transform .22s ease;
    box-shadow: 0 0 22px rgba(0, 0, 0, .3);
    border: 0;
  }
  #sidebar.open { transform: translateX(0); }

  #unmapped { bottom: 14px; }
  .options.scroll { max-height: 180px; }
}

@media (prefers-reduced-motion: reduce) {
  #sidebar { transition: none; }
}

/* ---------- add-restaurant action ---------- */

.add-cta {
  margin-inline-start: auto;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  flex: 0 0 auto;
}

.add-prompt {
  font-size: 11.5px;
  line-height: 1;
  color: var(--muted);
  /* Centred over the button; the group as a whole sits at the left of the bar. */
  text-align: center;
  white-space: nowrap;
}

#add-restaurant {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 600;
  border-radius: 8px;
  white-space: nowrap;

  /* The gleam is a pseudo-element sweeping across; clip it to the button. */
  position: relative;
  overflow: hidden;
  isolation: isolate;
}
#add-restaurant:hover { background: var(--accent-dark); }
#add-restaurant:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#add-restaurant svg { width: 15px; height: 15px; fill: none; flex: 0 0 auto; position: relative; z-index: 1; }
#add-restaurant span { position: relative; z-index: 1; }

/* A highlight crosses the button every 30 seconds so the action keeps
   announcing itself without moving or resizing anything.
   Driven by `transform`, not by a logical inset: Safari does not reliably
   interpolate inset-inline-start in keyframes, which left this invisible. */
#add-restaurant::after {
  content: "";
  position: absolute;
  top: -60%;
  bottom: -60%;
  left: 0;
  width: 54px;
  background: linear-gradient(90deg,
    rgba(255, 255, 255, 0) 0%,
    rgba(255, 255, 255, .75) 50%,
    rgba(255, 255, 255, 0) 100%);
  transform: translateX(-150%) skewX(-18deg);
  animation: gleam 30s linear infinite;
  pointer-events: none;
  z-index: 0;
}

/* The sweep itself lasts ~1s; the rest of the cycle it waits off-stage, so it
   reads as an occasional glint rather than a moving element. */
@keyframes gleam {
  0%    { transform: translateX(-150%) skewX(-18deg); }
  3.4%  { transform: translateX(460%)  skewX(-18deg); }
  100%  { transform: translateX(460%)  skewX(-18deg); }
}

@media (prefers-reduced-motion: reduce) {
  #add-restaurant::after { animation: none; opacity: 0; }
}

/* ---------- language ---------- */

/* i18n.js sets this before paint when the page isn't Hebrew, and clears it
   once the markup is translated, so the Hebrew source never flashes. */
html[data-i18n-pending] body { visibility: hidden; }

.lang-toggle {
  margin-inline-start: auto;
  flex: 0 0 auto;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
  font-size: 13.5px;
  cursor: pointer;
}
.lang-toggle:hover { background: var(--panel); }
.lang-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* The toggle now takes the push to the far end; the action sits right after it. */
.lang-toggle + .add-cta { margin-inline-start: 0; }
.lang-toggle .short { display: none; }

@media (max-width: 420px) {
  /* Room for the title next to the language toggle: the filter button keeps
     its icon (and its accessible name) but drops the word. */
  #filters-toggle > span { display: none; }
  #filters-toggle { padding: 0 10px; }
  .lang-toggle { padding: 0 9px; }
  .lang-toggle .long { display: none; }
  .lang-toggle .short { display: inline; }
}

/* English text inside the Hebrew layout. The page stays dir="rtl" in both
   languages, so everything keeps its place; these blocks hold text, and in
   English it reads left to right. Only elements whose own direction moves
   nothing else are listed -- not the language toggle, whose margin places it,
   nor #unmapped, whose inset does (its contents are turned instead). */
html[lang="en"] :is(.brand, .add-prompt, #filters-toggle, #add-restaurant,
                    #sidebar-scroll, #status, #unmapped-toggle, #unmapped-list,
                    .leaflet-popup-content, .pins-toggle) {
  direction: ltr;
}

/* Restaurant data reads in its own direction (dir="auto": Hebrew right to left
   on the English page too) but lines up with the page it sits on. */
html[lang="en"] [dir="auto"] { text-align: left; }
html[lang="he"] [dir="auto"] { text-align: right; }
