/* Colours for light and dark theme. Same names as in MitSpor's assets/style.css
   (which the editor does not load). Dark theme is switched on by assets/theme.js. */
:root {
  --bg-deep: #edf1f6;
  --surface: #ffffff;
  --surface-hover: #f8fafc;
  --surface-2: #f1f5f9;
  --toolbar-bg: #f1f5f9;
  --card-bg: #fcfcfc;
  --border: #e2e8f0;
  --border-strong: #cbd5e1;
  --text: #1e293b;
  --text-2: #334155;
  --text-3: #475569;
  --text-muted: #64748b;
  --primary: #2563eb;
  --link: #2563eb;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --danger-border: #fca5a5;
  --danger-border-soft: #fecaca;
  --danger-text: #991b1b;
  --warn-bg: #fff7ed;
  --warn-border: #fed7aa;
  --warn-text: #7c2d12;
  --info-bg: #eff6ff;
  --info-hover-border: #93c5fd;
  --info-text: #1e3a8a;
  --dialog-header-bg: #e2e8f0;
  --scroll-thumb: #94a3b8;
  --tint-1: rgba(30, 41, 59, 0.07);
  --tint-2: rgba(30, 41, 59, 0.13);
  --tint-3: rgba(30, 41, 59, 0.18);
  color-scheme: light;
}
html[data-theme="dark"] {
  --bg-deep: #0f172a;
  --surface: #1e293b;
  --surface-hover: #273449;
  --surface-2: #334155;
  --toolbar-bg: #0f172a;
  --card-bg: #172033;
  --border: #334155;
  --border-strong: #475569;
  --text: #e2e8f0;
  --text-2: #cbd5e1;
  --text-3: #cbd5e1;
  --text-muted: #94a3b8;
  --primary: #3b82f6;
  --link: #60a5fa;
  --danger: #f87171;
  --danger-bg: #450a0a;
  --danger-border: #7f1d1d;
  --danger-border-soft: #7f1d1d;
  --danger-text: #fecaca;
  --warn-bg: #431407;
  --warn-border: #7c2d12;
  --warn-text: #fed7aa;
  --info-bg: #172554;
  --info-hover-border: #3b82f6;
  --info-text: #bfdbfe;
  --dialog-header-bg: #0f172a;
  --scroll-thumb: #64748b;
  --tint-1: rgba(226, 232, 240, 0.08);
  --tint-2: rgba(226, 232, 240, 0.14);
  --tint-3: rgba(226, 232, 240, 0.2);
  color-scheme: dark;
}
html[data-theme="dark"] body {
  background: var(--bg-deep);
  color: var(--text);
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  display: flex;
  flex-direction: column; /* Makes the whole page a flexible column */
}

html {
  /* See the same comment in MitSpor's assets/style.css — stops mobile browsers from
     "font boosting" individual elements differently. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

/* The toolbar follows the top bar in MitSpor's dashboard and route page: arrow on
   the left, the editing buttons as separate buttons right after the arrow, and
   an ordinary "Help" text button on the right. Same colour and height as
   the top bar on MitSpor's front page and dashboard: --toolbar-bg (90 % opacity)
   over the page's light grey background (--bg-deep in assets/style.css) gives #f1f5f9. */
#toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  padding: 9px 20px; /* 59px tall in total (40px buttons), like the dashboard's top bar */
  background: var(--toolbar-bg);
  color: var(--text);
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  flex-shrink: 0; /* Makes sure the toolbar always keeps its full height */
}

#toolbar a {
  color: var(--text);
  font-weight: 600;
}

/* Same arrow as in MitSpor's dashboard and route page (assets/style.css).
   A little space on the right, so it does not stick to the editing buttons. */
#toolbar a.back-arrow {
  margin-right: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--tint-1);
  font-size: 0;
  line-height: 0;
  text-decoration: none;
  transition: background-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
