/* Perth Pathways — light, mobile-first, RTL-aware.
   Layout contract:
     mobile  → map fills the viewport; the list is a bottom sheet in 3 states (peek / half / full)
     desktop → map left, list as a fixed side panel; nothing overlaps the header or chip bar
*/

:root {
  --bg: #ffffff;
  --bg-soft: #f4f5f9;
  --ink: #15182b;
  --ink-soft: #5b6178;
  --line: #e4e6ef;
  --line-strong: #c8cbdb;
  --accent: #522569;
  --accent-soft: #f3eef6;
  --focus: #6B3A86;

  --radius: 12px;
  --radius-lg: 18px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .07), 0 6px 18px rgba(0, 0, 0, .07);
  --shadow-sheet: 0 -2px 8px rgba(0, 0, 0, .06), 0 -10px 34px rgba(0, 0, 0, .12);

  --sheet-min: 26px;       /* the bare handle: the map gets the whole screen */
  --sheet-peek: 76px;      /* handle, count and tabs */
  --sheet-half: 48%;       /* percentages here are of the map pane, never of the viewport,
                              so the sheet can never slide up underneath the header */
  --sheet-full: 4%;
  --detail-half: 42%;      /* a strip of map stays visible above the place card */
  --detail-full: 4%;
  --panel-w: 400px;

  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --tap: 44px;             /* minimum touch target */
}

* { box-sizing: border-box; }

/* `hidden` must beat any display rule below, or panels stack on top of each other */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  /* the sheets are translated downwards; without this they grow the document and the
     whole page becomes scrollable, which on a phone drags the header out of view */
  overflow: hidden;
  overscroll-behavior-y: none;
}

body {
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  font-size: 16px;
  letter-spacing: -.005em;
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

/* Arabic / Persian / Kurdish / Pashto: prefer a naskh face, slightly larger for legibility */
[dir="rtl"] body {
  font-family: "Noto Naskh Arabic", "Segoe UI", "Tahoma", system-ui, sans-serif;
  font-size: 16.5px;
  line-height: 1.6;
}

/* Amharic is written in Ge'ez (Ethiopic) script: Nyala / Ebrima on Windows, Noto elsewhere */
html[lang="am"] body {
  font-family: "Noto Sans Ethiopic", "Nyala", "Ebrima", "Kefa", system-ui, sans-serif;
  font-size: 16.5px;
}

/* shown only for languages marked "draft" in i18n/index.json */
.draft-note {
  margin: 0; padding: 6px 14px; font-size: .8rem; line-height: 1.4;
  background: #fff8e6; color: #6b4e00; border-bottom: 1px solid #f1e2b8; text-align: center;
}

/* ?embed=1 — the map shown inside the website, which has its own header */
.embed header { display: none; }

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 6px;
}

.sr {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

/* ============================ header ============================ */

header {
  flex: 0 0 auto;
  position: relative;
  z-index: 600;
  padding: calc(9px + var(--safe-t)) 16px 9px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
}

.brand-mark {
  flex: 0 0 auto;
  width: auto;
  height: 36px;
  display: block;
}

.brand h1 {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 1.12rem;
  font-weight: 760;
  letter-spacing: -.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lang-select {
  flex: 0 0 auto;
  min-height: 36px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 6px 30px 6px 12px;
  background: var(--bg-soft) no-repeat;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%),
                    linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-size: 5px 5px, 5px 5px;
  background-position: right 13px center, right 8px center;
  font-size: .85rem;
  appearance: none;
  -webkit-appearance: none;
  max-width: 9.5rem;
}
[dir="rtl"] .lang-select {
  padding: 6px 12px 6px 30px;
  background-position: left 8px center, left 13px center;
  background-image: linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%),
                    linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
}


/* ============================ category chips ============================ */

.chips {
  flex: 0 0 auto;            /* must not shrink — this is what let the map bleed upward */
  position: relative;
  z-index: 550;
  display: flex;
  gap: 7px;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-padding-inline: 16px;
}
.chips::-webkit-scrollbar { display: none; }

