:root {
  --bg: #ffffff;
  --fg: #1c2430;
  --muted: #6b7580;
  --line: #e2e6ea;
  --accent: #2c6bac;
  --shadow: 0 2px 12px rgba(0,0,0,.18);
  --header-h: 50px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--fg); overflow-x: hidden; }
#map { position: absolute; inset: 0; z-index: 0; background: #eaeaea; }

/* keep Leaflet's own controls (zoom top-left, layers top-right) below the header */
.leaflet-top { margin-top: var(--header-h); }

/* top bar */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 1100; height: var(--header-h);
  display: flex; align-items: center; gap: 8px; padding: 0 10px;
  background: rgba(255,255,255,.95); backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
}
#topbar .title { font-weight: 700; font-size: 15px; white-space: nowrap; min-width: 0; flex-shrink: 1; overflow: hidden; text-overflow: ellipsis; }
#topbar .count { color: var(--muted); font-size: 13px; white-space: nowrap; }
#topbar .spacer { flex: 1; }
button { cursor: pointer; font: inherit; padding: 8px 12px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--fg); }
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
button.ghost { background: #f4f6f8; }
input, select { font: inherit; padding: 7px 8px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--fg); }

/* legend */
#legend {
  position: absolute; left: 10px; bottom: 12px; z-index: 500;
  background: rgba(255,255,255,.95); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); padding: 8px 10px; font-size: 12px; max-width: 55vw;
}
#legend .row { display: flex; align-items: center; gap: 6px; }
#legend .pill { font-size: 10px; }
#legend .bar { height: 10px; border-radius: 5px; margin-top: 5px;
  background: linear-gradient(90deg,#00ff00,#ffff00,#ff0000); }
#legend .ends { display: flex; justify-content: space-between; color: var(--muted); margin-top: 2px; }

/* sheets */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1200;
  background: var(--bg); border-top-left-radius: 16px; border-top-right-radius: 16px;
  box-shadow: 0 -4px 20px rgba(0,0,0,.22); max-height: 84vh; overflow-x: hidden; overflow-y: auto;
  transform: translateY(110%); transition: transform .22s ease, max-height .22s ease; padding: 12px 16px 20px;
}
.sheet.open { transform: translateY(0); }
/* detail on mobile: peek at 45vh so map stays visible; grab to expand */
#detail.open { max-height: 45vh; }
#detail.open.expanded { max-height: 84vh; }
/* hide legend behind open detail sheet on mobile */
#legend.behind { display: none; }
.sheet .grab { width: 40px; height: 4px; background: #cfd6dd; border-radius: 3px; margin: 0 auto 8px; }
.sheet h2 { margin: 2px 0 8px; font-size: 17px; }
.sheet .close { position: absolute; top: 8px; right: 12px; border: none; background: none; font-size: 22px; color: var(--muted); padding: 4px 8px; }
.actions { display: flex; gap: 10px; margin-top: 12px; position: sticky; bottom: 0; background: var(--bg); padding-top: 8px; }
.actions button { flex: 1; }
.filter-count { background: var(--accent); color: #fff; border-radius: 8px; padding: 6px; text-align: center; font-size: 13px; margin-bottom: 10px; }

/* filter controls */
.filter { border-top: 1px solid var(--line); padding: 9px 0; }
.filter .head { display: flex; justify-content: space-between; align-items: center; }
.filter .head label { font-weight: 700; font-size: 13px; }
.filter .na { font-size: 11px; color: var(--muted); font-weight: 400; display: flex; align-items: center; gap: 4px; }
.filter .na input, .nolim input, .status input { width: auto; }
.range-row { display: flex; align-items: center; gap: 6px; margin-top: 6px; }
.range-row input[type=number] { width: 100%; }
.nolim { font-size: 10px; color: var(--muted); text-align: center; min-width: 52px; display: flex; flex-direction: column; align-items: center; gap: 1px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.chip { padding: 4px 9px; border-radius: 999px; border: 1px solid var(--line); background: #f4f6f8; font-size: 12px; cursor: pointer; }
.chip.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.status { display: flex; align-items: center; gap: 8px; font-size: 14px; margin: 6px 0; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 12px 0 2px; }

/* detail */
#detail .price { font-size: 20px; font-weight: 700; }
#detail .badges { margin: 2px 0; }
#detail .kv { font-size: 13px; margin: 3px 0; color: var(--fg); }
#detail .kv .lbl { color: var(--muted); }
#detail .links { margin: 8px 0; }
#detail .links a { margin-right: 12px; color: var(--accent); text-decoration: none; font-weight: 600; }
#detail table { width: 100%; border-collapse: collapse; margin: 6px 0 12px; font-size: 13px; }
#detail th, #detail td { padding: 5px 4px; border-bottom: 1px solid var(--line); text-align: right; }
#detail th:first-child, #detail td:first-child { text-align: left; }
#detail thead th { color: var(--muted); font-size: 11px; }
#detail tfoot td { font-weight: 700; background: #e8f4e8; }
#detail .status-btns { display: flex; gap: 8px; margin: 8px 0; }
#detail .status-btns button { flex: 1; }
#detail button.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.status-comments { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }
.status-comment { width: 100%; font: 13px/1.4 inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 8px; color: var(--fg); resize: vertical; background: #f9fafb; }
.route-ctrl { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 10px; font-size: 13px; padding-top: 8px; border-top: 1px solid var(--line); }
.route-ctrl label { display: flex; align-items: center; gap: 4px; cursor: pointer; }
.route-ctrl button { padding: 4px 10px; font-size: 12px; }
.pill { display:inline-block; padding:1px 7px; border-radius:999px; font-size:11px; background:#eef2f6; color:var(--muted); }
.badge { display:inline-block; padding:1px 7px; border-radius:999px; font-size:11px; margin-right:4px; color:#fff; }
.badge.fav { background:#f5a623; } .badge.seen { background:#7b8794; } .badge.hidden { background:#b0413e; }

/* desktop: side panels, header spans the top above everything */
@media (min-width: 760px) {
  #filter { left: 10px; right: auto; top: calc(var(--header-h) + 8px); bottom: 12px; width: 340px;
    border-radius: 14px; transform: translateX(-118%); max-height: none; }
  #filter.open { transform: translateX(0); }
  #detail { left: auto; right: 10px; top: calc(var(--header-h) + 8px); bottom: 12px; width: 370px;
    border-radius: 14px; transform: translateX(118%); max-height: none; }
  #detail.open { transform: translateX(0); }
  .sheet .grab { display: none; }
  #legend { left: 360px; }
}
