:root {
  --bg: #f5f5f4;
  --panel: #ffffff;
  --text: #1a1a1a;
  --muted: #666666;
  --border: #dddddd;
  --accent: #a30507;
  --accent-dark: #7d0405;
  --shadow: 0 6px 22px rgba(0,0,0,0.12);
}

* { box-sizing: border-box; }

body.routes-page {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, Segoe UI, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  border-radius: 7px;
  padding: .65rem .8rem;
  background: #1f1f1f;
  color: #ffffff;
  font-weight: 700;
  cursor: pointer;
}

button:hover { background: #000000; }

button:disabled {
  cursor: wait;
  opacity: .72;
}

input,
textarea {
  width: 100%;
  border: 1px solid #bbbbbb;
  border-radius: 7px;
  padding: .7rem;
  background: #ffffff;
}

input.routes-input-error,
textarea.routes-input-error,
#routes-map.routes-input-error {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(163,5,7,.18);
}

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

label {
  display: block;
  font-weight: 700;
  margin: .8rem 0 .35rem;
}

.routes-topbar {
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 1rem;
  background: #151515;
  color: #ffffff;
}

.routes-topbar a {
  color: #ffffff;
  text-decoration: none;
  font-weight: 700;
}

.routes-topbar nav {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.routes-topbar form { margin: 0; }

.routes-brand {
  letter-spacing: .01em;
}

.routes-app {
  height: calc(100vh - 64px);
  display: grid;
  grid-template-columns: minmax(320px, 400px) 1fr;
}

.routes-sidebar {
  overflow: auto;
  padding: 1rem;
  border-right: 1px solid var(--border);
  background: #eeeeec;
}

.routes-map-wrap {
  position: relative;
  min-width: 0;
  min-height: 420px;
}

.routes-map-undo {
  position: absolute;
  z-index: 500;
  left: 1rem;
  top: 1rem;
  width: 3rem;
  height: 3rem;
  display: none;
  place-items: center;
  border-radius: 999px;
  font-size: 1.4rem;
  box-shadow: var(--shadow);
  background: var(--accent);
}

#routes-map {
  width: 100%;
  height: 100%;
  background: #d8ded8;
}

.routes-map-watermark {
  position: absolute;
  right: .75rem;
  bottom: 2rem;
  z-index: 450;
  width: clamp(82px, 12vw, 132px);
  height: auto;
  opacity: .74;
  pointer-events: none;
  filter: drop-shadow(0 2px 5px rgba(0,0,0,.32));
}

.routes-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
  box-shadow: 0 1px 0 rgba(0,0,0,.03);
}

.routes-panel h1,
.routes-panel h2 {
  margin: 0 0 .75rem;
  line-height: 1.1;
}

.routes-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: .75rem;
}

.routes-builder-status {
  margin: 0 0 .8rem;
  padding: .7rem;
  border-radius: 7px;
  background: #f8f2e8;
  color: #5a3b08;
  font-size: .92rem;
}

.routes-inline-control {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: .45rem;
}

.routes-search-results {
  display: grid;
  gap: .4rem;
  margin-top: .5rem;
}

.routes-search-results button {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  background: #ffffff;
  color: var(--text);
  font-weight: 600;
  line-height: 1.25;
}

.routes-search-results button:hover {
  border-color: var(--accent);
  background: #fff8f8;
}

.routes-search-results small {
  display: block;
  margin-top: .2rem;
  color: var(--muted);
  font-weight: 500;
}

.routes-file-input {
  border-style: dashed;
  background: #fafafa;
}

.routes-list {
  display: grid;
  gap: .65rem;
  margin-top: .8rem;
}

body.routes-page:not(.routes-admin-page) .routes-sidebar {
  display: grid;
  grid-template-rows: minmax(180px, min(36vh, 360px)) minmax(0, 1fr);
  gap: 1rem;
}

body.routes-page:not(.routes-admin-page) .routes-panel {
  min-height: 0;
  margin-bottom: 0;
}

body.routes-page:not(.routes-admin-page) .routes-list-panel {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

body.routes-page:not(.routes-admin-page) .routes-list {
  overflow: auto;
  padding-right: .2rem;
}

body.routes-page:not(.routes-admin-page) .route-detail {
  overflow: auto;
}

.route-card {
  width: 100%;
  text-align: left;
  color: var(--text);
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .85rem;
  cursor: pointer;
}

.route-card:hover,
.route-card:focus-visible,
.route-card.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(163,5,7,.12);
  background: #ffffff;
  color: var(--text);
  outline: 0;
}

.route-card strong {
  display: block;
  margin-bottom: .25rem;
}