.chip {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 36px;
  padding: 7px 13px;
  border-radius: 10px;
  border: 1.5px solid var(--c-border, var(--line-strong));
  background: var(--c-bg, #fff);
  color: var(--c-text, var(--ink));
  font-size: .85rem;
  font-weight: 620;
  white-space: nowrap;
  transition: background .13s ease, color .13s ease, border-color .13s ease;
}
/* selected: the full category colour, with the text colour JavaScript measured as readable */
.chip[aria-pressed="true"] {
  background: var(--c-on-bg, var(--ink));
  color: var(--c-on-text, #fff);
  border-color: var(--c-on-bg, var(--ink));
  font-weight: 680;
}
.chip.chip-all { --c-bg: #fff; --c-text: var(--ink); --c-border: var(--line-strong);
                 --c-on-bg: var(--ink); --c-on-text: #fff; }
.chip.chip-open { --c-bg: #e8f7f1; --c-text: #08624a; --c-border: #a8ddc9;
                  --c-on-bg: #047857; --c-on-text: #fff; }
.chip.chip-open .ico { font-size: .82rem; line-height: 1; }

/* ============================ map area ============================ */

main {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;          /* clips the sheets when they sit below the fold */
  isolation: isolate;        /* keeps Leaflet's internal z-indexes out of the header */
}

#map { position: absolute; inset: 0; background: #e9ebf2; }

.map-btn {
  position: absolute;
  z-index: 420;
  inset-inline-end: 12px;
  top: 12px;
  min-height: 38px;
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: .84rem;
  font-weight: 620;
  box-shadow: var(--shadow);
  display: inline-flex;
  align-items: center;
  gap: 7px;
}
#btn-near[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }

/* map markers: a rounded tile carrying the category glyph */
.pin {
  width: 30px; height: 30px;
  border-radius: 11px 11px 11px 3px;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(21, 24, 43, .36);
  display: grid;
  place-items: center;
  color: #fff;
  transition: transform .14s ease, box-shadow .14s ease;
}
.pin .glyph { width: 17px; height: 17px; display: block; }
.pin.is-active {
  transform: scale(1.3);
  box-shadow: 0 0 0 4px rgba(49, 46, 129, .26), 0 3px 10px rgba(21, 24, 43, .45);
  z-index: 5;
}
.you-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: var(--focus); border: 3px solid #fff;
  box-shadow: 0 0 0 5px rgba(43, 108, 212, .2);
}

/* ============================ bottom sheet ============================ */

.sheet {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  z-index: 450;
  height: 100%;
  background: var(--bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-sheet);
  display: flex;
  flex-direction: column;
  transform: translateY(calc(100% - var(--sheet-peek)));
  transition: transform .32s cubic-bezier(.32, .72, 0, 1);
  will-change: transform;
  touch-action: none;
}
.sheet[data-state="min"]  { transform: translateY(calc(100% - var(--sheet-min))); }
.sheet[data-state="half"] { transform: translateY(var(--sheet-half)); }
.sheet[data-state="full"] { transform: translateY(var(--sheet-full)); }

.grabber {
  flex: 0 0 auto;
  position: relative;
  padding: 14px 16px 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.grabber:active { cursor: grabbing; }
.grabber::before {
  content: "";
  position: absolute;
  inset-inline: 0;
  top: 6px;
  margin: 0 auto;
  width: 40px; height: 4px;
  border-radius: 2px;
  background: var(--line-strong);
}

.count {
  flex: 1;
  min-width: 0;
  font-size: .83rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tabs { display: flex; gap: 3px; flex: 0 0 auto; }
.tab {
  min-height: 32px;
  padding: 6px 11px;
  border-radius: 999px;
  font-size: .79rem;
  color: var(--ink-soft);
  border: 1px solid transparent;
  white-space: nowrap;
}
.tab[aria-selected="true"] {
  background: var(--bg-soft);
  border-color: var(--line);
  color: var(--ink);
  font-weight: 640;
}

.sheet-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 0 12px calc(24px + var(--safe-b));
}

/* ============================ result rows ============================ */

.row {
  display: flex;
  align-items: stretch;
  gap: 4px;
  border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: 0; }

.row-open {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  gap: 11px;
  align-items: flex-start;
  text-align: start;
  padding: 12px 4px;
  border-radius: 10px;
}
.row-open:active { background: var(--bg-soft); }

.badge {
  flex: 0 0 auto;
  width: 34px; height: 34px;
  border-radius: 11px;
  color: #fff;
  display: grid;
  place-items: center;
}
.badge .glyph { width: 19px; height: 19px; display: block; }

/* the quiet reference code that replaced the printed map's numbering */
.row-code {
  font: 600 .68rem/1 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  letter-spacing: .06em;
  color: var(--ink-soft);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 6px;
}

.chip .chip-glyph { width: 15px; height: 15px; display: block; flex: 0 0 auto; }

.row-main { min-width: 0; flex: 1; }
.row-title { font-weight: 620; font-size: .95rem; line-height: 1.35; }
.row-orig {
  font-size: .78rem;
  color: var(--ink-soft);
  margin-top: 1px;
  direction: ltr;
  text-align: start;
}
[dir="rtl"] .row-orig { text-align: right; }

.row-meta {
  font-size: .79rem;
  color: var(--ink-soft);
  margin-top: 4px;
  display: flex;
  flex-wrap: wrap;
  gap: 3px 9px;
  line-height: 1.45;
}
.row-dist { font-weight: 640; color: var(--ink); }
.row-cat { display: inline-flex; align-items: center; gap: 5px; }
.row-cat .dot { width: 7px; height: 7px; border-radius: 50%; }

.heart {
  flex: 0 0 auto;
  width: var(--tap);
  display: grid;
  place-items: center;
  font-size: 1.15rem;
  line-height: 1;
  color: #c6c2ba;
  border-radius: 10px;
}
.heart[aria-pressed="true"] { color: var(--accent); }

.empty {
  padding: 40px 18px;
  text-align: center;
  color: var(--ink-soft);
  font-size: .92rem;
  line-height: 1.6;
}

.loading { padding: 40px; text-align: center; color: var(--ink-soft); font-size: .9rem; }

/* ============================ needs ("new here") ============================ */

.needs-wrap { padding: 4px 4px 16px; }
.needs-q { font-weight: 650; margin: 8px 2px 12px; font-size: .97rem; }
.needs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 8px;
}
.need {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 13px 13px;
  min-height: 60px;
  text-align: start;
  font-size: .88rem;
  font-weight: 560;
  line-height: 1.4;
  background: #fff;
  display: flex;
  align-items: center;
  gap: 10px;
}
.need .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.need:active { background: var(--bg-soft); }

/* ============================ detail ============================ */

/* A sheet over the map, not a new screen: the map stays visible above it so the
   person keeps their bearings, and the same pull gesture raises or dismisses it. */
.detail {
  position: absolute;
  inset-inline: 0;
  bottom: 0;
  height: 100%;
  z-index: 500;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-sheet);
  overflow: hidden;
  transform: translateY(var(--detail-half));
  transition: transform .3s cubic-bezier(.32, .72, 0, 1);
  will-change: transform;
  touch-action: none;
}
.detail[data-state="full"] { transform: translateY(var(--detail-full)); }
.detail[hidden] { display: none; }

.detail-head {
  flex: 0 0 auto;
  position: relative;
  padding: 18px 16px 13px;
  border-bottom: 1px solid var(--line);
  display: flex;
  align-items: flex-start;
  gap: 11px;
  touch-action: none;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
}
/* the same grab handle as the list sheet: pull down to dismiss */
.detail-head::before {
  content: "";
  position: absolute;
  inset-inline: 0;
  top: 7px;
  margin: 0 auto;
  width: 40px; height: 4px;
  border-radius: 2px;
  background: var(--line-strong);
}
.detail-head h2, .detail-head .detail-orig, .detail-head .detail-cat { user-select: text; -webkit-user-select: text; }
.detail-head .badge { width: 40px; height: 40px; border-radius: 13px; }
.detail-head .badge .glyph { width: 22px; height: 22px; }
.detail-title { flex: 1; min-width: 0; }
.detail-title h2 { margin: 0; font-size: 1.08rem; line-height: 1.32; }
.detail-orig { font-size: .82rem; color: var(--ink-soft); margin-top: 2px; direction: ltr; }
[dir="rtl"] .detail-orig { text-align: right; }
.detail-cat { font-size: .79rem; color: var(--ink-soft); margin-top: 4px; display: inline-flex; align-items: center; gap: 6px; }
.detail-cat .dot { width: 8px; height: 8px; border-radius: 50%; }

.icon-btn {
  flex: 0 0 auto;
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--bg-soft);
  display: grid;
  place-items: center;
  font-size: 1.1rem;
  line-height: 1;
}

.detail-body {
  flex: 1 1 auto;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 15px 16px calc(28px + var(--safe-b));
}
.detail-body > p { margin: 0 0 15px; line-height: 1.6; font-size: .95rem; }

.field { margin-bottom: 16px; }
.field h3 {
  margin: 0 0 4px;
  font-size: .71rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--ink-soft);
  font-weight: 680;
}
.field div, .field a { font-size: .95rem; line-height: 1.55; word-break: break-word; }
.field .ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

.actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 8px;
  margin: 2px 0 20px;
}
.action {
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 12px 6px;
  min-height: 62px;
  text-align: center;
  font-size: .79rem;
  font-weight: 620;
  text-decoration: none;
  color: var(--ink);
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.action .ico { font-size: 1.05rem; line-height: 1; }
.action:active { background: var(--bg-soft); }
.action.primary { background: var(--ink); color: #fff; border-color: var(--ink); }

.note {
  font-size: .81rem;
  color: var(--ink-soft);
  background: var(--bg-soft);
  border-radius: var(--radius);
  padding: 11px 13px;
  line-height: 1.55;
  margin: 0 0 12px;
}
.note.warn { background: var(--accent-soft); color: #522569; }

.toast {
  position: fixed;
  inset-inline: 0;
  bottom: calc(26px + var(--safe-b));
  margin: 0 auto;
  width: max-content;
  max-width: 86%;
  background: var(--ink);
  color: #fff;
  font-size: .86rem;
  padding: 10px 17px;
  border-radius: 999px;
  z-index: 1200;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity .2s, transform .2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }

/* ============================ desktop ============================ */

@media (min-width: 900px) and (pointer: fine) {
  main { display: flex; }

  #map { position: relative; flex: 1 1 auto; inset: auto; height: 100%; }

  .sheet {
    position: relative;
    inset: auto;
    z-index: 1;                 /* below Leaflet controls is fine — it is a sibling, not an overlay */
    order: 2;
    flex: 0 0 var(--panel-w);
    width: var(--panel-w);
    height: 100%;
    border-radius: 0;
    border-inline-start: 1px solid var(--line);
    box-shadow: none;
    transform: none !important;
  }
  .grabber { cursor: default; padding-top: 12px; }
  .grabber::before { display: none; }

  .detail {
    inset: 0 0 0 auto;
    height: auto;
    width: var(--panel-w);
    border-radius: 0;
    border-inline-start: 1px solid var(--line);
    box-shadow: none;
    transform: none !important;
    touch-action: auto;
    animation: fadeIn .18s ease;
  }
  @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

  .detail-head { padding-top: 13px; cursor: default; touch-action: auto; }
  .detail-head::before { display: none; }
  .detail { border-radius: 0; }
  #btn-near { inset-inline-end: calc(var(--panel-w) + 12px); }
  .row-open:hover { background: var(--bg-soft); }
  .chip:hover { border-color: var(--ink-soft); }
  .need:hover { border-color: var(--ink-soft); background: var(--bg-soft); }
}

/* map library missing (offline, blocked CDN, ancient browser) → plain full-height list */
body.no-map #map, body.no-map .map-btn { display: none; }
body.no-map .sheet {
  position: absolute;
  inset: 0;
  width: auto;
  height: auto;
  transform: none !important;
  border-radius: 0;
  box-shadow: none;
  border: 0;
}
body.no-map .grabber::before { display: none; }

/* Leaflet */
.leaflet-container { font: inherit; background: #e8e6e0; }
.leaflet-control-attribution { font-size: 10px; }
.leaflet-control-zoom a { width: 32px; height: 32px; line-height: 32px; }
.leaflet-bottom.leaflet-right { margin-bottom: 2px; }

/* ============================ open-now badges ============================ */

.open-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: .76rem;
  font-weight: 640;
  line-height: 1.5;
  white-space: nowrap;
}
.open-badge::before {
  content: "";
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: 0 0 auto;
}
.open-badge.now   { background: #e4f4e8; color: #1f6b38; }
.open-badge.today { background: #fdf1df; color: #8a5a10; }
.open-badge.next  { background: var(--bg-soft); color: var(--ink-soft); }

.detail-body > p > .open-badge { font-size: .84rem; padding: 4px 12px; }

