:root {
  --bg: #edf1eb;
  --panel: rgba(248, 249, 241, 0.94);
  --panel-border: rgba(51, 73, 55, 0.15);
  --text: #1f3123;
  --muted: #5d6d5f;
  --accent: #205847;
  --accent-soft: #dbe9d9;
  --point-green: #2f8f46;
  --point-red: #d43f2f;
  --turn: #d97706;
  --line: #1a3b33;
  --shadow: 0 20px 60px rgba(19, 35, 24, 0.16);
  --point-scale: 1;
  --app-width: 100vw;
  --app-height: 100dvh;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

body {
  overflow: hidden;
}

input,
textarea,
button {
  border: 1px solid rgba(31, 49, 35, 0.16);
  border-radius: 14px;
  font: inherit;
  font-size: 16px;
}

input,
textarea {
  width: 100%;
  padding: 13px 14px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--text);
}

textarea {
  resize: vertical;
  min-height: 104px;
}

button {
  cursor: pointer;
  padding: 12px 14px;
  color: #fff;
  background: var(--accent);
  transition: transform 0.15s ease, opacity 0.15s ease;
}

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

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.map-screen {
  position: relative;
  width: var(--app-width);
  height: var(--app-height);
  overflow: hidden;
}

#map {
  width: 100%;
  height: 100%;
}

.floating-top {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  z-index: 1200;
  pointer-events: none;
}

.top-left-stack,
.top-right-stack,
.floating-bottom {
  display: grid;
  gap: 8px;
}

.top-left-tools,
.top-right-tools {
  display: flex;
  gap: 8px;
}

.top-left-stack,
.top-right-stack,
.info-stack {
  pointer-events: none;
}

.top-left-stack {
  margin-left: 56px;
}

.top-left-stack > *,
.top-right-stack > *,
.floating-bottom > *,
.info-stack > * {
  pointer-events: auto;
}

.top-right-stack {
  justify-items: end;
}

.floating-bottom {
  position: absolute;
  left: calc(12px + env(safe-area-inset-left, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  z-index: 1200;
  display: flex;
  justify-content: space-between;
  align-items: end;
  pointer-events: none;
}

.layer-controls {
  display: grid;
  grid-template-columns: auto auto;
  grid-template-areas:
    "export badge"
    "cycle badge";
  gap: 8px;
  align-items: end;
  pointer-events: auto;
}

#exportPngButton {
  grid-area: export;
}

#cycleLayerButton {
  grid-area: cycle;
}

#totalDistanceBadge {
  grid-area: badge;
  align-self: end;
}

.distance-badges {
  min-height: 40px;
  display: grid;
  gap: 6px;
  align-content: end;
}

.distance-badge {
  min-height: 36px;
  padding: 7px 11px;
  display: flex;
  align-items: center;
  border-radius: 999px;
  background: color-mix(in srgb, var(--badge-color, rgba(248, 249, 241, 0.94)) 18%, rgba(248, 249, 241, 0.94));
  border: 1px solid color-mix(in srgb, var(--badge-color, var(--panel-border)) 36%, var(--panel-border));
  box-shadow: var(--shadow);
  color: var(--badge-color, var(--text));
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.distance-badge.active-path-badge {
  box-shadow:
    0 0 0 3px rgba(149, 76, 233, 0.92),
    0 0 0 7px rgba(149, 76, 233, 0.24),
    var(--shadow);
}

.info-stack {
  display: grid;
  justify-items: end;
  gap: 8px;
  margin-left: auto;
  width: fit-content;
  max-width: calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
}

.fab {
  min-width: 48px;
  min-height: 48px;
  padding: 10px 14px;
  border-radius: 16px;
  box-shadow: var(--shadow);
}

#toggleSearchButton,
#toggleQuickAddButton,
#toggleMenuButton {
  width: 48px;
  padding: 10px;
}

