:root {
  color-scheme: light;
  --bg: #f4f1ec;
  --panel: #ffffff;
  --panel-soft: #faf8f4;
  --panel-hover: #f2eee7;
  --ink: #20242c;
  --muted: #6f7683;
  --line: #e7e2d9;
  --line-strong: #d8d0c3;
  --accent: #a78bfa;
  --accent-hover: #b7a2fc;
  --accent-ink: #241b3d;
  --accent-soft: rgba(167, 139, 250, 0.16);
  --accent-line: rgba(139, 92, 246, 0.4);
  --danger: #b3261e;
  --danger-line: rgba(179, 38, 30, 0.28);
  --danger-soft: rgba(179, 38, 30, 0.07);
  --map-bg: #dfe7e2;
  --topbar-bg: rgba(255, 255, 255, 0.92);
  --toast-bg: #20242c;
  --toast-ink: #ffffff;
  --toast-btn: rgba(255, 255, 255, 0.14);
  --toast-btn-hover: rgba(255, 255, 255, 0.26);
  --pin-stroke: #ffffff;
  --thumb-bg: #efe9df;
  --radius: 16px;
  --shadow: 0 14px 40px rgba(32, 36, 44, 0.16), 0 2px 8px rgba(32, 36, 44, 0.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121017;
  --panel: #1c1925;
  --panel-soft: #242030;
  --panel-hover: #2b2639;
  --ink: #ece9f4;
  --muted: #a49dba;
  --line: #332d42;
  --line-strong: #443b58;
  --accent: #b9a2ff;
  --accent-hover: #cbb9ff;
  --accent-ink: #1a1329;
  --accent-soft: rgba(185, 162, 255, 0.16);
  --accent-line: rgba(185, 162, 255, 0.45);
  --danger: #ff8078;
  --danger-line: rgba(255, 128, 120, 0.35);
  --danger-soft: rgba(255, 128, 120, 0.12);
  --map-bg: #0d0b12;
  --topbar-bg: rgba(20, 17, 27, 0.9);
  --toast-bg: #ece9f4;
  --toast-ink: #1a1625;
  --toast-btn: rgba(26, 22, 37, 0.1);
  --toast-btn-hover: rgba(26, 22, 37, 0.18);
  --pin-stroke: #ffffff;
  --thumb-bg: #2a2537;
  --shadow: 0 18px 44px rgba(0, 0, 0, 0.55), 0 2px 10px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

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

body {
  display: flex;
  flex-direction: column;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}

/* ---------- Top bar ---------- */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 62px;
  padding: 0 18px;
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark { color: var(--accent); flex: 0 0 auto; }

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.brand-name {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tagline {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.auth-area {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.auth-btn {
  gap: 8px;
  padding: 0 12px;
}

.auth-short { display: none; }

.auth-user {
  display: flex;
  align-items: center;
  gap: 7px;
  min-width: 0;
  max-width: 230px;
  padding: 3px 9px 3px 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--panel-soft);
}

.auth-avatar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  overflow: hidden;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
}

.auth-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.auth-email {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 12px;
  color: var(--muted);
}

.auth-signout {
  gap: 6px;
  padding: 0 10px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

#placesBtn { display: none; }

.theme-btn { width: 38px; padding: 0; }
.theme-btn svg { width: 18px; height: 18px; flex: 0 0 auto; }
.label-short { display: none; }
#themeSun { display: none; }
html[data-theme="dark"] #themeMoon { display: none; }
html[data-theme="dark"] #themeSun { display: block; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 15px;
  border-radius: 10px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid rgba(167, 139, 250, 0.38); outline-offset: 1px; }

.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
}
.btn.primary:hover { background: var(--accent-hover); }

.btn.ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}
.btn.ghost:hover { background: var(--panel-hover); }

.btn.danger {
  background: transparent;
  border-color: var(--danger-line);
  color: var(--danger);
}
.btn.danger:hover { background: var(--danger-soft); }

.btn.small { height: 30px; padding: 0 12px; font-size: 13px; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.icon-btn:hover { background: var(--panel-hover); color: var(--ink); }

/* ---------- Map stage ---------- */

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
  background: var(--map-bg);
  font-family: var(--font);
}

#map.crosshair { cursor: crosshair; }
#map.crosshair .leaflet-interactive { cursor: crosshair; }

.leaflet-container { font-family: var(--font); }

/* English vector labels are drawn in a transparent canvas over the base map. */
.leaflet-gl-layer,
.leaflet-gl-layer canvas { pointer-events: none !important; }

/* Dark theme recolours the street base; satellite labels use a light halo. */
html[data-theme="dark"] .leaflet-tile-pane .base-street,
html[data-theme="dark"] .leaflet-street-pane {
  filter: invert(1) hue-rotate(180deg) brightness(1.06) contrast(0.93) saturate(0.9);
}

.leaflet-control-zoom a {
  color: var(--ink) !important;
  border-radius: 8px !important;
}

.leaflet-control-layers {
  border-radius: 10px !important;
  box-shadow: 0 2px 10px rgba(32, 36, 44, 0.16) !important;
  font-size: 13px;
}

.leaflet-control-attribution {
  font-size: 10px;
  line-height: 1.3;
  padding: 1px 6px;
}
.leaflet-control-attribution a { font-size: 10px; }

.leaflet-control-zoom,
.leaflet-control-layers { transition: opacity 0.15s ease; }

body.editor-open .leaflet-control-zoom,
body.editor-open .leaflet-control-layers {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

html[data-theme="dark"] .leaflet-bar,
html[data-theme="dark"] .leaflet-control-layers {
  border-color: var(--line) !important;
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.5) !important;
}
html[data-theme="dark"] .leaflet-bar a {
  background: var(--panel);
  color: var(--ink) !important;
  border-bottom-color: var(--line);
}
html[data-theme="dark"] .leaflet-bar a:hover { background: var(--panel-hover); }
html[data-theme="dark"] .leaflet-control-layers-toggle { filter: invert(1) hue-rotate(180deg); }
html[data-theme="dark"] .leaflet-control-attribution {
  background: rgba(13, 11, 18, 0.78);
  color: var(--muted);
}
html[data-theme="dark"] .leaflet-control-attribution a { color: var(--accent); }

/* ---------- Pins ---------- */

.pin-wrap {
  background: none;
  border: 0;
  cursor: pointer;
}

.leaflet-div-icon {
  background: transparent;
  border: 0;
}

.pin {
  display: block;
  filter: drop-shadow(0 3px 3px rgba(20, 18, 30, 0.35));
  transform-origin: 50% 92%;
  transition: transform 0.15s ease;
}

html[data-theme="dark"] .pin {
  filter: brightness(0.55) saturate(0.75) drop-shadow(0 3px 3px rgba(20, 18, 30, 0.55));
}

.pin path {
  fill: currentColor;
  stroke: var(--pin-stroke);
  stroke-width: 1.8;
  paint-order: stroke;
}

.pin-hole { fill: var(--pin-stroke); }

.pin .pin-glare {
  fill: none;
  stroke: #fff;
  stroke-opacity: 0.65;
  stroke-width: 1.5;
  stroke-linecap: round;
}

.pin-halo {
  fill: currentColor;
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
}

.pin-wrap:hover .pin { transform: scale(1.07); }
.pin-wrap.is-active .pin { transform: scale(1.12); }
.pin-wrap.is-active .pin-halo { animation: pin-pulse 2s ease-out infinite; }

@keyframes pin-pulse {
  0% { transform: scale(0.7); opacity: 0.35; }
  70% { transform: scale(1.4); opacity: 0; }
  100% { transform: scale(1.4); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  .pin-wrap.is-active .pin-halo { animation: none; opacity: 0.25; }
  .pin { transition: none; }
}

.leaflet-tooltip.pin-tip {
  background: var(--toast-bg);
  color: var(--toast-ink);
  border: 0;
  border-radius: 8px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 600;
  box-shadow: 0 4px 14px rgba(20, 18, 30, 0.24);
}
.leaflet-tooltip.pin-tip::before { display: none; }

/* ---------- Sidebar ---------- */

#sidebar {
  position: absolute;
  top: 16px;
  left: 16px;
  bottom: 16px;
  width: 318px;
  display: flex;
  flex-direction: column;
  padding: 16px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 1000;
}

.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.sidebar-head h2 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

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

.import-banner {
  margin: 10px 0 2px;
  padding: 10px;
  border: 1px solid var(--accent-line);
  border-radius: 10px;
  background: var(--accent-soft);
}

.import-banner p {
  margin: 0 0 8px;
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--ink);
}

