:root {
  --ink: #1d1b16;
  --ink-soft: #5c574c;
  --paper: #ffffff;
  --line: #ddd6c8;
  --gold: #b8862a;
  --gold-deep: #8f6619;
  --shadow: 0 2px 10px rgba(29, 27, 22, 0.16);
  --bar-h: 64px;
  --font-ui: "Instrument Sans", system-ui, sans-serif;
  --font-brand: "Merriweather", Georgia, serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: var(--font-ui);
  color: var(--ink);
  background: #ebe7df;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }

[hidden] { display: none !important; }

:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* Top bar */

.bar {
  position: fixed;
  inset: 0 0 auto 0;
  height: var(--bar-h);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top);
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.brand h1 {
  font-family: var(--font-brand);
  font-weight: 900;
  font-size: 1.35rem;
  line-height: 1.1;
  color: var(--gold-deep);
}

.brand p { font-size: 0.8rem; color: var(--ink-soft); }

.bar-actions { display: flex; gap: 8px; align-items: center; }

.call, .edit-toggle {
  display: inline-flex;
  align-items: center;
  height: 40px;
  padding: 0 16px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.9rem;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
}

.call { background: var(--gold); color: #fff; border: 0; }
.call:hover { background: var(--gold-deep); }

.edit-toggle { background: var(--paper); border: 1px solid var(--line); }
.edit-toggle[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }

/* Search */

.search {
  position: fixed;
  top: calc(var(--bar-h) + 10px);
  left: 16px;
  z-index: 18;
  width: min(420px, calc(100% - 32px));
}

.search-input {
  width: 100%;
  height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: var(--shadow);
  font-size: max(16px, 0.95rem);   /* iOS zooms into inputs under 16px */
}

.search-results {
  list-style: none;
  margin-top: 6px;
  padding: 6px;
  /* --vvh tracks the visible height above the on-screen keyboard (set in app.js) */
  max-height: min(calc(var(--vvh, 100vh) - var(--bar-h) - 80px), 420px);
  overflow-y: auto;
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 8px 32px rgba(29, 27, 22, 0.24);
}

.search-results li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.search-results li[aria-selected="true"], .search-results li:hover { background: #f4f1ea; }
.search-results .dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--c, var(--ink-soft)); }
.search-results .result-text { min-width: 0; display: grid; }
.search-results .result-name { font-size: 0.9rem; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.search-results small { color: var(--ink-soft); font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* Keep the street-search row reachable however long the list is */
.search-results li:last-child[data-i] { position: sticky; bottom: -6px; background: var(--paper); }
.search-results li:last-child[data-i][aria-selected="true"], .search-results li:last-child[data-i]:hover { background: #f4f1ea; }
.search-results .is-note { cursor: default; color: var(--ink-soft); font-size: 0.85rem; }
.search-results .is-note:hover { background: none; }

/* "Show my location" map control */

.locate-me {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 4px;
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
}

.locate-me:hover { background: #f4f1ea; }
.locate-me[aria-busy="true"] svg { animation: spin 1s linear infinite; }

@keyframes spin { to { rotate: 360deg; } }

/* Category filters */

.filters {
  position: fixed;
  top: calc(var(--bar-h) + 64px);
  left: 0;
  right: 0;
  z-index: 15;
  display: flex;
  gap: 8px;
  padding: 0 16px;
  overflow-x: auto;
  scrollbar-width: none;
  pointer-events: none;
}

.filters::-webkit-scrollbar { display: none; }

.chip {
  pointer-events: auto;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px 0 12px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background: var(--paper);
  box-shadow: var(--shadow);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
}

.chip .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.chip[aria-pressed="false"] { color: var(--ink-soft); box-shadow: none; background: rgba(255, 255, 255, 0.7); }
.chip[aria-pressed="false"] .dot { background: transparent; box-shadow: inset 0 0 0 2px var(--c); }

/* Map */

.map { position: fixed; inset: var(--bar-h) 0 0 0; }

.map.leaflet-container { background: #ebe7df; font: inherit; }

/* Soften OSM's default colours so the place cards stand out */
.map .leaflet-tile-pane { filter: saturate(0.5) contrast(0.95) brightness(1.03); }

.map .leaflet-control-attribution { font-size: 0.7rem; }

.status {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 15;
  width: max-content;   /* left: 50% would otherwise cap it at half the screen */
  max-width: calc(100% - 32px);
  padding: 8px 14px;
  border-radius: 18px;
  background: var(--ink);
  color: #fff;
  font-size: 0.85rem;
  text-align: center;
  pointer-events: none;
}

.status:empty { display: none; }

/* In add mode, sit above the "Use my location" button instead of over it */
.map.is-adding ~ .status { bottom: calc(120px + env(safe-area-inset-bottom)); }

/* Shown only in add mode; sits above the status pill */
.locate {
  position: fixed;
  left: 16px;
  bottom: calc(64px + env(safe-area-inset-bottom));
  z-index: 15;
  height: 44px;
  padding: 0 18px;
  border: 0;
  border-radius: 22px;
  background: #1f6fd1;
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.locate:disabled { opacity: 0.7; cursor: progress; }

/* Place labels drawn over the map */

.labels { position: absolute; left: 0; top: 0; }

.card, .pin {
  position: absolute;
  left: 0;
  top: 0;
}

.card {
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;   /* the labels container is 0px wide, so don't shrink to it */
  max-width: 200px;
  padding: 6px 10px 6px 8px;
  border: 0;
  border-left: 4px solid var(--c);
  border-radius: 8px;
  background: var(--paper);
  box-shadow: var(--shadow);
  text-align: left;
  cursor: pointer;
  /* anchor the card's bottom-centre on the place */
  translate: -50% calc(-100% - 8px);
}

.card::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -6px;
  width: 12px;
  height: 12px;
  background: var(--paper);
  transform: translateX(-50%) rotate(45deg);
  border-radius: 0 0 2px 0;
}

.card-text { min-width: 0; display: grid; }

.card-name {
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-type {
  font-size: 0.72rem;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.card-more {
  flex: none;
  min-width: 26px;
  height: 22px;
  padding: 0 6px;
  border-radius: 11px;
  background: var(--c);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 600;
  display: grid;
  place-items: center;
}

.card.is-own { background: var(--ink); color: #fff; border-left-color: var(--gold); }
.card.is-own::after { background: var(--ink); }
.card.is-own .card-type { color: #d8cfbd; }

.card.is-entering { animation: pop 260ms cubic-bezier(0.2, 0.9, 0.3, 1.25) both; }

@keyframes pop {
  from { opacity: 0; scale: 0.6; }
  to { opacity: 1; scale: 1; }
}

.pin {
  width: 14px;
  height: 14px;
  padding: 0;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--c);
  box-shadow: var(--shadow);
  translate: -50% -50%;
  cursor: pointer;
}

.pin.is-group { width: 18px; height: 18px; }

/* Detail / edit sheet */

.sheet {
  position: fixed;
  z-index: 30;
  left: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: min(360px, calc(100% - 32px));
  max-height: calc(100% - var(--bar-h) - 32px);
  overflow-y: auto;
  padding: 18px 18px 16px;
  border-radius: 12px;
  background: var(--paper);
  box-shadow: 0 8px 32px rgba(29, 27, 22, 0.24);
}

.sheet-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.sheet-close:hover { background: #f1ede5; }

.sheet h2 { font-size: 1.1rem; line-height: 1.3; padding-right: 32px; }

/* Focus is moved to these for screen readers; they aren't controls, so no ring */
.sheet h2:focus, .status-line:focus { outline: none; }
.sheet .meta { margin-top: 4px; font-size: 0.85rem; color: var(--ink-soft); line-height: 1.45; }
.sheet .note { margin-top: 10px; font-size: 0.9rem; line-height: 1.5; }

.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.btn {
  display: inline-flex;
  align-items: center;
  height: 38px;
  padding: 0 14px;
  border-radius: 19px;
  border: 1px solid var(--line);
  background: var(--paper);
  font-size: 0.88rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
}

.btn-primary { background: var(--gold); border-color: var(--gold); color: #fff; }
.btn-danger { color: #a3321f; }

.list { list-style: none; margin-top: 10px; display: grid; gap: 2px; }

.list button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 6px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.list button:hover { background: #f4f1ea; }
.list .dot { flex: none; width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.list small { color: var(--ink-soft); }

.form { display: grid; gap: 10px; margin-top: 12px; }
.form label { display: grid; gap: 4px; font-size: 0.82rem; font-weight: 600; }

.form input, .form select, .form textarea {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--paper);
  font-weight: 400;
  font-size: max(16px, 0.95rem);   /* iOS zooms into inputs under 16px */
}

.form small { font-weight: 400; color: var(--ink-soft); }

.form-error { color: #a3321f; font-size: 0.88rem; line-height: 1.4; }

/* Spam trap: off-screen rather than display:none, which some bots skip */
.trap { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.map.is-adding { cursor: crosshair; }

/* Admin review page (admin.html) */

body.admin { overflow: auto; }

.admin .edit-toggle { text-decoration: none; }

.admin-main {
  max-width: 40rem;
  margin: 0 auto;
  padding: calc(var(--bar-h) + 24px) 16px 48px;
}

.admin-login { max-width: 22rem; }

.admin-tabs, .admin-views { display: flex; gap: 8px; align-items: center; }
.admin-tabs .chip { box-shadow: none; }
.admin-tabs .chip[aria-pressed="true"] { background: var(--ink); color: #fff; border-color: var(--ink); }
.admin-logout { margin-left: auto; }

.status-line { margin: 16px 0 8px; color: var(--ink-soft); font-size: 0.9rem; }

.admin-list { list-style: none; display: grid; gap: 12px; }

.admin-item {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
}

.admin-item h2 { font-size: 1.05rem; }
.admin-item .meta a { color: var(--gold-deep); }

@media (max-width: 640px) {
  :root { --bar-h: 56px; }
  .brand h1 { font-size: 1.15rem; }
  .brand p, .wide-only { display: none; }
  .call, .edit-toggle { height: 36px; padding: 0 12px; font-size: 0.82rem; }
  .card { max-width: 160px; }
  .sheet { left: 16px; right: 16px; width: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .card.is-entering, .locate-me[aria-busy="true"] svg { animation: none; }
}
