@font-face { font-family: 'Figtree Variable'; font-style: normal; font-display: swap; font-weight: 300 900;
  src: url(/fonts/figtree-latin-wght-normal.woff2) format('woff2-variations'); }

/* CharterMate "Sun and sea" tokens. Money colours: lagoon = I receive, sun = neutral, coral = I pay. */
:root {
  --deep: #0E3B47; --body-text: #2D5560; --muted: #4F6F78; --line: #E3EEF1; --chip-line: #CFE4EA;
  --lagoon: #0E7C86; --lagoon-dark: #0B6670; --sun: #FFB547; --coral: #F2705B; --sky: #E6F5FB; --sand: #FBF3E4; --field: #F7FBFC;
  --recv: #0E7C86; --neutral: #FFB547; --pay: #F2705B; --unknown: #8A9AA0;
  --font: 'Figtree Variable', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --gutter: max(16px, env(safe-area-inset-left, 0px));
  --gutter-r: max(16px, env(safe-area-inset-right, 0px));
}
*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body { margin: 0; background: #FFFFFF; color: var(--deep); font-family: var(--font); font-size: 15px; line-height: 1.45; -webkit-font-smoothing: antialiased; }
a { color: var(--lagoon-dark); }
a:hover { color: var(--deep); }
button { font-family: inherit; }
:focus-visible { outline: 3px solid var(--sun); outline-offset: 2px; }
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }

.app { display: flex; flex-direction: column; min-height: 100%; }

