:root {
  --bg: #ffffff;
  --bg-alt: #f1f3f5;
  --fg: #212529;
  --muted: #6c757d;
  --border: #dee2e6;
  --accent: #d6336c;
  --link: #1c7ed6;
  --danger: #e03131;
  --sidebar-width: 360px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1b1e;
    --bg-alt: #25262b;
    --fg: #e9ecef;
    --muted: #909296;
    --border: #373a40;
    --accent: #f06595;
    --link: #4dabf7;
    --danger: #ff6b6b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a { color: var(--link); }
h1, h2 { margin: 0; line-height: 1.2; }
h1 { font-size: 1.25rem; }
h2 { font-size: 1.35rem; }

.muted { color: var(--muted); }
.error { color: var(--danger); }

button, input, textarea { font: inherit; color: inherit; }
button {
  border: 1px solid var(--border);
  background: var(--bg-alt);
  border-radius: 6px;
  padding: 0.35em 0.8em;
  cursor: pointer;
}
button.link { border: 0; background: none; padding: 0; color: var(--link); text-decoration: underline; }
button.danger { color: var(--danger); }
input, textarea {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.45em 0.6em;
}

/* Layout: sidebar beside the map on wide screens; on narrow ones, a
   draggable bottom sheet over a full-screen map (see src/sheet.ts). */

body:not(.login-page) {
  display: grid;
  grid-template-columns: var(--sidebar-width) 1fr;
  grid-template-areas: "sidebar map";
}
#map { grid-area: map; min-height: 0; }
#sidebar {
  grid-area: sidebar;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
}
.panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overscroll-behavior: contain;
}
#view { flex: 1 0 auto; }
.account {
  position: sticky;
  bottom: 0;
  display: flex;
  justify-content: space-between;
  gap: 1em;
  padding: 0.5em 1rem;
  background: var(--bg);
  border-top: 1px solid var(--border);
  font-size: 0.85rem;
}
.account form { margin: 0; }

.sheet-handle { display: none; }

@media (max-width: 700px) {
  body:not(.login-page) { display: block; overflow: hidden; }
  #map { position: fixed; inset: 0; }
  #sidebar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 2;
    height: 45dvh; /* replaced by the sheet's script */
    border-right: 0;
    border-radius: 14px 14px 0 0;
    box-shadow: 0 -2px 16px rgb(0 0 0 / 0.18);
  }
  #sidebar.snapping { transition: height 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); }
  .sheet-handle {
    display: flex;
    flex: none;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 22px;
    padding: 0;
    border: 0;
    border-radius: 14px 14px 0 0;
    background: none;
    cursor: grab;
    touch-action: none;
  }
  .sheet-handle::before {
    content: "";
    width: 38px;
    height: 5px;
    border-radius: 3px;
    background: var(--muted);
    opacity: 0.5;
  }
  .panel { padding-bottom: env(safe-area-inset-bottom); }
  .account { position: static; }
  #sidebar .list-header { padding-top: 0.2rem; }
  #sidebar .detail-bar { padding-top: 0.2rem; }
  #sidebar .photo img { max-height: 180px; }
}

/* List view */

