:root {
  --bg: #ffffff;
  --fg: #16181d;
  --muted: #6b7280;
  --line: #e4e6eb;
  --accent: #2563eb;
  --danger: #dc2626;
  --sidebar: 300px;
  --header: 48px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181d;
    --fg: #e9eaee;
    --muted: #9aa1ac;
    --line: #2b2f38;
    --accent: #4f86f7;
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--fg);
}

[hidden] { display: none !important; }

/* ---------- layout ---------- */

#app { display: flex; flex-direction: column; height: 100%; }

header {
  display: flex;
  align-items: center;
  gap: 10px;
  height: var(--header);
  padding: 0 12px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

main {
  flex: 1 1 auto;
  display: flex;
  min-height: 0;
}

#sidebar {
  width: var(--sidebar);
  flex: 0 0 auto;
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 10px;
}

#map {
  flex: 1 1 auto;
  min-width: 0;
  /* Leaflet needs a real height, not a percentage of an auto-height parent. */
  height: 100%;
}

.spacer { flex: 1 1 auto; }

/* ---------- pin list ---------- */

#pin-list, .map-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

#pin-list li, .map-list li {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  border: 1px solid transparent;
}

#pin-list li:hover, .map-list li:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
#pin-list li.active { border-color: var(--accent); }

#pin-list .t { font-weight: 600; }
#pin-list .n, .map-list .sub {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hint {
  color: var(--muted);
  font-size: 12px;
  padding: 4px 10px 10px;
}

/* ---------- layer panel ---------- */

#layer-panel {
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
  margin-bottom: 8px;
}

.layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  color: var(--fg);
}

.layer-row:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }

.layer-row input[type='checkbox'] { width: auto; margin: 0; flex: 0 0 auto; }

.swatch {
  width: 12px;
  height: 12px;
  border-radius: 3px;
  flex: 0 0 auto;
  border: 1px solid rgba(128, 128, 128, 0.4);
}

.layer-name {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-row .edit {
  background: none;
  border: none;
  color: var(--muted);
  padding: 2px 4px;
  min-height: auto;
  font-size: 12px;
  opacity: 0;
}

.layer-row:hover .edit { opacity: 1; }

.panel-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.panel-head button {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  padding: 2px 6px;
  min-height: auto;
}

input[type='color'] {
  padding: 2px;
  height: 34px;
  width: 48px;
  flex: 0 0 auto;
}

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.card {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px;
  width: min(420px, 100%);
  max-height: 90vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}

.card h1, .card h2 { margin: 0; font-size: 17px; }

label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }

input, textarea {
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
  width: 100%;
}

input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

textarea { resize: vertical; }

button {
  font: inherit;
  cursor: pointer;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 8px 14px;
  /* 40px keeps these tappable on a phone without a separate mobile layout. */
  min-height: 40px;
}

button:disabled { opacity: 0.55; cursor: default; }
button.secondary { background: transparent; color: var(--fg); border-color: var(--line); }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }

button.link {
  background: none;
  border: none;
  color: var(--muted);
  text-decoration: underline;
  padding: 4px;
  min-height: auto;
}

#back {
  background: none;
  border: none;
  color: var(--fg);
  font-size: 18px;
  padding: 4px 8px;
  min-height: auto;
}

.row { display: flex; gap: 8px; align-items: center; }
.row input { flex: 1 1 auto; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--danger); font-size: 12px; margin: 0; }

/* ---------- toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: #16181d;
  color: #fff;
  padding: 10px 16px;
  border-radius: 6px;
  z-index: 2000;
  font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}

/* ---------- phone ---------- */

@media (max-width: 700px) {
  main { flex-direction: column-reverse; }
  #sidebar {
    width: 100%;
    height: 38vh;
    border-right: none;
    border-top: 1px solid var(--line);
  }
  #map { height: auto; flex: 1 1 auto; }
}