#toolbar a.back-arrow::before {
  content: "";
  width: 20px;
  height: 20px;
  background-color: currentColor;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M19 12H5'/%3E%3Cpath d='M11 18l-6-6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23000' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M19 12H5'/%3E%3Cpath d='M11 18l-6-6 6-6'/%3E%3C/svg%3E") center / contain no-repeat;
}
#toolbar a.back-arrow:hover { background: var(--tint-2); }
#toolbar a.back-arrow:active { background: var(--tint-3); }

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Save / Undo / Redo / View page sit on the left next to the arrow;
   only the menu is pushed all the way to the right. */
.toolbar-group-help {
  margin-left: auto;
}

#toolbar select,
#toolbar input[type="text"] {
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
}

#toolbar input[type="text"] {
  width: 160px;
}

#toolbar select {
  font-size: 14px;
  width: 220px;
  max-width: 45vw;
}

#toolbar button {
  padding: 9px 14px;
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  box-sizing: border-box;
}

#toolbar button:hover:not(:disabled) {
  background: var(--surface-hover);
}

/* Monochrome line icons (Save, View page): inherit the button's text colour, so they
   follow the normal, disabled and red/green Save state — also in
   the dialogs' blue Save buttons. */
/* The toolbar icons have the page's blue colour; the button text is dark.
   The Save button is white on red/green, so there the icon follows the text. */
#toolbar button .tb-icon {
  color: var(--link);
}
#toolbar #btn-save-server.save-dirty .tb-icon,
#toolbar #btn-save-server.save-clean .tb-icon {
  color: #ffffff;
}

.tb-icon {
  display: inline-block;
  vertical-align: -3px; /* in dialog buttons (not flex): sits on the text's line */
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* The help icon: a small circle with "?", as on MitSpor's route page (assets/style.css). */
.help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 1.5px solid currentColor;
  font-weight: 700;
  font-size: 12px;
  line-height: 1;
  color: var(--link);
}

#toolbar button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* The editing buttons (Save, Undo, Redo, View page) are separate,
   white buttons as in the top bar of MitSpor's route page (route-view.php), and sit
   left-aligned right after the arrow. */
#toolbar .tool-group .tb-icon {
  width: 20px;
  height: 20px;
}

/* Visual hint that a click on the map now places a waypoint instead
   of drawing on the route. */
#map.waypoint-mode-cursor,
.leaflet-container.waypoint-mode-cursor {
  cursor: crosshair;
}

/* The mode picker button — sits as a Leaflet control on the map itself
   (top left, next to the zoom buttons) instead of in the toolbar, so it
   is clearly visible right where you click. By default Leaflet stacks
   controls in the same corner VERTICALLY — this rule turns the top left
   corner into a horizontal row instead, so the button lines up with the
   zoom buttons. */
.leaflet-top.leaflet-left {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-left: 10px; /* same distance from the map edge as Leaflet normally gives the first control */
}
.leaflet-top.leaflet-left .leaflet-control {
  margin-left: 0; /* the gap above now controls the horizontal spacing */
}
.waypoint-mode-map-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  border: 2px solid rgba(0, 0, 0, 0.2);
  border-radius: 4px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
  white-space: nowrap;
}
.waypoint-mode-map-btn:hover {
  background: var(--surface-hover);
}
.waypoint-mode-map-btn.mode-active {
  background: var(--info-bg);
  border-color: var(--primary);
  color: var(--link);
}

/* The list of modes below the mode picker. */
.edit-mode-control {
  position: relative;
}
.edit-mode-list {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 1000;
  min-width: 240px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
  display: flex;
  flex-direction: column;
}
.edit-mode-list[hidden] {
  display: none;
}
.edit-mode-list button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 48px;
  padding: 8px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.edit-mode-list button:hover,
.edit-mode-list button:focus-visible {
  background: var(--surface-2);
}
.edit-mode-list button[aria-checked="true"] {
  background: var(--info-bg);
}
.edit-mode-list strong {
  display: block;
  font-weight: 600;
}
.edit-mode-list small {
  display: block;
  color: var(--text-muted);
  font-size: 13px;
}