.import-banner .btn {
  width: 100%;
  height: auto;
  min-height: 32px;
  padding: 6px 9px;
  font-size: 12.5px;
  line-height: 1.3;
  text-align: left;
  white-space: normal;
}

#closeSidebar { display: none; }

.search-wrap {
  position: relative;
  margin: 12px 0 10px;
  color: var(--muted);
}

.search-wrap svg {
  position: absolute;
  top: 50%;
  left: 11px;
  transform: translateY(-50%);
  pointer-events: none;
}

.search-wrap input {
  width: 100%;
  height: 36px;
  padding: 0 12px 0 34px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
  font: inherit;
  font-size: 14px;
  color: var(--ink);
}
.search-wrap input:focus {
  outline: none;
  border-color: rgba(167, 139, 250, 0.6);
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.16);
}

.geo-block {
  flex: 0 0 auto;
  padding-bottom: 10px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.geo-block .field-label { font-size: 11px; }
.geo-block .search-wrap { margin: 7px 0 0; }

.geo-status {
  margin: 7px 2px 0;
  font-size: 12px;
  line-height: 1.4;
  color: var(--muted);
}

.geo-results {
  list-style: none;
  margin: 6px -4px 0;
  padding: 0 4px;
  max-height: 206px;
  overflow-y: auto;
  scrollbar-width: thin;
}

.geo-results li + li { margin-top: 2px; }

.geo-result {
  display: block;
  width: 100%;
  padding: 7px 9px;
  border: 1px solid transparent;
  border-radius: 9px;
  background: none;
  font: inherit;
  text-align: left;
  color: var(--ink);
  cursor: pointer;
}
.geo-result:hover { background: var(--panel-hover); }
.geo-result:focus-visible {
  outline: none;
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.geo-result strong {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.geo-result small {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.place-list {
  list-style: none;
  margin: 0 -6px;
  padding: 0 6px;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  scrollbar-width: thin;
}

.place-list li + li { margin-top: 4px; }

.place-item {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 8px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: none;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.place-item:hover { background: var(--panel-hover); }
.place-item.active {
  background: var(--accent-soft);
  border-color: var(--accent-line);
}

.thumb {
  flex: 0 0 auto;
  width: 46px;
  height: 46px;
  border-radius: 9px;
  overflow: hidden;
  background: var(--thumb-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-weight: 700;
  font-size: 18px;
  text-transform: uppercase;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.place-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.place-text strong {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.place-text small {
  font-size: 12px;
  color: var(--muted);
}

.empty {
  margin: 4px 2px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--muted);
}

.empty strong { color: var(--ink); }

/* ---------- Editor panel ---------- */

.editor {
  position: absolute;
  top: 16px;
  right: 16px;
  bottom: 16px;
  width: 386px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 1100;
  overflow-y: auto;
  padding: 18px;
  scrollbar-width: thin;
}

.editor form { display: flex; flex-direction: column; gap: 14px; }

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.panel-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.coords {
  margin: -8px 0 0;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.field { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; }

.field-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--muted);
}

.field input[type="text"],
.field input[type="date"],
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-soft);
  font: inherit;
  font-size: 14px;
  color: var(--ink);
  resize: vertical;
}

.field input[type="date"] { min-height: 41px; resize: none; }

.field input[type="text"]:focus,
.field input[type="date"]:focus,
.field textarea:focus {
  outline: none;
  border-color: rgba(167, 139, 250, 0.6);
  box-shadow: 0 0 0 3px rgba(167, 139, 250, 0.16);
  background: var(--panel);
}

/* Pin colour swatches */

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  padding: 3px 0 1px;
}

.swatch {
  position: relative;
  width: 26px;
  height: 26px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.14);
  transition: transform 0.12s ease;
}

.swatch:hover { transform: scale(1.1); }

.swatch::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  opacity: 0;
  transition: opacity 0.12s ease;
}

.swatch[aria-checked="true"]::after { opacity: 1; }

.swatch:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 5px;
}

