:root {
  --bg: #0f1720;
  --panel: #17212b;
  --panel-2: #1e2b38;
  --border: #2a3a4a;
  --text: #e6edf3;
  --muted: #9fb0c0;
  --accent: #4aa8ff;
  --accent-2: #3ddc97;
  --climb-up: #f4511e;
  --climb-down: #2e9e6b;
  --flag-dark: #1b1f23;
  --flag-light: #f7f7f2;
  --danger: #ff6b6b;
  --warn: #ffb454;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

body { display: flex; flex-direction: column; }

/* -- top bar -- */
.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0 1rem;
  height: 52px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 500;
}
.brand { font-weight: 700; font-size: 1.05rem; white-space: nowrap; }
.brand-status { margin-left: auto; color: var(--muted); font-size: 0.8rem; }
.account-actions { display: flex; align-items: center; gap: 0.5rem; }
.header-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 8px;
}
.header-icon svg { width: 1.15rem; height: 1.15rem; }
.logout-form { display: inline-flex; margin: 0; }
.logout-form.hidden { display: none; }
button.header-icon { background: transparent; padding: 0; font: inherit; }

/* -- login page -- */
.login-body { align-items: center; justify-content: center; padding: 1rem; }
.login-card {
  flex: 0 0 auto;
  width: min(100%, 22rem);
  display: grid;
  align-content: start;
  gap: 1rem;
  padding: 1.5rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  text-align: center;
}
.login-text { margin: 0; color: var(--muted); line-height: 1.45; }
.login-message {
  margin: 0;
  padding: 0.6rem 0.8rem;
  border: 1px solid var(--danger);
  border-radius: 8px;
  color: var(--danger);
  background: rgba(255, 107, 107, 0.08);
}
.login-button {
  display: block;
  padding: 0.65rem 1rem;
  border-radius: 8px;
  background: var(--accent);
  color: #04131f;
  font-weight: 600;
  text-decoration: none;
}
.login-button:hover { filter: brightness(1.08); }
.header-icon:hover, .header-icon.active { color: var(--text); background: var(--panel-2); border-color: var(--border); }
.profile-switch-wrap {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  white-space: nowrap;
}
.profile-switch-label { color: var(--muted); font-size: 0.8rem; }

