/* ── Stages (Collections) ─────────────────────────────────────────────── */
#route-planner-panel .rp-coll-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  gap: 8px;
  border-bottom: 1px solid var(--bdr, var(--bg3));
}
#route-planner-panel .rp-coll-cap {
  color: var(--dim, var(--dim));
  font-size: var(--fs-xs);
}
#route-planner-panel .rp-coll-row {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--bdr, var(--bg3));
  cursor: pointer;
  gap: 8px;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}
#route-planner-panel .rp-coll-row:hover { background: var(--bg3, var(--bg3)); }

/* Type badge on each list row. Collection = neutral (loose group of
   routes); Stage = amber (organised into days). Same record — the badge
   reflects whether any route has a day_number assigned. */
#route-planner-panel .rp-coll-kind {
  display: inline-block;
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.6px;
  padding: 1px 5px;
  border-radius: 3px;
  vertical-align: middle;
  margin-right: 6px;
}
#route-planner-panel .rp-coll-kind.is-collection {
  background: var(--bg3, var(--bg3));
  color: var(--dim, var(--dim));
}
#route-planner-panel .rp-coll-kind.is-stage {
  background: rgba(var(--amber-wash), 0.18);
  color: var(--amber, var(--amber));
}

/* Modal shell — generic, reused by the add-to-collection picker and the
   collection detail overlay. */
.rp-modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 10000;
}
.rp-modal {
  background: var(--bg1);
  color: var(--txt);
  border: 1px solid var(--bdr);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  max-width: 96vw;
  max-height: 92vh;
  overflow: hidden;
  font-family: inherit;
}
.rp-modal-sm { width: 420px; }
.rp-modal-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--bdr);
  background: var(--bg1);
}
.rp-modal-head h3 {
  margin: 0;
  flex: 1;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--amber-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rp-modal-body {
  flex: 1;
  min-height: 0;
  overflow: auto;
  padding: 12px 16px;
}
.rp-modal-foot {
  padding-top: 10px;
  border-top: 1px solid var(--bdr);
  margin-top: 10px;
  display: flex;
  justify-content: flex-end;
}
/* Amber primary button inside the picker modal — the modal lives outside
   #route-planner-panel (it's appended to <body>), so the panel-scoped
   .rp-btn-primary rule doesn't reach it. */
.rp-modal-foot .rp-btn-primary {
  background: var(--amber);
  color: var(--on-amber);
  /* Transparent border for parity with sibling .rp-btn (which has a
     1px coloured border) — keeps the rendered height consistent. */
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 7px 14px;
  font-weight: 600;
  cursor: pointer;
}
.rp-modal-foot .rp-btn-primary:hover { filter: brightness(1.1); }

/* Add-to-collection picker */
.rp-coll-picker-hint {
  font-size: var(--fs-sm);
  color: var(--dim);
  margin-bottom: 10px;
}
.rp-coll-picker-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  max-height: 50vh;
  overflow: auto;
}
.rp-coll-picker-row {
  display: block;
  width: 100%;
  text-align: left;
  padding: 10px 12px;
  background: var(--bg1);
  border: 1px solid var(--bdr);
  border-radius: 6px;
  color: var(--txt);
  cursor: pointer;
}
.rp-coll-picker-row:hover {
  background: var(--bg2);
  border-color: var(--amber-ink);
}
.rp-coll-picker-row .rp-row-title {
  font-weight: 600;
  font-size: var(--fs-base);
}
.rp-coll-picker-row .rp-row-meta {
  color: var(--dim);
  font-size: var(--fs-xs);
  margin-top: 2px;
}

/* ── Collection page ─────────────────────────────────────────────────── */
/* Shows inside .rp-body alongside the sidebar when viewing a collection.
   .rp-main and .rp-rightpanel are hidden while this is visible. */
.rp-coll-page {
  display: flex;
  flex: 1;
  min-height: 0;
  min-width: 0;
}
.rp-coll-page[hidden] { display: none; }

/* Main area: map + profile stacked vertically, takes all available width */
.rp-coll-main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

/* Route picker drawer — sits to the LEFT of the right panel inside
   .rp-coll-right-area, so it slides out adjacent to the items list. */
.rp-coll-page-picker {
  width: 300px;
  flex-shrink: 0;
  background: var(--bg1);
  border-right: 1px solid var(--bdr);
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-left: 1px solid var(--bdr);
}
.rp-coll-page-picker[hidden] { display: none; }
/* Active while a collection item is dragged over the drawer — signals
   "drop here to remove from the collection". Red to distinguish from the
   amber add-target outline on the items list. */