/* Select mode: the bar at the bottom above the map. */
.selection-bar {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  z-index: 1000;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 12px;
  max-width: calc(100vw - 24px);
  box-sizing: border-box;
  padding: 8px 10px 8px 14px;
  background: var(--surface);
  border: 2px solid #16a34a;
  border-radius: 10px;
  box-shadow: 0 6px 20px rgba(15, 23, 42, 0.25);
  color: var(--text);
  font-size: 14px;
}
.selection-bar[hidden] {
  display: none;
}
.selection-summary {
  font-weight: 600;
  white-space: nowrap;
}
.selection-buttons {
  display: flex;
  gap: 6px;
}
.selection-buttons button {
  min-height: 40px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.selection-buttons button:hover:not(:disabled) {
  background: var(--surface-hover);
}
.selection-buttons button:disabled {
  opacity: 0.5;
  cursor: default;
}
.selection-buttons .selection-delete {
  color: var(--danger);
  border-color: var(--danger-border-soft);
}
.selection-buttons .selection-clear {
  min-width: 40px;
  font-size: 20px;
  line-height: 1;
  color: var(--text-muted);
}
.plain-fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
}
.save-selection-links {
  display: flex;
  gap: 18px;
}
.save-selection-links a {
  color: var(--link);
  font-weight: 600;
}

#toolbar #btn-save-server.save-dirty {
  background: #b91c1c;
  border-color: #991b1b;
  color: #ffffff;
}

#toolbar #btn-save-server.save-dirty:hover:not(:disabled) {
  background: #dc2626;
}

#toolbar #btn-save-server.save-clean {
  background: #15803d;
  border-color: #166534;
  color: #ffffff;
}

#toolbar #btn-save-server.save-clean:hover:not(:disabled) {
  background: #16a34a;
}

#map {
  flex-grow: 1; /* Makes the map fill all remaining space automatically */
  position: relative;
  width: 100%;
}

/* Latest message, below the route title (in #route-title-bar). Long messages
   may wrap, so they can be read on a phone. */
#status {
  margin-top: 2px;
  font-size: 12px;
  color: var(--text-3);
}
#status:empty {
  display: none;
}

.gpx-popup input[type="text"] {
  width: 180px;
  margin-bottom: 6px;
  padding: 3px 5px;
}

.gpx-popup textarea {
  width: 180px;
  height: 50px;
  margin-bottom: 6px;
  padding: 3px 5px;
  font-family: inherit;
}

.gpx-popup .popup-buttons {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.gpx-popup button {
  padding: 4px 8px;
  border-radius: 4px;
  border: 1px solid var(--border-strong);
  background: var(--dialog-header-bg);
  cursor: pointer;
  font-size: 12px;
}

.gpx-popup button.danger {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger-text);
}

.gpx-popup button.primary {
  background: var(--info-bg);
  border-color: var(--info-hover-border);
  color: var(--info-text);
}

.gpx-popup .wpt-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 6px;
  max-width: 260px;
}

.gpx-popup .wpt-link-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  padding: 3px 5px;
}

.gpx-popup .wpt-link-item a {
  flex-shrink: 0;
  color: var(--info-text);
  text-decoration: none;
}
.gpx-popup .wpt-link-comment {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  padding: 3px 5px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
}

.gpx-popup button.small {
  padding: 1px 6px;
  font-size: 11px;
  line-height: 1.4;
}

/* Replace Leaflet's hand cursor with a pointer on the map */
.leaflet-grab {
  cursor: pointer !important;
}

/* Make sure it is still a pointer while holding the mouse button down and panning */
.leaflet-grab:active {
  cursor: pointer !important;
}

#help-dialog,
#meta-help-dialog,
#about-dialog {
  max-width: 600px;
  width: 90%;
  max-height: 85vh; /* Keeps the box from getting taller than the screen */
  overflow-y: auto; /* Adds a scrollbar if the content is too long */
  background: var(--surface-hover);
  border: none;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 10px 25px rgba(0,0,0,0.3);
  color: var(--text-2);
}

/* Dark backdrop behind the dialog box */
#help-dialog::backdrop,
#meta-help-dialog::backdrop,
#about-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

/* ------------------------------ */
/* Title line: shows which route is being edited */
/* ------------------------------ */
#route-title-bar {
  flex-shrink: 0;
  padding: 6px 14px;
  background: var(--surface-hover);
  border-bottom: 1px solid var(--border-strong);
  font-size: 13px;
  color: var(--text-2);
}

