/* Afternoon Trail Finder — app layer.
   Everything here is built from the Organic design system's tokens in
   organic.css. No hard-coded hexes, fonts or spacing values; the only raw
   pixels are layout geometry the token scale doesn't cover (map heights,
   sheet snap points, hairlines). */

/* ── app frame ─────────────────────────────────────────────────────────── */
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--color-neutral-900);
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
}

.app {
  --banner-h: 25px;
  --banner-total: calc(var(--banner-h) + env(safe-area-inset-top));
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  background: var(--color-bg);
  overflow: hidden;
}
@media (min-width: 520px) and (min-height: 700px) {
  .app { height: min(880px, calc(100dvh - 48px)); margin-top: 24px; border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); }
}

/* ── prototype banner ──────────────────────────────────────────────────
   Sits above every screen and is not dismissible: while the conditions,
   traffic and reports are invented, anyone looking at this needs to know. */
.protobar {
  flex: none; display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: var(--banner-total); padding: env(safe-area-inset-top) var(--space-3) 0;
  border: 0; cursor: pointer; text-align: center;
  background: var(--color-neutral-900); color: var(--color-neutral-200);
  font: 600 10.5px/1 var(--font-body); letter-spacing: .02em;
}
.protobar:hover { background: var(--color-neutral-800); }
.protobar > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.protobar-more { flex: none; text-decoration: underline; text-underline-offset: 2px; opacity: .8; }

.screen { position: relative; flex: 1; min-height: 0; display: flex; flex-direction: column; }
.scroller { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.hidden { display: none !important; }

/* ── shared type ───────────────────────────────────────────────────────── */
.kicker {
  font-size: 10.5px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: color-mix(in srgb, var(--color-text) 52%, transparent);
}
.sub { font-size: 12px; color: color-mix(in srgb, var(--color-text) 58%, transparent); }
.on-dark .kicker, .on-dark .sub { color: color-mix(in srgb, var(--color-bg) 72%, transparent); }

/* ── chips ─────────────────────────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  font: 600 11.5px/1 var(--font-body);
  padding: 6px 11px; border-radius: 999px; white-space: nowrap;
  background: color-mix(in srgb, var(--color-text) 7%, transparent);
  color: var(--color-text); border: 0; cursor: default;
}
/* on the dark hero bands a 7%-ink fill is invisible — lift it off the ground instead */
.on-dark .chip { background: color-mix(in srgb, var(--color-bg) 20%, transparent); color: var(--color-bg); }
.chip-2 { background: var(--color-accent-2-200); color: var(--color-accent-2-800); }
.chip-warn { background: var(--color-accent-200); color: var(--color-accent-800); }
.chip-bad { background: var(--color-accent-600); color: var(--color-bg); }

button.chip { cursor: pointer; transition: background .12s, color .12s; }
button.chip:hover { background: color-mix(in srgb, var(--color-text) 13%, transparent); }
button.chip[aria-pressed="true"] { background: var(--color-accent); color: var(--color-bg); }
button.chip[aria-pressed="true"]:hover { background: var(--color-accent-600); }

.chiprow {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  padding-bottom: 2px; -webkit-overflow-scrolling: touch;
}
.chiprow::-webkit-scrollbar { display: none; }
.chipwrap { display: flex; gap: 6px; flex-wrap: wrap; }

/* ── score ring ────────────────────────────────────────────────────────── */
.ring {
  width: 44px; height: 44px; flex: none; border-radius: 999px;
  display: grid; place-items: center;
  font-family: var(--font-heading); font-size: 15px;
  color: var(--color-bg);
}
.ring-lg { width: 56px; height: 56px; font-size: 19px; }
.ring-sm { width: 34px; height: 34px; font-size: 13px; }

/* ── trail card ────────────────────────────────────────────────────────── */
.tcard {
  display: flex; gap: 11px; align-items: center; width: 100%; text-align: left;
  padding: 11px 12px; border: 0; border-radius: var(--radius-md);
  background: var(--color-bg); box-shadow: var(--shadow-sm);
  font-family: var(--font-body); color: var(--color-text); cursor: pointer;
  transition: box-shadow .12s, transform .12s;
}
.tcard:hover { box-shadow: var(--shadow-md); }
.tcard:active { transform: scale(.988); }
.tcard-body { min-width: 0; flex: 1; }
.tname { display: block; font-family: var(--font-heading); font-size: 15.5px; line-height: 1.14; }
.metarow { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }
.tcard .chip { font-size: 10.5px; padding: 4px 9px; }
.tcard.is-done .tname::after {
  content: '✓'; margin-left: 6px; font-family: var(--font-body); font-size: 12px;
  color: var(--color-accent-2-600);
}

/* ── the daylight header ───────────────────────────────────────────────── */
.daylight {
  background: var(--color-accent-800); color: var(--color-bg);
  padding: var(--space-4);              /* the banner carries the safe-area inset */
  flex: none; z-index: 500;
}
.daylight h4 { margin: 0; color: var(--color-bg); }
.daylight-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-2); }

