:root {
  --bg: #ffffff;
  --panel: #fafafa;
  --text: #18181b;
  --muted: #71717a;
  --line: #e4e4e7;
  --accent: #e11d48;
  --accent-soft: #fff1f2;
  --radius: 10px;
}

* { box-sizing: border-box; }

/* The browser hides [hidden] elements with a user-agent rule, and ANY author
   rule setting `display` outranks it. Several components below set display on a
   class they also toggle with `hidden` — without this line those elements can
   never be hidden. It cost an afternoon once already. */
[hidden] { display: none !important; }

body {
  margin: 0;
  height: 100vh;
  display: grid;
  grid-template-columns: 340px 1fr;
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

.muted { color: var(--muted); font-size: 13px; }

/* ---------- sidebar ---------- */

#sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--panel);
}

#sidebar header { padding: 20px 20px 12px; }
#sidebar h1 { margin: 0; font-size: 19px; letter-spacing: -0.01em; }
#sidebar header p { margin: 2px 0 0; }
#sidebar footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 20px;
  border-top: 1px solid var(--line);
}
#export { font-size: 13px; color: var(--accent); text-decoration: none; white-space: nowrap; }
#export:hover { text-decoration: underline; }

.search { position: relative; padding: 0 20px 12px; }

input, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  font: inherit;
  color: inherit;
}
input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
textarea { resize: vertical; }

.results {
  position: absolute;
  left: 20px; right: 20px; top: 44px;
  z-index: 500;
  margin: 0;
  padding: 4px;
  list-style: none;
  max-height: 240px;
  overflow-y: auto;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.08);
}
.results li {
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
  font-size: 13px;
}
.results li:hover { background: var(--panel); }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 20px 12px;
}

.tag {
  padding: 3px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
.tag.on { background: var(--accent); border-color: var(--accent); color: #fff; }

.list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  margin: 0;
  padding: 0 12px 12px;
  list-style: none;
}

.card {
  padding: 11px 12px;
  margin-bottom: 6px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
}
.card:hover { background: var(--bg); border-color: var(--line); }
.card.active { background: var(--bg); border-color: var(--accent); }
.card h3 { margin: 0 0 3px; font-size: 14px; font-weight: 600; }
.card .card-tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.card .card-tags span {
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11px;
}
.card p { margin: 0; font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.card p.when, .popup p.when { color: var(--accent); font-size: 12px; font-weight: 500; }
.card .thumbs { display: flex; gap: 4px; margin-top: 7px; }
.card .thumbs img {
  width: 34px; height: 34px;
  object-fit: cover;
  border-radius: 6px;
  cursor: zoom-in;
}
.card .thumbs img:hover { outline: 2px solid var(--accent); outline-offset: 1px; }

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

#map { height: 100vh; background: #eee; }
.leaflet-container { font: inherit; }

/* base layer switcher */
.leaflet-control-layers {
  border: 1px solid var(--line) !important;
  border-radius: var(--radius) !important;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08) !important;
}
.leaflet-control-layers-toggle {
  width: 32px !important;
  height: 32px !important;
  background-size: 18px 18px !important;
}
.leaflet-control-layers-expanded { padding: 8px 10px !important; }
.leaflet-control-layers label {
  display: flex;
  align-items: center;
  gap: 7px;
  margin: 0;
  padding: 3px 0;
  font-size: 13px;
  cursor: pointer;
}
.leaflet-control-layers input { width: auto; accent-color: var(--accent); }

.add-pin {
  position: fixed;
  right: 18px;
  bottom: 104px;
  z-index: 650;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  box-shadow: 0 6px 18px rgba(225, 29, 72, 0.4);
  cursor: pointer;
}
.add-pin:hover { filter: brightness(1.08); }
.add-pin:active { transform: scale(0.94); }

/* ---------- timeline ---------- */

.timeline {
  position: fixed;
  bottom: 22px;
  left: calc(340px + (100vw - 340px) / 2);
  transform: translateX(-50%);
  z-index: 600;
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(6px);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
}

.timeline-row { display: flex; align-items: center; gap: 12px; }

.timeline .play {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  padding: 0;
  border-radius: 50%;
  border: 1px solid var(--line);
  font-size: 11px;
  color: var(--accent);
}
.timeline .play:hover { border-color: var(--accent); }

.timeline .track { position: relative; width: 260px; height: 22px; }
.timeline .track::before {
  content: '';
  position: absolute;
  left: 0; right: 0; top: 9px;
  height: 4px;
  border-radius: 2px;
  background: var(--line);
}
.timeline .track-fill {
  position: absolute;
  top: 9px; height: 4px;
  border-radius: 2px;
  background: var(--accent);
}

/* Two range inputs stacked on one track: the input itself ignores pointer
   events so both handles stay reachable, the thumbs opt back in. */
.timeline .handle {
  position: absolute;
  left: 0; top: 0;
  width: 100%; height: 22px;
  margin: 0; padding: 0;
  border: none;
  background: none;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}
.timeline .handle:focus { outline: none; box-shadow: none; }
.timeline .handle::-webkit-slider-thumb {
  pointer-events: auto;
  -webkit-appearance: none;
  width: 15px; height: 15px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  cursor: grab;
}
.timeline .handle::-moz-range-thumb {
  pointer-events: auto;
  width: 15px; height: 15px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: var(--accent);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.35);
  cursor: grab;
}
.timeline .handle:focus-visible::-webkit-slider-thumb { border-color: var(--text); }