.list-header {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 0.6rem 1rem 0.5rem;
  background: var(--bg);
  /* Works around Chromium drawing a blank band across the map behind the
     sheet when this sticky header has a background under its border. */
  background-clip: padding-box;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
}
.list-header .status { margin: 0.35rem 0 0; }
.tabs { display: flex; gap: 0.25rem; }
.tab {
  padding: 0.3em 0.75em;
  border-radius: 999px;
  color: var(--muted);
  font-size: 1rem;
  font-weight: 600;
  text-decoration: none;
}
.tab[aria-current="page"] { background: var(--bg-alt); color: var(--fg); }
.chips {
  display: flex;
  gap: 0.4rem;
  margin: 0.5rem -1rem 0;
  padding: 0 1rem 0.1rem;
  overflow-x: auto;
  scrollbar-width: none;
}
.chip {
  flex: none;
  border-radius: 999px;
  padding: 0.25em 0.8em;
  font-size: 0.85rem;
  background: var(--bg);
}
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.list ol { list-style: none; margin: 0; padding: 0; }
.search-form { margin-top: 0.5rem; }
.search-form input { width: 100%; font-size: 1rem; /* 16px+ stops iOS zooming in on focus */ }
.search-section h3 {
  margin: 0;
  padding: 0.9rem 1rem 0.3rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.search-section > p { margin: 0; padding: 0 1rem 0.5rem; }
.search-addresses { margin: 0.25rem 1rem 1rem; }
.list li a {
  display: grid;
  grid-template-columns: 1fr auto;
  column-gap: 0.75em;
  padding: 0.65rem 1rem;
  border-bottom: 1px solid var(--border);
  color: inherit;
  text-decoration: none;
}
.list li a:hover, .list li a:focus-visible { background: var(--bg-alt); }
.list .name { font-weight: 600; }
.list .distance { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.list .address { grid-column: 1 / -1; color: var(--muted); font-size: 0.85rem; }
.empty { padding: 1rem; }

/* Detail view */

.detail { padding: 0 1rem 1.5rem; display: flex; flex-direction: column; gap: 0.75rem; }
.detail > * { margin: 0; }
.detail-bar {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: baseline;
  gap: 0.75em;
  margin: 0 -1rem;
  padding: 0.75rem 1rem 0.5rem;
  background: var(--bg);
  border-bottom: 1px solid transparent;
  transition: border-color 0.2s;
}
.detail-bar.collapsed { border-bottom-color: var(--border); }
.back { flex: none; text-decoration: none; font-size: 0.9rem; }
.bar-title {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-weight: 600;
  opacity: 0;
  transform: translateY(0.4em);
  transition: opacity 0.2s, transform 0.2s;
}
.detail-bar.collapsed .bar-title { opacity: 1; transform: none; }
.photo { margin: 0 -1rem; }
.photo img {
  display: block;
  width: 100%;
  max-height: 260px;
  object-fit: cover;
  background: var(--bg-alt);
}
.photo figcaption { padding: 0.25rem 1rem 0; font-size: 0.75rem; color: var(--muted); }
.photo figcaption a { color: inherit; }
.meta { display: flex; flex-wrap: wrap; gap: 0.4em 1em; font-size: 0.9rem; color: var(--muted); }
.detail .address { color: var(--fg); }
.address-edit { display: flex; flex-wrap: wrap; gap: 0.5em; align-items: center; }
.address-edit input { flex: 1 1 12em; min-width: 0; }
.notes { display: flex; flex-direction: column; gap: 0.35em; }
.notes label { font-weight: 600; display: flex; justify-content: space-between; }
.save-status { font-weight: normal; font-size: 0.85rem; }
.notes textarea { width: 100%; resize: vertical; min-height: 7em; }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 0.3em 1em; margin: 0; font-size: 0.9rem; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; overflow-wrap: anywhere; }
.actions { display: flex; align-items: center; gap: 0.75em; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; padding: 0.45em 1em; }
button:disabled { opacity: 0.6; cursor: default; }
.photo-editor { font-size: 0.9rem; }
.photo-editor summary { cursor: pointer; color: var(--link); }
.photo-editor > * + * { margin-top: 0.6em; }
.photo-editor .file { display: block; }
.photo-url { display: flex; gap: 0.5em; }
.photo-url input { flex: 1; min-width: 0; }

/* Map controls */

.locate-button {
  background: no-repeat center / 18px url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23333' stroke-width='2'%3E%3Ccircle cx='12' cy='12' r='4'/%3E%3Cpath d='M12 2v3M12 19v3M2 12h3M19 12h3'/%3E%3C/svg%3E");
}

/* Login */

.login-page { display: grid; place-items: center; padding: 1rem; }
.login {
  width: 100%;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.login label { display: flex; flex-direction: column; gap: 0.25em; font-size: 0.9rem; }
.login button { background: var(--accent); border-color: var(--accent); color: #fff; padding: 0.55em; }