.rp-coll-page-picker.rp-coll-remove-target {
  outline: 2px dashed var(--red, var(--red));
  outline-offset: -4px;
  background: color-mix(in srgb, var(--red, var(--red)) 8%, var(--bg1));
}
.rp-coll-page-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--bdr);
  min-height: 42px;
  box-sizing: border-box;
}
.rp-coll-page-picker-head h4 {
  margin: 0;
  font-size: var(--fs-base);
  color: var(--txt);
}
.rp-coll-page-picker-search {
  padding: 8px 14px;
  border-bottom: 1px solid var(--bdr);
}
/* Match the .rp-list-q look used by the Routes / Stages tab list filters
   so the search inputs feel like the same control across the app. */
.rp-coll-page-picker-search input {
  width: 100%;
  box-sizing: border-box;
  padding: 6px 8px;
  border: 1px solid var(--bdr);
  border-radius: 4px;
  background: var(--bg0);
  color: var(--txt);
  font: inherit;
  font-size: var(--fs-base);
}
.rp-coll-page-picker-search input::placeholder { color: var(--dim2); }
.rp-coll-page-picker-search input:focus {
  outline: none;
  border-color: var(--amber-ink);
}
.rp-coll-page-picker-body {
  flex: 1;
  overflow-y: auto;
}

/* Map area in collection page */
.rp-coll-map-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}
.rp-coll-page .rp-coll-detail-map {
  position: absolute;
  inset: 0;
}
/* ── Map Layers control position ─────────────────────────────────────────
   The control is core/map-layers.js + core/map-layers.css, the same module the
   planner, both activity maps and the two public pages mount (TKF-265). Only
   where the Leaflet corner sits is this map's own — the planner's rule is
   scoped to `.rp-map`, which this container is not. Same 12/18 inset as every
   other surface, so the button lands in the same place on all of them and
   lines up with the fullscreen button opposite it. */
.rp-coll-detail-map .leaflet-top.leaflet-right .tk-ml-ctl {
  margin-top: 12px;
  margin-right: 18px;
}

/* Small hide/show profile toggle — sits above profile panel, right-aligned */
.rp-coll-profile-toggle {
  flex-shrink: 0;
  align-self: flex-end;
  background: none;
  border: none;
  color: var(--dim);
  padding: 2px 10px;
  font-size: var(--fs-xs);
  cursor: pointer;
}
.rp-coll-profile-toggle:hover { color: var(--txt); }
.rp-coll-profile-toggle[hidden] { display: none; }

/* Elevation/gradient profile beneath the map in stages detail */
.rp-coll-profile {
  height: 150px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-top: 1px solid var(--bdr);
  background: var(--bg1);
  position: relative;
}
.rp-coll-profile[hidden] { display: none; }
.rp-coll-profile-resize {
  height: 6px;
  cursor: ns-resize;
  background: transparent;
  position: relative;
}
.rp-coll-profile-resize::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 40px;
  height: 3px;
  border-radius: 2px;
  background: var(--bg3);
}
.rp-coll-profile-resize:hover::after {
  background: var(--amber);
}
.rp-coll-profile-chart-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}
.rp-coll-profile-chart-wrap canvas {
  position: absolute !important;
  width: 100% !important;
  height: 100% !important;
}

/* Right area — wraps picker drawer + collapse button + side panel */
.rp-coll-right-area {
  display: flex;
  flex-shrink: 0;
  position: relative;
  transition: width 0.18s ease, opacity 0.18s ease;
}

/* Collapse handle for the stages right panel */
.rp-coll-side-collapse {
  position: absolute;
  top: 12px;
  right: 340px;
  transform: translateX(50%);
  width: 22px;
  height: 36px;
  background: var(--bg2);
  color: var(--txt);
  border: 1px solid var(--bdr);
  border-radius: 4px;
  cursor: pointer;
  z-index: 400;
  font-size: var(--fs-base);
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: right 0.18s ease;
}
.rp-coll-page-side.collapsed ~ .rp-coll-side-collapse,
.rp-coll-side-collapse:has(~ .rp-coll-page-side.collapsed) {
  /* Fallback: JS positions via class */
}
.rp-coll-side-collapse:hover { border-color: var(--amber-ink); }

/* Right sidebar in collection page */
.rp-coll-page-side {
  width: 340px;
  flex-shrink: 0;
  border-left: 1px solid var(--bdr);
  background: var(--bg1);
  display: flex;
  flex-direction: column;
  min-height: 0;
  transition: width 0.18s ease;
  overflow: hidden;
}
.rp-coll-page-side.collapsed {
  width: 0;
  border-left: 0;
  overflow: hidden;
}