.overlay-panel,
.overlay-menu {
  width: min(420px, calc(100vw - 24px));
  padding: 12px;
  border: 1px solid var(--panel-border);
  border-radius: 22px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

.overlay-panel.hidden,
.overlay-menu.hidden,
.side-panel.hidden,
.adjustments-tab.hidden,
.modal.hidden {
  display: none;
}

.search-row {
  display: flex;
  gap: 8px;
}

.search-row input {
  min-width: 0;
  flex: 1 1 auto;
}

.search-row button {
  flex: 0 0 auto;
}

.overlay-menu {
  display: grid;
  gap: 8px;
}

.menu-fabs {
  width: auto;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  backdrop-filter: none;
  box-shadow: none;
  justify-items: end;
  pointer-events: none;
}

.menu-fabs > * {
  pointer-events: auto;
}

.info-panel {
  display: grid;
  gap: 10px;
  justify-self: end;
  width: min(420px, calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
  max-width: 100%;
}

.indicator-popup {
  display: grid;
  gap: 8px;
  min-width: 170px;
}

.indicator-popup label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
}

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

.indicator-popup input {
  padding: 10px 12px;
}

.indicator-popup button {
  padding: 10px 12px;
  border-radius: 12px;
}

.indicator-popup .indicator-direction {
  min-width: 44px;
  padding: 8px 10px;
  border-radius: 999px;
}

.distance-stack {
  display: grid;
  gap: 8px;
}

.real-distance-inline {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  font-size: 14px;
}

.real-distance-inline span {
  font-weight: 600;
}

.obs-field {
  display: grid;
  gap: 6px;
  font-size: 14px;
}

.obs-field span {
  font-weight: 600;
}

.obs-field textarea {
  min-height: 72px;
}

.generated-note {
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(31, 49, 35, 0.08);
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}

#status {
  font-size: 14px;
  color: var(--muted);
}

.points {
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
  padding-right: 4px;
}

.size-control {
  display: grid;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
  align-content: start;
}

.size-control span {
  display: block;
}

.size-control input {
  width: 100%;
}

.point-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  padding: 12px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(31, 49, 35, 0.08);
}

.point-item.active-move {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 2px rgba(32, 88, 71, 0.18);
}

.point-item-main {
  min-width: 0;
}

.point-item small {
  display: block;
  color: var(--muted);
  margin-top: 3px;
}

.point-item-actions {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
}

.mini-btn {
  min-width: 0;
  width: 100%;
  padding: 8px 0;
  border-radius: 10px;
  background: #fff;
  color: #8f3030;
  font-size: 15px;
  line-height: 1;
}

.mini-btn.secondary-action {
  color: var(--text);
}

.mini-btn.toggle-on {
  background: var(--accent-soft);
  border-color: rgba(32, 88, 71, 0.28);
}

.swatch {
  width: 21px;
  height: 21px;
  flex: 0 0 auto;
  background: var(--point-green);
}

.swatch.register {
  background: #ffffff;
  border: 3px solid var(--point-red);
  border-radius: 999px;
}

.swatch.well {
  border-radius: 999px;
}

.swatch.half-well {
  border-radius: 4px;
}

.swatch.pipe {
  width: 21px;
  height: 21px;
  background: #245caa;
  border-radius: 999px;
}

.swatch.turn {
  background: linear-gradient(135deg, transparent 45%, var(--turn) 46%, var(--turn) 54%, transparent 55%);
  border: 1px dashed var(--turn);
}

.address-pin {
  display: grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 999px 999px 999px 0;
  transform: rotate(-45deg);
  background: #d43f2f;
  border: 2px solid #fff;
  box-shadow: 0 10px 22px rgba(212, 63, 47, 0.35);
}

.address-pin::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: #fff;
}

.well-marker {
  display: grid;
  place-items: center;
  position: absolute;
  left: 0;
  top: 0;
  width: 27px;
  height: 27px;
  border-radius: 999px;
  border: 2px solid #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.18);
  transform: translate(-50%, -50%) scale(var(--point-scale));
  transform-origin: center;
}