.clockbtn {
  flex: none; border: 1px solid color-mix(in srgb, var(--color-bg) 34%, transparent);
  background: transparent; color: var(--color-bg);
  font: 600 11.5px var(--font-body); padding: 5px 11px; border-radius: 999px; cursor: pointer;
}
.clockbtn:hover { background: color-mix(in srgb, var(--color-bg) 15%, transparent); }

.bar {
  margin-top: var(--space-3); height: 34px; border-radius: 999px; overflow: hidden;
  background: color-mix(in srgb, var(--color-neutral-900) 34%, transparent);
  display: flex; font: 700 10px var(--font-body);
}
.bar > div {
  display: grid; place-items: center; overflow: hidden; white-space: nowrap;
  color: var(--color-accent-900); min-width: 0;
}
.bar > .seg-spare { color: color-mix(in srgb, var(--color-bg) 70%, transparent); }

.budgetline { display: flex; align-items: baseline; justify-content: space-between; gap: var(--space-3); margin-top: var(--space-2); }
.budgetline p { margin: 0; font-size: 12px; color: color-mix(in srgb, var(--color-bg) 85%, transparent); }

.togglebtn {
  flex: none; border: 1px solid color-mix(in srgb, var(--color-bg) 38%, transparent);
  background: transparent; color: var(--color-bg);
  font: 600 10px var(--font-body); letter-spacing: .04em; text-transform: uppercase;
  padding: 5px 9px; border-radius: 999px; cursor: pointer; opacity: .8;
}
.togglebtn[aria-pressed="true"] { background: color-mix(in srgb, var(--color-bg) 18%, transparent); opacity: 1; }

/* ── controls strip ────────────────────────────────────────────────────── */
.controls {
  padding: var(--space-3) var(--space-4) var(--space-2);
  background: var(--color-bg); box-shadow: var(--shadow-sm); z-index: 450; flex: none;
}
/* ── origin bar ────────────────────────────────────────────────────────── */
.originbar {
  display: flex; align-items: center; gap: var(--space-2); width: 100%;
  padding: 8px 10px 8px 9px; border: 1px solid var(--color-divider);
  border-radius: 999px; background: var(--color-bg); cursor: pointer;
  font-family: var(--font-body); color: var(--color-text); text-align: left;
}
.originbar:hover { background: color-mix(in srgb, var(--color-text) 5%, transparent); }
.originbar > svg { width: 17px; height: 17px; stroke-width: 2.75; flex: none; color: var(--color-accent-700); }
.originbar-text { min-width: 0; flex: 1; line-height: 1.2; }
.originbar-text b { display: block; font-size: 12.5px; font-weight: 700; }
.originbar-text .sub { display: block; font-size: 11px; }
.originbar-text b, .originbar-text .sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.originbar .chip { flex: none; }

/* ── autocomplete ──────────────────────────────────────────────────────── */
.ac-wrap { position: relative; }
.ac-list {
  list-style: none; margin: var(--space-2) 0 0; padding: 0;
  max-height: 232px; overflow-y: auto;
  border-radius: var(--radius-md); background: var(--color-bg);
  box-shadow: var(--shadow-md);
}
.ac-list:empty { display: none; }
.ac-list li {
  display: flex; align-items: center; gap: var(--space-2);
  padding: 10px 13px; cursor: pointer; border-bottom: 1px solid var(--color-divider);
}
.ac-list li:last-child { border-bottom: 0; }
.ac-list li:hover, .ac-list li[aria-selected="true"] {
  background: color-mix(in srgb, var(--color-accent) 12%, transparent);
}
.ac-list svg { width: 15px; height: 15px; stroke-width: 2.75; flex: none; color: var(--color-accent-700); }
.ac-list b { display: block; font-size: 13.5px; font-weight: 600; }
.ac-list span { display: block; font-size: 11.5px; color: color-mix(in srgb, var(--color-text) 58%, transparent); }
.ac-note { font-size: 11.5px; color: color-mix(in srgb, var(--color-text) 55%, transparent); margin-top: var(--space-2); }