.profile-settings-list { display: grid; gap: 0.75rem; }
.profile-setting {
  display: grid;
  grid-template-columns: minmax(10rem, 1fr) minmax(12rem, 1fr) 8.5rem;
  align-items: end;
  gap: 0.75rem;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.profile-setting-head { grid-column: 1 / -1; display: flex; align-items: baseline; gap: 0.6rem; }
.profile-key { color: var(--muted); font-size: 0.72rem; }
.profile-setting label { display: grid; gap: 0.25rem; color: var(--muted); font-size: 0.8rem; }
.profile-setting input, .profile-setting select { width: 100%; box-sizing: border-box; }
.profile-actions { display: flex; gap: 0.5rem; align-items: end; }
.profile-actions .primary { flex: 1; }
.autosave-status { color: var(--muted); font-size: 0.75rem; min-width: 5.5rem; text-align: right; }
.profile-delete { margin-left: 0.15rem; }
.profile-add { border-style: dashed; background: transparent; }
@media (max-width: 700px) {
  .topbar { height: auto; min-height: 52px; padding: 0.55rem 0.75rem 0; flex-wrap: wrap; gap: 0.5rem; }
  .brand { flex: 1; }
  .brand-status { display: none; }
  .account-actions { order: 2; }
  nav { order: 3; width: calc(100% + 1.5rem); margin: 0 -0.75rem; padding: 0 0.5rem 0.45rem; overflow-x: auto; scrollbar-width: none; }
  nav::-webkit-scrollbar { display: none; }
  nav a { flex: 0 0 auto; }
  .profile-switch-label { display: none; }
  #profile-switch { max-width: 9rem; }
  .profile-setting { grid-template-columns: 1fr; }
  .profile-actions { justify-content: space-between; }
  .profile-actions .primary { flex: 1; }
}
#profile-switch {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.3rem 0.5rem;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}
.profile-switch-wrap.hidden { display: none; }
nav { display: flex; gap: 0.25rem; }
nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 0.4rem 0.8rem;
  border-radius: 8px;
  font-weight: 600;
}
nav a:hover { background: var(--panel-2); color: var(--text); }
nav a.active { background: var(--accent); color: #04131f; }

main {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: auto;
}

/* -- generic layout -- */
.page { padding: 1rem; height: 100%; }
.page.full { padding: 0; }
/* List pages: the content column is only as wide as its widest child (the table)
   and is centred on wide screens, so a narrow table is not stranded on the left
   while heading/filters stay flush-left with it. */
.page:not(.full) { width: fit-content; max-width: 100%; margin-inline: auto; }

/* Drafts: a full-width batch-controls bar above the drafts collection table.
   Fields grow to share the row so no empty space is left beside them; the page
   shrinks to its widest child (the table) and is centred via the rule above. */
.gen-controls { margin: 0.5rem 0 1.25rem; }
.gen-controls h2 { margin: 0 0 0.5rem; font-size: 1rem; }
.gen-controls .gen-field { flex: 1 1 8rem; }
.gen-controls .gen-field select, .gen-controls .gen-field input { width: 100%; }
.gen-collection { margin-top: 0.5rem; }
.split { display: grid; grid-template-columns: 340px 1fr; height: 100%; min-height: 0; }
.panel {
  background: var(--panel);
  border-right: 1px solid var(--border);
  overflow: auto;
  padding: 1rem;
}
.panel h2 { margin: 0 0 0.75rem; font-size: 1rem; }
.map-wrap { position: relative; height: 100%; }
.map-wrap > div { height: 100%; width: 100%; }
#map, .leaflet-map { height: 100%; width: 100%; }
#map .map-tour-route { transition: opacity 120ms ease; }
.map-start-marker, .map-end-marker { background: transparent; border: 0; transition: opacity 120ms ease; }
.route-direction-arrow { background: transparent; border: 0; pointer-events: none; }
.route-direction-arrow span {
  display: block;
  height: 18px;
  position: relative;
  transform-origin: center;
  width: 22px;
}
.route-direction-arrow span::before,
.route-direction-arrow span::after {
  background: var(--route-arrow-color);
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.85), 0 1px 2px rgba(7,21,34,0.55);
  content: "";
  height: 3px;
  position: absolute;
  right: 2px;
  top: 8px;
  transform-origin: right center;
  width: 14px;
}
.route-direction-arrow span::before { transform: rotate(32deg); }
.route-direction-arrow span::after { transform: rotate(-32deg); }
.map-start-marker { width: 16px !important; height: 16px !important; border-radius: 50%; background: var(--accent-2); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.55); }
.map-end-marker { width: 18px !important; height: 18px !important; border-radius: 50%; background-color: var(--flag-light); background-image: linear-gradient(45deg, var(--flag-dark) 25%, transparent 25%, transparent 75%, var(--flag-dark) 75%), linear-gradient(45deg, var(--flag-dark) 25%, transparent 25%, transparent 75%, var(--flag-dark) 75%); background-position: 0 0, 4px 4px; background-size: 8px 8px; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.55); }
.map-col-marker { width: 16px !important; height: 16px !important; border-radius: 50%; background: #1565c0; border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,0.65); }
.map-col-marker.col-used { border-color: #90a4ae; opacity: 0.6; }

h1 { font-size: 1.3rem; margin: 0 0 1rem; }
h3 { margin: 1rem 0 0.5rem; font-size: 0.95rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.settings-page { width: min(760px, 100%); }
.settings-eyebrow { margin: 0 0 0.25rem; color: var(--accent); font-size: 0.72rem; font-weight: 700; text-transform: uppercase; }
.settings-section { border-top: 1px solid var(--border); padding-top: 1rem; margin-top: 1.25rem; }
.settings-section h2 { margin: 0 0 0.75rem; font-size: 1rem; }
.settings-section .checkline { color: var(--text); font-size: 0.9rem; }
.settings-section p { margin: 0.25rem 0 0; }

/* -- forms -- */
label { display: block; margin: 0.6rem 0 0.2rem; color: var(--muted); font-size: 0.8rem; }
input, select, textarea {
  width: 100%;
  padding: 0.45rem 0.55rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.85rem;
}
input[type="checkbox"] { width: auto; }
.row { display: flex; gap: 0.5rem; }
.row > * { flex: 1; }
.checkline { display: flex; align-items: center; gap: 0.5rem; margin: 0.5rem 0; }
.checkline label { margin: 0; color: var(--text); }
.checkline.disabled { opacity: 0.5; }

/* Compact inline drafts form (drafts page): fields keep a fixed width
   instead of stretching across the full-width page. */
.gen-form { margin-bottom: 0.75rem; }
.gen-form summary { cursor: pointer; font-weight: 600; }
.gen-grid { display: flex; flex-wrap: wrap; gap: 0.4rem 0.9rem; align-items: end; margin-top: 0.6rem; }
.gen-field { display: flex; flex-direction: column; }
.gen-field label { margin: 0 0 0.15rem; }
.gen-field select { width: 9rem; }
.gen-field input { width: 6rem; }
.gen-field.wide select, .gen-field.wide input { width: 12rem; }
.gen-actions { display: flex; align-items: center; gap: 0.75rem; margin-top: 0.8rem; flex-wrap: wrap; }
.gen-progress { display: flex; align-items: center; gap: 0.6rem; margin-top: 0.5rem; }
.gen-progress-bar { width: 16rem; max-width: 100%; }
.advanced { margin-top: 0.6rem; }
.advanced summary { font-weight: 400; color: var(--muted); font-size: 0.8rem; }

button {
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 0.5rem 0.9rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.85rem;
}
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); color: #04131f; border-color: var(--accent); }
button.good { background: var(--accent-2); color: #04131f; border-color: var(--accent-2); }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
button.small { padding: 0.25rem 0.5rem; font-size: 0.75rem; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* -- tables -- */
/* Responsive: the wrapper shrinks to the table's content but never exceeds the
   available width; only the title column is capped and truncated when long. */
.table-wrap {
  overflow: auto;
  overscroll-behavior-inline: contain;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: 10px;
  width: fit-content;
  max-width: 100%;
}
table { width: auto; border-collapse: collapse; }
th, td { padding: 0.5rem 0.7rem; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.tours-table { width: 72rem; table-layout: fixed; }
.tours-table th:nth-child(1), .tours-table td:nth-child(1) { width: 6rem; }
.tours-table th:nth-child(2), .tours-table td:nth-child(2) { width: 5rem; }
.tours-table th:nth-child(3), .tours-table td:nth-child(3) { width: 24rem; }
.tours-table th:nth-child(4), .tours-table td:nth-child(4) { width: 7rem; }
.tours-table th:nth-child(5), .tours-table td:nth-child(5) { width: 8.5rem; }
.tours-table th:nth-child(6), .tours-table td:nth-child(6) { width: 6rem; }
.tours-table th:nth-child(7), .tours-table td:nth-child(7) { width: 9.5rem; }
.tours-table th:nth-child(8), .tours-table td:nth-child(8) { width: 6.5rem; }
.id-cell { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.72rem; }
th.title-cell, td.title-cell { max-width: 24rem; overflow: hidden; text-overflow: ellipsis; }
th {
  position: sticky; top: 0;
  background: var(--panel);
  cursor: pointer;
  user-select: none;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
}
th:hover { color: var(--text); }
tbody tr:hover { background: var(--panel-2); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.filter-row td {
  position: sticky; top: 2.1rem;
  background: var(--panel);
  padding: 0.3rem 0.5rem;
  cursor: default;
}
.filter-row input[type="search"], .filter-row select {
  width: 100%;
  min-width: 5.5rem;
  font-size: 0.78rem;
  padding: 0.2rem 0.35rem;
}
.filter-row .checkline { margin: 0; font-size: 0.75rem; white-space: nowrap; }
.toolbar { display: flex; gap: 0.5rem; align-items: center; margin-bottom: 0.75rem; flex-wrap: wrap; }
.toolbar input[type="search"] { max-width: 260px; }
.spacer { flex: 1; }

/* Row selection + bulk-action bar (drafts table). */
.select-cell { width: 1%; white-space: nowrap; text-align: center; cursor: default; }
.summary-row { display: flex; align-items: center; gap: 0.75rem; margin: 0.25rem 0 0.5rem; min-height: 1.9rem; }
.bulk-bar { display: flex; align-items: center; gap: 0.6rem; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; padding: 0.3rem 0.45rem; line-height: 0; }
.icon-btn svg { width: 1.05rem; height: 1.05rem; display: block; }

/* -- badges & chips -- */
.badge {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}
.badge.g1 { background: #3a2a4a; color: #d6a8ff; }
.badge.g2 { background: #23384a; color: #8fd0ff; }
.badge.easy { background: #1f3a2c; color: #7fe0a8; }
.badge.moderate { background: #34401f; color: #cfe07f; }
.badge.hard { background: #43331f; color: #ffcb8a; }
.badge.very_hard { background: #43232a; color: #ff9aa2; }
.badge.ok { background: #1f3a2c; color: #7fe0a8; }
.badge.no { background: #43232a; color: #ff9aa2; }
.badge.used { background: #2a3a4a; color: var(--muted); }
.badge.warn { background: #43331f; color: #ffcb8a; }
.badge.incidental { background: var(--panel-2); color: var(--muted); font-weight: 600; }

/* -- a draft that did not clear the release gates -- */
.gate-notice {
  margin: 0.6rem 0 0;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--warn);
  border-left-width: 3px;
  border-radius: 8px;
  background: var(--panel-2);
  color: var(--warn);
  font-size: 0.8rem;
  line-height: 1.45;
}
.gate-notice strong { font-weight: 600; }
.gate-notice ul { margin: 0.3rem 0 0; padding-left: 1.1rem; }
.gate-notice li { margin: 0.1rem 0; }
.catalog-gap { margin: 0 0 .6rem; line-height: 1.45; }
.catalog-gap strong { color: #ffcb8a; }

/* -- catalog health: a road written down twice -- */
.catalog-health {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem;
  margin: 0 0 0.8rem; padding: 0.7rem 0.9rem; line-height: 1.45;
  background: var(--panel-2);
  border: 1px solid var(--warn); border-left-width: 4px; border-radius: 8px;
}
.catalog-health strong { color: var(--warn); }
.gen-scope { margin: -0.3rem 0 0.7rem; line-height: 1.45; }
.start-profile { align-items: center; gap: 0.6rem; margin-bottom: 0.35rem; }
.start-profile label { min-width: 8rem; }
.start-profile select { flex: 0 1 20rem; }
.catalog-health span { flex: 1 1 22rem; color: var(--muted); font-size: 0.9rem; }
.catalog-health button { flex: none; }

.twin-modal .twin-lede { margin: 0 0 0.9rem; color: var(--muted); line-height: 1.5; }
.twin-sides { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.twin-side {
  display: flex; gap: 0.6rem; align-items: flex-start;
  padding: 0.6rem 0.7rem; border: 1px solid var(--border);
  border-radius: 8px; background: var(--panel-2);
}
.twin-swatch { width: 12px; height: 12px; border-radius: 3px; margin-top: 0.25rem; flex: none; }
.twin-name { font-weight: 600; }
.twin-facts { font-size: 0.82rem; margin-top: 0.15rem; }
.twin-why { font-size: 0.78rem; margin-top: 0.3rem; color: var(--accent); }
.twin-legend { display: flex; flex-wrap: wrap; gap: 0.4rem 1.1rem; margin: -0.35rem 0 0.2rem; font-size: 0.82rem; color: var(--muted); }
.twin-legend-item { display: inline-flex; align-items: center; gap: 0.35rem; }
.twin-legend .twin-swatch { margin-top: 0; }
.twin-evidence {
  margin: 0.75rem 0 0; padding: 0.5rem 0.7rem;
  background: var(--panel-2); border-radius: 8px;
  font-size: 0.88rem; color: var(--text);
}
.twin-note { margin: 0.6rem 0 0; color: var(--warn); font-size: 0.88rem; line-height: 1.45; }
.twin-modal .modal-actions { flex-wrap: wrap; }
@media (max-width: 700px) {
  .twin-sides { grid-template-columns: 1fr; }
}

/* -- layer control -- */
.layer-toggle { display: flex; align-items: center; gap: 0.5rem; padding: 0.35rem 0; }
.layer-toggle .swatch { width: 14px; height: 14px; border-radius: 3px; flex: none; border: 1px solid rgba(0,0,0,0.25); }
.layer-toggle .count { margin-left: auto; color: var(--muted); font-size: 0.75rem; }
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 0 0.75rem; }
.legend .layer-toggle { padding: 0.2rem 0; }
.legend label { margin: 0; font-size: 0.78rem; }

/* Permanent climb name labels on the map. */
.leaflet-tooltip.climb-label {
  background: rgba(20, 30, 40, 0.85);
  color: #fff;
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  font-weight: 600;
  font-size: 0.72rem;
  padding: 1px 5px;
}
.leaflet-tooltip.climb-label::before { display: none; }

/* Permanent col name labels: rectangular speech bubble whose corner tail
   touches the col dot below-left. */
.leaflet-tooltip.col-label {
  background: rgba(20, 30, 40, 0.85);
  color: #fff;
  border: none;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  font-weight: 600;
  font-size: 0.72rem;
  padding: 1px 5px;
  cursor: pointer;
}
.leaflet-tooltip.col-label::before { display: none; }
.leaflet-tooltip.col-label::after {
  content: "";
  position: absolute;
  left: -5px;
  bottom: -8px;
  border-width: 8px 9px 0 0;
  border-style: solid;
  border-color: rgba(20, 30, 40, 0.85) transparent transparent transparent;
}
.hide-col-labels .leaflet-tooltip.col-label { display: none; }

/* Small round color marker inline in a row (e.g. climb color in a col's climb list). */
.climb-swatch { flex: none; align-self: center; width: 10px; height: 10px; border-radius: 50%; }
.col-climb-entry { border-top: 1px solid var(--border); padding: 0.5rem 0; }
.col-climb-jump { flex: 0 0 auto; }

/* Read-only climb row (draft detail): name without the tour's edit inputs. */
.climb-row-name { align-self: center; font-weight: 600; }

/* Route climbs are a compact, clickable data table. */
.route-detail-climbs { container-type: inline-size; }
.route-climbs-heading { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.route-climbs-heading h3 { margin: 0; }
.route-climbs-switch { display: inline-flex; align-items: center; gap: 0.25rem; color: var(--muted); font-size: 0.72rem; cursor: pointer; white-space: nowrap; }
.route-climbs-switch-input { position: absolute; inline-size: 1px; block-size: 1px; opacity: 0; }
.route-climbs-switch-track { position: relative; inline-size: 32px; block-size: 16px; border: 2px solid var(--border); border-radius: 999px; background: var(--panel-2); transition: background 150ms ease, border-color 150ms ease; }
.route-climbs-switch-track::after { content: ""; position: absolute; inset: 2px auto auto 2px; inline-size: 8px; block-size: 8px; border-radius: 999px; background: var(--muted); transition: transform 150ms ease, background 150ms ease; }
.route-climbs-switch-input:checked + .route-climbs-switch-track { border-color: var(--accent); background: var(--accent); }
.route-climbs-switch-input:checked + .route-climbs-switch-track::after { background: var(--text); transform: translateX(16px); }
.route-climbs-switch-input:focus-visible + .route-climbs-switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.route-climbs-table { width: 100%; table-layout: fixed; font-size: 0.78rem; }
.route-climbs-table th, .route-climbs-table td { padding: 0.3rem 0.35rem; }
.route-climbs-table th { font-size: 0.68rem; }
.route-climbs-table th:nth-child(1), .route-climbs-table td:nth-child(1) { width: 7%; }
.route-climbs-table th:nth-child(2), .route-climbs-table td:nth-child(2) { width: 29%; white-space: normal; }
.route-climbs-table th:nth-child(3), .route-climbs-table td:nth-child(3) { width: 13%; }
.route-climbs-table th:nth-child(4), .route-climbs-table td:nth-child(4) { width: 10%; }
.route-climbs-table th:nth-child(5), .route-climbs-table td:nth-child(5) { width: 12%; }
.route-climbs-table th:nth-child(6), .route-climbs-table td:nth-child(6) { width: 15%; }
.route-climbs-table th:nth-child(7), .route-climbs-table td:nth-child(7) { width: 14%; }
.route-climbs-table .badge { padding: 0.05rem 0.25rem; font-size: 0.66rem; }
.route-climbs-table .climb-row-name { display: flex; align-items: baseline; flex-wrap: wrap; gap: 0.25rem; }
.route-climb-row { cursor: pointer; }
.route-climb-row.up { --route-climb-color: var(--climb-up); }
.route-climb-row.down { --route-climb-color: var(--climb-down); }
.route-climb-row:hover, .route-climb-row.active {
  background: color-mix(in srgb, var(--route-climb-color) 22%, var(--panel-2));
  box-shadow: inset 3px 0 var(--route-climb-color);
}
.route-climb-direction { font-size: 1.2rem; font-weight: 700; line-height: 1; text-align: center; }
.route-climb-direction.up { color: var(--climb-up); }
.route-climb-direction.down { color: var(--climb-down); }

.ride-history-scroll { max-height: 10rem; overflow-y: auto; scrollbar-gutter: stable; }
.ride-history-table { width: 100%; table-layout: fixed; font-size: 0.78rem; }
.ride-history-table th, .ride-history-table td { padding: 0.3rem 0.5rem; }
.ride-history-table th { position: sticky; top: 0; z-index: 1; font-size: 0.68rem; }
.ride-history-table th:first-child, .ride-history-table td:first-child { width: 52%; }
.ride-direction { display: flex; align-items: center; gap: 0.4rem; font-weight: 600; }
.ride-direction.up { color: var(--climb-up); }
.ride-direction.down { color: var(--climb-down); }


/* -- cards / stats -- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 0.6rem; margin: 0.75rem 0; }
.stat { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px; padding: 0.6rem 0.8rem; min-width: 0; }
.stat .k { color: var(--muted); font-size: 0.72rem; text-transform: uppercase; }
.stat .v { font-size: 1.05rem; font-weight: 700; overflow-wrap: anywhere; line-height: 1.25; }
.entity-id { color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.72rem; margin: 0.25rem 0 0.75rem; }
.detail-header { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem; margin: 0.25rem 0 0.5rem; }
.detail-header .entity-id { margin: 0; }
.entity-link { color: var(--accent); text-decoration: none; font-weight: 600; font-size: 0.85rem; }
.entity-link:hover { text-decoration: underline; }
.quality-pass { color: var(--accent-2); }
.quality-fail { color: var(--danger); }

/* -- detail drawer / modal -- */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  width: min(960px, 94vw);
  max-height: 92vh;
  overflow: auto;
  padding: 1.2rem;
}
.modal h2 { margin-top: 0; }
.modal .title-input {
  display: block;
  width: 100%;
  font-size: 1.4rem;
  font-weight: 600;
  margin: 0 0 0.6rem;
  padding: 0.15rem 0;
  background: transparent;
  color: inherit;
  border: none;
  border-bottom: 1px solid transparent;
}
.modal .title-input:hover,
.modal .title-input:focus {
  border-bottom-color: var(--border);
  outline: none;
}
.modal-actions { display: flex; gap: 0.5rem; justify-content: flex-end; margin-top: 1rem; }
.modal .mini-map { height: 380px; border-radius: 10px; margin: 0.75rem 0; }
.entity-detail-modal { width: min(1440px, 96vw); }
.modal .entity-detail-title { font-size: 1.05rem; line-height: 1.2; margin-bottom: 0.2rem; }
.entity-detail-stats {
  grid-template-columns: repeat(auto-fit, minmax(6.75rem, 1fr));
  gap: 0.3rem;
  margin: 0.3rem 0 0.5rem;
}
.entity-detail-stats .stat { border-radius: 8px; padding: 0.3rem 0.45rem; }
.entity-detail-stats .stat .k { font-size: 0.62rem; line-height: 1.1; }
.entity-detail-stats .stat .v { font-size: 0.85rem; line-height: 1.1; }
.entity-detail-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(30rem, 0.95fr);
  gap: 1rem;
  align-items: start;
}
.entity-detail-workspace h3 { margin-top: 0; }
.entity-detail-visuals, .entity-detail-side, .entity-detail-section { min-width: 0; }
.entity-detail-visuals .mini-map { height: min(52vh, 470px); }
.entity-detail-visuals .elevation { margin-bottom: 0; }
.entity-detail-side { display: grid; gap: 1rem; align-content: start; }
.entity-detail-section + .entity-detail-section { border-top: 1px solid var(--border); padding-top: 1rem; }
.entity-detail-scroll { max-height: min(64vh, 590px); overflow: auto; }
.route-detail-climbs { max-height: min(64vh, 590px); overflow: auto; }
.route-detail-climbs thead { position: sticky; top: 0; z-index: 1; }

/* -- elevation profile -- */
.elevation {
  position: relative;
  width: 100%;
  margin: 0.75rem 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.4rem 0.2rem 0.2rem;
  user-select: none;
}
.elevation svg { display: block; width: 100%; height: auto; overflow: visible; cursor: crosshair; }
.ele-area { fill: var(--accent); fill-opacity: 0.18; stroke: none; }
.ele-line { fill: none; stroke: var(--accent); stroke-width: 1.5; stroke-linejoin: round; }
.ele-climb-band { fill: none; stroke-width: 4; stroke-linejoin: round; stroke-linecap: round; }
.ele-grid { stroke: var(--border); stroke-width: 1; opacity: 0.6; }
.ele-axis { fill: var(--muted); font-size: 10px; font-family: system-ui; }
.ele-cursor { stroke: var(--text); stroke-width: 1; opacity: 0.8; }
.ele-dot { fill: #fff; stroke: var(--accent); stroke-width: 2; }
.ele-tooltip {
  position: absolute;
  pointer-events: none;
  z-index: 5;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.55rem;
  font-size: 0.78rem;
  line-height: 1.35;
  box-shadow: var(--shadow);
  white-space: nowrap;
}

.muted { color: var(--muted); }
.hidden { display: none !important; }
.empty { color: var(--muted); padding: 2rem; text-align: center; }

/* -- toast -- */
.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--border);
  padding: 0.6rem 1rem; border-radius: 10px; box-shadow: var(--shadow);
  z-index: 2000; max-width: 80vw;
}
.toast.error { border-color: var(--danger); color: #ffd7d7; }
.toast.success { border-color: var(--accent-2); color: #d7ffe9; }

.leaflet-popup-content { font-size: 0.82rem; }
.leaflet-popup-content b { color: #04131f; }

@media (max-width: 700px) {
  button, .header-icon, #profile-switch { min-height: 44px; }
  input:not([type="checkbox"]), select, textarea { min-height: 44px; }
  .checkline { min-height: 44px; }
  nav a { min-height: 44px; display: inline-flex; align-items: center; }
  .split {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(12rem, 42%) minmax(18rem, 1fr);
  }
  .split > .panel { border-right: 0; border-bottom: 1px solid var(--border); }
  .tools-page .row { flex-direction: column; align-items: stretch; }
  .modal { width: calc(100vw - 1rem); max-height: calc(100vh - 1rem); padding: 0.8rem; }
  .modal .mini-map { height: 240px; }
  .modal-actions { flex-wrap: wrap; }
  .modal-actions button { flex: 1 1 8rem; }
  .col-climb-fields {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) minmax(0, 1fr);
  }
  .col-climb-fields select { grid-column: 2 / 3; }
  .col-climb-fields .col-climb-jump { grid-column: 3; justify-self: end; }
}

@media (max-width: 1100px) {
  .entity-detail-workspace { grid-template-columns: 1fr; }
  .entity-detail-scroll, .route-detail-climbs { max-height: none; }
}
