:root {
  color-scheme: light;
  --surface: #ffffff;
  --surface-quiet: #f2f6f9;
  --surface-raised: #ffffff;
  --ink: #1b3a5c;
  --muted: #5a6b7b;
  --line: #d8e2ea;
  --line-strong: #b3c0cc;
  /* Batas kontrol harus 3:1 terhadap latar (WCAG 1.4.11); --line dan
     --line-strong tidak mencapainya, jadi input dan tombol memakai ini. */
  --line-control: #7a8794;
  --accent: #1b7fa8;
  --accent-strong: #0f5b7a;
  --orange: #f5a623;
  --orange-hover: #e2961a;
  --orange-active: #d9971b;
  --focus: #1b3a5c;
  --error-ink: #6f241b;
  --error-bg: #fbf0ed;
  --error-line: #d9a79e;
  --success-ink: #1e4d3a;
  --success-bg: #edf4ef;
  --success-line: #b7cfc0;
  --warn-ink: #6b450a;
  --warn-bg: #fbf3e3;
  --warn-line: #c99a4a;
  --serif: ui-serif, Georgia, "Times New Roman", serif;
  --radius: 10px;
  --shadow-sheet: 0 -8px 24px rgba(27, 58, 92, 0.16);
}

* {
  box-sizing: border-box;
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--surface);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

a {
  color: var(--accent-strong);
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  position: relative;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--surface);
}

.map-shell {
  position: absolute;
  inset: 0;
}

#map {
  position: absolute;
  inset: 0;
  background: var(--line);
}

#map:focus-visible {
  outline-offset: -4px;
}

.panel {
  position: absolute;
  z-index: 1000;
  right: 0;
  bottom: 0;
  left: 0;
  max-height: min(58dvh, 560px);
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom, 0px));
  background: var(--surface);
  border-top: 1px solid var(--line);
  border-radius: 14px 14px 0 0;
  box-shadow: var(--shadow-sheet);
}

.masthead {
  display: grid;
  gap: 4px;
}

h1 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1.35rem;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.01em;
}

.masthead p {
  max-width: 44ch;
  margin: 0;
  color: var(--muted);
  font-size: 0.875rem;
}

h2 {
  margin: 0;
  font-family: var(--serif);
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: -0.01em;
}

.control {
  display: grid;
  gap: 7px;
}

.control-label {
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  padding: 3px;
  background: var(--surface-quiet);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.segment {
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 0.9375rem;
  font-weight: 600;
}

.segment:hover {
  background: #e4ecf4;
  color: var(--ink);
}

.segment:active {
  background: #d5e0ea;
}

.segment[aria-pressed="true"] {
  background: var(--surface-raised);
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(27, 58, 92, 0.16);
}

.points {
  display: grid;
  gap: 8px;
}

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

.point-key {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #ffffff;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
}

.point-key--from {
  background: var(--accent);
}

.point-key--to {
  background: var(--ink);
}

.point-copy {
  display: grid;
  gap: 1px;
  min-width: 0;
}

.point-role {
  color: var(--muted);
  font-size: 0.75rem;
}

.point-coord {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}

.point-name {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 600;
}

.search {
  display: grid;
  gap: 7px;
}

.search-input {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line-control);
  border-radius: var(--radius);
  background: var(--surface-raised);
  color: var(--ink);
  font-size: 0.9375rem;
  appearance: none;
}

.search-input::placeholder {
  color: var(--muted);
  opacity: 1;
}

.search-input:disabled {
  border-color: var(--line);
  background: var(--surface-quiet);
  color: var(--muted);
}

.search-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.8125rem;
}

.place-results {
  display: grid;
  gap: 0;
  max-height: 13rem;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  list-style: none;
  border: 1px solid var(--line-control);
  border-radius: var(--radius);
  background: var(--surface-raised);
}

.place-hit {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 8px 6px 10px;
  border-bottom: 1px solid var(--line);
}

.place-hit:last-child {
  border-bottom: 0;
}

.place-hit__text {
  display: grid;
  flex: 1 1 auto;
  gap: 1px;
  min-width: 0;
}

.place-hit__name {
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 600;
}

.place-hit__context {
  display: -webkit-box;
  overflow: hidden;
  color: var(--muted);
  font-size: 0.75rem;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.place-hit__actions {
  display: flex;
  flex: 0 0 auto;
  gap: 4px;
}

.place-set {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line-control);
  border-radius: 6px;
  background: var(--surface-raised);
  color: var(--ink);
  font-size: 0.8125rem;
  font-weight: 700;
}