.register-marker {
  display: grid;
  place-items: center;
  position: absolute;
  left: 0;
  top: 0;
  width: 27px;
  height: 27px;
  border-radius: 999px;
  background: #ffffff;
  border: 3px solid var(--point-red);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.18);
  transform: translate(-50%, -50%) scale(var(--point-scale));
  transform-origin: center;
}

.half-well-marker {
  position: absolute;
  left: 0;
  top: 0;
  width: 27px;
  height: 27px;
  border-radius: 4px;
  border: 2px solid #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.18);
  transform: translate(-50%, -50%) scale(var(--point-scale));
  transform-origin: center;
}

.pipe-marker {
  display: grid;
  place-items: center;
  position: absolute;
  left: 0;
  top: 0;
  width: 27px;
  height: 27px;
  border-radius: 999px;
  background: #245caa;
  border: 2px solid #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.18);
  transform: translate(-50%, -50%) scale(var(--point-scale));
  transform-origin: center;
}

.turn-marker {
  position: absolute;
  left: 0;
  top: 0;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #ffffff;
  border: 3px dashed var(--turn);
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.18);
  transform: translate(-50%, -50%);
  transform-origin: center;
}

.point-green {
  background: var(--point-green);
}

.point-red {
  background: var(--point-red);
}

.register-label {
  padding: 8px 12px;
  border-radius: 999px;
  background: #ffffff;
  color: var(--text);
  font-size: 24px;
  font-weight: 600;
  border: 1px solid rgba(31, 49, 35, 0.08);
  display: inline-block;
  width: max-content;
  max-width: 240px;
  box-shadow: 0 6px 16px rgba(255, 255, 255, 0.95);
  white-space: nowrap;
}

.indicator-label {
  padding: 6px 10px;
  border-radius: 999px;
  background: #ffffff;
  color: #cf2e2e;
  font-size: 18px;
  font-weight: 700;
  border: 1px solid rgba(207, 46, 46, 0.2);
  display: inline-block;
  width: max-content;
  box-shadow: 0 6px 16px rgba(255, 255, 255, 0.95);
  white-space: nowrap;
}

.indicator-label.indicator-adjusted {
  color: #7b35d6;
  border-color: rgba(123, 53, 214, 0.25);
}

.marker-selected {
  box-shadow:
    0 0 0 4px rgba(255, 196, 0, 0.9),
    0 0 0 8px rgba(255, 196, 0, 0.22),
    0 0 0 3px rgba(255, 255, 255, 0.18);
}

.point-marker-wrap {
  position: relative;
  width: 0;
  height: 0;
}

.label-marker-shell {
  transform: translate(-50%, -50%);
}

.point-order-badge {
  position: absolute;
  left: 0;
  bottom: 18px;
  min-width: 26px;
  padding: 4px 8px;
  border-radius: 999px;
  background: #ffffff;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  border: 1px solid rgba(31, 49, 35, 0.12);
  box-shadow: 0 4px 12px rgba(255, 255, 255, 0.95);
  transform: translateX(-50%);
}

.type-buttons {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.type-button {
  background: #fff;
  color: var(--text);
  padding: 9px 10px;
  font-size: 14px;
  line-height: 1.15;
}

.type-button.active {
  background: var(--accent);
  color: #fff;
}

.curve-handle {
  width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #fff;
  border: 3px solid var(--line);
  box-shadow: 0 6px 16px rgba(26, 59, 51, 0.18);
  touch-action: none;
}

.break-marker {
  position: absolute;
  left: 0;
  top: 0;
  width: 40px;
  height: 40px;
  transform: rotate(var(--break-angle, 0deg));
  transform-origin: 34px 20px;
}

.break-arrow-shaft,
.break-arrow-head {
  position: absolute;
}

.break-arrow-shaft {
  left: 6px;
  top: 18px;
  width: 22px;
  height: 4px;
  border-radius: 999px;
  background: #cf2e2e;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.9);
}

.break-arrow-head {
  left: 24px;
  top: 12px;
  width: 0;
  height: 0;
  border-top: 8px solid transparent;
  border-bottom: 8px solid transparent;
  border-left: 13px solid #cf2e2e;
  filter: drop-shadow(0 0 1px rgba(255, 255, 255, 0.95));
}

.side-panel {
  position: fixed;
  top: 12px;
  right: 12px;
  bottom: 12px;
  left: 12px;
  z-index: 1600;
}

.side-panel-card {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  background: var(--panel);
  backdrop-filter: blur(12px);
  box-shadow: var(--shadow);
}

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

.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(16, 25, 19, 0.4);
  backdrop-filter: blur(6px);
}