/* Photos */

.photos-field { gap: 9px; }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}

.photo-grid:empty { display: none; }

.photo {
  position: relative;
  margin: 0;
  aspect-ratio: 1;
  border-radius: 10px;
  overflow: hidden;
  background: var(--thumb-bg);
}

.photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  cursor: zoom-in;
}

.photo-remove {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(24, 26, 31, 0.72);
  color: #fff;
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.photo-remove:hover { background: rgba(24, 26, 31, 0.92); }

.file-drop {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 44px;
  border: 1.5px dashed var(--line-strong);
  border-radius: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: var(--panel-soft);
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}
.file-drop:hover, .file-drop.drag {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-soft);
}
.file-drop.busy { pointer-events: none; opacity: 0.7; }

.actions {
  display: flex;
  gap: 8px;
  padding-top: 4px;
}
.actions .btn.primary { flex: 1 1 auto; }

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

/* ---------- Add-mode hint bar ---------- */

.hint-bar {
  position: absolute;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 9px 9px 9px 18px;
  background: var(--toast-bg);
  color: var(--toast-ink);
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: 0 12px 30px rgba(20, 18, 30, 0.3);
  z-index: 1200;
  white-space: nowrap;
}

.hint-bar .btn.small {
  background: var(--toast-btn);
  color: var(--toast-ink);
  border: 0;
}
.hint-bar .btn.small:hover { background: var(--toast-btn-hover); }