.place-set--from {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.place-set--to {
  border-color: var(--ink);
  color: var(--ink);
}

.place-set:hover {
  background: #e4ecf4;
}

.place-set:active {
  background: #d5e0ea;
}

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

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.button {
  min-height: 44px;
  padding: 9px 14px;
  border: 1px solid var(--line-control);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.9375rem;
  font-weight: 600;
}

.button:hover:not(:disabled) {
  background: #eef3f7;
}

.button:active:not(:disabled) {
  background: #dde7f0;
}

.button:disabled {
  opacity: 0.46;
}

.button--primary {
  grid-column: 1 / -1;
  background: var(--orange);
  border-color: var(--orange);
  color: var(--ink);
}

.button--primary:hover:not(:disabled) {
  background: var(--orange-hover);
}

.button--primary:active:not(:disabled) {
  background: var(--orange-active);
}

.status {
  margin: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-quiet);
  font-size: 0.875rem;
  overflow-wrap: anywhere;
}

.status[data-tone="loading"] {
  border-color: var(--line-strong);
}

.status[data-tone="success"] {
  border-color: var(--success-line);
  background: var(--success-bg);
  color: var(--success-ink);
}

.status[data-tone="error"] {
  border-color: var(--error-line);
  background: var(--error-bg);
  color: var(--error-ink);
}

.result {
  display: grid;
  gap: 12px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

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

.region {
  max-width: 55%;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  font-size: 0.75rem;
  overflow-wrap: anywhere;
  text-align: right;
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}

.metric {
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-quiet);
}

.metric dt,
.meta dt {
  color: var(--muted);
  font-size: 0.75rem;
}

.metric dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
  font-family: var(--serif);
  font-size: 1.2rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 0;
}

.meta dd {
  margin: 1px 0 0;
  font-size: 0.875rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.badge {
  padding: 3px 7px;
  border: 1px solid var(--line-strong);
  border-radius: 4px;
  background: var(--surface-quiet);
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 600;
}

.badge--warn {
  border-color: var(--warn-line);
  background: var(--warn-bg);
  color: var(--warn-ink);
}

.result-note {
  margin: 0;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--surface-quiet);
  color: var(--muted);
  font-size: 0.8125rem;
}

.fineprint {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.75rem;
}

.route-pin {
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 0;
}

.pin {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 2px solid var(--surface);
  border-radius: 50%;
  box-shadow: 0 1px 4px rgba(27, 58, 92, 0.45);
  color: #ffffff;
  font-size: 0.8125rem;
  font-weight: 700;
  line-height: 1;
}

.pin--from {
  background: var(--accent-strong);
}

.pin--to {
  background: var(--orange);
  color: var(--ink);
}

/* inti rute digambar sekali setiap geometri baru muncul; casing tetap statis */
.route-core {
  stroke-dasharray: 1;
  stroke-dashoffset: 0;
}

@keyframes route-draw {
  from {
    stroke-dashoffset: 1;
  }
}

.route-core-draw {
  animation: route-draw 700ms cubic-bezier(0.22, 0.61, 0.36, 1) both;
}

.leaflet-container {
  background: var(--line);
  color: var(--ink);
  font: inherit;
}

/* Tile OSM memakai warna penuh; rute harus jadi lapisan paling menonjol,
   jadi tile diturunkan saturasi dan kontrasnya lewat CSS, bukan tile server lain. */
.leaflet-tile {
  filter: saturate(0.55) contrast(1.04) brightness(1.02);
}

.leaflet-container a {
  color: var(--accent-strong);
}

.leaflet-container .leaflet-control-attribution {
  padding: 3px 6px;
  background: var(--surface-quiet);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.leaflet-bar {
  border: 1px solid var(--line) !important;
  box-shadow: 0 1px 3px rgba(27, 58, 92, 0.22) !important;
}

.map-locate {
  border-color: var(--muted) !important;
  border-radius: var(--radius);
}

.map-locate__button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 14px;
  border: 0;
  border-radius: inherit;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.map-locate__button:hover:not([aria-disabled="true"]) {
  background: #eef3f7;
}

.map-locate__button:active:not([aria-disabled="true"]) {
  background: #dde7f0;
}

.map-locate__button[aria-disabled="true"] {
  color: var(--muted);
  cursor: progress;
}

.map-locate__icon {
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.leaflet-bar a {
  width: 44px !important;
  height: 44px !important;
  line-height: 44px !important;
  background: var(--surface) !important;
  border-bottom-color: var(--line) !important;
  color: var(--ink) !important;
  font-size: 20px !important;
}

.leaflet-bar a:hover {
  background: #eef3f7 !important;
}

.leaflet-bar a:last-child {
  border-bottom: 0 !important;
}

@media (min-width: 720px) {
  .app {
    display: grid;
    grid-template-columns: clamp(340px, 30vw, 400px) minmax(0, 1fr);
  }

  .panel {
    position: static;
    grid-column: 1;
    grid-row: 1;
    width: auto;
    height: 100dvh;
    max-height: none;
    padding: 24px;
    border-top: 0;
    border-right: 1px solid var(--line);
    border-radius: 0;
    box-shadow: none;
  }

  .map-shell {
    position: relative;
    inset: auto;
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
  }

  .fineprint {
    margin-top: auto;
    padding-top: 6px;
  }
}

@media (pointer: coarse) {
  .place-set {
    width: 44px;
    height: 44px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
}
