*, *::before, *::after { box-sizing: border-box; }

:root {
  --bg: #ffffff;
  --panel: #f7f8fa;
  --line: #e2e5ea;
  --ink: #14171c;
  --muted: #697080;
  --accent: #2563eb;
  --start: #16a34a;
  --end: #dc2626;
  --stop: #2563eb;
  --warn: #b45309;
  --radius: 8px;
}

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

body {
  display: flex;
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

/* ---------- panel ---------- */

.panel {
  width: 380px;
  flex: 0 0 380px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 20px;
  overflow-y: auto;
  background: var(--panel);
  border-right: 1px solid var(--line);
}

.panel-head h1 {
  margin: 0;
  font-size: 18px;
  letter-spacing: -0.01em;
}

.sub {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 12px;
}

/* ---------- address rows ---------- */

.row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.badge {
  flex: 0 0 26px;
  height: 26px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: var(--stop);
}

.badge.start { background: var(--start); }
.badge.end   { background: var(--end); }

.row input[type="text"] {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 10px;
  font: inherit;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.row input[type="text"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

.row input.resolved { border-color: var(--start); }

.remove {
  flex: 0 0 26px;
  height: 26px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
}

.remove:hover { color: var(--end); background: #fff; }
.remove[hidden] { display: none; }

/* ---------- autocomplete ---------- */

.ac {
  position: absolute;
  top: calc(100% + 2px);
  left: 34px;
  right: 34px;
  z-index: 1000;
  max-height: 220px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0,0,0,.10);
}

.ac[hidden] { display: none; }

.ac-item {
  padding: 8px 10px;
  cursor: pointer;
  border-bottom: 1px solid var(--line);
}

.ac-item:last-child { border-bottom: 0; }
.ac-item:hover, .ac-item.sel { background: #eff4ff; }

.ac-title { font-weight: 500; }

.ac-meta {
  color: var(--muted);
  font-size: 12px;
}

/* ---------- controls ---------- */

.btn {
  padding: 9px 12px;
  font: inherit;
  font-weight: 500;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .12s, border-color .12s;
}

.btn.ghost {
  width: 100%;
  color: var(--muted);
  background: #fff;
  border: 1px dashed var(--line);
}

.btn.ghost:hover { color: var(--accent); border-color: var(--accent); }

.btn.primary {
  color: #fff;
  background: var(--accent);
  border: 1px solid var(--accent);
}

.btn.primary:hover { background: #1d4ed8; }
.btn.primary:disabled { opacity: .55; cursor: default; }

.opts {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.check input { margin: 0; }

/* ---------- output ---------- */

.status {
  padding: 9px 11px;
  font-size: 13px;
  border-radius: var(--radius);
  background: #eff4ff;
  color: #1e40af;
}

.status.error { background: #fef2f2; color: #991b1b; }

.result {
  padding: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.totals {
  display: flex;
  gap: 20px;
  padding-bottom: 12px;
  margin-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.total-num {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.total-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.leg {
  display: flex;
  gap: 9px;
  align-items: baseline;
  padding: 5px 0;
}

.leg-badge {
  flex: 0 0 20px;
  height: 20px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  background: var(--stop);
}

.leg-badge.start { background: var(--start); }
.leg-badge.end   { background: var(--end); }

.leg-name {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leg-dist {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.note {
  margin: 12px 0 0;
  padding-top: 10px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.note strong { color: var(--ink); }

/* ---------- view switch ---------- */

.view-switch {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.switch-label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}

.seg {
  display: flex;
  padding: 2px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.seg-btn {
  flex: 1 1 0;
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

.seg-btn.active {
  color: #fff;
  background: var(--accent);
}

.key-row input {
  width: 100%;
  padding: 8px 10px;
  font: inherit;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* ---------- footer ---------- */

.panel-foot {
  margin-top: auto;
  padding-top: 14px;
  font-size: 11px;
  color: var(--muted);
  border-top: 1px solid var(--line);
}

.panel-foot p { margin: 0 0 4px; }
.panel-foot a { color: var(--muted); }
.warn { color: var(--warn); }

/* ---------- map ---------- */

.stage {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
}

#map, #embed, .embed-empty {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
}

#map[hidden], #embed[hidden], .embed-empty[hidden] { display: none; }

.embed-empty {
  display: grid;
  place-items: center;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.pin {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  font: 600 12px/1 system-ui, sans-serif;
  color: #fff;
  background: var(--stop);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 1px 5px rgba(0,0,0,.35);
}

.pin.start { background: var(--start); }
.pin.end   { background: var(--end); }

/* ---------- responsive ---------- */

@media (max-width: 820px) {
  body { flex-direction: column; }
  .panel { width: 100%; flex: 0 0 auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .stage { flex: 1 1 auto; min-height: 60vh; }
}

.leg-cum {
  flex: 0 0 auto;
  min-width: 52px;
  text-align: right;
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}

.leg-dist {
  flex: 0 0 auto;
  min-width: 56px;
  text-align: right;
}

/* ---------- login ---------- */

.login-veil {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(20, 23, 28, .55);
  backdrop-filter: blur(3px);
}

.login-veil[hidden] { display: none; }

.login-box {
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 320px;
  padding: 26px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 12px 40px rgba(0,0,0,.28);
}

.login-box h2 { margin: 0; font-size: 18px; }

.login-sub {
  margin: 4px 0 18px;
  font-size: 13px;
  color: var(--muted);
}

.login-box label {
  margin-bottom: 4px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.login-box input {
  margin-bottom: 14px;
  padding: 9px 11px;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.login-box input:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: transparent;
}

.login-error {
  margin: 0 0 12px;
  padding: 8px 10px;
  font-size: 13px;
  color: #991b1b;
  background: #fef2f2;
  border-radius: var(--radius);
}

.login-error[hidden] { display: none; }

.logout {
  position: absolute;
  top: 20px;
  right: 20px;
  padding: 4px 9px;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.logout:hover { color: var(--end); border-color: var(--end); }
.logout[hidden] { display: none; }

.panel-head { position: relative; }

.embed-share {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.embed-share a { color: var(--accent); }

.copy-embed {
  margin-left: auto;
  padding: 4px 9px;
  font: inherit;
  font-size: 12px;
  color: var(--muted);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
}

.copy-embed:hover { color: var(--accent); border-color: var(--accent); }