/* ---------- Messages ---------- */

.app-message {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 2100;
  width: max-content;
  max-width: min(520px, calc(100vw - 24px));
  padding: 11px 15px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: var(--toast-bg);
  color: var(--toast-ink);
  font-size: 13.5px;
  line-height: 1.4;
  box-shadow: 0 12px 30px rgba(20, 18, 30, 0.3);
  transform: translateX(-50%);
}

.app-message.is-error {
  border-color: var(--danger-line);
  background: var(--panel);
  color: var(--danger);
}

/* ---------- Lightbox ---------- */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 28px;
  background: rgba(12, 11, 16, 0.9);
  cursor: zoom-out;
}

.lightbox img {
  max-width: 100%;
  max-height: 100%;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
  object-fit: contain;
  cursor: default;
}

/* ---------- Responsive ---------- */

@media (max-width: 900px) {
  .topbar { height: 58px; padding: 0 12px; }
  .tagline { display: none; }

  .auth-email { display: none; }
  .auth-user { padding-right: 3px; }
  .auth-btn { padding: 0 10px; }

  #placesBtn { display: inline-flex; }
  .theme-btn { width: 38px; }

  #sidebar {
    top: 12px;
    left: 12px;
    right: 12px;
    bottom: 12px;
    width: auto;
    transform: translateX(calc(-100% - 30px));
    transition: transform 0.24s ease;
  }
  body.sidebar-open #sidebar { transform: none; }
  #closeSidebar { display: inline-flex; }

  .editor {
    top: auto;
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
    max-height: 84%;
    padding: 16px;
  }

  .hint-bar {
    left: 12px;
    right: 12px;
    bottom: 12px;
    transform: none;
    justify-content: space-between;
  }

  .photo-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 560px) {
  .places-label { display: none; }
  #placesBtn { width: 38px; padding: 0; }
  .topbar-actions { gap: 6px; }
  .auth-full,
  .auth-short { display: none; }
  .auth-btn { width: 38px; padding: 0; }
  .auth-signout-label { display: none; }
  .auth-signout { width: 38px; padding: 0; }
  #addBtn { width: 38px; padding: 0; }
  #addBtn .label-full,
  #addBtn .label-short { display: none; }
}

@media (max-width: 400px) {
  .label-full { display: none; }
  .label-short { display: inline; }
}

@media (max-width: 420px) {
  .brand-name { font-size: 15px; }
  .btn { padding: 0 12px; }
  .theme-btn { padding: 0; }
  .photo-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  .btn, #sidebar, .file-drop { transition: none; }
}
