:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --surface: #ffffff;
  --surface-strong: #edf3ef;
  --ink: #1c2522;
  --muted: #65706a;
  --line: #d7ded8;
  --accent: #0d766e;
  --accent-dark: #084f49;
  --amber: #b7791f;
  --danger: #b42318;
  --route: #f59e0b;
  --photo: #0ea5e9;
  --shadow: 0 12px 32px rgba(31, 41, 36, 0.14);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: relative;
  z-index: 600;
}

.topbar h1,
.panel h2 {
  margin: 0;
  letter-spacing: 0;
}

.topbar h1 {
  font-size: 1.35rem;
  line-height: 1.1;
}

.eyebrow {
  margin: 0 0 3px;
  font-size: 0.72rem;
  color: var(--accent);
  font-weight: 800;
  text-transform: uppercase;
}

.topbar-actions,
.button-row,
.search-row,
.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
}

.topbar-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(330px, 390px) 1fr;
}

.sidebar {
  height: calc(100vh - 72px);
  overflow: auto;
  background: #fbfcfb;
  border-right: 1px solid var(--line);
  padding: 14px;
}

.panel {
  padding: 14px 0 16px;
  border-bottom: 1px solid var(--line);
}

.panel:first-child {
  padding-top: 0;
}

.panel h2 {
  font-size: 0.96rem;
}

.panel-head {
  justify-content: space-between;
  margin-bottom: 10px;
}

label {
  display: grid;
  gap: 6px;
  margin: 10px 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.label-with-help {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.help-button {
  position: relative;
  width: 18px;
  height: 18px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-strong);
  color: var(--accent-dark);
  cursor: help;
  font-size: 0.72rem;
  font-weight: 900;
  line-height: 1;
}

.help-button::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  z-index: 900;
  width: min(260px, 70vw);
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1.35;
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(3px);
  transition: opacity 120ms ease, transform 120ms ease;
}

.help-button:hover::after,
.help-button:focus-visible::after {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  padding: 9px 10px;
  outline: none;
}

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

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 118, 110, 0.14);
}

input[readonly] {
  background: #eef2ef;
  color: #59645e;
  cursor: not-allowed;
}

