/* Retning D – «Opp av sofaen»: tykke strek, harde skygger, mint/tomat/solsikke. */
:root {
  --primary: #1f6b4e;
  --primary-deep: #174f3a;
  --primary-50: #e3f1e9;
  --tomato: #f2603d;
  --tomato-ink: #b23a1c;
  --tomato-50: #ffe4dc;
  --sun: #ffc93c;
  --sun-50: #fff4d6;
  --pale: #b7d8c4;
  --danger: #b42318;

  --ink: #13241b;
  --ink-2: #3d5146;
  --muted: #4f6358;
  --line-soft: #d3e8db;
  --field: #f5faf7;
  --surface: #fff;
  --bg: #eaf4ee;

  --stroke: 2.5px solid var(--ink);
  --r: 22px;
  --r-sm: 14px;
  --sh-1: 3px 3px 0 var(--ink);
  --sh-2: 5px 5px 0 var(--ink);
  --sidebar-w: 348px;
  --font: "Bricolage Grotesque", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font: 15px/1.5 var(--font);
  color: var(--ink);
  background: var(--bg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
/* iOS Safari: 100% includes the area under the toolbars; dvh is what is actually visible. */
@supports (height: 100dvh) { body { height: 100dvh; } }

button, a, label, select, summary { touch-action: manipulation; }

/* `hidden` must win over the display rules below (buttons, grids, flex cards). */
[hidden] { display: none !important; }

/* Icon sizing only — must not touch Leaflet's SVG overlay pane. */
.tab svg, .input-icon svg, button svg { width: 1em; height: 1em; flex: none; }

:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }

/* ===================================================== boot overlay === */
.boot {
  position: fixed; inset: 0; z-index: 9000;
  display: grid; place-items: center;
  background: var(--bg);
  transition: opacity .35s ease, visibility .35s;
}
.boot.is-gone { opacity: 0; visibility: hidden; }
.boot-inner { display: flex; align-items: center; gap: 12px; color: var(--ink-2); font-size: 16px; font-weight: 600; }
.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--ink); border-top-color: var(--sun);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* =========================================================== topbar === */
.topbar {
  display: flex; align-items: center; gap: 28px;
  padding: 16px 24px 10px;
  z-index: 500;
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand > div { min-width: 0; }
/* The mascot (docs/avatar.png) carries its own ring, fill and shadow. */
.brand-mark { display: block; width: 68px; height: 68px; flex: none; margin: -4px 0; }
.brand h1 {
  margin: 0; font-size: 32px; font-weight: 800; line-height: 1;
  letter-spacing: -.02em; white-space: nowrap;
}
.brand h1 span {
  display: inline-block; vertical-align: middle;
  margin-left: 6px; padding: 2px 9px;
  font-size: 14px; font-weight: 800; letter-spacing: 0;
  background: var(--sun); border: 2px solid var(--ink); border-radius: 10px;
  transform: rotate(4deg) translateY(-3px);
}
.brand p {
  margin: 4px 0 0; font-size: 14px; font-weight: 600; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.score { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.score-badge {
  width: 84px; height: 84px; border-radius: 50%; flex: none;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: var(--sun); border: var(--stroke); box-shadow: var(--sh-1);
  transform: rotate(4deg);
}
.score-badge strong { font-size: 30px; font-weight: 800; line-height: 1; letter-spacing: -.03em; }
.score-badge span { font-size: 12.5px; font-weight: 600; }
.score-info { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.score-info > span { font-size: 14px; font-weight: 600; white-space: nowrap; }
.score-bar {
  width: 240px; height: 18px; border-radius: 999px; overflow: hidden;
  background: var(--surface); border: var(--stroke);
}
.score-bar i {
  display: block; height: 100%; width: 0;
  background: var(--primary);
  transition: width .45s cubic-bezier(.4, 0, .2, 1);
}

.freshness {
  display: flex; align-items: center; gap: 9px;
  padding: 6px 6px 6px 14px; border: var(--stroke); border-radius: 999px;
  background: var(--surface); font-size: 13px; font-weight: 600; white-space: nowrap;
}
.freshness .dot {
  width: 10px; height: 10px; border-radius: 50%; flex: none;
  background: var(--primary); border: 2px solid var(--ink);
}
.freshness .dot.stale { background: var(--sun); }
.freshness .dot.offline { background: var(--tomato); }

/* ============================================================= tabs === */
.tabs {
  align-self: flex-start;
  display: flex; gap: 4px;
  margin: 2px 24px 16px; padding: 5px;
  background: var(--surface);
  border: var(--stroke); border-radius: 999px;
  z-index: 400;
  max-width: calc(100% - 48px);
}
.tab {
  display: flex; align-items: center; gap: 8px;
  border: 0; border-radius: 999px; background: none; width: auto; margin: 0;
  min-height: 42px; padding: 0 18px; cursor: pointer; box-shadow: none;
  font: inherit; font-size: 15px; font-weight: 600; color: var(--ink);
  white-space: nowrap;
  transition: background .15s, color .15s;
}
.tab svg { font-size: 17px; }
.tab:hover:not(:disabled) { background: var(--primary-50); color: var(--ink); box-shadow: none; transform: none; }
.tab.is-active, .tab.is-active:hover:not(:disabled) { background: var(--primary); color: #fff; font-weight: 800; }

/* ============================================================ views === */
main { flex: 1; min-height: 0; }
.view { display: none; height: 100%; }
.view.is-active { display: flex; gap: 20px; padding: 0 24px 24px; }

.scroll-area { flex: 1; overflow: auto; padding: 4px 8px 16px 0; }
.map-wrap {
  flex: 1; min-width: 0; position: relative;
  background: var(--surface);
  border: var(--stroke); border-radius: 28px;
  box-shadow: var(--sh-2);
  overflow: hidden;
  margin: 0 5px 5px 0;
}
#map, #plan-map { position: absolute; inset: 0; }

/* ========================================================== sidebar === */
.sidebar {
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  padding: 0 8px 8px 0; overflow: auto;
}
.panel {
  background: var(--surface);
  border: var(--stroke);
  border-radius: var(--r);
  box-shadow: var(--sh-2);
  padding: 18px 18px 6px;
  margin-bottom: 18px;
}

.label {
  display: block; font-size: 15px; font-weight: 800; color: var(--ink);
  margin-bottom: 8px;
}
.label b { float: right; font-weight: 600; color: var(--ink-2); font-size: 14px; }
.field { display: block; margin: 0 0 18px; border: 0; padding: 0; }

.input-icon { position: relative; display: block; }
.input-icon svg {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: 17px; color: var(--ink-2); pointer-events: none;
}
input[type="search"], select {
  width: 100%; min-height: 46px; padding: 0 14px; border: 2px solid var(--ink);
  border-radius: var(--r-sm); font: inherit; font-size: 16px; /* < 16px makes iOS zoom on focus */
  background: var(--field); color: var(--ink); transition: box-shadow .15s;
}
.input-icon input { padding-left: 40px; }
input[type="search"]:focus, select:focus {
  outline: 0; box-shadow: 0 0 0 3px var(--sun);
}
select { appearance: none; background-image:
  url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2313241b' stroke-width='2.6'><path d='M6 9l6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px; padding-right: 40px; }

input[type="range"] {
  width: 100%; height: 12px; border-radius: 999px; appearance: none;
  background: var(--field); border: 2px solid var(--ink);
  margin: 10px 0 6px; cursor: pointer;
}
input[type="range"]::-webkit-slider-thumb {
  appearance: none; width: 24px; height: 24px; border-radius: 50%;
  background: var(--sun); border: 2.5px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); cursor: grab;
}
input[type="range"]::-moz-range-thumb {
  width: 20px; height: 20px; border-radius: 50%;
  background: var(--sun); border: 2.5px solid var(--ink); box-shadow: 2px 2px 0 var(--ink); cursor: grab;
}

/* toggle switch */
.switch {
  display: flex; align-items: center; gap: 12px; min-height: 44px; margin-bottom: 8px;
  cursor: pointer; font-size: 15px; font-weight: 600; color: var(--ink);
}
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch i {
  width: 46px; height: 28px; border-radius: 999px; background: var(--field);
  border: 2.5px solid var(--ink);
  position: relative; flex: none; transition: background .18s;
}
.switch i::after {
  content: ""; position: absolute; top: 2px; left: 2px;
  width: 19px; height: 19px; border-radius: 50%; background: var(--surface);
  border: 2px solid var(--ink); box-sizing: border-box; transition: transform .18s;
}
.switch input:checked + i { background: var(--primary); }
.switch input:checked + i::after { transform: translateX(18px); background: var(--sun); }
.switch input:focus-visible + i { outline: 3px solid var(--primary); outline-offset: 2px; }

/* buttons */
button {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font: inherit; font-size: 16px; font-weight: 800;
  min-height: 48px; padding: 0 20px; border-radius: 999px;
  border: var(--stroke); background: var(--primary); color: #fff;
  box-shadow: var(--sh-1);
  cursor: pointer; width: 100%; margin-bottom: 12px;
  transition: background .15s, box-shadow .1s, transform .1s, opacity .15s;
}
button:hover:not(:disabled) { background: var(--primary-deep); transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--ink); }
button:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--ink); }
button:disabled { opacity: .45; cursor: not-allowed; }
button.ghost { background: var(--surface); color: var(--ink); font-weight: 600; }
button.ghost:hover:not(:disabled) { background: var(--primary-50); color: var(--ink); }
button.small { min-height: 44px; padding: 0 16px; font-size: 14px; }
button.danger, .file-label.danger { color: var(--danger); }
button.danger:hover:not(:disabled) { background: #fdecea; color: var(--danger); }

#refresh-btn {
  width: auto; margin: 0; min-height: 34px; padding: 0 14px; font-size: 13px;
  box-shadow: none; border-width: 2px;
}
#refresh-btn:hover:not(:disabled) { transform: none; box-shadow: none; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  min-height: 44px; min-width: 44px; padding: 0 14px;
  border: 2px solid var(--ink); border-radius: 999px;
  background: var(--surface); cursor: pointer; font-size: 15px; font-weight: 600;
  width: auto; margin: 0; color: var(--ink); box-shadow: none;
}
.chip:hover:not(:disabled) { background: var(--sun-50); color: var(--ink); transform: none; box-shadow: none; }
.chip.is-on, .chip.is-on:hover:not(:disabled) { background: var(--ink); color: #fff; font-weight: 800; }

.hint { font-size: 14px; color: var(--muted); margin: 0 0 14px; }
.count {
  font-size: 14px; font-weight: 600; color: var(--ink-2); margin: 0 0 16px; padding: 0 4px;
  font-variant-numeric: tabular-nums;
}
.count b { color: var(--ink); font-weight: 800; }

.legend { font-size: 14px; color: var(--ink); padding-bottom: 16px; }
.legend p { margin: 0 0 10px; }
.legend p.label { margin-bottom: 10px; }
.legend-scale { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; color: var(--ink-2); font-size: 13px; font-weight: 600; }
.legend-scale i {
  flex: 1; height: 14px; border-radius: 999px; border: 2px solid var(--ink);
  background: linear-gradient(90deg, var(--tomato) 0 40%, var(--sun) 65%, var(--pale));
}
.legend-item { display: flex; align-items: center; gap: 10px; }
.swatch { width: 16px; height: 16px; border-radius: 50%; flex: none; border: 2px solid var(--ink); }
.swatch.gem { background: var(--tomato); box-shadow: 0 0 0 3px var(--sun); }
.swatch.done { background: var(--ink); }

/* ====================================================== map popups === */
.leaflet-popup-content-wrapper {
  border-radius: var(--r); border: var(--stroke); box-shadow: var(--sh-2);
  padding: 0; overflow: hidden;
}
.leaflet-popup-content { margin: 0; width: 270px !important; }
.leaflet-popup-tip { border: var(--stroke); box-shadow: none; }
.leaflet-container { font: inherit; background: var(--line-soft); }
.leaflet-control-zoom { border: var(--stroke) !important; border-radius: 16px !important; overflow: hidden; box-shadow: var(--sh-1) !important; }
.leaflet-control-zoom a {
  width: 40px !important; height: 40px !important; line-height: 38px !important;
  color: var(--ink) !important; font: 800 20px var(--font) !important;
}
.leaflet-control-zoom a:first-child { border-bottom: 2px solid var(--ink) !important; }
.leaflet-bar { box-shadow: none !important; }
.leaflet-tooltip {
  border: 2px solid var(--ink); border-radius: 10px; box-shadow: 2px 2px 0 var(--ink);
  font-size: 13px; font-weight: 600; padding: 4px 10px; color: var(--ink);
}
.leaflet-tooltip-top::before { border-top-color: var(--ink); }

.popup .shot { position: relative; height: 150px; background: var(--primary-50); border-bottom: var(--stroke); }
.popup .shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.popup .shot h3 {
  position: absolute; left: 14px; right: 14px; bottom: 10px; margin: 0; z-index: 1;
  font-size: 20px; font-weight: 800; line-height: 1.1; color: #fff; text-shadow: 0 1px 6px rgba(0, 0, 0, .8);
}
.popup .shot::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(transparent 40%, rgba(0, 0, 0, .7));
}
.popup .credit {
  position: absolute; top: 8px; left: 8px; z-index: 2; padding: 1px 8px; border-radius: 999px;
  background: rgba(19, 36, 27, .72); color: #fff; font-size: 11px; font-weight: 600;
}
/* No photo: the mascot on mint, title in ink. */
.popup .shot.none { display: flex; align-items: center; gap: 12px; padding: 12px 14px; height: auto; background: var(--bg); }
.popup .shot.none::after { display: none; }
.popup .shot.none img { width: 72px; height: 72px; flex: none; object-fit: contain; }
.popup .shot.none h3 { position: static; color: var(--ink); text-shadow: none; }
/* Gallery arrows and counter (only when a turmål has several photos). */
.popup .gallery-btn {
  position: absolute; top: 50%; z-index: 2; transform: translateY(-50%);
  width: 40px; min-height: 40px; height: 40px; margin: 0; padding: 0;
  border: 2px solid var(--ink); border-radius: 50%; background: var(--surface); color: var(--ink);
  box-shadow: 2px 2px 0 var(--ink); font-size: 24px; font-weight: 800; line-height: 1;
}
.popup .gallery-btn.prev { left: 8px; }
.popup .gallery-btn.next { right: 8px; }
.popup .gallery-btn:hover:not(:disabled), .popup .gallery-btn:active:not(:disabled) {
  background: var(--sun); transform: translateY(-50%); box-shadow: 2px 2px 0 var(--ink);
}
.popup .gallery-count {
  position: absolute; top: 8px; right: 8px; z-index: 2; padding: 1px 8px; border-radius: 999px;
  background: rgba(19, 36, 27, .72); color: #fff; font-size: 11px; font-weight: 700;
}

