/* ---------------------------------------------------------------- tokens */
:root {
  color-scheme: light;
  --bg:        #f6f7f8;
  --panel:     #ffffff;
  --panel-2:   #f1f3f5;
  --ink:       #1b2126;
  --ink-2:     #5b6670;
  --ink-3:     #8a959e;
  --line:      #dfe3e7;
  --accent:    #b4451f;
  --accent-in: #ffffff;
  --accent-soft:#fdeee8;
  --good:      #2f7a4f;
  --shadow:    0 1px 2px rgba(16,24,32,.06), 0 8px 24px rgba(16,24,32,.08);
  --radius:    10px;
  --side-w:    336px;
}

/* Dark palette lives in one place and is applied twice: once for the OS
   preference (unless the page has been explicitly set to light), and once for
   an explicit dark choice, so the toggle wins in both directions. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:        #14181b;
    --panel:     #1b2024;
    --panel-2:   #232a2f;
    --ink:       #e7ecf0;
    --ink-2:     #a3aeb7;
    --ink-3:     #78848d;
    --line:      #2e373d;
    --accent:    #e2703f;
    --accent-in: #17191a;
    --accent-soft:#33221b;
    --good:      #5fbd87;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.45);
  }
}

:root[data-theme="dark"] {
    color-scheme: dark;
    --bg:        #14181b;
    --panel:     #1b2024;
    --panel-2:   #232a2f;
    --ink:       #e7ecf0;
    --ink-2:     #a3aeb7;
    --ink-3:     #78848d;
    --line:      #2e373d;
    --accent:    #e2703f;
    --accent-in: #17191a;
    --accent-soft:#33221b;
    --good:      #5fbd87;
    --shadow:    0 1px 2px rgba(0,0,0,.4), 0 10px 30px rgba(0,0,0,.45);
}

* { box-sizing: border-box; }

/* The `hidden` attribute is only a UA-stylesheet `display: none`, so any class
 * that sets its own display quietly overrides it — which is exactly how the
 * drop overlay ended up permanently visible. Settle it once, globally. */
[hidden] { display: none !important; }

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------------------------------------------------------------- layout */
#app {
  display: grid;
  grid-template-columns: var(--side-w) 1fr;
  height: 100dvh;
  transition: grid-template-columns .22s ease;
}
#app.collapsed { grid-template-columns: 0 1fr; }
#app.collapsed #sidebar { transform: translateX(-100%); pointer-events: none; visibility: hidden; }

#map { height: 100%; width: 100%; background: var(--panel-2); }

/* --------------------------------------------------------------- sidebar */
#sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
  /* Explicit width, not the grid track's: the collapsed track is 0 wide, and a
     0-wide box cannot translate itself off screen. */
  width: var(--side-w);
  overflow: hidden;
  background: var(--panel);
  border-right: 1px solid var(--line);
  transition: transform .22s ease, visibility .22s;
  z-index: 900;
}