.route-title-line {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
}

#route-stats {
  flex: none;
  color: var(--text-muted);
  white-space: nowrap;
}

#route-title-bar strong {
  font-weight: 600;
  color: var(--text-3);
}

#route-title-bar .truncate {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ------------------------------ */
/* Edit metadata dialog — matches the look of the corresponding dialog in */
/* MitSpor's dashboard (assets/style.css' .modal-dialog) */
/* ------------------------------ */
.modal-dialog {
  max-width: 380px;
  width: 90%;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--surface);
  border: none;
  border-radius: 8px;
  padding: 24px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.3);
  color: var(--text);
  position: relative;
}
.modal-dialog::backdrop {
  background: rgba(0, 0, 0, 0.5);
}
.modal-dialog h2 {
  margin: 0 0 14px;
  font-size: 18px;
}
/* Some dialogs (the links dialog) need to be wider than the
   380px that suit the metadata/waypoint dialogs. */
.modal-dialog.images-dialog {
  max-width: 480px;
}
.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--surface-hover);
  color: var(--text-muted);
  font-size: 16px;
  cursor: pointer;
  padding: 0;
}
.modal-close:hover {
  color: var(--text);
}
.modal-close.meta-help-btn {
  right: 44px;
  font-weight: 600;
}
.link-btn {
  background: none;
  border: none;
  padding: 0;
  font: inherit;
  color: var(--link);
  cursor: pointer;
  text-decoration: none;
}
.link-btn:hover {
  text-decoration: underline;
}
.link-btn.danger {
  color: var(--danger);
}
.modal-dialog .link-btn.danger {
  display: block;
  margin: 10px auto 0;
}
/* display:block above must not override the hidden attribute — otherwise
   "Delete waypoint" also shows in the dialog for a NEW waypoint, which does not exist yet. */
.modal-dialog .link-btn.danger[hidden] {
  display: none;
}
.modal-errors {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger-text);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
  margin-bottom: 12px;
}
.modal-dialog .btn-primary {
  margin-top: 14px;
  width: 100%;
  padding: 10px 16px;
  border-radius: 6px;
  border: 1px solid #1d4ed8;
  background: #2563eb;
  color: #ffffff;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
}
.modal-dialog .btn-primary:hover {
  background: #1d4ed8;
}
.modal-dialog .btn-primary:disabled {
  opacity: 0.6;
  cursor: default;
}

/* The menu (☰) in the toolbar: a list below the button, right-aligned. */
.menu-wrap {
  position: relative;
}
.editor-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 1100; /* above Leaflet's controls */
  min-width: 220px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.18);
  display: flex;
  flex-direction: column;
}
.editor-menu[hidden] {
  display: none;
}
#toolbar .editor-menu button,
#toolbar .editor-menu a {
  display: flex;
  align-items: center;
  gap: 6px;
  box-sizing: border-box;
  color: var(--text);
  font-weight: normal;
  text-decoration: none;
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: none;
  border-radius: 6px;
  background: transparent;
  text-align: left;
  font-size: 15px;
  white-space: nowrap;
}
#toolbar .editor-menu button:hover:not(:disabled),
#toolbar .editor-menu button:focus-visible,
#toolbar .editor-menu a:hover,
#toolbar .editor-menu a:focus-visible {
  background: var(--surface-2);
}
.editor-menu-sep {
  height: 1px;
  margin: 6px 4px;
  background: var(--dialog-header-bg);
}