/* Small photo thumbnails in lists. */
.thumb {
  flex: none; object-fit: cover; border-radius: 12px; border: 2px solid var(--ink);
  background: var(--primary-50);
}
.thumb.none { object-fit: contain; padding: 6px; background: var(--bg); }
.with-thumb { display: inline-flex; align-items: center; gap: 10px; }
.popup .body { padding: 14px 16px 16px; }
.popup .body > h3 { margin: 0 0 10px; font-size: 22px; font-weight: 800; line-height: 1.1; }
.popup .tags { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.tag {
  font-size: 12.5px; font-weight: 800; padding: 3px 10px; border-radius: 999px;
  border: 2px solid var(--ink); background: var(--sun); color: var(--ink); white-space: nowrap;
}
.tag.gem { background: var(--tomato); color: var(--ink); transform: rotate(-3deg); }
.tag.done { background: var(--primary-50); color: var(--ink); }
.tag.plain { background: var(--surface); color: var(--ink); font-weight: 600; }
.popup .desc {
  font-size: 14px; line-height: 1.5; color: var(--ink-2);
  max-height: 92px; overflow: auto; margin: 0 0 14px;
}
.popup button { margin: 0 0 10px; min-height: 44px; font-size: 15px; }
.popup a { font-size: 14px; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; font-weight: 600; }
.popup a:hover { color: var(--primary); }

/* ===================================================== plan result === */
#plan-result:empty { display: none; }
.plan-summary {
  background: var(--sun); color: var(--ink);
  border: var(--stroke); border-radius: var(--r); box-shadow: var(--sh-2);
  padding: 16px 18px; margin: 6px 0 20px;
}
.plan-summary .big { font-size: 32px; font-weight: 800; letter-spacing: -.02em; line-height: 1.05; }
.plan-summary .sub { font-size: 14px; font-weight: 600; margin-top: 4px; }
.plan-summary .note { font-size: 13px; color: var(--ink-2); margin-top: 6px; }

.route { list-style: none; margin: 0; padding: 0 0 0 2px; }
.route li { position: relative; padding: 0 0 18px 42px; }
.route li::before {
  content: attr(data-step);
  position: absolute; left: 0; top: 0;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--tomato); color: var(--ink); border: 2.5px solid var(--ink);
  font-size: 14px; font-weight: 800; display: grid; place-items: center;
}
.route li::after {
  content: ""; position: absolute; left: 14px; top: 32px; bottom: 2px;
  border-left: 2.5px dashed var(--ink);
}
.route li:last-child { padding-bottom: 0; }
.route li:last-child::after { display: none; }
.route .name { font-weight: 800; font-size: 16px; }
.route .stop { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.route .meta { font-size: 13px; color: var(--muted); }

/* ======================================================== analysis === */
.analysis-grid {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px; max-width: 1240px; margin: 0 auto;
}
.card {
  background: var(--surface); border: var(--stroke);
  border-radius: var(--r); padding: 20px 22px; box-shadow: var(--sh-2);
}
.card.wide { grid-column: 1 / -1; }
.card h2 { margin: 0 0 4px; font-size: 24px; font-weight: 800; letter-spacing: -.02em; }
.card .hint { margin-bottom: 16px; }
.chart { height: 300px; position: relative; }

.stats {
  grid-column: 1 / -1;
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px;
}
.stat { min-width: 0; }
.stat {
  background: var(--surface); border: var(--stroke); border-radius: 18px;
  padding: 14px 18px; box-shadow: var(--sh-1);
}
.stat.gem { background: var(--tomato-50); }
.stat.done { background: var(--sun); }
.stat b {
  display: block; font-size: 24px; font-weight: 800; letter-spacing: -.02em;
  color: var(--ink); line-height: 1.2;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.stat span { font-size: 13px; color: var(--ink-2); font-weight: 600; }
.stat em { display: block; font-style: normal; font-size: 13px; color: var(--ink-2); margin-top: 2px; }

.table-wrap { max-height: 400px; overflow: auto; border-radius: var(--r-sm); border: 2px solid var(--ink); }
table { width: 100%; border-collapse: collapse; font-size: 14.5px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1.5px solid var(--line-soft); }
th {
  position: sticky; top: 0; z-index: 1; background: var(--field);
  font-size: 13px; color: var(--ink); font-weight: 800; border-bottom: 2px solid var(--ink);
}
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: var(--primary-50); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.rank { color: var(--muted); font-variant-numeric: tabular-nums; width: 40px; font-weight: 600; }
tr.top td.rank { color: var(--tomato-ink); font-weight: 800; }
td.name { font-weight: 600; }
td.area-cell { color: var(--muted); font-size: 13.5px; }
.score-pill {
  display: inline-block; min-width: 50px; padding: 1px 10px; border-radius: 999px; text-align: center;
  background: var(--tomato-50); border: 2px solid var(--ink); color: var(--ink); font-weight: 800; font-size: 13px;
}
.bar { height: 12px; border-radius: 999px; background: var(--field); border: 2px solid var(--ink); overflow: hidden; min-width: 60px; }
.bar i { display: block; height: 100%; background: var(--primary); }

/* ======================================================= checklist === */
.checklist-page { max-width: 1100px; margin: 0 auto; }
.toolbar { display: flex; gap: 10px; margin-bottom: 22px; flex-wrap: wrap; }
.toolbar button, .file-label { width: auto; margin: 0; }
.file-label {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px;
  border: var(--stroke); border-radius: 999px; box-shadow: var(--sh-1);
  color: var(--ink); background: var(--surface); cursor: pointer;
  font-size: 14px; font-weight: 600;
}
.file-label:hover { background: var(--primary-50); }

.area {
  background: var(--surface); border: var(--stroke); border-radius: var(--r);
  padding: 18px 20px; margin-bottom: 18px; box-shadow: var(--sh-2); break-inside: avoid;
}
.area-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.area-head h3 { margin: 0; font-size: 20px; font-weight: 800; letter-spacing: -.01em; flex: 1; }
.area-head .bar { width: 100px; flex: none; }
.area-head small { color: var(--ink-2); font-size: 13px; font-weight: 600; white-space: nowrap; font-variant-numeric: tabular-nums; }
.area ul { list-style: none; margin: 0; padding: 0; columns: 2; column-gap: 32px; }
.area li {
  display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 2px 0;
  font-size: 15px; break-inside: avoid;
}
.area li label { display: flex; align-items: center; gap: 10px; flex: 1; cursor: pointer; min-width: 0; }
.area li .txt { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.area li input { accent-color: var(--primary); width: 20px; height: 20px; flex: none; cursor: pointer; }
.area li.done .txt { color: var(--primary); text-decoration: line-through; }
.area li em { font-style: normal; font-size: 13px; font-weight: 600; color: var(--muted); margin-left: auto; flex: none; }
.area li.gem em { color: var(--tomato-ink); font-weight: 800; }

/* ======================================================= statistikk === */
.stats-page { max-width: 1240px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.stats-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 12px 24px; }
.stats-head h2 { margin: 0; font-size: 32px; font-weight: 800; letter-spacing: -.02em; line-height: 1.1; }
.stats-head .hint { margin: 4px 0 0; }
.stats-head .toolbar { margin: 0; }
.stats-filters {
  display: grid; grid-template-columns: minmax(150px, 1fr) minmax(200px, 2fr) minmax(190px, 1.2fr) auto;
  align-items: end; gap: 0 18px; margin: 0; padding-bottom: 10px;
}
.stats-filters .switch { margin-bottom: 18px; white-space: nowrap; }
.stats-page .count { margin: 0; }
.stats-loading {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  min-height: 260px; padding: 40px 24px; text-align: center;
  background: var(--surface); border: var(--stroke); border-radius: var(--r); box-shadow: var(--sh-2);
}
.stats-locked {
  display: flex; flex-direction: column; align-items: stretch; gap: 12px;
  width: 100%; max-width: 440px; margin: 8px auto; padding: 28px;
  background: var(--surface); border: var(--stroke); border-radius: var(--r); box-shadow: var(--sh-2);
}
.stats-locked .lock {
  width: 52px; height: 52px; padding: 11px; align-self: center;
  color: var(--ink); background: var(--sun); border: var(--stroke); border-radius: 50%;
}
.stats-locked h3 { margin: 0; text-align: center; font-size: 24px; font-weight: 800; }
.stats-locked .field { margin: 6px 0 0; }
.stats-locked input[type="password"] {
  width: 100%; min-height: 48px; padding: 0 14px; border: 2px solid var(--ink); border-radius: var(--r-sm);
  background: var(--field); color: var(--ink); font: inherit; font-size: 16px;
}
.stats-locked input[type="password"]:focus { outline: 0; box-shadow: 0 0 0 3px var(--sun); }
.stats-locked .error { margin: 0; color: var(--danger); font-weight: 600; }
.stats-locked button { margin: 4px 0 0; }
.stats-loading b { font-size: 20px; font-weight: 800; }
.stats-loading .hint { margin: 0; }
.stats-loading .spinner { width: 56px; height: 56px; border-width: 5px; margin-bottom: 6px; }
.stats-page.is-loading .stats-filters, .stats-page.is-loading .count { opacity: .5; pointer-events: none; }
/* Before the first answer we don't know yet whether to show the table or the login card. */
.stats-page.is-pending .stats-filters, .stats-page.is-pending .count, .stats-page.is-pending .stats-head .toolbar { display: none; }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
.stats-table { max-height: none; }
.stats-table th { white-space: nowrap; }
.stats-table td.fav, .stats-table th.fav { width: 44px; padding: 0 0 0 6px; }
tr.is-fav td { background: var(--sun-50); }

/* Table buttons must not inherit the big primary-button look. */
button.star, button.link {
  width: auto; min-height: 0; margin: 0; padding: 0; border: 0; border-radius: 8px;
  background: none; box-shadow: none; color: var(--ink); font-weight: 600;
}
button.star:hover:not(:disabled), button.link:hover:not(:disabled) { background: none; transform: none; box-shadow: none; }
button.star { width: 40px; height: 40px; font-size: 22px; line-height: 1; color: var(--muted); }
button.star[aria-pressed="true"] { color: var(--tomato-ink); }
button.link { font-size: inherit; text-align: left; text-decoration: underline; text-decoration-color: var(--line-soft); text-underline-offset: 3px; }
button.link:hover:not(:disabled) { color: var(--primary); text-decoration-color: currentColor; }
.team-inline { display: none; font-size: 13px; font-weight: 400; color: var(--muted); margin-top: 1px; }
.up { color: var(--primary); font-weight: 800; }
.muted { color: var(--muted); }

.person-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.person-head h3 { margin: 0; font-size: 24px; font-weight: 800; }
.person-head .hint { margin: 2px 0 0; }
.person-head button { width: auto; margin: 0; }

.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;
}

/* =========================================================== print === */
@media print {
  body { height: auto; overflow: visible; display: block; background: #fff; }
  .topbar, .tabs, .no-print, .boot { display: none !important; }
  .view { display: none !important; }
  #view-checklist.is-active { display: block !important; padding: 0; }
  .scroll-area { padding: 0; overflow: visible; }
  .area { border: 1px solid #999; box-shadow: none; page-break-inside: avoid; }
  .area-head .bar { display: none; }
}

/* ===================================================== touch / iOS === */
/* Hover lift only where there is a real pointer – on iPhone/iPad :hover sticks after a tap. */
@media (hover: none) {
  button:hover:not(:disabled) { transform: none; box-shadow: var(--sh-1); background: var(--primary); }
  button.ghost:hover:not(:disabled) { background: var(--surface); }
  button.danger:hover:not(:disabled) { background: var(--surface); }
  .tab:hover:not(:disabled), .chip:hover:not(:disabled), button.star:hover:not(:disabled),
  button.link:hover:not(:disabled) { background: none; box-shadow: none; }
  .tab.is-active:hover:not(:disabled) { background: var(--primary); }
  .chip.is-on:hover:not(:disabled) { background: var(--ink); }
  #refresh-btn:hover:not(:disabled) { background: var(--primary); }
  tbody tr:hover td { background: none; }
  tr.is-fav:hover td { background: var(--sun-50); }
}
@media (pointer: coarse) {
  .area li { min-height: 44px; }
  .area li input { width: 22px; height: 22px; }
}

/* ===================================================== iPad portrait === */
@media (max-width: 1000px) {
  :root { --sidebar-w: 290px; }
  .view.is-active { gap: 16px; padding: 0 max(16px, env(safe-area-inset-right)) 16px max(16px, env(safe-area-inset-left)); }
  .sidebar .panel { padding: 16px 16px 4px; }
  .topbar { gap: 16px; padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  .brand p { display: none; }
  .score-bar { width: 150px; }
  .freshness span:not(.dot) { display: none; }
  .freshness { padding: 4px; }
  .tabs { margin-left: 16px; margin-right: 16px; max-width: calc(100% - 32px); }
  .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .stats-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats-filters .switch { margin-bottom: 14px; }
  .opt-md { display: none; }
  .stats-table th { white-space: normal; line-height: 1.2; }
  .stats-table th, .stats-table td { padding: 10px; }
}

/* ================================================= phone landscape === */
/* Wide but short (iPhone sideways): squeeze the header and tabs so the map gets the height. */
@media (max-height: 500px) and (min-width: 761px) {
  .topbar { padding-top: max(6px, env(safe-area-inset-top)); padding-bottom: 6px; gap: 12px; }
  .brand-mark { width: 42px; height: 42px; margin: 0; }
  .brand h1 { font-size: 22px; }
  .brand h1 span, .score-info { display: none; }
  .score-badge { width: 46px; height: 46px; box-shadow: 2px 2px 0 var(--ink); }
  .score-badge strong { font-size: 17px; }
  .score-badge span { font-size: 9.5px; }
  .tabs { margin-top: 0; margin-bottom: 8px; padding: 3px; }
  .tab { min-height: 34px; padding: 0 14px; font-size: 14px; }
  .view.is-active { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
}

/* ============================================================ phone === */
@media (max-width: 760px) {
  /* Tabs become a bottom bar, like an iOS app, clear of the home indicator. */
  .tabs {
    order: 3; align-self: stretch; z-index: 600;
    margin: 0; max-width: none; padding: 6px 4px max(6px, env(safe-area-inset-bottom));
    border: 0; border-top: var(--stroke); border-radius: 0; gap: 0;
  }
  .tab {
    flex: 1 1 0; min-width: 0; flex-direction: column; gap: 3px;
    min-height: 52px; padding: 4px 2px; border-radius: 14px;
    font-size: 11.5px; font-weight: 600; letter-spacing: -.01em;
  }
  .tab svg { font-size: 22px; }
  .tab.is-active, .tab.is-active:hover:not(:disabled) { background: var(--primary-50); color: var(--ink); font-weight: 800; }
  .tab.is-active svg { color: var(--primary); }

  .topbar { gap: 10px; padding: max(10px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) 10px max(14px, env(safe-area-inset-left)); }
  .brand { flex: 1 1 auto; gap: 10px; }
  .brand h1 { font-size: 24px; overflow: hidden; text-overflow: ellipsis; }
  .brand h1 span { display: none; }
  .brand-mark { width: 50px; height: 50px; margin: -2px 0; }
  .score { flex: none; gap: 0; }
  .score-badge { width: 58px; height: 58px; box-shadow: 2px 2px 0 var(--ink); }
  .score-badge strong { font-size: 21px; }
  .score-badge span { font-size: 11px; }
  .score-info { display: none; }
  .freshness { border: 0; background: none; padding: 0; gap: 8px; }
  #refresh-btn { width: 44px; min-height: 44px; padding: 0; border-radius: 50%; font-size: 18px; }
  #refresh-btn span { display: none; }

  /* Map views: the map first, controls scroll underneath. */
  .view.is-active { flex-direction: column; gap: 16px; padding: 0 max(14px, env(safe-area-inset-right)) 16px max(14px, env(safe-area-inset-left)); overflow-y: auto; }
  #view-map.is-active, #view-planner.is-active { -webkit-overflow-scrolling: touch; }
  .map-wrap { order: -1; flex: none; height: 58vh; height: 58dvh; min-height: 300px; border-radius: 22px; margin: 0 4px 4px 0; box-shadow: var(--sh-1); }
  .sidebar { width: auto; flex: none; max-height: none; overflow: visible; padding: 0 4px 4px 0; }
  .panel { box-shadow: var(--sh-1); }

  .scroll-area { padding: 0 4px 4px 0; overflow: visible; }
  .view#view-analysis.is-active, .view#view-checklist.is-active, .view#view-stats.is-active { display: block; }
  .analysis-grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
  .stat { padding: 12px 14px; }
  .stat b { font-size: 20px; }
  .card { padding: 16px; box-shadow: var(--sh-1); }
  .card h2 { font-size: 21px; }
  .chart { height: 260px; }
  .table-wrap { max-height: none; }

  .area { padding: 16px; box-shadow: var(--sh-1); }
  .area ul { columns: 1; }
  .area-head { flex-wrap: wrap; gap: 6px 12px; }
  .area-head h3 { flex: 1 1 100%; font-size: 18px; }
  .area-head .bar { flex: 1 1 auto; }

  .stats-head h2 { font-size: 26px; }
  .stats-head .toolbar { width: 100%; }
  .stats-head .toolbar button { flex: 1 1 auto; }
  /* Search on its own row, day + sort side by side, toggle last. */
  .stats-filters { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; padding: 14px 14px 4px; }
  .stats-filters .field { margin-bottom: 12px; }
  .stats-filters .field:nth-child(2) { order: -1; grid-column: 1 / -1; }
  .stats-filters .switch { grid-column: 1 / -1; margin-bottom: 6px; }
  .stats-card { padding: 0; border: 0; box-shadow: none; background: none; }
  .opt-sm { display: none; }
  .team-inline { display: block; }
  .stats-table th, .stats-table td { padding: 10px 8px; }
  .stats-table th { white-space: normal; font-size: 12px; line-height: 1.2; }
  .person-head h3 { font-size: 21px; }
}