.timeline .window {
  min-width: 92px;
  text-align: right;
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

.timeline .undated {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 7px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
.timeline .undated input { width: auto; accent-color: var(--accent); }

.hint {
  position: fixed;
  bottom: 96px; left: 50%;
  transform: translate(-50%, 0);
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(24, 24, 27, 0.85);
  color: #fff;
  font-size: 12px;
  pointer-events: none;
  transition: opacity 0.4s;
}
.hint.gone { opacity: 0; }

/* ---------- dialog ---------- */

dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: none;
  border-radius: 14px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.22);
}
dialog::backdrop { background: rgba(24, 24, 27, 0.35); }

#form { display: flex; flex-direction: column; gap: 13px; padding: 20px; }
#form h2 { margin: 0; font-size: 17px; }
#form label { display: block; font-size: 13px; font-weight: 500; }
#form label input, #form label textarea { margin-top: 5px; font-weight: 400; }
#form label .muted { font-weight: 400; }
.coords { margin: -4px 0 0; font-variant-numeric: tabular-nums; }
#form .when { display: flex; gap: 10px; }
#form .when label { flex: 1; }

.photos { border-top: 1px solid var(--line); padding-top: 13px; }
.photo-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.photo-grid figure { position: relative; margin: 0; }
.photo-grid img {
  width: 62px; height: 62px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--line);
  cursor: zoom-in;
}
.photo-grid img:hover { border-color: var(--accent); }
.photo-grid button {
  position: absolute; top: -6px; right: -6px;
  width: 19px; height: 19px;
  display: grid; place-items: center;
  padding: 0;
  border: none; border-radius: 50%;
  background: var(--text); color: #fff;
  font-size: 12px; line-height: 1;
  cursor: pointer;
}

.file-btn {
  display: inline-block;
  margin-top: 10px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  font-size: 13px;
  cursor: pointer;
}
.file-btn:hover { border-color: var(--accent); color: var(--accent); }
#photo-hint { margin: 8px 0 0; }

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

button {
  padding: 8px 15px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg);
  font: inherit;
  font-size: 14px;
  color: inherit;
  cursor: pointer;
}
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
button.primary:hover { filter: brightness(1.08); }
button.ghost:hover { background: var(--panel); }
button.danger { border-color: transparent; color: var(--accent); padding-left: 0; }
button.danger:hover { background: var(--accent-soft); padding-left: 15px; }

