:root {
  --fog: #e6ecee;
  --paper: #f8f9f7;
  --ink: #10222b;
  --ink-soft: #4d626c;
  --line: #cbd6da;
  --teal: #0f5c63;
  --teal-dark: #0a4349;
  --tape: #ffc933;
  --tape-soft: #fff6d6;
  --err: #a3261b;
  --radius: 6px;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Schibsted Grotesk', system-ui, sans-serif;
  color: var(--ink);
  background: var(--fog);
  font-size: 15px;
  line-height: 1.45;
}

.app { display: grid; grid-template-columns: 420px 1fr; height: 100%; }

.panel {
  background: var(--paper);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  padding: 20px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand h1 { margin: 0; font-size: 28px; font-weight: 900; letter-spacing: -0.02em; display: flex; align-items: center; gap: 9px; }
.brand h1 img { display: block; margin-top: -3px; }
.brand p { margin: 4px 0 0; color: var(--ink-soft); }

h2 { margin: 0 0 8px; font-size: 17px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
h3 { margin: 0; font-size: 15px; font-weight: 700; }
.n {
  display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  background: var(--ink); color: #fff; font-size: 13px; font-weight: 700; flex: none;
}
.lead { margin: 0 0 10px; color: var(--ink-soft); }
.lead strong { color: var(--ink); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.step { border-top: 1px solid var(--line); padding-top: 16px; }

.stack { display: flex; flex-direction: column; gap: 12px; }
.sub { margin-top: 14px; padding: 14px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.row { display: flex; align-items: center; gap: 10px; }
#list-actions { justify-content: space-between; margin-top: 10px; }
#count { color: var(--ink-soft); }

label { display: flex; flex-direction: column; gap: 4px; font-weight: 500; }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
label.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
small { color: var(--ink-soft); font-weight: 400; }

input[type='text'], input[type='url'], input[type='search'], select, textarea {
  font: inherit; color: var(--ink); background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 10px 11px; width: 100%;
}
label.inline select { width: auto; }
textarea { resize: vertical; }

button { font: inherit; }
button.primary, button.quiet, #url-form button, .card {
  border-radius: var(--radius); padding: 10px 14px; font-weight: 700; cursor: pointer;
}
button.primary { background: var(--teal); color: #fff; border: 1px solid var(--teal); }
button.primary:hover:not(:disabled) { background: var(--teal-dark); }
button.quiet { background: transparent; border: 1px solid var(--line); color: var(--ink); font-weight: 500; padding: 8px 12px; }
button.quiet:hover, #url-form button:hover { background: var(--tape-soft); }
#url-form button { background: #fff; color: var(--ink); border: 1px solid var(--ink); margin-top: 10px; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.busy { cursor: progress; }

:focus-visible { outline: 3px solid var(--tape); outline-offset: 2px; box-shadow: 0 0 0 1px var(--ink); }

details summary { cursor: pointer; color: var(--ink); font-weight: 500; }
details.more { margin-top: 14px; border: 1px dashed var(--ink-soft); border-radius: var(--radius); padding: 12px; }
details.more[open] { background: #fff; border-style: solid; border-color: var(--line); }
details.more > * + * { margin-top: 12px; }
details > label { margin-top: 10px; }

/* Place search */
.place { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.place #locate { grid-column: 1 / -1; justify-self: start; }

/* Type cards */
.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.card {
  text-align: left; background: #fff; border: 1px solid var(--ink); color: var(--ink);
  display: flex; flex-direction: column; gap: 2px; padding: 11px 12px;
}
.card small { font-weight: 400; }
.card:hover, .card[aria-pressed='true'] { background: var(--tape); }
.card[aria-pressed='true'] small { color: var(--ink); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: var(--fog); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; cursor: pointer; font-weight: 500; }
.chip:hover { background: var(--tape-soft); border-color: var(--ink-soft); }

/* Lists */
.picklist, .rows { list-style: none; margin: 0; padding: 0; border: 1px solid var(--line); border-radius: var(--radius); background: #fff; max-height: 240px; overflow-y: auto; }
.picklist li + li, .rows li + li { border-top: 1px solid var(--line); }
.picklist button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 9px 10px; cursor: pointer; }
.picklist button:hover { background: var(--tape-soft); }
.picklist .t { font-weight: 700; display: block; }
.picklist .s { color: var(--ink-soft); font-size: 13px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.picklist li.hint { padding: 8px 10px; color: var(--ink-soft); font-size: 13px; background: var(--fog); }

.rows li { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 10px; }
.rows .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rows .name button { background: none; border: 0; padding: 4px 0; font: inherit; cursor: pointer; text-align: left; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
.rows .name button:hover { text-decoration: underline; }
.rows .kind { color: var(--ink-soft); font-size: 13px; }
.rows .act { flex: none; border: 1px solid var(--ink); background: #fff; border-radius: var(--radius); padding: 5px 10px; font-weight: 700; cursor: pointer; }
.rows .act:hover:not(:disabled) { background: var(--tape); }
.rows .act.remove { border-color: var(--line); font-weight: 500; }
.rows .act:disabled { border-color: var(--line); color: var(--ink-soft); cursor: default; background: #eef2f3; }
.rows li.preview-hover { background: var(--tape-soft); }

.here { margin-bottom: 12px; }
#here-list { max-height: none; }
.here h3 { margin-bottom: 6px; }

/* Formats */
fieldset.formats { border: 0; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
fieldset.formats legend { font-weight: 700; padding: 0; margin-bottom: 6px; }
label.fmt {
  flex-direction: row; align-items: flex-start; gap: 10px; padding: 10px 12px; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer; font-weight: 400;
}
label.fmt:has(input:checked) { border-color: var(--ink); background: var(--tape-soft); }
label.fmt input { margin-top: 4px; accent-color: var(--teal); }
label.fmt small { display: block; }

#status:empty { display: none; }
#status { padding: 10px 12px; border-left: 4px solid var(--teal); background: #e3eff0; }
#status.error { border-left-color: var(--err); background: #f8e4e1; color: #5d130c; }
#status.busy { border-left-color: var(--tape); background: var(--tape-soft); }

.foot { margin-top: auto; color: var(--ink-soft); font-size: 13px; padding-top: 8px; border-top: 1px solid var(--line); }
.foot p { margin: 4px 0; }
.foot a { color: var(--teal); }

.stage { position: relative; min-width: 0; }
#map { position: absolute; inset: 0; }
#map canvas { cursor: crosshair; }
.sheet-toggle { display: none; }

.maplibregl-popup-content { font-family: inherit; max-width: 280px; max-height: 240px; overflow: auto; }
.maplibregl-popup-content h3 { margin: 0 0 6px; font-size: 14px; }
.maplibregl-popup-content table { border-collapse: collapse; font-size: 12px; }
.maplibregl-popup-content td { padding: 1px 8px 1px 0; vertical-align: top; word-break: break-word; }
.maplibregl-popup-content td:first-child { color: var(--ink-soft); }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 1fr; }
  .stage { grid-area: 1 / 1; }
  .panel {
    grid-area: 1 / 1; z-index: 2; align-self: end; max-height: 58vh; border-right: 0;
    border-top: 1px solid var(--line); box-shadow: 0 -8px 24px rgba(16, 34, 43, 0.18);
  }
  .panel.collapsed { display: none; }
  .sheet-toggle {
    display: block; position: absolute; z-index: 3; top: 12px; left: 12px; background: var(--paper);
    border: 1px solid var(--ink); border-radius: var(--radius); padding: 8px 12px; font-weight: 700;
  }
}

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }

/* ---- Find data ---- */
.find { display: flex; gap: 8px; margin: 10px 0 8px; }
.find input { flex: 1; min-width: 0; }
#find-results h3 { margin: 14px 0 6px; font-size: 14px; }
.results .t { font-weight: 700; display: block; }
.results .s { white-space: normal; }
.picklist.results { max-height: none; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; background: var(--tape); border-radius: 999px; padding: 1px 8px; margin-left: 6px; vertical-align: 1px; }
.badge.soft { background: var(--fog); border: 1px solid var(--line); font-weight: 500; }
.warn { background: #fff4d6; border: 1px solid var(--tape); border-radius: var(--radius); padding: 8px 10px; margin: 0; }
.linkish { background: none; border: 0; padding: 0; color: var(--ink-soft); cursor: pointer; text-align: left; text-decoration: underline; }
#detail-label-wrap small { display: block; color: var(--ink-soft); margin-top: 4px; }
.sub .chips, .chips { margin-bottom: 10px; }

/* ---- Map click modes ---- */
.stage { position: relative; }
.modebar { position: absolute; top: 10px; left: 10px; z-index: 5; display: flex; background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 3px; box-shadow: 0 2px 8px rgba(0,0,0,.18); }
.modebar button { border: 0; background: none; border-radius: 999px; padding: 7px 14px; font-weight: 700; cursor: pointer; }
.modebar button[aria-pressed='true'] { background: var(--tape); }
.modebar button:disabled { opacity: .45; cursor: default; }
.hits { max-width: 280px; max-height: 260px; overflow-y: auto; font-family: inherit; }
.hits .hit + .hit { border-top: 1px solid var(--line); margin-top: 8px; padding-top: 8px; }
.hits .hn { font-weight: 700; }
.hits .hk { color: var(--ink-soft); font-size: 12px; }
.hits .acts { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.hits .acts button { font-size: 12px; padding: 4px 9px; cursor: pointer; }
.hits dl { margin: 6px 0 0; font-size: 12px; display: grid; grid-template-columns: auto 1fr; gap: 2px 8px; }
.hits dt { color: var(--ink-soft); } .hits dd { margin: 0; word-break: break-word; }

/* ---- Source links ---- */
.results li { display: flex; align-items: stretch; }
.results li > button { flex: 1; min-width: 0; }
.src { display: inline-flex; align-items: center; gap: 4px; padding: 0 12px; border-left: 1px solid var(--line); color: var(--ink-soft); font-size: 13px; font-weight: 700; text-decoration: none; white-space: nowrap; }
.src:hover, .src:focus-visible { background: var(--tape-soft); color: var(--ink); }
.src.inline { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px; }

/* ---- List filter, export look ---- */
#list-filter-wrap { margin-bottom: 8px; }
#filter-actions { flex-wrap: wrap; gap: 6px; }
.tucked { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; background: #fff; }
.tucked > * + * { margin-top: 10px; }
.tucked summary { cursor: pointer; font-weight: 700; }
.swatches { display: flex; gap: 14px; flex-wrap: wrap; align-items: end; }
.swatches input[type='color'] { display: block; width: 46px; height: 32px; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: none; cursor: pointer; }
input[type='range'] { width: 100%; }
#size-note { margin: 0; }
#detail-report { font-size: 13px; }

/* ---- Routes ---- */
.modes { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.modes label { cursor: pointer; }
.modes input { position: absolute; opacity: 0; pointer-events: none; }
.modes span { display: inline-block; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--fog); font-weight: 700; }
.modes input:checked + span { background: var(--tape); border-color: var(--ink-soft); }
.modes input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }
#r-stops { list-style: none; max-height: 220px; }
#r-stops li { display: flex; align-items: center; gap: 8px; padding: 6px 10px; }
#r-stops .num, .stop-pin { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: #0a4349; color: #fff; font-weight: 700; font-size: 13px; flex: none; }
.stop-pin { border: 2px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); cursor: grab; }
#r-stops .lbl { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#r-stops button { font-size: 12px; padding: 3px 8px; cursor: pointer; }

/* ---- Right-click "Pick an area" menu ---- */
.pick-pop .maplibregl-popup-content { padding: 0; border-radius: 10px; border: 1px solid var(--ink); box-shadow: 0 6px 22px rgba(0,0,0,.25); overflow: hidden; }
.pick-pop .maplibregl-popup-close-button { font-size: 20px; padding: 6px 10px; }
.pick { font-family: inherit; min-width: min(310px, 78vw); }
.pick-head { font-weight: 900; font-size: 15px; padding: 11px 14px; border-bottom: 1px solid var(--line); }
.pick-list { list-style: none; margin: 0; padding: 4px 0; max-height: 380px; overflow-y: auto; }
.pick-list button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 14px; border: 0; background: none; text-align: left; cursor: pointer; color: var(--ink); font-size: 14px; }
.pick-list button:hover, .pick-list button:focus-visible { background: var(--tape-soft); }
.pick-list button svg { flex: none; }
.pick-list .pn { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 1 auto; min-width: 0; }
.pick-list .pk { color: var(--ink-soft); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 0 100 auto; min-width: 0; }
.pick-list .pk::before { content: '— '; }
.pick-list button.done { cursor: default; }
.pick-list button.done .pk { color: var(--ink); font-weight: 700; }
.pick-note { padding: 10px 14px; color: var(--ink-soft); font-size: 13px; }

/* ---- Fill and outline colors, next to the list ---- */
.colors { display: flex; align-items: center; gap: 16px; margin-top: 10px; padding: 8px 10px; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); }
.colors label { flex-direction: row; align-items: center; gap: 8px; cursor: pointer; }
.colors input[type='color'] { width: 34px; height: 28px; padding: 0; border: 1px solid var(--ink-soft); border-radius: 6px; background: none; cursor: pointer; }
.colors { flex-wrap: wrap; row-gap: 8px; }
.colors label.w select { padding: 4px 6px; font-size: 14px; }
.colors .linkish { margin-left: auto; font-size: 13px; }
.cairn-pin { filter: drop-shadow(0 2px 3px rgba(0,0,0,.35)); pointer-events: none; }

/* ---- Phones: map on top, menu as a bottom sheet, one button to switch ---- */
@media (max-width: 760px) {
  html, body { height: 100dvh; }
  /* The map gets the space above the sheet, so its center (and whatever was just found) is never hidden under it. */
  .app { height: 100dvh; grid-template-rows: minmax(0, 1fr) auto; }
  .stage { grid-area: 1 / 1; min-height: 0; }
  .panel { grid-area: 2 / 1; height: 58dvh; max-height: 58dvh; padding: 14px 14px 10px; gap: 14px; border-radius: 14px 14px 0 0; margin-top: -12px; }
  .brand p { display: none; }
  .brand h1 { font-size: 22px; }
  .brand h1 img { width: 24px; height: 24px; }
  /* 16px stops iPhones from zooming the page when a field is tapped */
  input[type='text'], input[type='url'], input[type='search'], select, textarea { font-size: 16px; }
  .sheet-toggle { top: auto; left: auto; right: 12px; bottom: 24px; border-radius: 999px; padding: 9px 16px; box-shadow: 0 2px 8px rgba(0,0,0,.25); cursor: pointer; }
  .panel-closed .sheet-toggle { bottom: 38px; background: var(--tape); }
  .modebar { top: 8px; left: 8px; }
  .modebar button { padding: 7px 11px; font-size: 14px; }
  .maplibregl-ctrl-top-right { top: 44px; }
  .maplibregl-ctrl-bottom-left, .maplibregl-ctrl-bottom-right { display: none; }
  .panel-closed .maplibregl-ctrl-bottom-right { display: block; }
  .cards { grid-template-columns: 1fr 1fr; }
  .pick { min-width: min(280px, 80vw); }
}

/* ---- Keyboard focus is always visible on map popups ---- */
.pick-list button:focus-visible, .hits button:focus-visible, .modebar button:focus-visible, .maplibregl-popup-close-button:focus-visible, .src:focus-visible { outline: 3px solid var(--ink); outline-offset: -3px; }
.maplibregl-canvas:focus-visible { outline: 3px solid var(--tape); outline-offset: -3px; }
.stop-pin:focus-visible { outline: 3px solid var(--tape); outline-offset: 2px; }
