/* Layout: full-bleed map with a floating white panel on the left; on phones the panel becomes a bottom sheet.
   Light theme only, by request. */
:root {
  color-scheme: light;
  --canvas: #F3F3EF;        /* page ground, slightly warm neutral */
  --surface: #FFFFFF;
  --ink: #1C1E26;           /* text and primary buttons */
  --ink-2: #3B3E4B;
  --muted: #6A6D7A;
  --line: #E4E3DD;
  --marigold: #F29E0C;      /* the one accent: selection and focus */
  --marigold-bg: #FFF4DD;
  --ok-bg: #E8F5EC; --ok-ink: #1F6B3A;
  --warn-bg: #FFF4DD; --warn-ink: #875200;
  --err-bg: #FDECEC; --err-ink: #A51D1D;

  --font-display: "Bricolage Grotesque", "Segoe UI", system-ui, sans-serif;
  --font-ui: "Figtree", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, Consolas, monospace;

  --text-xs: 12px; --text-sm: 13px; --text-md: 15px; --text-lg: 18px; --text-xl: 26px;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(28, 30, 38, .06), 0 10px 30px rgba(28, 30, 38, .12);
  --panel-w: 392px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--canvas); color: var(--ink);
  font: var(--text-md)/1.45 var(--font-ui);
  overflow: hidden;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--font-display); text-wrap: balance; margin: 0; letter-spacing: -0.01em; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--marigold); outline-offset: 2px; }
.muted { color: var(--muted); }

/* ---------- Map ---------- */
#map { position: fixed; inset: 0; background: var(--canvas); }
body.adding #map .mapboxgl-canvas-container { cursor: crosshair; }

.map-tools {
  position: fixed; z-index: 5;
  top: calc(16px + env(safe-area-inset-top, 0px));
  right: calc(16px + env(safe-area-inset-right, 0px));
}
.seg {
  display: flex; background: var(--surface); border-radius: 999px; padding: 4px; box-shadow: var(--shadow);
}
.seg button {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 999px; cursor: pointer;
  font-size: var(--text-sm); font-weight: 600; color: var(--muted);
}
.seg button[aria-pressed="true"] { background: var(--ink); color: var(--surface); }

.map-hint {
  position: fixed; z-index: 5;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: calc(var(--panel-w) + 32px + (100% - var(--panel-w) - 32px) / 2);
  transform: translateX(-50%);
  background: var(--ink); color: var(--surface); padding: 9px 16px; border-radius: 999px;
  font-size: var(--text-sm); font-weight: 600; box-shadow: var(--shadow); white-space: nowrap;
}

/* ---------- Panel ---------- */
.panel {
  position: fixed; z-index: 10;
  top: calc(16px + env(safe-area-inset-top, 0px));
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  left: calc(16px + env(safe-area-inset-left, 0px));
  width: var(--panel-w);
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  overflow: hidden;
}
.panel-head { padding: 20px 20px 12px; border-bottom: 1px solid var(--line); }
.title-row { display: flex; align-items: center; gap: 10px; }
.panel-head h1 { font-size: var(--text-xl); font-weight: 800; line-height: 1.05; }
.summary { margin-top: 6px; color: var(--muted); font-size: var(--text-sm); }
.badge {
  font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase;
  padding: 3px 8px; border-radius: 999px; background: var(--warn-bg); color: var(--warn-ink);
}
.panel-body {
  flex: 1 1 auto; overflow-y: auto; padding: 14px 20px 20px; min-height: 0;
  scrollbar-width: thin; scrollbar-color: var(--line) transparent;
}
/* Keep the Mapbox logo visible beside the panel (required by Mapbox's terms). */
.mapboxgl-ctrl-bottom-left { left: calc(var(--panel-w) + 24px + env(safe-area-inset-left, 0px)); }
.panel-foot { padding: 12px 20px 16px; border-top: 1px solid var(--line); background: var(--surface); }