.camera-details {
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.camera-details summary {
  cursor: pointer;
  color: var(--ink);
}

.button,
.icon-button,
.file-trigger {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 800;
  text-decoration: none;
  transition:
    transform 120ms ease,
    background-color 120ms ease,
    border-color 120ms ease;
}

.button:active,
.icon-button:active,
.file-trigger:active {
  transform: translateY(1px);
}

.button svg,
.icon-button svg,
.file-trigger svg {
  width: 17px;
  height: 17px;
}

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

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

.button.secondary,
.file-trigger,
.icon-button {
  background: var(--surface-strong);
  color: var(--ink);
  border-color: var(--line);
}

.button.secondary:hover,
.file-trigger:hover,
.icon-button:hover {
  border-color: #9fb0a6;
  background: #e5eee8;
}

.button.small {
  min-height: 30px;
  padding: 5px 9px;
  font-size: 0.78rem;
}

.button.full {
  width: 100%;
}

.icon-button {
  width: 38px;
  padding: 0;
}

.file-trigger {
  width: 100%;
  margin-top: 10px;
  color: var(--muted);
}

.file-trigger input {
  display: none;
}

.control-grid {
  display: grid;
  gap: 8px;
}

.search-row {
  align-items: end;
}

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

.search-button {
  width: 42px;
  padding: 0;
  flex: 0 0 42px;
}

.place-results {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.place-result {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  padding: 8px 10px;
  text-align: left;
  font-size: 0.78rem;
  line-height: 1.35;
}

.place-result:hover {
  border-color: var(--accent);
  background: var(--surface-strong);
}

.control-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.inline-check {
  display: inline-flex;
  grid-template-columns: auto;
  align-items: center;
  gap: 6px;
  margin: 0;
}

.inline-check input {
  width: auto;
}

.action-check {
  min-height: 38px;
  align-items: center;
  justify-content: flex-start;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.78rem;
}

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

.metric-grid div,
.map-overlay div {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
}

.metric-grid span,
.map-overlay span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.metric-grid strong,
.map-overlay strong {
  display: block;
  margin-top: 3px;
  font-size: 1rem;
}

.range-line {
  display: grid;
  grid-template-columns: 44px 1fr 68px;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.range-line input {
  padding: 0;
}

.range-line output {
  color: var(--ink);
  text-align: right;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(13, 118, 110, 0.1);
  color: var(--accent-dark);
  font-size: 0.72rem;
  font-weight: 800;
}

.status-pill.muted {
  background: #f4ead9;
  color: var(--amber);
}

.workflow {
  margin: 8px 0 12px 20px;
  padding: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.55;
}

.small-note {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

.map-area {
  min-width: 0;
  min-height: calc(100vh - 72px);
  position: relative;
}

#map {
  width: 100%;
  height: calc(100vh - 72px);
  background: #d9e3de;
}

.map-overlay {
  position: absolute;
  left: 72px;
  top: 16px;
  z-index: 500;
  display: grid;
  grid-template-columns: repeat(2, minmax(110px, 1fr));
  gap: 8px;
  max-width: min(360px, calc(100% - 88px));
}

.map-overlay div {
  box-shadow: var(--shadow);
}

.coordinate-editor {
  position: absolute;
  right: 16px;
  bottom: 16px;
  width: min(430px, calc(100% - 32px));
  z-index: 500;
  padding: 12px;
  background: rgba(255, 255, 255, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  backdrop-filter: blur(8px);
}

.coordinate-editor textarea {
  min-height: 104px;
  margin-top: 8px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
}

.leaflet-draw-toolbar a {
  background-size: 300px 30px;
}

.waypoint-arrow {
  width: 22px;
  height: 22px;
  margin-left: -11px;
  margin-top: -11px;
  display: grid;
  place-items: center;
}

.waypoint-arrow-shape {
  width: 0;
  height: 0;
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-bottom: 17px solid var(--photo);
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.45));
}

.waypoint-arrow.selected .waypoint-arrow-shape {
  border-bottom-color: #ef4444;
  filter:
    drop-shadow(0 0 4px rgba(239, 68, 68, 0.8))
    drop-shadow(0 2px 3px rgba(0, 0, 0, 0.4));
}

.waypoint-actions {
  margin-top: 8px;
}

.location-marker {
  width: 18px;
  height: 18px;
  margin-left: -9px;
  margin-top: -9px;
  border: 3px solid #ffffff;
  border-radius: 999px;
  background: #2563eb;
  box-shadow:
    0 0 0 6px rgba(37, 99, 235, 0.18),
    0 2px 8px rgba(0, 0, 0, 0.35);
}

.place-marker {
  width: 16px;
  height: 16px;
  margin-left: -8px;
  margin-top: -16px;
  border: 3px solid #ffffff;
  border-radius: 999px 999px 999px 0;
  background: #b42318;
  transform: rotate(-45deg);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
}

@media (max-width: 980px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .sidebar {
    height: auto;
    max-height: none;
    order: 2;
    border-right: 0;
    border-top: 1px solid var(--line);
  }

  .map-area,
  #map {
    min-height: 62vh;
    height: 62vh;
  }
}

@media (max-width: 680px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions {
    justify-content: stretch;
  }

  .topbar-actions .button {
    flex: 1 1 130px;
  }

  .control-grid.two,
  .metric-grid,
  .map-overlay {
    grid-template-columns: 1fr;
  }

  .map-overlay {
    top: 10px;
    left: 62px;
    max-width: 180px;
  }

  .coordinate-editor {
    left: 10px;
    right: 10px;
    bottom: 10px;
    width: auto;
  }
}
