:root {
  color-scheme: light;
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #17202a;
  --muted: #67717f;
  --line: #d7dde5;
  --primary: #116a7b;
  --primary-strong: #0d5361;
  --visited: #2f855a;
  --unvisited: #d13f32;
  --focus: #f4b23d;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
}

#app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

.leaflet-container {
  overflow: hidden;
  touch-action: none;
}

.leaflet-pane,
.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow,
.leaflet-tile-container,
.leaflet-pane > svg,
.leaflet-pane > canvas,
.leaflet-zoom-box,
.leaflet-image-layer,
.leaflet-layer {
  position: absolute;
  left: 0;
  top: 0;
}

.leaflet-pane {
  z-index: 400;
}

.leaflet-tile-pane {
  z-index: 200;
}

.leaflet-overlay-pane {
  z-index: 400;
}

.leaflet-shadow-pane {
  z-index: 500;
}

.leaflet-marker-pane {
  z-index: 600;
}

.leaflet-tooltip-pane {
  z-index: 650;
}

.leaflet-popup-pane {
  z-index: 700;
}

.leaflet-tile,
.leaflet-marker-icon,
.leaflet-marker-shadow {
  user-select: none;
  -webkit-user-drag: none;
}

.leaflet-tile {
  width: 256px;
  height: 256px;
  max-width: none;
}

.leaflet-control-container .leaflet-top,
.leaflet-control-container .leaflet-bottom {
  position: absolute;
  z-index: 1000;
  pointer-events: none;
}

.leaflet-control-container .leaflet-top {
  top: 0;
}

.leaflet-control-container .leaflet-bottom {
  bottom: 0;
}

.leaflet-control-container .leaflet-left {
  left: 0;
}

.leaflet-control-container .leaflet-right {
  right: 0;
}

.leaflet-control {
  position: relative;
  z-index: 1000;
  pointer-events: auto;
}

.leaflet-right .leaflet-control {
  float: right;
  clear: both;
  margin-right: 12px;
}

.leaflet-left .leaflet-control {
  float: left;
  clear: both;
  margin-left: 12px;
}

.leaflet-top .leaflet-control {
  margin-top: 12px;
}

.leaflet-bottom .leaflet-control {
  margin-bottom: 12px;
}

.leaflet-control-zoom {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
  box-shadow: 0 8px 20px rgb(17 24 39 / 0.12);
}

.leaflet-control-zoom a {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: var(--text);
  text-decoration: none;
  font-size: 20px;
  font-weight: 700;
  line-height: 1;
}

.leaflet-control-zoom a + a {
  border-top: 1px solid var(--line);
}

.leaflet-control-attribution {
  margin: 0 8px 8px 0;
  padding: 3px 6px;
  border-radius: 6px;
  background: rgb(255 255 255 / 0.86);
  color: var(--muted);
  font-size: 11px;
}

.leaflet-control-attribution a {
  color: var(--primary);
}

.leaflet-popup {
  position: absolute;
  text-align: center;
  margin-bottom: 20px;
}

.leaflet-popup-content-wrapper {
  background: var(--surface);
  border-radius: 8px;
  box-shadow: 0 12px 36px rgb(17 24 39 / 0.22);
  padding: 12px;
  text-align: left;
}

.leaflet-popup-content {
  margin: 0;
}

.leaflet-popup-tip-container {
  width: 20px;
  height: 10px;
  position: absolute;
  left: 50%;
  margin-left: -10px;
  overflow: hidden;
  pointer-events: none;
}

.leaflet-popup-tip {
  width: 14px;
  height: 14px;
  margin: -7px auto 0;
  background: var(--surface);
  transform: rotate(45deg);
  box-shadow: 0 12px 36px rgb(17 24 39 / 0.14);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 72px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 20;
}

.topbar h1,
.topbar p,
.panel-head h2,
.dialog h2 {
  margin: 0;
}

.topbar h1 {
  font-size: 20px;
  line-height: 1.2;
}

.topbar p {
  color: var(--muted);
  font-size: 13px;
  margin-top: 2px;
}

.layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(300px, 360px);
  overflow: hidden;
}

.map-section {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  isolation: isolate;
}

#map {
  width: 100%;
  height: 100%;
  min-height: 0;
  background: #dce5df;
  position: relative;
  z-index: 1;
}

.places-panel {
  min-width: 0;
  background: var(--surface);
  border-left: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  position: relative;
  z-index: 10;
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--line);
}

.panel-head h2 {
  font-size: 16px;
}

.places-list {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 8px;
}

