:root {
  --red: #b32025;
  --red-dark: #8d171c;
  --navy: #1b2b5a;
  --ink: #1b2b5a;
  --muted: #4d5872;
  --bg: #f4efe6;
  --panel: #fffcf8;
  --line: #e4d9cc;
  --green: #157a3a;
  --grey: #8b919a;
  --info-bg: #e7eefc;
  --warn-bg: #fff1d6;
  --warn-ink: #6d4a08;
  --error-bg: #fde8e8;
  --error-ink: #8d171c;
  --focus: #1b2b5a;
  --shadow: 0 10px 30px rgba(27, 43, 90, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #f6f1e8;
    --muted: #c9c2b6;
    --bg: #10141d;
    --panel: #171e2c;
    --line: #2d3648;
    --green: #3dce73;
    --info-bg: #243044;
    --warn-bg: #3d3018;
    --warn-ink: #ffd78a;
    --error-bg: #3d1c20;
    --error-ink: #ffb4b6;
    --focus: #ffee58;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow-x: clip;
  background: var(--bg);
  color: var(--ink);
  font-family: Manrope, "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

button, input, textarea, select { font: inherit; color: inherit; }

button, a, input, textarea, select, summary {
  -webkit-tap-highlight-color: transparent;
}

:focus { outline: none; }

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.app {
  display: flex;
  height: 100dvh;
  overflow: hidden;
  max-width: 100%;
}

.panel {
  width: 400px;
  flex: none;
  height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom));
}

.map-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 100dvh;
}

#map {
  height: 100%;
  width: 100%;
  background: #d9e2dc;
}

#map.is-drawing,
#map.is-drawing .leaflet-container {
  cursor: crosshair;
  touch-action: none;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.logo-plate {
  background: #fff;
  border-radius: 12px;
  padding: 6px 8px;
  display: flex;
  box-shadow: var(--shadow);
  flex: none;
}

.logo-plate img {
  height: 52px;
  width: auto;
  display: block;
}

.brand-copy h1 {
  margin: 0;
  font-size: 1.55rem;
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.eyebrow, .tagline, .meta, .fine {
  margin: 0;
  color: var(--muted);
}

.eyebrow {
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--red);
}

.tagline { font-weight: 600; }

.step {
  padding: 14px 0;
  border-top: 1px solid var(--line);
}

.step h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 10px;
  font-size: 1.15rem;
}

.step-num {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--red);
  color: #fff;
  font-size: 0.9rem;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
  font-weight: 700;
}

textarea, input[type="text"], input[type="number"], select {
  width: 100%;
  border: 2px solid var(--line);
  background: var(--bg);
  border-radius: 12px;
  padding: 12px;
  min-height: 48px;
}

textarea {
  resize: vertical;
  min-height: 132px;
  font-weight: 600;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 2px solid transparent;
  font-weight: 800;
  text-decoration: none;
  text-align: center;
  cursor: pointer;
}

.btn-block { width: 100%; margin-bottom: 8px; }

.btn-red { background: var(--red); color: #fff; }
.btn-red:hover { background: var(--red-dark); }

.btn-navy {
  background: var(--navy);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.note {
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 12px;
  font-weight: 700;
}

.note-info { background: var(--info-bg); }
.note-warn { background: var(--warn-bg); color: var(--warn-ink); }
.note-error { background: var(--error-bg); color: var(--error-ink); }

.progress, .count, .summary {
  font-weight: 800;
}

.count, .summary { margin: 8px 0; }

.meta { margin: 6px 0 0; font-weight: 650; }

details {
  margin-top: 8px;
  background: var(--error-bg);
  color: var(--error-ink);
  border-radius: 12px;
  padding: 8px 12px;
}

summary { cursor: pointer; font-weight: 800; min-height: 44px; display: flex; align-items: center; }

#failed-list {
  margin: 8px 0 4px;
  padding-left: 18px;
}

#failed-list li { margin: 4px 0; overflow-wrap: anywhere; }

.stops {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.stop {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 8px;
  padding: 8px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--bg);
}

.stop .outcome { grid-column: 1 / -1; }

.stop.is-done { opacity: 0.55; }

.stop-num {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

.stop.is-done .stop-num { background: var(--grey); }

.stop-body {
  display: grid;
  min-width: 0;
}

.wrap { overflow-wrap: anywhere; }

.leg { color: var(--muted); font-weight: 700; font-size: 0.92rem; }

.nav-links {
  display: grid;
  gap: 8px;
  margin: 8px 0;
}

.fine {
  font-size: 0.82rem;
  padding-top: 8px;
}

.fine a { color: inherit; }

.legend {
  position: absolute;
  z-index: 500;
  top: 10px;
  right: 10px;
  left: auto;
  margin: 0;
  padding: 8px 10px;
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  border-radius: 12px;
  font-size: 0.82rem;
  font-weight: 800;
  max-width: calc(100% - 20px);
}

.legend li { display: flex; align-items: center; gap: 6px; }

.swatch {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #fff;
  display: inline-grid;
  place-items: center;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

.swatch-in { background: var(--green); }
.swatch-out { background: var(--grey); width: 12px; height: 12px; }
.swatch-start, .swatch-stop {
  width: 20px;
  height: 20px;
  background: var(--navy);
  color: #fff;
  font-size: 11px;
}
.swatch-stop { background: var(--red); }

.pin-wrap { background: transparent; border: none; }

.pin-num, .pin-start {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  color: #fff;
  border: 2px solid #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  font-family: Manrope, sans-serif;
}

.pin-start { width: 36px; height: 36px; background: var(--navy); }
.pin-num { background: var(--red); }
.pin-num.is-done { background: var(--grey); }

.pin-popup { font-family: Manrope, sans-serif; max-width: 220px; }
.pin-popup strong { display: block; }

.leaflet-control-attribution {
  background: rgba(255, 255, 255, 0.92) !important;
  color: #1b2b5a !important;
  font-size: 11px;
  max-width: min(70%, 420px);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

@media (max-width: 800px) {
  html, body {
    height: auto;
    min-height: 100%;
  }

  .app {
    flex-direction: column;
    height: auto;
    min-height: 100dvh;
    overflow: visible;
  }

  .map-wrap {
    order: -1;
    position: sticky;
    top: 0;
    z-index: 20;
    height: 55dvh;
    width: 100%;
    flex: none;
    background: #d9e2dc;
  }

  .panel {
    order: 1;
    width: 100%;
    height: auto;
    overflow: visible;
    border-right: 0;
  }

  html {
    scroll-padding-top: 58dvh;
  }

  .panel button,
  .panel input,
  .panel textarea,
  .panel select,
  .panel summary,
  .stop {
    scroll-margin-top: 58dvh;
  }
}