.route-card span {
  display: block;
  color: var(--muted);
  font-size: .9rem;
}

.route-card em {
  display: inline-block;
  margin-top: .45rem;
  color: var(--accent);
  font-style: normal;
  font-weight: 800;
}

.route-stat-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .65rem;
  margin: .8rem 0;
}

.route-stat-grid div:only-child {
  grid-column: 1 / -1;
}

.route-stat-grid div {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .75rem;
  background: #fafafa;
}

.route-stat-grid span {
  display: block;
  font-size: 1.4rem;
  font-weight: 800;
}

.route-stat-grid small {
  color: var(--muted);
}

.routes-elevation-profile {
  min-height: 126px;
  margin: .8rem 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .7rem;
  background: #fafafa;
}

.routes-elevation-profile p {
  margin: 0;
  color: var(--muted);
  font-size: .92rem;
}

.routes-elevation-profile svg {
  display: block;
  width: 100%;
  height: 110px;
}

.routes-elevation-fill {
  fill: rgba(163,5,7,.14);
}

.routes-elevation-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.routes-elevation-profile div {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: .82rem;
  font-weight: 700;
}

.routes-control-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .55rem;
  margin: .8rem 0;
}

.routes-control-grid button:only-child {
  grid-column: 1 / -1;
}

.routes-control-grid button.is-active,
.routes-primary {
  background: var(--accent);
}

.routes-control-grid button.is-active:hover,
.routes-primary:hover {
  background: var(--accent-dark);
}

.routes-export-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .55rem;
  margin: .8rem 0;
}

.routes-export-heading {
  margin: .95rem 0 .45rem;
  color: var(--muted);
  font-size: .95rem;
  line-height: 1.25;
  font-weight: 800;
}

.routes-export-grid a {
  display: grid;
  place-items: center;
  min-height: 2.65rem;
  padding: .55rem;
  border-radius: 7px;
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.routes-export-grid a:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.routes-danger {
  width: 100%;
  margin-top: .45rem;
  background: #666666;
}

.routes-danger:hover { background: #444444; }

.routes-check {
  display: flex;
  gap: .5rem;
  align-items: flex-start;
  font-weight: 500;
  color: var(--muted);
}

.routes-check input {
  width: auto;
  margin-top: .25rem;
}

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

.routes-waypoints {
  list-style: none;
  display: grid;
  gap: .45rem;
  padding: 0;
  margin: 0;
}

.routes-waypoints li {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: .55rem;
  padding: .55rem;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: #fafafa;
}

.routes-waypoints li[data-waypoint-row] {
  cursor: pointer;
}

.routes-waypoints li[data-waypoint-row]:hover,
.routes-waypoints li[data-waypoint-row]:focus-visible {
  border-color: #f2c94c;
  box-shadow: 0 0 0 2px rgba(242,201,76,.32);
  outline: 0;
}

.routes-waypoints span:first-child {
  display: inline-grid;
  place-items: center;
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 999px;
  background: #1f1f1f;
  color: #ffffff;
  font-size: .82rem;
  font-weight: 800;
}

.routes-waypoints small {
  color: var(--muted);
}

.routes-waypoints button {
  padding: .35rem .5rem;
  background: #777777;
}

.routes-error {
  color: #b71c1c;
  background: #ffebee;
  border-radius: 7px;
  padding: .7rem;
}

.routes-field-error {
  margin: .35rem 0 .1rem;
  color: #b71c1c;
  font-size: .9rem;
  font-weight: 700;
}

.routes-login {
  min-height: calc(100vh - 64px);
  display: grid;
  place-items: center;
  padding: 1rem;
}

.routes-login-panel {
  width: min(420px, 100%);
}

.routes-modal[hidden] {
  display: none;
}

.routes-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.routes-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.46);
}

.routes-modal__panel {
  position: relative;
  width: min(430px, 100%);
  border-radius: 8px;
  background: #ffffff;
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.routes-modal__panel h2 {
  margin: 0 0 .5rem;
}

.routes-modal__panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.4;
}

.routes-modal__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .55rem;
  margin-top: 1rem;
}

.routes-modal__actions a {
  display: grid;
  place-items: center;
  min-height: 2.65rem;
  padding: .55rem;
  border-radius: 7px;
  background: var(--accent);
  color: #ffffff;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
}

.routes-modal__actions a:hover {
  background: var(--accent-dark);
}

.routes-tour[hidden] {
  display: none;
}

.routes-tour {
  position: fixed;
  z-index: 2100;
  width: min(340px, calc(100vw - 24px));
  border: 1px solid #e0b43a;
  border-radius: 8px;
  background: #fff4c7;
  padding: 1rem;
  box-shadow: 0 8px 30px rgba(0,0,0,.24);
}