.status-message {
  margin: 12px 16px 0;
  padding: 10px 12px;
  border: 1px solid #f0c2bd;
  border-radius: 8px;
  background: #fff2f0;
  color: #9b2c23;
  font-size: 13px;
  font-weight: 700;
}

.place-item {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr);
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-radius: 8px;
}

.place-item + .place-item {
  margin-top: 2px;
}

.place-item:hover {
  background: #eef4f6;
}

.place-item-visited .place-text strong {
  color: var(--visited);
}

.visited-toggle {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
}

.visited-toggle input {
  position: absolute;
  opacity: 0;
}

.visited-toggle span {
  width: 22px;
  height: 22px;
  border: 2px solid var(--line);
  border-radius: 6px;
  display: grid;
  place-items: center;
}

.visited-toggle input:checked + span {
  border-color: var(--visited);
  background: var(--visited);
}

.visited-toggle input:checked + span::after {
  content: "✓";
  color: #fff;
  font-weight: 800;
  font-size: 14px;
}

.place-text {
  min-width: 0;
  padding: 4px 0;
  border: 0;
  background: transparent;
  text-align: left;
}

.place-text strong,
.place-text small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.place-text strong {
  font-size: 14px;
  line-height: 1.3;
}

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

.primary-button,
.secondary-button,
.ghost-button,
.icon-button {
  border-radius: 8px;
  border: 1px solid transparent;
  min-height: 40px;
  padding: 0 14px;
  font-weight: 700;
}

.primary-button {
  background: var(--primary);
  color: #fff;
}

.primary-button:hover {
  background: var(--primary-strong);
}

.primary-button:disabled {
  background: #9aa7b2;
  cursor: not-allowed;
}

.secondary-button {
  background: #fff8e9;
  color: #6b4a05;
  border-color: #edc76b;
}

.ghost-button {
  background: transparent;
  color: var(--muted);
  border-color: var(--line);
}

.icon-button {
  width: 40px;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font-size: 24px;
  line-height: 1;
}

.dialog {
  width: min(440px, calc(100vw - 24px));
  border: 0;
  border-radius: 10px;
  padding: 0;
  color: var(--text);
  box-shadow: 0 24px 80px rgb(17 24 39 / 0.24);
}

.dialog::backdrop {
  background: rgb(17 24 39 / 0.38);
}

.dialog form {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.dialog-head,
.dialog-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.field input {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--text);
}

.field input:focus {
  outline: 2px solid rgb(244 178 61 / 0.35);
  border-color: var(--focus);
}

.coords-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
}

.coords-row span {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pick-hint {
  position: absolute;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  z-index: 500;
  background: #17202a;
  color: #fff;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 12px 36px rgb(17 24 39 / 0.22);
  white-space: nowrap;
}

.is-picking {
  cursor: crosshair;
}

.place-marker {
  background: transparent;
  border: 0;
  display: block;
  pointer-events: auto;
}

.marker-dot {
  width: 32px;
  height: 32px;
  border-radius: 50% 50% 50% 8px;
  transform: rotate(-45deg);
  background: var(--unvisited);
  border: 3px solid #fff;
  box-shadow: 0 8px 18px rgb(17 24 39 / 0.28);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 900;
}

.marker-dot::first-letter {
  transform: rotate(45deg);
}

.marker-dot-visited {
  background: var(--visited);
  transform: rotate(-45deg);
}

.marker-dot-visited,
.marker-dot-draft {
  font-size: 18px;
  line-height: 1;
}

.marker-dot-visited {
  color: transparent;
  position: relative;
}

.marker-dot-visited::after {
  content: "✓";
  color: #fff;
  transform: rotate(45deg);
}

.marker-dot-draft {
  background: var(--focus);
  color: transparent;
  position: relative;
}

.marker-dot-draft::after {
  content: "+";
  color: #17202a;
  transform: rotate(45deg);
}

.popup {
  display: grid;
  gap: 7px;
  min-width: 180px;
}

.popup strong {
  font-size: 15px;
}

.popup span {
  color: var(--muted);
}

.popup label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
}

@media (max-width: 760px) {
  body {
    overflow: hidden;
  }

  .topbar {
    min-height: 68px;
  }

  .layout {
    display: grid;
    grid-template-columns: 1fr;
    grid-template-rows: minmax(320px, 58%) minmax(220px, 42%);
  }

  .map-section {
    min-height: 0;
  }

  .places-panel {
    min-height: 0;
    border-left: 0;
    border-top: 1px solid var(--line);
  }

  .coords-row,
  .dialog-actions {
    grid-template-columns: 1fr;
    display: grid;
  }

  .dialog-actions button,
  .coords-row button {
    width: 100%;
  }
}