.minsrow { display: flex; gap: 6px; align-items: center; margin-top: var(--space-2); flex-wrap: wrap; }
.mins-input { width: 96px; flex: none; text-align: center; font-variant-numeric: tabular-nums; }

/* ── elevation-gain filter ─────────────────────────────────────────────── */
.filterrow {
  display: flex; align-items: center; gap: var(--space-2);
  margin: var(--space-3) 0 var(--space-2);
}
.filterrow > label { flex: none; }
.pillselect {
  flex: 1; min-width: 0;
  font: 600 12px var(--font-body); color: var(--color-text);
  background: color-mix(in srgb, var(--color-text) 7%, transparent);
  border: 0; border-radius: 999px; padding: 7px 12px; cursor: pointer;
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23201e1d' stroke-width='2.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; background-size: 13px;
  padding-right: 30px;
}
.pillselect:hover { background-color: color-mix(in srgb, var(--color-text) 13%, transparent); }
.pillselect.is-set { background-color: var(--color-accent); color: var(--color-bg); }
.pillselect.is-set {
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23f5ead8' stroke-width='2.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
}
.pillselect.is-set:hover { background-color: var(--color-accent-600); }

.sliderrow { display: flex; align-items: center; gap: var(--space-2); }
.slider {
  -webkit-appearance: none; appearance: none; width: 100%; height: 6px; border-radius: 999px;
  background: linear-gradient(90deg, var(--color-accent-2-400), var(--color-accent-500));
  outline: none; cursor: pointer;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 22px; height: 22px; border-radius: 999px;
  background: var(--color-bg); border: 3px solid var(--color-text); cursor: pointer;
}
.slider::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 999px;
  background: var(--color-bg); border: 3px solid var(--color-text); cursor: pointer;
}
.slider:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 3px; }

/* ── map ───────────────────────────────────────────────────────────────── */
/* isolate: Leaflet's controls carry z-index 800-1000 of their own, which would
   otherwise paint over the detail panel and the modals. */
.mapwrap { position: relative; flex: 1; min-height: 0; z-index: 0; isolation: isolate; }
.lmap { width: 100%; height: 100%; background: var(--color-neutral-200); }
.lmap .leaflet-tile-pane { filter: saturate(.5) contrast(.9) brightness(1.06) sepia(.1); }
.leaflet-container { background: var(--color-neutral-200); font-family: var(--font-body); }
.leaflet-control-attribution {
  font-size: 8px;
  background: color-mix(in srgb, var(--color-bg) 78%, transparent) !important;
}
.home-dot, .pin { border-radius: 999px; }
.leaflet-tooltip {
  font: 600 11px var(--font-body); border: 0; border-radius: var(--radius-sm);
  background: var(--color-text); color: var(--color-bg); box-shadow: var(--shadow-md);
}
.leaflet-tooltip-top::before { border-top-color: var(--color-text); }

/* ── bottom sheet ──────────────────────────────────────────────────────── */
.sheet {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: var(--sheet-h, 300px);
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg);
  padding: var(--space-1) var(--space-3) var(--space-3);
  display: flex; flex-direction: column; gap: var(--space-2);
  z-index: 500; transition: height .22s cubic-bezier(.2, .8, .3, 1);
  touch-action: none;
}
.sheet.dragging { transition: none; }
.sheet-grip { padding: 6px 0 2px; cursor: grab; flex: none; }
.sheet-grip::before {
  content: ''; display: block; width: 38px; height: 4px; margin: 0 auto;
  border-radius: 999px; background: var(--color-neutral-400);
}
.sheet-head { display: flex; align-items: baseline; justify-content: space-between; flex: none; }
.sheet-head h5 { margin: 0; }
.sheet-list {
  display: flex; flex-direction: column; gap: var(--space-2);
  overflow-y: auto; flex: 1; min-height: 0; padding-bottom: var(--space-2);
  -webkit-overflow-scrolling: touch; touch-action: pan-y;
}