/* ── Stages full-screen map mode ──────────────────────────────────────── */
.rp-coll-page.rp-coll-fullscreen .rp-coll-right-area {
  width: 0;
  overflow: hidden;
  border: 0;
  opacity: 0;
  transition: width 0.18s ease, opacity 0.18s ease;
}
.rp-coll-page.rp-coll-fullscreen .rp-coll-side-collapse {
  display: none;
}

.rp-coll-page-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--bdr);
}
.rp-coll-page-header h3 {
  margin: 6px 0 0;
  font-size: var(--fs-md);
  font-weight: 600;
  color: var(--amber-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Collection detail overlay — near-full-screen, map + items side by side */
.rp-coll-detail-backdrop .rp-modal {
  width: 96vw;
  height: 92vh;
  max-width: 1400px;
}
.rp-coll-detail-stats {
  display: flex;
  gap: 16px;
  font-size: var(--fs-sm);
  color: var(--dim);
}
.rp-coll-detail-stats b {
  color: var(--amber-ink);
  font-weight: 600;
  margin-left: 4px;
}
.rp-coll-detail-body {
  flex: 1;
  display: flex;
  min-height: 0;
}
.rp-coll-detail-map {
  flex: 1;
  background: var(--bg2);
  min-width: 0;
}
.rp-coll-detail-side {
  width: 340px;
  border-left: 1px solid var(--bdr);
  background: var(--bg1);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.rp-coll-detail-items {
  flex: 1;
  overflow: auto;
}
/* Collection-detail Share section — visually mirrors the right-panel Share
   accordion in #route-planner-panel. Because the modal is appended to
   document.body (outside #route-planner-panel), we redeclare the relevant
   pieces here so rp-switch / rp-share-link look the same. */
.rp-coll-share {
  padding: 10px 14px 12px;
  border-bottom: 1px solid var(--bdr);
  background: var(--bg1);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.rp-coll-share-head {
  font-weight: 700;
  font-size: var(--fs-sm);
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--txt);
  padding: 0;
  background: none;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  text-align: left;
}
.rp-coll-share-head:hover { color: var(--amber-ink); }
.rp-coll-share-caret {
  display: inline-block;
  font-size: var(--fs-xs);
  width: 12px;
}
.rp-coll-share-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.rp-coll-share-body[hidden] { display: none; }
.rp-coll-share .rp-rp-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--dim);
  font-size: var(--fs-sm);
  margin: 0;
}
.rp-coll-share .rp-rp-hint {
  color: var(--dim2);
  font-size: var(--fs-xs);
  line-height: 1.4;
}
.rp-coll-share .rp-switch {
  position: relative;
  display: inline-block;
  width: 36px;
  height: 20px;
}
.rp-coll-share .rp-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}
.rp-coll-share .rp-switch-slider {
  position: absolute;
  inset: 0;
  background: var(--bg3);
  border: 1px solid var(--bdr);
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.15s;
}
.rp-coll-share .rp-switch-slider::before {
  content: '';
  position: absolute;
  left: 2px;
  top: 1px;
  width: 14px;
  height: 14px;
  background: var(--dim);
  border-radius: 50%;
  transition: transform 0.15s, background 0.15s;
}
.rp-coll-share .rp-switch input:checked + .rp-switch-slider {
  background: var(--amber);
  border-color: var(--amber);
}
.rp-coll-share .rp-switch input:checked + .rp-switch-slider::before {
  transform: translateX(16px);
  background: #fff;
}
.rp-coll-share .rp-share-link {
  display: flex;
  gap: 6px;
  align-items: stretch;
}
.rp-coll-share .rp-share-link input {
  flex: 1;
  min-width: 0;
  background: var(--bg2);
  color: var(--txt);
  border: 1px solid var(--bdr);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: var(--fs-xs);
  font-family: ui-monospace, Menlo, Consolas, monospace;
}
.rp-coll-share .rp-share-link .rp-btn {
  flex-shrink: 0;
  padding: 6px 10px;
  font-size: var(--fs-xs);
  background: var(--bg1);
  color: var(--txt);
  border: 1px solid var(--bdr);
  border-radius: 4px;
  cursor: pointer;
}
.rp-coll-share .rp-share-link .rp-btn:hover {
  background: var(--bg2);
  border-color: var(--amber-ink);
}
/* The day's colour is the square before its name (--kind, set inline by
   stages.js from colorForDay), matching the day's line on the map. */
