:root {
  --paramo: #2E4A3B;      /* moss green of the high páramo */
  --paramo-soft: #DCE6DF;
  --mist: #EEF2EF;        /* cloud-forest mist */
  --paper: #FFFFFF;
  --basalt: #2A2725;      /* volcanic rock */
  --muted: #66706A;
  --line: #CCD6CF;
  --pacific: #1D6A86;
  --sun: #F0C419;         /* flag yellow */
  --stay: #B8323A;        /* Otavalo textile red */
  --radius-s: 6px;
  --radius-m: 10px;
  --display: 'Bricolage Grotesque', 'Segoe UI', system-ui, sans-serif;
  --body: 'Figtree', 'Segoe UI', system-ui, sans-serif;
  --panel-w: clamp(360px, 34vw, 480px);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 var(--body); color: var(--basalt); background: var(--mist); }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--pacific); outline-offset: 2px; }

button {
  cursor: pointer; border: 1px solid var(--paramo); background: var(--paramo); color: #fff;
  border-radius: var(--radius-s); padding: 6px 12px; font-weight: 600;
}
button:hover { filter: brightness(1.12); }
button:disabled { opacity: .5; cursor: default; }
button.ghost { background: var(--paper); color: var(--paramo); }
button.link { background: none; border: 0; padding: 0; color: inherit; text-decoration: underline; font-weight: 500; }
button.icon { background: none; border: 0; color: var(--muted); padding: 2px 6px; font-weight: 500; line-height: 1; }
button.icon:hover { color: var(--basalt); background: var(--mist); filter: none; }
input, select, textarea { border: 1px solid var(--line); border-radius: var(--radius-s); padding: 6px 8px; background: var(--paper); }
input[type=checkbox], input[type=radio] { accent-color: var(--paramo); }
.hint { color: var(--muted); font-size: 13px; margin: 6px 0 0; }

/* ---------- app shell ---------- */
.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.bar {
  display: flex; align-items: center; gap: 16px; padding: 8px 16px;
  background: var(--paramo); color: #fff; flex: none;
}
.brand { display: flex; align-items: center; gap: 10px; font: 700 21px/1 var(--display); letter-spacing: -.01em; min-width: 0; }
.brand span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mark { width: 30px; height: 30px; color: var(--sun); flex: none; }
.modes { display: flex; margin: 0 auto; background: rgba(255,255,255,.12); border-radius: 999px; padding: 3px; }
.modes button { background: none; border: 0; border-radius: 999px; padding: 6px 16px; color: #fff; font-weight: 600; }
.modes button[aria-selected=true] { background: var(--sun); color: var(--basalt); }
.who { display: flex; gap: 12px; align-items: center; font-size: 14px; white-space: nowrap; }

.layout { flex: 1; display: grid; grid-template-columns: 1fr var(--panel-w); min-height: 0; }
.map-wrap { position: relative; min-height: 0; }
#map { position: absolute; inset: 0; background: #cfdcd4; }

.map-card {
  position: absolute; z-index: 500; top: 12px; left: 56px; width: min(360px, calc(100% - 72px));
  background: var(--paper); border-radius: var(--radius-m); padding: 10px; box-shadow: 0 2px 12px rgba(30,45,38,.22);
}
#searchForm { display: flex; gap: 6px; }
#searchForm input { flex: 1; min-width: 0; }
.tool-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; font-size: 14px; flex-wrap: wrap; }
.tool-row button { padding: 4px 10px; font-size: 13px; }
.results { list-style: none; margin: 8px 0 0; padding: 0; max-height: 40vh; overflow: auto; border-top: 1px solid var(--line); }
.results li button { width: 100%; text-align: left; background: none; border: 0; color: var(--basalt); padding: 7px 4px; border-bottom: 1px solid var(--mist); border-radius: 0; font-weight: 600; }
.results li button small { display: block; font-weight: 400; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.results li button:hover { background: var(--mist); filter: none; }

body.mode-discover .itinerary-only, body.mode-itinerary .discover-only { display: none; }

#legend { font-size: 13px; }
#legend h3 { margin: 0 0 6px; font: 600 14px var(--display); }
#legend ul { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
#legend li { display: flex; align-items: center; gap: 8px; }
#legend .sw { width: 18px; height: 4px; border-radius: 2px; flex: none; }
#legend .sw.dash { background: repeating-linear-gradient(90deg, var(--muted) 0 4px, transparent 4px 7px) !important; }

/* ---------- itinerary panel ---------- */
.panel { background: var(--paper); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; overflow: auto; }
.panel-head { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--paper); z-index: 2; }
.plan-row { display: flex; align-items: center; gap: 10px; }
.plan-row label { font: 600 15px var(--display); }
.plan-row select { flex: 1; font-weight: 600; }
.plan-note { margin: 8px 0 0; font-size: 13px; color: var(--muted); }
.plan-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; font-size: 13px; }
.plan-actions button { font-size: 13px; padding: 4px 10px; }
.plan-actions label { display: flex; gap: 6px; align-items: center; }
.trip-settings { margin-top: 10px; font-size: 14px; }
.trip-settings summary { cursor: pointer; color: var(--paramo); font-weight: 600; }
#settingsForm { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 8px; }
#settingsForm label { display: grid; gap: 2px; font-size: 13px; color: var(--muted); }
#settingsForm label:first-child { grid-column: 1 / -1; }
#settingsForm button { grid-column: 1 / -1; justify-self: start; }