.modal-card {
  width: min(100%, 420px);
  display: grid;
  gap: 12px;
  padding: 20px;
  border-radius: 22px;
  background: rgba(248, 249, 241, 0.97);
  border: 1px solid rgba(31, 49, 35, 0.1);
  box-shadow: var(--shadow);
}

#pointModal .modal-card {
  width: min(100%, 360px);
  gap: 10px;
  padding: 16px;
}

.modal-card h2 {
  margin: 0;
}

.adjustments-card {
  width: min(100%, 380px);
  gap: 10px;
  padding: 16px;
}

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

.adjustments-head h2 {
  margin: 0;
  font-size: 18px;
  line-height: 1.15;
}

.adjustments-switch,
.adjustments-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
}

.adjustments-tab {
  display: grid;
  gap: 8px;
}

.adjustment-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 8px;
  align-items: center;
  font-size: 13px;
}

.adjustment-row span {
  min-width: 0;
}

.adjustments-card .type-button,
.adjustments-card .secondary,
.adjustments-card input,
.adjustments-card .modal-actions button {
  padding: 9px 10px;
  font-size: 14px;
  line-height: 1.1;
}

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

.modal-card .modal-actions button {
  flex: 1 1 0;
  min-width: 0;
  padding: 9px 10px;
  font-size: 14px;
  line-height: 1.1;
  white-space: nowrap;
}

@media (min-width: 768px) {
  .top-left-stack {
    margin-left: 64px;
  }

  .top-left-stack .overlay-panel,
  .top-right-stack .overlay-menu,
  .floating-bottom .overlay-panel {
    width: min(460px, 46vw);
  }

  .info-stack {
    max-width: min(460px, calc(100vw - 24px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
  }

  .side-panel {
    left: auto;
    width: min(360px, calc(100vw - 24px));
    bottom: 12px;
    top: 12px;
  }
}

@media (max-width: 767px) {
  .top-left-stack {
    margin-left: 52px;
    width: auto;
  }

  .top-left-stack .overlay-panel {
    width: min(320px, calc(100vw - 132px));
  }

  .search-row {
    width: 100%;
  }

  .top-right-stack {
    gap: 10px;
  }

  .points {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(260px, 80vw);
    align-items: start;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 6px;
    scroll-snap-type: x proximity;
  }

  .point-item {
    min-height: 170px;
    align-content: start;
    scroll-snap-align: start;
  }

  .point-item-actions {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    padding-bottom: 2px;
  }

  .point-item-actions .mini-btn {
    min-width: 0;
  }

  .side-panel {
    top: auto;
    right: 12px;
    bottom: 12px;
    left: 12px;
    height: 300px;
  }

  .side-panel-card {
    grid-template-rows: auto auto 1fr;
    padding: 12px;
  }

  .floating-bottom {
    left: calc(10px + env(safe-area-inset-left, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .info-stack {
    width: min(100%, calc(100vw - 20px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px)));
    max-width: calc(100vw - 20px - env(safe-area-inset-left, 0px) - env(safe-area-inset-right, 0px));
  }

  .floating-bottom .overlay-panel {
    width: 100%;
    max-width: 100%;
  }

}