.routes-tour::before {
  content: "";
  position: absolute;
  top: -.45rem;
  left: 1.2rem;
  width: .9rem;
  height: .9rem;
  transform: rotate(45deg);
  background: #fff4c7;
  border-left: 1px solid #e0b43a;
  border-top: 1px solid #e0b43a;
}

.routes-tour p {
  margin: 0 0 .4rem;
  color: var(--accent);
  font-size: .78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.routes-tour h2 {
  margin: 0 0 .45rem;
  font-size: 1.05rem;
  line-height: 1.2;
}

.routes-tour [data-route-tour-body] {
  color: var(--muted);
  font-size: .94rem;
  line-height: 1.35;
}

.routes-tour__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .5rem;
  margin-top: .85rem;
}

.routes-tour__actions button:first-child {
  background: #f2c94c;
  color: #1a1a1a;
}

.routes-tour__actions button:first-child:hover {
  background: #dfb82f;
}

.routes-tour__actions button:last-child {
  background: var(--accent);
}

.routes-tour__actions button:last-child:hover {
  background: var(--accent-dark);
}

.routes-tour-target {
  position: relative;
  z-index: 2050;
  outline: 3px solid rgba(163,5,7,.35);
  outline-offset: 3px;
  box-shadow: 0 0 0 8px rgba(163,5,7,.08);
}

.leaflet-popup-content {
  margin: .75rem;
}

.route-location-pulse {
  width: 16px;
  height: 16px;
  margin: -8px 0 0 -8px;
  border-radius: 999px;
  background: #1976d2;
  border: 3px solid #ffffff;
  box-shadow: 0 0 0 6px rgba(25,118,210,.22);
}

.route-waypoint-marker {
  display: grid;
  place-items: center;
}

.route-waypoint-marker span {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border: 2px solid #1f1f1f;
  border-radius: 999px;
  background: #ffffff;
  color: #1f1f1f;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  cursor: move;
  box-shadow: 0 2px 7px rgba(0,0,0,.34), 0 0 0 4px rgba(255,255,255,.72);
}

.leaflet-drag-target .route-waypoint-marker span {
  cursor: grabbing;
  box-shadow: 0 2px 10px rgba(0,0,0,.42), 0 0 0 5px rgba(242,201,76,.48);
}

.route-endpoint-marker {
  display: grid;
  place-items: center;
}

.route-endpoint-marker span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border: 2px solid #ffffff;
  border-radius: 999px;
  color: #ffffff;
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
  box-shadow: 0 2px 7px rgba(0,0,0,.36);
}

.route-endpoint-start span {
  background: #177245;
}

.route-endpoint-finish span {
  background: var(--accent);
}

.route-endpoint-combined {
  display: flex;
  gap: 3px;
}

.route-endpoint-combined span:first-child {
  background: #177245;
}

.route-endpoint-combined span:last-child {
  background: var(--accent);
}

.route-direction-arrow {
  display: grid;
  place-items: center;
  opacity: .9;
}

.route-direction-arrow span {
  width: 0;
  height: 0;
  display: block;
  border-top: 7px solid transparent;
  border-bottom: 7px solid transparent;
  border-left: 15px solid rgba(26,26,26,.86);
  filter: drop-shadow(0 1px 2px rgba(255,255,255,.95)) drop-shadow(0 1px 2px rgba(0,0,0,.24));
}

.route-elevation-hover-marker {
  display: grid;
  place-items: center;
}

.route-elevation-hover-marker span {
  width: 20px;
  height: 20px;
  border: 3px solid #ffffff;
  border-radius: 999px;
  background: #f2c94c;
  box-shadow: 0 0 0 3px rgba(163,5,7,.78), 0 2px 8px rgba(0,0,0,.38);
}

@media (max-width: 820px) {
  .routes-app {
    height: auto;
    min-height: calc(100vh - 64px);
    grid-template-columns: 1fr;
  }

  .routes-sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  body.routes-page:not(.routes-admin-page) .routes-sidebar {
    display: block;
  }

  body.routes-page:not(.routes-admin-page) .routes-panel {
    margin-bottom: 1rem;
  }

  body.routes-page:not(.routes-admin-page) .routes-list-panel {
    display: block;
  }

  body.routes-page:not(.routes-admin-page) .routes-list,
  body.routes-page:not(.routes-admin-page) .route-detail {
    overflow: visible;
  }

  .routes-map-wrap {
    height: 65vh;
  }

  .routes-map-undo {
    display: grid;
  }

  .routes-tour {
    left: .75rem !important;
    right: .75rem;
    width: auto;
  }
}