/* Header and controls */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: max(12px, env(safe-area-inset-top, 0px)) var(--gutter-r) 8px var(--gutter); }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--deep); font-weight: 800; font-size: 19px; }
.brand b { color: var(--lagoon); font-weight: 800; }
.filters-btn { display: inline-flex; align-items: center; gap: 6px; height: 44px; padding: 0 14px; border-radius: 22px;
  border: 1px solid var(--chip-line); background: #FFFFFF; color: var(--deep); font-size: 14px; font-weight: 700; cursor: pointer; }
.filters-btn span:not(:empty) { margin-left: 2px; background: var(--lagoon); color: #FFFFFF; border-radius: 10px; padding: 0 7px; font-size: 12px; line-height: 20px; }

.controls { display: flex; flex-direction: column; gap: 10px; padding: 0 var(--gutter-r) 10px var(--gutter); }
.seg { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; padding: 4px; border-radius: 14px; background: var(--sky); max-width: 560px; }
.seg button { height: 44px; border: 0; border-radius: 11px; background: transparent; color: var(--body-text); font-size: 14px; font-weight: 600; cursor: pointer; }
.seg button[aria-pressed="true"] { background: #FFFFFF; color: var(--deep); font-weight: 800; box-shadow: 0 1px 3px rgba(14, 59, 71, .12); }

.chip-row { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.chip-row::-webkit-scrollbar { display: none; }
.chip { flex-shrink: 0; min-height: 36px; padding: 0 12px; border-radius: 18px; border: 1px solid var(--chip-line); background: #FFFFFF;
  color: var(--deep); font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.chip[aria-pressed="true"] { background: var(--lagoon); border-color: var(--lagoon); color: #FFFFFF; font-weight: 700; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.chip[aria-pressed="true"] .dot { box-shadow: 0 0 0 2px #FFFFFF; }

/* Map and list */
.body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.map-wrap { position: relative; height: 42vh; min-height: 260px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--sky); }
#map { position: absolute; inset: 0; }
.legend { position: absolute; left: 8px; bottom: 8px; display: flex; flex-wrap: wrap; gap: 4px 10px; max-width: calc(100% - 16px);
  padding: 5px 8px; border-radius: 8px; background: rgba(255, 255, 255, .92); font-size: 11px; color: var(--body-text); }
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }

.results { padding: 12px var(--gutter-r) 24px var(--gutter); min-width: 0; }
.results-head { display: flex; align-items: baseline; justify-content: space-between; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 10px; }
.results-head h1 { font-size: 17px; font-weight: 800; }
.results-sub { font-size: 13px; color: var(--muted); }
.list { display: flex; flex-direction: column; gap: 8px; }
.card { text-align: left; width: 100%; display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; border-radius: 14px;
  border: 1px solid var(--line); background: #FFFFFF; color: var(--deep); cursor: pointer; font: inherit; }
.card:hover { border-color: var(--chip-line); }
.card[aria-current="true"] { border-color: var(--lagoon); box-shadow: 0 0 0 1px var(--lagoon); }
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card h2 { font-size: 15px; font-weight: 800; line-height: 1.25; }
.card .sum { font-size: 13px; color: var(--body-text); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.age { display: inline-flex; align-items: center; gap: 6px; }
.fresh { width: 36px; height: 4px; border-radius: 2px; background: var(--line); position: relative; overflow: hidden; display: inline-block; }
.fresh b { position: absolute; left: 0; top: 0; bottom: 0; background: var(--lagoon); }
.money { flex-shrink: 0; font-size: 11px; font-weight: 800; padding: 3px 8px; border-radius: 10px; white-space: nowrap; }
.money.recv { background: var(--recv); color: #FFFFFF; }
.money.neutral { background: var(--neutral); color: var(--deep); }
.money.pay { background: var(--pay); color: #FFFFFF; }
.money.unknown { background: #EEF2F3; color: #4A5E63; }
.empty { padding: 20px 4px; color: var(--muted); }
.empty button { margin-top: 8px; }
.hidden-note { font-size: 13px; color: var(--muted); margin: 12px 0 0; }
.link-btn { border: 0; background: none; color: var(--lagoon-dark); font-weight: 700; font-size: 14px; cursor: pointer; padding: 8px; min-height: 44px; }
.foot { margin-top: 24px; padding-top: 16px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--muted); max-width: 70ch; }
.foot p { margin: 0; }
.addr { font-weight: 700; color: var(--deep); user-select: all; }
.copy { border: 1px solid var(--chip-line); background: #FFFFFF; border-radius: 12px; font-size: 12px; padding: 2px 8px; cursor: pointer; color: var(--deep); }

/* Sheets: listing detail and filters */
.sheet { position: fixed; z-index: 20; background: #FFFFFF; box-shadow: 0 -8px 30px rgba(14, 59, 71, .18);
  left: 0; right: 0; bottom: 0; max-height: 86vh; border-radius: 18px 18px 0 0; overflow: hidden; display: flex; }
.sheet-inner { position: relative; display: flex; flex-direction: column; width: 100%; overflow-y: auto;
  padding: 16px var(--gutter-r) max(20px, env(safe-area-inset-bottom, 0px)) var(--gutter); }
.close { position: absolute; top: 8px; right: max(8px, env(safe-area-inset-right, 0px)); width: 44px; height: 44px; border-radius: 22px; border: 0;
  background: #FFFFFF; color: var(--deep); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.dialog-backdrop { position: fixed; inset: 0; z-index: 19; background: rgba(14, 59, 71, .32); }

.d { display: flex; flex-direction: column; gap: 14px; padding-top: 4px; }
.d-tags { display: flex; flex-wrap: wrap; gap: 6px; padding-right: 48px; }
.tag { font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 10px; background: var(--sky); }
.tag.inf { background: transparent; border: 1px dashed #4A5E63; color: #4A5E63; font-weight: 500; }
.d h2 { font-size: 22px; line-height: 1.2; font-weight: 800; text-wrap: balance; }
.d .age-line { font-size: 13px; color: var(--muted); }
.d .summary { font-size: 15px; }
.facts { border: 1px solid var(--line); border-radius: 14px; }
.facts div { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); font-size: 14px; }
.facts div:last-child { border-bottom: 0; }
.facts dt { color: var(--muted); margin: 0; }
.facts dd { margin: 0; }
.note { padding: 12px 14px; border-radius: 14px; background: var(--sand); font-size: 13px; color: var(--body-text); }
.sources { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.sources b { color: var(--deep); }
.d-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 50px; padding: 0 20px; border-radius: 25px;
  background: var(--lagoon); color: #FFFFFF; text-decoration: none; font-weight: 800; font-size: 16px; border: 0; cursor: pointer; flex: 1; }
.btn:hover { background: var(--lagoon-dark); color: #FFFFFF; }
.btn.ghost { background: #FFFFFF; color: var(--deep); border: 1px solid var(--chip-line); flex: 0 0 auto; font-weight: 700; }
.btn.ghost:hover { background: var(--field); color: var(--deep); }

.filters .sheet-inner { padding-top: 8px; padding-bottom: 0; }
.f-head { display: flex; align-items: center; justify-content: space-between; min-height: 52px; border-bottom: 1px solid var(--line); }
.f-head .close { position: static; }
.f-head h2 { font-size: 18px; font-weight: 800; }
.f-body { display: flex; flex-direction: column; gap: 20px; padding: 16px 0 20px; }
.f-sec { display: flex; flex-direction: column; gap: 10px; }
.f-sec h3 { font-size: 13px; font-weight: 800; color: var(--body-text); display: flex; justify-content: space-between; }
.f-sec h3 small { font-weight: 500; color: var(--muted); }
.wrap-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.band { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px; border-radius: 12px; }
.band h4 { margin: 0; font-size: 12px; font-weight: 800; }
.band.recv { background: #F2FAF9; } .band.recv h4 { color: var(--lagoon-dark); }
.band.neutral { background: #FFF7EA; } .band.neutral h4 { color: #7A4F0E; }
.band.pay { background: #FEF1EE; } .band.pay h4 { color: #A63A25; }
.band.unknown { background: #F4F6F7; } .band.unknown h4 { color: #4A5E63; }
.scale { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.scale i { height: 6px; border-radius: 3px; }
.len { display: flex; flex-direction: column; gap: 10px; padding: 12px 14px; border-radius: 14px; background: var(--field); }
.len-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14px; }
.len-row input[type=number] { width: 84px; height: 44px; padding: 0 10px; border-radius: 10px; border: 1px solid var(--chip-line); font: inherit; font-size: 15px; color: var(--deep); background: #FFFFFF; }
.check { display: flex; align-items: center; gap: 10px; min-height: 44px; font-size: 14px; color: var(--body-text); }
.check input { width: 20px; height: 20px; accent-color: var(--lagoon); }
.f-foot { position: sticky; bottom: 0; background: #FFFFFF; border-top: 1px solid var(--line); padding: 12px 0 max(16px, env(safe-area-inset-bottom, 0px)); display: flex; }

.maplibregl-popup-content { font-family: var(--font); font-size: 13px; padding: 8px 10px; border-radius: 10px; color: var(--deep); }

/* Desktop: map beside the list; sheets on the right */
@media (min-width: 900px) {
  .app { height: 100%; }
  .controls { flex-direction: row; align-items: center; }
  .controls .seg { flex: 0 0 440px; }
  .chip-row { flex: 1; min-width: 0; }
  .body { flex-direction: row; overflow: hidden; }
  .map-wrap { height: auto; flex: 1 1 60%; border-bottom: 0; border-right: 1px solid var(--line); }
  .results { flex: 0 0 420px; overflow-y: auto; border-top: 1px solid var(--line); }
  .sheet { left: auto; top: 0; width: 440px; max-height: none; border-radius: 0; box-shadow: -8px 0 30px rgba(14, 59, 71, .16); }
}
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