/* Delete data fields and Edit elevation data */
.data-fields-list {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  max-height: 50vh;
  overflow-y: auto;
}
.data-field-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.data-field-row:last-child {
  border-bottom: none;
}
.data-field-note {
  flex: 1;
  min-width: 0;
}
.btn-small {
  flex-shrink: 0;
  padding: 5px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.btn-small.btn-danger {
  border-color: #dc2626;
  background: #dc2626;
  color: #ffffff;
}
.modal-dialog .btn-primary.btn-danger {
  border-color: #b91c1c;
  background: #dc2626;
}
.modal-dialog .btn-primary.btn-danger:hover {
  background: #b91c1c;
}
.modal-dialog .btn-primary[hidden] {
  display: none;
}
.ele-stats {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: baseline;
  gap: 0 16px;
  margin: 0 0 12px;
  font-size: 14px;
  line-height: 1.45;
}
.ele-stats dt {
  margin: 0;
  color: var(--text-muted);
}
.ele-stats dd {
  margin: 0;
  font-weight: 600;
}

/* Question about thinning when there are many points */
.thin-hint {
  font-size: 13px;
  color: var(--text-muted);
}
.thin-buttons .btn-primary {
  margin-top: 8px;
}
.modal-dialog .thin-skip {
  display: block;
  margin: 14px auto 0;
}
.modal-dialog .thin-skip[hidden] {
  display: none;
}

/* ------------------------------ */
/* Metadata panel (the route's title, activity, visibility) */
/* ------------------------------ */
#meta-panel,
.modal-dialog-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  font-size: 14px;
}

#meta-panel label,
.modal-dialog-body label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

#meta-panel [hidden] {
  display: none;
}

#meta-panel input[type="text"],
#meta-panel textarea,
#meta-panel select,
.modal-dialog-body input[type="text"],
.modal-dialog-body textarea,
.modal-dialog-body select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
}

#meta-panel textarea,
.modal-dialog-body textarea {
  min-height: 60px;
  resize: vertical;
}

#meta-panel fieldset {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
}

#meta-panel legend,
.plain-fieldset legend {
  font-size: 12px;
  color: var(--text-muted);
  padding: 0 4px;
}

#meta-panel .checkbox-field,
.modal-dialog-body .checkbox-field {
  flex-direction: row;
  align-items: center;
  gap: 6px;
  font-weight: normal;
  color: var(--text);
  font-size: 14px;
}

#meta-panel .notice-field {
  font-size: 12px;
  color: var(--warn-text);
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: 6px;
  padding: 8px 10px;
  margin: 0;
}

/* ------------------------------ */
/* Links dialog (sortable list with thumbnails + comments) */
/* ------------------------------ */
.images-dialog-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

.images-sortable-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
}

.image-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card-bg);
}

.image-row-handle {
  flex-shrink: 0;
  cursor: grab;
  font-size: 18px;
  color: var(--scroll-thumb);
  padding: 4px;
  touch-action: none; /* Needed for SortableJS to take over touch-drag correctly */
}
.image-row-handle:active {
  cursor: grabbing;
}

.image-row-thumb {
  flex-shrink: 0;
  width: 56px;
  height: 56px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: var(--surface-2);
}
/* A link that is not one of the user's own images (e.g. from a copied GPX file). */
.image-row-foreign {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: 11px;
  line-height: 1.2;
  color: var(--text-muted);
}

.image-row-comment {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 40px;
  resize: vertical;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: inherit;
  color: var(--text);
}

.image-row-remove {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: var(--danger-bg);
  color: var(--danger-text);
  cursor: pointer;
  font-size: 13px;
}
.image-row-remove:hover {
  background: var(--danger-border-soft);
}

/* SortableJS' own classes while dragging */
.image-row.sortable-ghost {
  opacity: 0.4;
}
.image-row.sortable-chosen {
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}


.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 15px 20px;
  background: var(--dialog-header-bg);
  border-bottom: 1px solid var(--border-strong);
  position: sticky; /* Keeps the header at the top while scrolling */
  top: 0;
}

.dialog-header h2 {
  margin: 0;
  font-size: 18px;
}

.close-btn {
  background: none !important;
  border: none !important;
  font-size: 20px;
  cursor: pointer;
  color: var(--text-muted) !important;
  padding: 0 !important;
}

.close-btn:hover {
  color: var(--text) !important;
}

.dialog-content {
  padding: 20px;
  font-size: 14px;
  line-height: 1.6;
}

.dialog-content h3 {
  margin-top: 0;
  margin-bottom: 8px;
  font-size: 15px;
  color: var(--text);
}

.dialog-content ul {
  padding-left: 20px;
  margin-bottom: 24px;
}

.dialog-content li {
  margin-bottom: 6px;
}