/* Search + chips */
.search {
  display: flex; align-items: center; gap: 10px; padding: 0 14px; height: 44px;
  background: var(--canvas); border: 1px solid transparent; border-radius: 12px;
}
.search:focus-within { background: var(--surface); border-color: var(--ink); }
.search svg { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; flex: 0 0 auto; }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; height: 100%; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--surface); cursor: pointer;
  font-size: var(--text-sm); font-weight: 600; color: var(--ink-2);
}
.chip:hover { border-color: var(--ink-2); }
.chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.chip .n { font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] .n { color: #C9CAD2; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--tc); flex: 0 0 auto; box-shadow: 0 0 0 2px var(--surface); }

.count {
  margin: 16px 0 8px; font-size: var(--text-xs); font-weight: 700; letter-spacing: .07em;
  text-transform: uppercase; color: var(--muted);
}

/* Temple cards */
.cards { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.card {
  display: grid; gap: 3px; width: 100%; text-align: left; cursor: pointer;
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface);
}
.card:hover { border-color: var(--ink-2); }
.card.selected { border-color: var(--marigold); box-shadow: 0 0 0 3px var(--marigold-bg); }
.card-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.card-name { font-family: var(--font-display); font-weight: 700; font-size: 16px; line-height: 1.25; }
.card-place { color: var(--ink-2); font-size: var(--text-sm); }
.card-time { color: var(--muted); font-size: var(--text-xs); }
.deity { color: var(--muted); font-size: var(--text-xs); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }

.tag {
  display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto;
  font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-2);
}
.tag::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--tc); }

.empty { padding: 24px 4px; color: var(--muted); display: grid; gap: 4px; }
.empty strong { color: var(--ink); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 42px; padding: 0 16px; border-radius: 10px; cursor: pointer; text-decoration: none; white-space: nowrap;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); font-weight: 600;
}
.btn:hover { border-color: var(--ink); }
.btn.primary { background: var(--ink); border-color: var(--ink); color: var(--surface); }
.btn.primary:hover { background: #000; }
.btn.ghost { background: var(--canvas); border-color: transparent; }
.btn.danger { color: var(--err-ink); }
.btn.block { width: 100%; }
.btn.sm { height: 34px; padding: 0 12px; font-size: var(--text-sm); border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: wait; }

/* ---------- Add a temple ---------- */
.back {
  border: 0; background: none; padding: 0; cursor: pointer; color: var(--muted);
  font-size: var(--text-sm); font-weight: 600; margin-bottom: 10px;
}
.back:hover { color: var(--ink); }
#add h2 { font-size: 22px; font-weight: 800; margin-bottom: 12px; }
.steps { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 10px; }
.steps li { display: flex; gap: 10px; font-size: var(--text-sm); color: var(--ink-2); }
.steps li > span {
  flex: 0 0 22px; height: 22px; border-radius: 50%; background: var(--marigold-bg); color: var(--warn-ink);
  display: grid; place-items: center; font-size: 12px; font-weight: 700;
}
.steps strong { color: var(--ink); }

.field-row { display: flex; gap: 8px; }
.field-row input { flex: 1; min-width: 0; }
#locate { margin-top: 8px; }
.results { list-style: none; margin: 6px 0 0; padding: 0; }
.results li.muted { padding: 8px 2px; font-size: var(--text-sm); }
.results button {
  width: 100%; text-align: left; padding: 9px 4px; border: 0; border-bottom: 1px solid var(--line);
  background: none; cursor: pointer; font-size: var(--text-sm); color: var(--ink-2);
}
.results button:hover { color: var(--ink); background: var(--canvas); }

.pin-status {
  margin-top: 14px; padding: 12px; border-radius: 10px; background: var(--canvas);
  font-size: var(--text-sm); color: var(--ink-2); display: grid; gap: 2px;
}
.pin-status.ok { background: var(--ok-bg); color: var(--ok-ink); }
.pin-status.warn { background: var(--warn-bg); color: var(--warn-ink); }
.notice { margin-top: 8px; padding: 12px; border-radius: 10px; font-size: var(--text-sm); }
.notice.err { background: var(--err-bg); color: var(--err-ink); }

#add-form { display: grid; margin-top: 6px; }
#add-form label { font-size: var(--text-sm); font-weight: 600; color: var(--ink-2); margin: 14px 0 6px; }
input:not([type="search"]):not(.hp), select, textarea, .field-row input {
  width: 100%; height: 42px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface);
}
textarea { height: auto; padding: 10px 12px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px var(--marigold-bg); }
.search input:focus { box-shadow: none; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two > div { display: grid; min-width: 0; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; opacity: 0; }
.fine { margin: 16px 0 10px; font-size: var(--text-xs); color: var(--muted); }

.new-pin {
  width: 30px; height: 40px; cursor: grab; display: grid; place-items: start center;
}
.new-pin span {
  width: 26px; height: 26px; margin-top: 1px; background: var(--tc);
  border: 3px solid #fff; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  box-shadow: 0 2px 6px rgba(0, 0, 0, .35);
}
.new-pin::after {
  content: ""; position: absolute; bottom: 0; left: 50%; width: 6px; height: 6px; margin-left: -3px;
  border-radius: 50%; background: var(--ink); box-shadow: 0 0 0 2px #fff;
}

/* ---------- Popup ---------- */
.mapboxgl-popup-content {
  padding: 14px 16px 12px; border-radius: 12px; box-shadow: var(--shadow); font-family: var(--font-ui);
}
.mapboxgl-popup-close-button { font-size: 20px; padding: 2px 8px; color: var(--muted); }
.popup { display: grid; gap: 5px; font-size: var(--text-sm); color: var(--ink-2); }
.popup img { width: 100%; max-height: 150px; object-fit: cover; border-radius: 8px; margin-bottom: 4px; }
.popup h3 { font-size: 18px; font-weight: 800; color: var(--ink); line-height: 1.2; padding-right: 16px; }
.popup .deity { font-size: var(--text-sm); }
.popup .label {
  font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin-right: 4px;
}
.popup .desc { color: var(--muted); }
.popup-links { display: flex; gap: 8px; margin-top: 6px; }
.popup-links .btn.primary { color: var(--surface); }
.coords { font-family: var(--font-mono); font-size: 11.5px; color: var(--muted); font-variant-numeric: tabular-nums; }
.pin-status .coords { color: inherit; font-size: 12.5px; font-weight: 500; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); z-index: 50;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--surface); padding: 11px 16px; border-radius: 10px;
  box-shadow: var(--shadow); font-size: var(--text-sm); font-weight: 600;
  transition: opacity .2s, transform .2s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--err-ink); }