.side-head {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 14px 10px;
}
.side-head h1 {
  display: flex; align-items: center; gap: 9px;
  margin: 0; font-size: 16px; font-weight: 650; letter-spacing: -.01em; flex: 1;
}
.logo { width: 22px; height: 22px; flex: none; border-radius: 5px; }
.logo .lo-bg   { fill: var(--accent); }
.logo .lo-far  { fill: #f4c7b4; }
.logo .lo-near { fill: #fff; }
.logo .lo-cap  { fill: var(--accent); opacity: .5; }

.icon-btn, .expand-btn {
  appearance: none; border: 1px solid var(--line); background: var(--panel);
  color: var(--ink-2); border-radius: 8px; cursor: pointer;
  width: 28px; height: 28px; font-size: 12px; line-height: 1; flex: none;
}
.icon-btn:hover, .expand-btn:hover { background: var(--panel-2); color: var(--ink); }

.expand-btn {
  position: absolute; top: 14px; left: 12px; z-index: 900;
  width: 32px; height: 32px; box-shadow: var(--shadow);
}

/* ----------------------------------------------------------------- stats */
.stats {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 1px; margin: 0 14px 12px;
  background: var(--line); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden;
}
.stat {
  background: var(--panel-2); padding: 8px 6px; text-align: center;
  display: flex; flex-direction: column; gap: 1px;
}
.stat b {
  font-size: 15px; font-weight: 650; font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.stat span { font-size: 9.5px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; }

/* ---------------------------------------------------------------- search */
.search-wrap { position: relative; padding: 0 14px 10px; }
#search {
  width: 100%; padding: 9px 11px; font: inherit; color: var(--ink);
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; outline: none;
}
#search:focus { border-color: var(--accent); background: var(--panel); }
#search::placeholder { color: var(--ink-3); }

.results {
  position: absolute; left: 14px; right: 14px; top: calc(100% - 4px);
  z-index: 50; margin: 0; padding: 4px; list-style: none;
  max-height: 320px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.results li {
  display: flex; align-items: baseline; gap: 8px;
  padding: 7px 9px; border-radius: 6px; cursor: pointer;
}
.results li.on, .results li:hover { background: var(--accent-soft); }
.results .r-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .r-ele { color: var(--ink-3); font-variant-numeric: tabular-nums; font-size: 12px; flex: none; }
.results .r-done { color: var(--good); flex: none; }

/* ------------------------------------------------------------------ tabs */
.tabs {
  display: flex; gap: 0; padding: 0 8px; border-bottom: 1px solid var(--line);
  /* Five tabs in a 336 px rail: keep each on one line, and if a long badge
     ever pushes past the edge, scroll rather than wrap. */
  overflow-x: auto; scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  appearance: none; border: 0; background: none; cursor: pointer; white-space: nowrap; flex: none;
  padding: 8px 5px; font: inherit; font-size: 12px; color: var(--ink-3);
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--ink); }
.tab.is-active { color: var(--ink); border-bottom-color: var(--accent); font-weight: 550; }

.panel { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; padding: 10px 14px 14px; }

.panel-tools { display: flex; justify-content: flex-end; margin-bottom: 8px; }
select, input[type="date"], input[type="text"], textarea {
  font: inherit; color: var(--ink); background: var(--panel-2);
  border: 1px solid var(--line); border-radius: 7px; padding: 6px 8px; outline: none;
}
select:focus, input:focus, textarea:focus { border-color: var(--accent); }
.panel-tools select { font-size: 12.5px; padding: 4px 6px; }

/* -------------------------------------------------------------- log list */
.log-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.log-item {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 10px;
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent;
  align-items: baseline;
}
.log-item.has-rank { grid-template-columns: auto 1fr auto; }
.li-rank {
  font-size: 11.5px; font-weight: 650; color: var(--ink-3);
  font-variant-numeric: tabular-nums; min-width: 26px;
}
.log-item.is-sel .li-rank { color: var(--accent); }
.li-nth {
  font-style: normal; color: var(--accent);
  margin-left: 7px; font-size: 11px;
}
.log-item:hover { background: var(--panel-2); }
.log-item.is-sel { background: var(--accent-soft); border-color: var(--accent); }
.log-item .li-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-item .li-ele { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.log-item .li-meta { grid-column: 1 / -1; color: var(--ink-3); font-size: 12px; }
.log-item.has-rank .li-meta { padding-left: 26px; }
.log-item .li-count {
  display: inline-block; margin-left: 6px; padding: 0 5px; border-radius: 99px;
  background: var(--good); color: #fff; font-size: 10px; font-weight: 600;
}

.empty { color: var(--ink-3); font-size: 13px; text-align: center; padding: 28px 12px; margin: 0; }

/* --------------------------------------------------------------- filters */
.field { display: block; margin-bottom: 14px; }
.field > span { display: flex; justify-content: space-between; font-size: 12.5px; color: var(--ink-2); margin-bottom: 5px; }
.field > span b { color: var(--ink); font-variant-numeric: tabular-nums; }
.field select { width: 100%; }
input[type="range"] { width: 100%; accent-color: var(--accent); }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; font-size: 13px; cursor: pointer; }
.check input { accent-color: var(--accent); }
.hint { color: var(--ink-3); font-size: 12px; margin: 14px 0 0; border-top: 1px solid var(--line); padding-top: 10px; }

/* ---------------------------------------------------------------- footer */
.side-foot {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px; border-top: 1px solid var(--line);
  font-size: 11.5px; color: var(--ink-3);
}
.side-foot a { color: var(--ink-3); }
.save-state.saving { color: var(--accent); }
.save-state.saved  { color: var(--good); }
.save-state.error  { color: #d14343; font-weight: 600; }

/* ---------------------------------------------------------- detail panel */
.detail {
  position: absolute; right: 14px; top: 14px; width: 310px; max-width: calc(100vw - 28px);
  max-height: calc(100dvh - 28px); overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); z-index: 800;
}
.d-head { display: flex; gap: 8px; align-items: flex-start; padding: 14px 14px 10px; }
.d-head h2 { margin: 0; font-size: 15.5px; line-height: 1.3; flex: 1; letter-spacing: -.01em; }
.d-sub { padding: 0 14px 12px; color: var(--ink-2); font-size: 12.5px; display: flex; flex-wrap: wrap; gap: 4px 10px; }
.d-sub .pill {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 99px; padding: 1px 8px; font-variant-numeric: tabular-nums;
}
.d-body { padding: 0 14px 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.d-body h3 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 600; }

.form-row { display: flex; gap: 8px; margin-bottom: 8px; }
.form-row > * { flex: 1; min-width: 0; }
.d-body input[type="date"], .d-body input[type="text"], .d-body textarea { width: 100%; }
.d-body textarea { resize: vertical; min-height: 54px; font-size: 13px; }

.btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 550; font-size: 13px;
  padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--ink);
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-in); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: none; border-color: transparent; color: var(--ink-3); padding: 4px 6px; }
.btn.ghost:hover { color: #d14343; background: var(--panel-2); }
.btn[disabled] { opacity: .5; cursor: default; }

.ascents { list-style: none; margin: 0 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.ascent {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px; font-size: 12.5px;
}
.ascent .a-top { display: flex; align-items: center; gap: 6px; }
.ascent .a-date { font-weight: 600; font-variant-numeric: tabular-nums; flex: 1; }
.ascent .a-note { color: var(--ink-2); margin-top: 3px; white-space: pre-wrap; word-wrap: break-word; }
.ascent .a-with { color: var(--ink-3); margin-top: 3px; }

.d-links { display: flex; gap: 12px; padding: 10px 14px; border-top: 1px solid var(--line); font-size: 12px; }
.d-links a { color: var(--ink-2); }

/* -------------------------------------------------------------- leaflet */
.leaflet-container { background: var(--panel-2); font: inherit; }
.leaflet-control-attribution {
  background: rgba(255,255,255,.82) !important; color: #333 !important; font-size: 10.5px !important;
}
.leaflet-control-attribution a { color: #0b6cb0 !important; }
.leaflet-bar a {
  background: var(--panel); color: var(--ink); border-bottom-color: var(--line);
}
.leaflet-bar a:hover { background: var(--panel-2); color: var(--ink); }
.peak-canvas { cursor: crosshair; }

/* ---------------------------------------------------------------- tracks */
.tab-count {
  display: inline-block; min-width: 15px; padding: 0 3px; margin-left: 2px;
  border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line);
  font-size: 10px; font-variant-numeric: tabular-nums; color: var(--ink-2);
}
.tab.is-active .tab-count { background: var(--accent); border-color: var(--accent); color: var(--accent-in); }

.track-tools { justify-content: space-between; align-items: center; }
.track-tools .btn { font-size: 12.5px; padding: 5px 10px; }

.track-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.track-item {
  padding: 8px 10px; border-radius: 8px; cursor: pointer;
  border: 1px solid transparent; position: relative;
}
.track-item:hover { background: var(--panel-2); }
.track-item.is-sel { background: var(--accent-soft); border-color: var(--accent); }
.track-item .t-top { display: flex; align-items: baseline; gap: 8px; }
.track-item .t-name {
  font-weight: 550; flex: 1; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.track-item .t-date { color: var(--ink-3); font-size: 12px; font-variant-numeric: tabular-nums; flex: none; }
.track-item .t-meta {
  color: var(--ink-2); font-size: 12px; margin-top: 2px;
  display: flex; flex-wrap: wrap; gap: 2px 9px; font-variant-numeric: tabular-nums;
}
.track-item .t-peaks { color: var(--accent); font-weight: 550; }
.track-item .t-actions { display: none; gap: 4px; margin-top: 7px; flex-wrap: wrap; }
.track-item.is-sel .t-actions { display: flex; }
.track-item .btn { font-size: 12px; padding: 4px 8px; }
.track-swatch {
  position: absolute; left: 0; top: 8px; bottom: 8px; width: 3px; border-radius: 0 2px 2px 0;
}

.two-up { display: flex; gap: 8px; }
.two-up label { flex: 1; display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--ink-2); }
.two-up input { width: 58px; font-variant-numeric: tabular-nums; }
.hint.tight { margin-top: 8px; padding-top: 8px; }

/* Dropping a file anywhere over the map imports it. */
.drop {
  position: absolute; inset: 0; z-index: 700;
  background: rgba(180, 69, 31, .12);
  border: 2px dashed var(--accent);
  display: grid; place-items: center; pointer-events: none;
}
.drop-inner {
  background: var(--panel); color: var(--ink);
  padding: 12px 20px; border-radius: 10px; box-shadow: var(--shadow);
  font-weight: 600;
}

.toast {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: 950; max-width: min(520px, calc(100vw - 32px));
  background: var(--panel); color: var(--ink);
  border: 1px solid var(--line); border-left: 3px solid var(--accent);
  border-radius: 9px; box-shadow: var(--shadow);
  padding: 10px 14px; font-size: 13px; line-height: 1.45;
}
.toast.error { border-left-color: #d14343; }
.toast b { font-weight: 600; }
.toast .t-list { color: var(--ink-2); margin-top: 3px; }

/* Ascents the tracks found, rather than ones you typed. */
.ascent.from-gpx { border-left: 3px solid var(--accent); }
.a-src {
  display: block; color: var(--ink-3); font-size: 11px; margin-top: 3px;
  line-height: 1.5;
}
/* Inline, not flex: flex columns turn each fragment into its own narrow
   column and break the line mid-phrase. */
.a-src > * { display: inline; }
.a-src > * + * { margin-left: 4px; }
.a-src .warn { color: #b8860b; }

#map { position: relative; }

/* Peaks a track passed but did not log, and why. */
.near-miss {
  margin-top: 8px; padding-top: 8px;
  border-top: 1px dashed var(--line);
}
.near-miss h4 {
  margin: 0 0 6px; font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3);
}
.nm-row {
  display: flex; align-items: baseline; gap: 8px;
  padding: 3px 0; font-size: 12.5px;
}
.nm-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nm-why { color: var(--ink-3); font-size: 11.5px; font-variant-numeric: tabular-nums; flex: none; }
.nm-add { flex: none; font-size: 11.5px !important; padding: 2px 6px !important; color: var(--accent) !important; }
.nm-add:hover { background: var(--accent-soft) !important; color: var(--accent) !important; }
.nm-more { margin: 4px 0 0; font-size: 11.5px; color: var(--ink-3); }

/* Date field inside a track's actions row. */
.t-date-edit {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 6px !important;
}
.t-date-label { color: var(--ink-3); font-size: 11.5px; }
.t-date-edit .df-text { width: 82px; font-size: 11.5px; padding: 2px 4px; }
.t-date-edit .df-open { width: 20px; height: 20px; }
.t-date-edit .df-open svg { width: 11px; height: 11px; }

.track-item .t-date.no-date { color: var(--accent); font-style: italic; }
.track-item .t-date.guessed { border-bottom: 1px dotted var(--ink-3); cursor: help; }

/* Inline editor for a logged ascent. */
.ascent.editing { background: var(--panel); border-color: var(--accent); }
.a-edit { color: var(--ink-3) !important; }
.a-edit:hover { color: var(--accent) !important; background: var(--accent-soft) !important; }

.a-edit-form { display: flex; flex-direction: column; gap: 6px; }
.a-edit-form h4 {
  margin: 0 0 2px; font-size: 10.5px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .05em; color: var(--accent);
}
.a-edit-form input, .a-edit-form textarea { width: 100%; font-size: 12.5px; }
.a-edit-form textarea { min-height: 62px; resize: vertical; }
.a-edit-form .form-row { margin: 2px 0 0; }
.a-edit-form .btn { font-size: 12.5px; padding: 6px 10px; }
.a-hint { margin: 2px 0 0; font-size: 11.5px; color: var(--ink-3); }

/* ------------------------------------------------------------- date field */
/* A text field we format ourselves, because <input type="date"> always draws
   its text in the browser's UI language and no page-level setting overrides
   that. The native control is still here, collapsed, to supply the calendar. */
.datefield { position: relative; display: inline-flex; align-items: center; gap: 4px; }

.df-text {
  font-variant-numeric: tabular-nums; letter-spacing: .01em;
  min-width: 0; flex: 1;
}
.df-text.is-bad { border-color: #d14343; color: #d14343; }
.df-text.is-bad:focus { border-color: #d14343; }

/* Rendered but invisible: showPicker() refuses to open on a display:none
   element, and the popup anchors to wherever this sits. */
.df-picker {
  position: absolute; left: 6px; bottom: 0;
  width: 1px; height: 1px; padding: 0; border: 0;
  opacity: 0; pointer-events: none;
}

.df-open {
  appearance: none; flex: none; cursor: pointer;
  width: 26px; height: 26px; padding: 0;
  display: inline-grid; place-items: center;
  border: 1px solid var(--line); border-radius: 7px;
  background: var(--panel-2); color: var(--ink-2);
}
.df-open:hover { color: var(--accent); border-color: var(--accent); }
.df-open svg {
  width: 13px; height: 13px;
  fill: none; stroke: currentColor; stroke-width: 1.4;
  stroke-linecap: round;
}

.a-edit-form .datefield, .d-body .datefield { width: 100%; }

/* Theme switch in the sidebar header. */
#theme svg { width: 15px; height: 15px; display: block; margin: auto; }
#theme svg circle, #theme svg path {
  fill: none; stroke: currentColor; stroke-width: 1.5;
  stroke-linecap: round; stroke-linejoin: round;
}
#theme svg .fill { fill: currentColor; stroke: none; }
#theme:hover { color: var(--accent); border-color: var(--accent); }
.t-date-edit .tw-text {
  width: 96px; font-size: 11.5px; padding: 2px 4px;
  border: 1px solid var(--line); border-radius: 5px;
  background: var(--panel); color: var(--ink);
}
.t-date-edit .tw-text::placeholder { color: var(--ink-3); font-style: italic; }

/* ------------------------------------------------------------- statistics */
/* Charts get more room than the rail: the panel widens while Stats is open. */
/* Only on wide screens, and never while collapsed — this rule comes later
   than #app.collapsed and would otherwise hold a 580px hole open. */
@media (min-width: 981px) {
  #app.stats-wide:not(.collapsed) { grid-template-columns: 580px 1fr; }
  #app.stats-wide #sidebar { width: 580px; }
}

#panel-stats { padding-bottom: 24px; }

.kpi-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(92px, 1fr));
  gap: 1px; background: var(--line);
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
}
.kpi { background: var(--panel-2); padding: 9px 8px; display: flex; flex-direction: column; gap: 1px; }
.kpi b { font-size: 17px; font-weight: 650; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.kpi span { font-size: 9.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); }
.kpi i {
  font-style: normal; font-size: 10.5px; color: var(--ink-2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.stat-head { margin: 22px 0 6px; }
.stat-head h3 {
  margin: 0; font-size: 11px; font-weight: 600;
  text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3);
}
.stat-head p { margin: 3px 0 0; font-size: 11.5px; color: var(--ink-3); line-height: 1.4; }

/* Single-hue sequential ramp, validated for lightness monotonicity and for
   >=3:1 contrast against both surfaces. */
.chart { width: 100%; height: auto; display: block; overflow: visible; }
.chart .bar   { fill: #b4451f; }
.chart .span  { fill: #dd9b7c; }
.chart .mean  { fill: #b4451f; stroke: var(--panel); stroke-width: 2; }
.chart .axis  { stroke: var(--line); stroke-width: 1; }
.chart .grid  { stroke: var(--line); stroke-width: 1; }
.chart .val   { font: 600 10.5px ui-sans-serif, system-ui, sans-serif; fill: var(--ink); text-anchor: middle; font-variant-numeric: tabular-nums; }
.chart .val.end { text-anchor: start; font-weight: 500; fill: var(--ink-2); }
.chart .tick  { font: 500 10px ui-sans-serif, system-ui, sans-serif; fill: var(--ink-3); text-anchor: middle; font-variant-numeric: tabular-nums; }
.chart .rowlab { font: 550 11px ui-sans-serif, system-ui, sans-serif; fill: var(--ink-2); text-anchor: start; }
.chart rect, .chart circle { cursor: default; }

:root[data-theme="dark"] .chart .bar,
:root[data-theme="dark"] .chart .mean { fill: #e2703f; }
:root[data-theme="dark"] .chart .span { fill: #9a5334; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .chart .bar,
  :root:not([data-theme="light"]) .chart .mean { fill: #e2703f; }
  :root:not([data-theme="light"]) .chart .span { fill: #9a5334; }
}

.stat-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 4px; }
.stat-table th {
  text-align: right; font-weight: 600; font-size: 10px; color: var(--ink-3);
  text-transform: uppercase; letter-spacing: .04em;
  padding: 4px 6px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.stat-table th:first-child, .stat-table td:first-child { text-align: left; }
.stat-table th:last-child, .stat-table td.peakcell { text-align: left; }
.stat-table td {
  padding: 5px 6px; border-bottom: 1px solid var(--line);
  text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2);
}
.stat-table td:first-child { color: var(--ink); font-weight: 550; }
.stat-table td.peakcell {
  color: var(--ink); max-width: 160px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.stat-table tbody tr:hover td { background: var(--panel-2); }

/* ---------------------------------------------------------------- legend */
.legend { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 3px; }
.legend li { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--ink-2); }
.legend svg { width: 15px; height: 14px; flex: none; }
.legend .lg-band { font-variant-numeric: tabular-nums; color: var(--ink-3); margin-left: auto; }
.d-sub .pill { cursor: pointer; }
.d-sub .pill.missing { border-style: dashed; color: var(--accent); }
.d-sub .pill.soft { cursor: default; color: var(--ink-3); font-size: 11px; }

/* --------------------------------------------------- elevation profile */
.profile {
  position: absolute; left: 12px; right: 12px; bottom: 12px; z-index: 750;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow);
  padding: 8px 10px 6px;
}
/* Leaflet's own corners — attribution included — move up out of the way, by
   however tall the panel actually turned out to be. */
#map.has-profile .leaflet-bottom { bottom: var(--profile-lift, 176px); }

.pf-load { padding: 18px 8px; text-align: center; color: var(--ink-3); font-size: 12.5px; }

.pf-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.pf-name {
  font-weight: 600; font-size: 13px; flex: 0 1 auto;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 34%;
}
.pf-figs {
  display: flex; align-items: baseline; gap: 10px; flex: 1; min-width: 0;
  font-size: 12px; color: var(--ink-2); font-variant-numeric: tabular-nums;
  overflow: hidden; white-space: nowrap;
}
.pf-figs b { font-weight: 600; color: var(--ink); }
.pf-figs .pf-hr { color: #d32f2f; }

.pf-axis { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; flex: none; }
.pf-seg {
  appearance: none; border: 0; background: var(--panel-2); color: var(--ink-2);
  font: inherit; font-size: 11.5px; padding: 3px 9px; cursor: pointer;
}
.pf-seg + .pf-seg { border-left: 1px solid var(--line); }
.pf-seg.on { background: var(--accent); color: var(--accent-in); font-weight: 600; }
.pf-seg[disabled] { opacity: .4; cursor: default; }

.pf-plot { cursor: crosshair; touch-action: none; user-select: none; }
.pf-svg { display: block; width: 100%; height: 150px; }

.pf-area { fill: #1f6fb4; opacity: .10; stroke: none; }
.pf-line-ele { fill: none; stroke: #1f6fb4; stroke-width: 1.8; stroke-linejoin: round; }
.pf-line-hr  { fill: none; stroke: #d32f2f; stroke-width: 1.4; stroke-linejoin: round; opacity: .9; }
.pf-grid { stroke: var(--line); stroke-width: 1; }
.pf-cross { stroke: var(--ink-2); stroke-width: 1; stroke-dasharray: 3 3; }
.pf-dot { stroke: var(--panel); stroke-width: 2; }
.pf-dot.ele { fill: #1f6fb4; }
.pf-dot.hr  { fill: #d32f2f; }
.pf-band { fill: var(--accent); opacity: .16; }

/* Each axis wears its series' colour — with two scales on one frame that is
   the only thing telling the reader which numbers belong to which line. */
.pf-ytick { font: 500 9.5px ui-sans-serif, system-ui, sans-serif; font-variant-numeric: tabular-nums; }
.pf-ytick.left  { fill: #1f6fb4; text-anchor: end; }
.pf-ytick.right { fill: #d32f2f; text-anchor: start; }
.pf-cap { font: 600 8.5px ui-sans-serif, system-ui, sans-serif; text-transform: uppercase; letter-spacing: .05em; }
.pf-cap.left  { fill: #1f6fb4; text-anchor: end; }
.pf-cap.right { fill: #d32f2f; text-anchor: start; }
.pf-xtick { font: 500 10px ui-sans-serif, system-ui, sans-serif; fill: var(--ink-3); font-variant-numeric: tabular-nums; }

.pf-tip {
  position: absolute; z-index: 5; pointer-events: none;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; box-shadow: var(--shadow); padding: 6px 9px;
  font-size: 11.5px; min-width: 116px;
}
.pf-tip-row { display: flex; justify-content: space-between; gap: 14px; line-height: 1.55; }
.pf-tip-row .k { color: var(--ink-3); }
.pf-tip-row .v { color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; }

.pf-reset {
  appearance: none; border: 1px solid var(--accent); background: var(--accent-soft);
  color: var(--accent); border-radius: 7px; font: inherit; font-size: 11.5px;
  padding: 3px 9px; cursor: pointer; flex: none;
}
.pf-hint { font-size: 10.5px; color: var(--ink-3); text-align: center; height: 14px; }


:root[data-theme="dark"] .pf-area { fill: #5aa9e8; }
:root[data-theme="dark"] .pf-line-ele { stroke: #5aa9e8; }
:root[data-theme="dark"] .pf-line-hr { stroke: #ff7a6b; }
:root[data-theme="dark"] .pf-figs .pf-hr,
:root[data-theme="dark"] .pf-ytick.right,
:root[data-theme="dark"] .pf-cap.right { color: #ff7a6b; fill: #ff7a6b; }
:root[data-theme="dark"] .pf-dot.hr { fill: #ff7a6b; }
:root[data-theme="dark"] .pf-ytick.left,
:root[data-theme="dark"] .pf-cap.left { fill: #5aa9e8; }
:root[data-theme="dark"] .pf-dot.ele { fill: #5aa9e8; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .pf-area { fill: #5aa9e8; }
  :root:not([data-theme="light"]) .pf-line-ele { stroke: #5aa9e8; }
  :root:not([data-theme="light"]) .pf-line-hr { stroke: #ff7a6b; }
  :root:not([data-theme="light"]) .pf-figs .pf-hr,
  :root:not([data-theme="light"]) .pf-ytick.right,
  :root:not([data-theme="light"]) .pf-cap.right { color: #ff7a6b; fill: #ff7a6b; }
  :root:not([data-theme="light"]) .pf-ytick.left,
  :root:not([data-theme="light"]) .pf-cap.left { fill: #5aa9e8; }
  :root:not([data-theme="light"]) .pf-dot.hr { fill: #ff7a6b; }
  :root:not([data-theme="light"]) .pf-dot.ele { fill: #5aa9e8; }
}

@media (max-width: 760px) {
  .profile { left: 6px; right: 6px; bottom: 6px; padding: 6px 8px 4px; }
  .pf-name { display: none; }
  #map.has-profile .leaflet-bottom { bottom: var(--profile-lift, 160px); }
}

/* --------------------------------------------------------------- wishlist */
.wish-btn {
  appearance: none; flex: none; cursor: pointer;
  display: inline-flex; align-items: center; gap: 5px;
  height: 28px; padding: 0 9px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink-2);
  font: inherit; font-size: 12px; font-weight: 550;
}
.wish-btn svg { width: 13px; height: 13px; }
.wish-btn svg path { fill: none; stroke: #7a3fd6; stroke-width: 1.8; stroke-linejoin: round; }
.wish-btn svg path.f { fill: #7a3fd6; }
.wish-btn:hover { border-color: #7a3fd6; color: #5b2aa8; }
.wish-btn.on { background: rgba(122, 63, 214, .10); border-color: #7a3fd6; color: #5b2aa8; }

.r-wish { color: #7a3fd6; flex: none; }

.wish-item .grip { cursor: grab; user-select: none; }
.wish-item.dragging { opacity: .45; }
.wish-item.drop-before { box-shadow: inset 0 2px 0 #7a3fd6; }
.wish-item.drop-after  { box-shadow: inset 0 -2px 0 #7a3fd6; }
.wish-item:focus-visible { outline: 2px solid #7a3fd6; outline-offset: -2px; }
.wish-item .li-meta { display: flex; align-items: center; }
.wish-item .wish-rm { margin-left: auto; font-size: 11.5px; padding: 1px 6px; }

:root[data-theme="dark"] .wish-btn svg path { stroke: #b28cff; }
:root[data-theme="dark"] .wish-btn svg path.f { fill: #b28cff; }
:root[data-theme="dark"] .wish-btn.on,
:root[data-theme="dark"] .wish-btn:hover { border-color: #b28cff; color: #d7c4ff; background: rgba(178, 140, 255, .10); }
:root[data-theme="dark"] .r-wish { color: #b28cff; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .wish-btn svg path { stroke: #b28cff; }
  :root:not([data-theme="light"]) .wish-btn svg path.f { fill: #b28cff; }
  :root:not([data-theme="light"]) .wish-btn.on,
  :root:not([data-theme="light"]) .wish-btn:hover { border-color: #b28cff; color: #d7c4ff; background: rgba(178, 140, 255, .10); }
  :root:not([data-theme="light"]) .r-wish { color: #b28cff; }
}

/* --------------------------------------------- peak markers outside the map */
.pk-marker { width: 18px; height: 18px; flex: none; display: block; }
.d-head h2 { display: flex; align-items: flex-start; gap: 7px; }
.d-head h2 .d-marker { width: 20px; height: 20px; margin-top: 0; }
.legend .pk-marker { width: 16px; height: 16px; }
.li-name .li-marker {
  display: inline-block; width: 17px; height: 17px;
  vertical-align: -3px; margin-right: 4px; margin-left: -2px;
}
.wish-done { color: var(--accent); }

/* Separators in the log — a year when sorted by date, a 500 m band when
   sorted by height. Sticky, so you can see which one you are in. */
.log-sep {
  position: sticky; top: -10px; z-index: 2;
  display: flex; align-items: baseline; gap: 8px;
  margin: 6px -14px 0; padding: 10px 24px 5px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.ls-title { font-size: 13px; font-weight: 700; letter-spacing: -.01em; color: var(--ink); font-variant-numeric: tabular-nums; }
.ls-sum  { font-size: 11px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

/* The summary is also the button that highlights the section on the map. */
.ls-show {
  display: inline-flex; align-items: center; gap: 4px;
  margin-left: auto; padding: 2px 7px 2px 5px; align-self: center;
  border: 1px solid transparent; border-radius: 999px;
  background: none; font: inherit; font-size: 11px; color: var(--ink-3);
  cursor: pointer;
}
.ls-show svg { width: 12px; height: 12px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.ls-show svg .f { fill: currentColor; stroke: none; }
.ls-show:hover { color: var(--ink); border-color: var(--line); }
.ls-show:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.ls-show.on { color: var(--panel); background: var(--ink); border-color: var(--ink); }

/* Hover label for the triangles (and anything else with data-tip). */
.hovertip {
  position: fixed; z-index: 2000; pointer-events: none;
  max-width: 260px; padding: 5px 9px; border-radius: 7px;
  background: var(--ink); color: var(--panel);
  font-size: 11.5px; font-weight: 550; line-height: 1.35;
  box-shadow: 0 4px 14px rgba(0,0,0,.18);
}
.pk-marker[data-tip] { cursor: help; }
/* Rows scrolled into view must not end up under a pinned year / height heading. */
.log-item { scroll-margin-top: 44px; scroll-margin-bottom: 8px; }
/* One group per year / height band; see renderLogList. */
.log-group { list-style: none; }
.log-group-items {
  list-style: none; margin: 4px 0 0; padding: 0;
  display: flex; flex-direction: column; gap: 4px;
}

/* Map markers in the My log / Wishlist tab headings. */
.tab-mk { display: inline-block; width: 13px; height: 13px; margin-right: 2px; vertical-align: -2px; }
.tab-mk .pk-marker { width: 13px; height: 13px; }
.tab:not(.is-active) .tab-mk { opacity: .8; }

/* ------------------------------------------------------------- ownership */
/* Visitors read; the owner edits. This only tidies the page — the server is
   what refuses changes from anyone who is not logged in. */
.is-visitor .owner-only { display: none !important; }
.d-sub .pill.static { cursor: default; }
.wish-btn.static { cursor: default; }
.d-none { margin: 0; color: var(--ink-3); font-size: 12.5px; }

.owner-btn {
  appearance: none; border: 0; background: none; padding: 0; cursor: pointer;
  font: inherit; font-size: 11.5px; color: var(--ink-3); text-decoration: underline;
  text-underline-offset: 2px;
}
.owner-btn:hover { color: var(--accent); }

.login {
  margin: 0 14px 10px; padding: 12px; border-radius: var(--radius);
  background: var(--panel-2); border: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 7px;
}
.login label { font-size: 12px; font-weight: 600; color: var(--ink-2); }
.login input { width: 100%; }
.login-row { display: flex; gap: 6px; }
.login-msg { margin: 0; font-size: 12px; color: #d14343; min-height: 0; }
.login-msg:empty { display: none; }
.login-msg code { font-size: 11.5px; color: var(--ink); }
.login.unset label, .login.unset input, .login.unset .login-row .primary { display: none; }
.login.unset .login-msg { color: var(--ink-2); }

/* ------------------------------------------------------------------ demo */
.is-demo .no-demo { display: none !important; }
.demo-note {
  margin: 0 14px 10px; padding: 8px 10px; border-radius: 8px;
  background: var(--accent-soft); border: 1px solid var(--accent);
  font-size: 12px; line-height: 1.45; color: var(--ink-2);
}
.demo-note b { color: var(--accent); }
.demo-note .owner-btn { margin-left: 2px; }

/* -------------------------------------------------------------- responsive */
/* Last in the file, so the phone layout wins over everything above it. */
@media (max-width: 760px) {
  :root { --side-w: 100%; }
  #app { grid-template-columns: 1fr; grid-template-rows: minmax(0, 50%) 1fr; }
  .panel { padding: 6px 12px 12px; }
  .panel-tools { margin-bottom: 2px; }
  .log-sep { margin-top: 0; padding: 6px 20px 4px; top: -6px; }
  .log-item { padding: 6px 8px; }
  #app.collapsed { grid-template-columns: 1fr; grid-template-rows: 0 1fr; }
  #app.collapsed #sidebar { display: none; }
  /* Pinned: with the panel display:none the map would otherwise move up into
     the panel's row, which is 0 high while collapsed. */
  #map { grid-row: 2; grid-column: 1; }
  #sidebar { width: auto; }
  #sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .detail { right: 8px; left: 8px; width: auto; top: auto; bottom: 8px; max-width: none; max-height: 34dvh; z-index: 1001; }   /* over the zoom buttons */

  /* Every pixel of the panel's half of the screen goes to the list. The
     headline numbers are in the Stats tab as well, so they go here. */
  .side-head { padding: 8px 12px 6px; }
  #stats { display: none; }
  .search-wrap { padding: 0 12px 6px; }
  /* 16px: iOS zooms the whole page into any text field smaller than that. */
  #search { padding: 7px 10px; font-size: 16px; }
  input[type="text"], input[type="password"], textarea { font-size: 16px; }
  .tab { padding: 8px 6px; font-size: 13px; }
  .side-foot { padding: 5px 12px; }
  .demo-note { margin: 0 12px 6px; padding: 5px 8px; font-size: 11.5px; }

  /* The panel folds up, not sideways. */
  #collapse { transform: rotate(90deg); }
  .expand-btn { transform: rotate(90deg); top: 8px; left: 8px; }

  /* The profile shares the map's half with the map itself. */
  .profile { left: 6px; right: 6px; bottom: 6px; padding: 6px 8px 4px; }
  .pf-svg { height: 104px; }
  .pf-head { flex-wrap: wrap; gap: 4px 8px; }
  .pf-name { max-width: 60%; }
  .pf-figs { order: 3; flex-basis: 100%; }
  .pf-hint { display: none; }
}