/* Stop the browser from taking over touch gestures on markers —
   ONLY on touch devices. This rule must not affect the mouse, since Leaflet's
   marker dragging (and our "click = 0px drag" logic) is built
   on the same drag system that touch-action would otherwise disturb. */
@media (pointer: coarse) {
  .leaflet-marker-icon,
  .leaflet-interactive {
    touch-action: none !important;
  }
}

/* The invisible, large touch area (hitbox) */
.touch-marker {
  background: transparent;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* The visible blue track point dot */
.touch-marker .dot-track {
  width: 14px;
  height: 14px;
  background-color: #3b82f6;
  border: 2px solid #1e3a8a;
  border-radius: 50%;
  opacity: 0.9;
}

/* The visible orange waypoint dot */
.touch-marker .dot-wpt {
  width: 16px;
  height: 16px;
  background-color: #f97316;
  border: 2px solid #9a3412;
  border-radius: 50%;
  opacity: 0.95;
}

/* Selected track point (select mode) */
.touch-marker .dot-track.dot-selected {
  background-color: #22c55e;
  border-color: #14532d;
}

/* Split point in split mode */
.touch-marker .dot-track.dot-split {
  width: 18px;
  height: 18px;
  background-color: #ffffff;
  border: 4px solid #0f172a;
  opacity: 1;
}

/* Purple waypoint dot: used when the waypoint has at least one link */
.touch-marker .dot-wpt-img {
  width: 16px;
  height: 16px;
  background-color: #a855f7;
  border: 2px solid #6b21a8;
  border-radius: 50%;
  opacity: 0.95;
}



/* Responsive design (for mobile screens below 800px wide) */
@media (max-width: 800px) {
  /* The map's copyright line slightly smaller than Leaflet's 12px. */
  .leaflet-control-attribution {
    font-size: 10px;
  }

  /* The buttons only show the icon on mobile, with the same space around the icon as on
     MitSpor's route page. */
  #toolbar .tool-group button,
  #toolbar #btn-menu {
    padding: 0 10px;
    justify-content: center; /* Centres the icon */
  }

  /* Slightly smaller side margin, so the arrow, four buttons and Help fit on one
     line on a narrow phone. */
  #toolbar {
    padding-left: 14px;
    padding-right: 14px;
  }
  
  /* Hide the text, so only the icon is left */
  .btn-text {
    display: none;
  }
  #toolbar .tool-group .tb-icon {
    width: 22px;
    height: 22px;
  }

  #route-title-bar {
    font-size: 12px;
    padding: 5px 10px;
  }
}

/* Split mode: the stages in the save dialog */
#split-group-fields[hidden] {
  display: none;
}
.split-stage-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 45vh;
  overflow-y: auto;
}
.split-stage-list label {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.split-stage-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-3);
}
.split-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex: 0 0 auto;
}

/* Dark theme: Leaflet's own controls and popups (the vendor CSS is not changed).
   The map tiles themselves are unchanged. Matches the rules in MitSpor's assets/style.css. */
html[data-theme="dark"] .leaflet-bar a,
html[data-theme="dark"] .leaflet-control-layers,
html[data-theme="dark"] .leaflet-popup-content-wrapper,
html[data-theme="dark"] .leaflet-popup-tip {
  background: var(--surface);
  color: var(--text);
}
html[data-theme="dark"] .leaflet-bar a { border-bottom-color: var(--border); }
html[data-theme="dark"] .leaflet-bar a:hover,
html[data-theme="dark"] .leaflet-bar a:focus { background: var(--surface-2); }
html[data-theme="dark"] .leaflet-bar a.leaflet-disabled { background: var(--bg-deep); color: var(--text-muted); }
html[data-theme="dark"] .leaflet-container .leaflet-control-attribution {
  background: rgba(15, 23, 42, 0.8);
  color: var(--text-muted);
}
html[data-theme="dark"] .leaflet-container .leaflet-control-attribution a { color: var(--link); }
html[data-theme="dark"] .leaflet-container a.leaflet-popup-close-button { color: var(--text-muted); }
html[data-theme="dark"] .leaflet-container { background: var(--bg-deep); }
html[data-theme="dark"] dialog { background: var(--surface); color: var(--text); }