#toast.ok { background: var(--ok-ink); }
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }

/* ---------- Admin ---------- */
.login {
  position: fixed; inset: 0; display: grid; place-items: center; z-index: 20; background: var(--canvas);
  padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px));
}
.login form {
  width: 100%; max-width: 360px; padding: 28px; display: grid; gap: 6px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
}
.login h1 { font-size: 22px; font-weight: 800; margin-bottom: 8px; }
.login label { font-size: var(--text-sm); font-weight: 600; color: var(--ink-2); margin-top: 8px; }
.login .btn { margin-top: 16px; }
.review-card { padding: 14px; border: 1px solid var(--line); border-radius: 12px; display: grid; gap: 4px; }
.review-card.selected { border-color: var(--marigold); box-shadow: 0 0 0 3px var(--marigold-bg); }
.review-card h3 { font-size: 16px; font-weight: 700; }
.review-card .from { font-size: var(--text-xs); color: var(--muted); }
.review-actions { display: flex; gap: 8px; margin-top: 8px; }
.review-actions .btn { flex: 1; height: 36px; font-size: var(--text-sm); }
.head-links { display: flex; gap: 8px; margin-top: 12px; }
.pending-pin {
  width: 20px; height: 20px; border-radius: 50%; background: var(--tc); cursor: pointer;
  border: 3px solid #fff; box-shadow: 0 0 0 2px var(--ink), 0 2px 6px rgba(0, 0, 0, .3);
}

/* ---------- Phones: bottom sheet ---------- */
@media (max-width: 760px) {
  :root { --sheet-h: 48svh; }
  .panel {
    top: auto; left: 0; right: 0; bottom: 0; width: auto; height: var(--sheet-h);
    border-radius: 18px 18px 0 0;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  body.adding .panel { --sheet-h: 56svh; height: 56svh; }
  .panel-head, .panel-body, .panel-foot {
    padding-left: max(16px, env(safe-area-inset-left, 0px));
    padding-right: max(16px, env(safe-area-inset-right, 0px));
  }
  .panel-head { padding-top: 14px; padding-bottom: 10px; }
  .panel-head::before {
    content: ""; display: block; width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 10px;
  }
  .panel-head h1 { font-size: 21px; }
  .map-hint { left: 50%; top: calc(64px + env(safe-area-inset-top, 0px)); }
  .mapboxgl-ctrl-bottom-right, .mapboxgl-ctrl-bottom-left { bottom: calc(var(--sheet-h) + 4px); }
  .mapboxgl-ctrl-bottom-left { left: env(safe-area-inset-left, 0px); }
  body.adding .mapboxgl-ctrl-bottom-right, body.adding .mapboxgl-ctrl-bottom-left { bottom: calc(56svh + 4px); }
  .two { grid-template-columns: 1fr; gap: 0; }
  #toast { bottom: calc(var(--sheet-h) + 12px); }
}