/* ---------- boot ---------- */

/* Until we know whether there is a session, show neither the app nor the
   sign-in card. `visibility` rather than `display` so the map container keeps
   its size — Leaflet measures it at startup and would render into a 0×0 box. */
body.booting #sidebar,
body.booting #map,
body.booting .timeline,
body.booting .add-pin,
body.booting .hint { visibility: hidden; }

.splash {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: none;
  place-items: center;
  background: var(--panel);
  animation: splash-in 0.6s ease both;
}
body.booting .splash { display: grid; }

@keyframes splash-in {
  from { opacity: 0.55; }
  to   { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .splash { animation: none; }
}

/* ---------- account / signed out ---------- */

.account {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 20px 12px;
  font-size: 12px;
}
.account #who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.link {
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  font-size: 12px;
  cursor: pointer;
}
button.link:hover { text-decoration: underline; }

.signed-out {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  background: var(--panel);
}
.signed-out-card {
  width: min(360px, calc(100vw - 40px));
  padding: 36px 32px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--bg);
  box-shadow: 0 20px 50px -30px rgba(24, 24, 27, 0.4);
}
.signed-out-card svg { margin-bottom: 10px; }
.signed-out-card h2 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.signed-out-card p { margin: 8px 0 22px; font-size: 14px; color: var(--muted); }
.auth-error {
  padding: 10px 12px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent) !important;
  text-align: left;
  font-size: 13px !important;
}
.signed-out-card button { width: 100%; padding: 11px; font-weight: 500; }

.boot-error {
  position: fixed;
  top: 16px;
  left: calc(340px + (100vw - 340px) / 2);
  transform: translateX(-50%);
  z-index: 700;
  max-width: min(560px, calc(100vw - 380px));
  padding: 10px 16px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

/* ---------- lightbox ---------- */

#lightbox {
  width: 100vw;
  max-width: 100vw;
  height: 100dvh;
  max-height: 100dvh;
  padding: 0;
  border: none;
  background: none;
  overflow: hidden;
}
#lightbox::backdrop { background: rgba(9, 9, 11, 0.86); }

#lightbox img {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  max-width: 92vw;
  max-height: 84dvh;
  object-fit: contain;
  border-radius: 6px;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
  cursor: default;
  transition: filter 0.25s ease;
}
/* An upscaled thumbnail standing in until the original arrives. */
#lightbox img.waiting { filter: blur(8px); }

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

#lightbox figcaption {
  position: absolute;
  left: 0; right: 0; bottom: 26px;
  text-align: center;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.75);
  pointer-events: none;
}

#lightbox button {
  position: absolute;
  display: grid;
  place-items: center;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  line-height: 1;
}
#lightbox button:hover { background: rgba(255, 255, 255, 0.24); }

#lightbox .close {
  top: 20px; right: 20px;
  width: 40px; height: 40px;
  font-size: 24px;
}
#lightbox .step {
  top: 50%;
  transform: translateY(-50%);
  width: 46px; height: 46px;
  font-size: 30px;
}
#lightbox .prev { left: 20px; }
#lightbox .next { right: 20px; }

/* ---------- popup ---------- */

.leaflet-popup-content { margin: 12px 14px; }
.popup h3 { margin: 0 0 4px; font-size: 14px; }
.popup p { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.popup img { width: 100%; border-radius: 8px; margin-bottom: 8px; cursor: zoom-in; }
.popup button { padding: 4px 10px; font-size: 12px; }

@media (max-width: 720px) {
  body { grid-template-columns: 1fr; grid-template-rows: 45vh 55vh; }
  #sidebar { border-right: none; border-bottom: 1px solid var(--line); }
  #map { height: 100%; }
  .timeline { left: 50%; }
  .timeline .track { width: 180px; }
}