/* ── tab bar ───────────────────────────────────────────────────────────── */
.tabbar {
  flex: none; display: flex; z-index: 600;
  background: var(--color-bg);
  border-top: 1px solid var(--color-divider);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar button {
  flex: 1; border: 0; background: transparent; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 8px 0 9px;
  font: 600 10.5px var(--font-body);
  color: color-mix(in srgb, var(--color-text) 55%, transparent);
}
.tabbar button svg { width: 21px; height: 21px; stroke-width: 2.75; }
.tabbar button[aria-current="page"] { color: var(--color-accent-700); }
.tabbar button:hover { color: var(--color-accent); }

/* ── plain screen header ───────────────────────────────────────────────── */
.topbar {
  flex: none; padding: var(--space-4) var(--space-4) var(--space-3);
  background: var(--color-bg);
}
.topbar h3 { margin: 0; }
.topbar-row { display: flex; align-items: flex-end; justify-content: space-between; gap: var(--space-2); }

.searchrow { display: flex; gap: var(--space-2); margin-top: var(--space-3); }
.input {
  flex: 1; width: 100%; font: 400 14px var(--font-body); color: var(--color-text);
  background: var(--color-bg); border: 1px solid var(--color-divider);
  border-radius: 999px; padding: 9px 14px;
}
.input::placeholder { color: color-mix(in srgb, var(--color-text) 42%, transparent); }
.input:focus-visible { border-color: var(--color-accent); outline: none; }
select.input { flex: none; width: auto; padding-right: var(--space-3); cursor: pointer; }

.list { display: flex; flex-direction: column; gap: var(--space-2); padding: 0 var(--space-4) var(--space-6); }
.empty {
  margin: var(--space-6) var(--space-4); padding: var(--space-6) var(--space-4);
  border-radius: var(--radius-lg); background: var(--color-surface); text-align: center;
}
.empty h5 { margin: 0 0 var(--space-1); }

/* ── detail ────────────────────────────────────────────────────────────── */
.detail {
  position: absolute; inset: var(--banner-total) 0 0 0; z-index: 700;
  background: var(--color-bg); display: flex; flex-direction: column;
  animation: slideup .24s cubic-bezier(.2, .8, .3, 1);
}
@keyframes slideup { from { transform: translateY(18px); opacity: .4; } to { transform: none; opacity: 1; } }

.detail-hero {
  background: var(--color-accent-800); color: var(--color-bg);
  padding: var(--space-3) var(--space-4) var(--space-4);
  flex: none;
}
.detail-hero h3 { margin: var(--space-2) 0 2px; color: var(--color-bg); }
.backbtn {
  display: inline-flex; align-items: center; gap: 5px;
  border: 0; background: transparent; color: var(--color-bg);
  font: 600 12px var(--font-body); padding: 4px 0; cursor: pointer; opacity: .85;
}
.backbtn:hover { opacity: 1; }
.backbtn svg { width: 16px; height: 16px; stroke-width: 2.75; }

.statgrid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px;
  background: var(--color-divider); border-radius: var(--radius-sm); overflow: hidden;
}
.statgrid > div { background: var(--color-bg); padding: 10px 4px; text-align: center; }
.statgrid b { display: block; font-family: var(--font-heading); font-size: 16px; font-weight: 400; }
.statgrid span {
  font-size: 9.5px; text-transform: uppercase; letter-spacing: .07em;
  color: color-mix(in srgb, var(--color-text) 52%, transparent);
}

.section { padding: var(--space-4); border-bottom: 1px solid var(--color-divider); }
.section:last-child { border-bottom: 0; }
.section > h6 { margin: 0 0 var(--space-2); color: var(--color-accent-700); }

.why { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 7px; font-size: 13px; }
.why li { display: flex; gap: 9px; align-items: flex-start; }
.why i { width: 6px; height: 6px; border-radius: 999px; background: var(--color-accent-2-500); margin-top: 6px; flex: none; }
.why i.bad { background: var(--color-accent-500); }