.days { list-style: none; margin: 0; padding: 8px 16px 40px; display: grid; gap: 10px; }

/* Each day carries a woven band in its route colour — the same colour as its line on the map. */
.day {
  --c: var(--pacific);
  position: relative; padding: 10px 12px 10px 22px; border-radius: var(--radius-m);
  background: var(--mist); border: 1px solid transparent; cursor: default;
}
.day::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 10px; border-radius: var(--radius-m) 0 0 var(--radius-m);
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.35) 0 2px, transparent 2px 6px),
    repeating-linear-gradient(-45deg, rgba(0,0,0,.18) 0 2px, transparent 2px 6px),
    var(--c);
}
.day.active { border-color: var(--c); background: var(--paper); box-shadow: 0 0 0 1px var(--c); }
.day.beyond { opacity: .75; }
.day-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; cursor: pointer; }
.day-head h3 { margin: 0; font: 700 17px var(--display); }
.day-head .date { color: var(--muted); font-size: 14px; }
.day-head .drive { margin-left: auto; font-size: 13px; color: var(--muted); }
.day-links { display: flex; gap: 12px; font-size: 13px; margin-top: 2px; }
.day-links a, .day-links button.link { color: var(--pacific); font-size: 13px; }

.stops { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 4px; }
.stop { display: grid; grid-template-columns: 24px 1fr auto; gap: 8px; align-items: start; background: var(--paper); border-radius: var(--radius-s); padding: 6px 6px 6px 8px; border: 1px solid var(--line); }
.day.active .stop { background: var(--mist); border-color: transparent; }
.stop .n { width: 22px; height: 22px; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center; font-size: 12px; font-weight: 700; margin-top: 1px; }
.stop.wake, .stop.sleep { border-style: dashed; }
.stop.stay .n { background: var(--stay); border-radius: 5px; }
.stop.wake .n { background: none; border: 2px solid var(--stay); color: var(--stay); }
.stop .t { min-width: 0; }
.stop .name { font-weight: 600; cursor: pointer; overflow-wrap: anywhere; }
.stop .meta { font-size: 12px; color: var(--muted); }
.stop .notes { font-size: 13px; color: var(--basalt); white-space: pre-wrap; margin-top: 2px; }
.stop .ctl { display: flex; align-items: center; gap: 0; flex-wrap: wrap; justify-content: flex-end; }
.stop .ctl select { padding: 1px 2px; font-size: 12px; max-width: 74px; }
.stop .ctl input[type=number] { width: 44px; padding: 1px 4px; font-size: 12px; }
.stop .ctl .nights { display: flex; align-items: center; gap: 3px; font-size: 12px; color: var(--muted); margin-left: 4px; }
.stop textarea { width: 100%; margin-top: 4px; font-size: 13px; min-height: 52px; }
.empty-stay { font-size: 13px; color: var(--muted); padding: 4px 8px; border: 1px dashed var(--line); border-radius: var(--radius-s); margin-top: 4px; }
.day-empty { font-size: 13px; color: var(--muted); margin: 6px 0 0; }
.added-by { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 999px; color: #fff; margin-left: 4px; vertical-align: 1px; }

/* ---------- map markers & popups ---------- */
.pin {
  width: 26px; height: 26px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg);
  background: var(--c, var(--pacific)); border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.35);
  display: grid; place-items: center;
}
.pin b { transform: rotate(45deg); color: #fff; font: 700 11px var(--body); }
.pin.stay { border-radius: 6px; transform: none; }
.pin.stay b { transform: none; }
.pin.faded { opacity: .55; }
.hl { width: 14px; height: 14px; background: var(--sun); border: 2px solid var(--basalt); transform: rotate(45deg); border-radius: 2px; }
.res { width: 14px; height: 14px; background: var(--pacific); border: 2px solid #fff; border-radius: 50%; box-shadow: 0 0 0 2px var(--pacific); }
.poi-dot { width: 10px; height: 10px; background: #fff; border: 3px solid var(--paramo); border-radius: 50%; }

.leaflet-popup-content { margin: 12px 14px; font: 14px/1.4 var(--body); }
.leaflet-popup-content-wrapper { border-radius: var(--radius-m); }
.add-pop { width: 250px; }
.add-pop .ttl { font: 700 16px/1.2 var(--display); margin: 0; }
.add-pop .name-input { width: 100%; font: 700 15px var(--display); }
.add-pop .sub { color: var(--muted); font-size: 12px; margin: 2px 0 6px; }
.add-pop .blurb { margin: 0 0 6px; }
.add-pop form { display: grid; gap: 6px; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 6px; }
.add-pop label { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-size: 13px; }
.add-pop .kinds { display: flex; gap: 4px; }
.add-pop .kinds label { flex: 1; justify-content: center; border: 1px solid var(--line); border-radius: var(--radius-s); padding: 4px; cursor: pointer; }
.add-pop .kinds input { position: absolute; opacity: 0; }
.add-pop .kinds label:has(input:checked) { background: var(--paramo); color: #fff; border-color: var(--paramo); }
.add-pop .kinds label:has(input:focus-visible) { outline: 2px solid var(--pacific); }
.add-pop select, .add-pop input[type=number] { width: 150px; padding: 3px 6px; }
.add-pop input.note { width: 100%; }
.add-pop .links { font-size: 12px; }
.add-pop .links a { color: var(--pacific); }
.add-pop .in-plans { font-size: 12px; color: var(--muted); margin: 4px 0 0; }

#toast {
  position: fixed; left: 50%; bottom: 20px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--basalt); color: #fff; padding: 9px 16px; border-radius: 999px; font-size: 14px; z-index: 2000;
  transition: opacity .2s, transform .2s; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--stay); }

/* ---------- login ---------- */
.login { display: grid; place-items: center; min-height: 100vh; background: var(--paramo); color: #fff; padding: 16px; }
.login-wrap { width: min(440px, 100%); }
.login-title .ridge { width: 100%; height: 70px; color: var(--sun); display: block; }
.login-title h1 { font: 700 clamp(56px, 16vw, 88px)/0.9 var(--display); letter-spacing: -.03em; margin: 8px 0 10px; }
.login-title p { margin: 0 0 24px; color: var(--paramo-soft); max-width: 36ch; }
.login-form { display: grid; gap: 12px; background: var(--paper); color: var(--basalt); padding: 20px; border-radius: var(--radius-m); }
.login-form label { display: grid; gap: 4px; font-weight: 600; font-size: 14px; }
.login-form button { padding: 9px; font-size: 16px; }
.err { color: var(--stay); margin: 0; min-height: 1.2em; font-size: 14px; }

/* ---------- small screens: map on top, itinerary below ---------- */
@media (max-width: 860px) {
  .bar { flex-wrap: wrap; gap: 8px; padding: 8px 12px; }
  .modes { order: 3; margin: 0; width: 100%; }
  .modes button { flex: 1; }
  .who { margin-left: auto; }
  .app { height: auto; min-height: 100dvh; }
  .layout { grid-template-columns: 1fr; }
  .map-wrap { height: 58vh; }
  .map-card { left: 12px; width: calc(100% - 24px); top: auto; bottom: 12px; }
  .map-card .hint { display: none; }
  .panel { border-left: 0; border-top: 1px solid var(--line); overflow: visible; }
  .panel-head { position: static; }
  .days { padding: 8px 12px 32px; }
  .stop { grid-template-columns: 24px 1fr; }
  .stop .ctl { grid-column: 2; justify-content: flex-start; }
  .stop .ctl:empty { display: none; }
}
@media (prefers-reduced-motion: reduce) { #toast { transition: none; } }