.rp-coll-day-head {
  --kind: var(--dim);
  padding: 10px 14px 6px;
  font-weight: 700;
  color: var(--txt);
  font-size: var(--fs-sm);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.rp-coll-day-head::before {
  content: '';
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 2px;
  background: var(--kind);
  margin-right: 8px;
  vertical-align: 0;
}
.rp-coll-item-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--bg1);
  cursor: pointer;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
}
.rp-coll-item-row:hover { background: var(--bg1); }
.rp-coll-item-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.rp-coll-drag {
  color: var(--dim2);
  font-size: var(--fs-base);
  cursor: grab;
  user-select: none;
  padding: 0 4px;
  letter-spacing: -2px;
}
.rp-coll-drag:hover { color: var(--amber-ink); }
.rp-coll-item-row.dragging {
  opacity: 0.45;
  background: var(--bg1);
}
.rp-coll-item-row[draggable="true"] { cursor: default; }

/* Add-route bar inside collection detail sidebar */
.rp-coll-detail-add-bar {
  padding: 8px 10px;
  border-bottom: 1px solid var(--bdr);
  display: flex;
  gap: 6px;
}
.rp-coll-detail-add-bar .rp-btn-primary {
  background: var(--amber, var(--amber));
  color: var(--on-amber);
  border: 0;
  padding: 6px 14px;
  border-radius: 6px;
  font-weight: 700;
  font-size: var(--fs-sm);
  cursor: pointer;
}
.rp-coll-detail-add-bar .rp-btn-primary:hover {
  filter: brightness(1.1);
}
.rp-coll-detail-add-bar .rp-btn-create-route {
  background: var(--bg1);
  color: var(--txt);
  border: 1px solid var(--bdr);
  padding: 6px 14px;
  border-radius: 6px;
  font-weight: 600;
  font-size: var(--fs-sm);
  cursor: pointer;
}
.rp-coll-detail-add-bar .rp-btn-create-route:hover {
  border-color: var(--amber-ink);
  color: var(--amber-ink);
}
.rp-coll-detail-add-bar .rp-btn-add-day {
  background: var(--bg1);
  color: var(--txt);
  border: 1px solid var(--bdr);
  border-radius: 6px;
  padding: 5px 10px;
  font-size: var(--fs-sm);
  cursor: pointer;
}
.rp-coll-detail-add-bar .rp-btn-add-day:hover {
  border-color: var(--amber-ink);
  color: var(--amber-ink);
}

/* Route picker drawer — slides in from the right inside the detail modal */
.rp-route-picker-drawer {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 340px;
  background: var(--bg1);
  border-left: 1px solid var(--bdr);
  display: flex;
  flex-direction: column;
  z-index: 10;
  transform: translateX(100%);
  transition: transform 0.25s ease;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
}
.rp-route-picker-drawer.open {
  transform: translateX(0);
}
.rp-route-picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--bdr);
}
.rp-route-picker-head h4 {
  margin: 0;
  font-size: var(--fs-base);
  color: var(--txt);
}
.rp-route-picker-body {
  flex: 1;
  overflow: auto;
}
.rp-route-picker-row {
  display: flex;
  align-items: center;
  padding: 10px 14px;
  gap: 10px;
  border-bottom: 1px solid var(--bg1);
  cursor: default;
}
.rp-route-picker-row:hover {
  background: var(--bg1);
}
.rp-route-picker-row .rp-row-main {
  flex: 1;
  min-width: 0;
}
.rp-route-picker-row .rp-row-title {
  font-weight: 600;
  font-size: var(--fs-base);
  color: var(--txt);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rp-route-picker-row .rp-row-meta {
  font-size: var(--fs-xs);
  color: var(--dim);
  margin-top: 2px;
}
.rp-route-picker-add {
  flex-shrink: 0;
  background: var(--amber, var(--amber));
  color: var(--on-amber);
  border: 0;
  padding: 4px 12px;
  border-radius: 4px;
  font-weight: 700;
  font-size: var(--fs-xs);
  cursor: pointer;
}
.rp-route-picker-add:hover {
  filter: brightness(1.1);
}
.rp-route-picker-tag {
  flex-shrink: 0;
  font-size: var(--fs-xs);
  color: var(--dim);
  font-style: italic;
}

/* The detail modal needs position:relative so the drawer can anchor to it */
.rp-coll-detail {
  position: relative;
  overflow: hidden;
}

/* Toast styles moved to core/toast.css — one shared toast for the whole app
   (TKB-028). */