.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-row { display: flex; gap: var(--space-3); align-items: center; padding: 7px 0; font-size: 13px; }
.tl-time { font-family: var(--font-heading); font-size: 14px; width: 68px; flex: none; }
.tl-dot { width: 9px; height: 9px; border-radius: 999px; background: var(--color-accent-400); flex: none; }
.tl-dot.end { background: var(--color-accent-2-600); }

.note {
  margin: 0; font-size: 13px; line-height: 1.5;
  color: color-mix(in srgb, var(--color-text) 78%, transparent);
}
.report { display: flex; gap: var(--space-2); padding: var(--space-2) 0; border-bottom: 1px solid var(--color-divider); }
.report:last-child { border-bottom: 0; }
.report-dot { width: 8px; height: 8px; border-radius: 999px; margin-top: 6px; flex: none; background: var(--color-accent-2-500); }
.report-dot.warn { background: var(--color-accent-500); }
.report b { font-size: 12px; font-weight: 700; }

.actions { display: flex; gap: var(--space-2); padding: var(--space-4); padding-bottom: calc(env(safe-area-inset-bottom) + var(--space-4)); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  font-family: var(--font-heading); font-weight: 400; font-size: 14px; line-height: 1.2;
  padding: 11px var(--space-4); border-radius: 999px; border: 1px solid transparent;
  cursor: pointer; text-decoration: none; color: var(--color-text); background: transparent;
}
.btn-primary { background: var(--color-accent); color: var(--color-bg); flex: 1; }
.btn-primary:hover { background: var(--color-accent-600); }
.btn-primary:active { background: var(--color-accent-700); }
.btn-secondary { border-color: var(--color-divider); }
.btn-secondary:hover { background: color-mix(in srgb, var(--color-text) 7%, transparent); }
.btn-block { width: 100%; }

/* ── modal sheet (clock / filters) ─────────────────────────────────────── */
.modal-backdrop {
  position: absolute; inset: 0; z-index: 800;
  background: color-mix(in srgb, var(--color-neutral-900) 45%, transparent);
  display: flex; align-items: flex-end;
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  width: 100%; background: var(--color-bg);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: var(--space-4) var(--space-4) calc(env(safe-area-inset-bottom) + var(--space-4));
  box-shadow: var(--shadow-lg);
  animation: slideup .2s cubic-bezier(.2, .8, .3, 1);
}
.modal h5 { margin: 0 0 var(--space-3); }
.field { margin-bottom: var(--space-4); }
.field > label { display: block; margin-bottom: 6px; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 6px; }
.field-head b { font-family: var(--font-heading); font-weight: 400; font-size: 14px; }

/* ── log screen ────────────────────────────────────────────────────────── */
.bigstats { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-2); padding: 0 var(--space-4) var(--space-3); }
.bigstat { background: var(--color-surface); border-radius: var(--radius-md); padding: var(--space-3); text-align: center; }
.bigstat b { display: block; font-family: var(--font-heading); font-weight: 400; font-size: 22px; line-height: 1.1; }
.bigstat span { font-size: 10px; text-transform: uppercase; letter-spacing: .07em; color: color-mix(in srgb, var(--color-text) 55%, transparent); }

.progress {
  height: 10px; border-radius: 999px; overflow: hidden; margin: var(--space-2) 0 var(--space-1);
  background: color-mix(in srgb, var(--color-text) 10%, transparent);
}
.progress > div { height: 100%; background: var(--color-accent-2-500); border-radius: 999px; }

.logentry {
  display: flex; gap: var(--space-3); padding: var(--space-3); align-items: flex-start;
  background: var(--color-bg); border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
  border: 0; width: 100%; text-align: left; cursor: pointer; font-family: var(--font-body); color: var(--color-text);
}
.logdate {
  flex: none; width: 46px; text-align: center; border-radius: var(--radius-sm);
  background: var(--color-accent-2-200); color: var(--color-accent-2-800); padding: 5px 0;
}
.logdate b { display: block; font-family: var(--font-heading); font-weight: 400; font-size: 17px; line-height: 1; }
.logdate span { font-size: 9.5px; text-transform: uppercase; letter-spacing: .06em; }
.yearhead { margin: var(--space-4) 0 var(--space-1); }

/* focus ring, per the design system */
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--color-accent); outline-offset: 2px; }
