:root {
  --brand: #0b7a55;
  --brand-ink: #ffffff;
  --brand-soft: #e3f3ec;
  --ink: #1a1d21;
  --ink-2: #4a5360;
  --ink-3: #7b8592;
  --line: #e4e7eb;
  --surface: #ffffff;
  --surface-2: #f3f4f6;
  --shadow: 0 2px 10px rgba(16, 24, 40, .14), 0 1px 3px rgba(16, 24, 40, .10);
  --radius: 16px;
  --topbar-h: 54px;
  --sheet-h: 168px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--surface-2);
  overscroll-behavior: none; /* no pull-to-refresh fighting the map */
}
button { font: inherit; color: inherit; }
button, a { touch-action: manipulation; }

#map { position: fixed; inset: 0; }

/* ---------- top bar: brand + search + language ---------- */
.topbar {
  position: fixed; z-index: 4; top: calc(10px + var(--safe-t)); left: 10px; right: 10px;
  height: var(--topbar-h); padding: 0 6px 0 8px;
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border-radius: 28px; box-shadow: var(--shadow);
}
.brand { display: flex; text-decoration: none; flex: none; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 19px; display: grid; place-items: center;
  background: var(--brand); color: var(--brand-ink); font-weight: 800; font-size: 20px;
}
.lang {
  flex: none; min-width: 44px; height: 44px; display: grid; place-items: center;
  font-size: 13px; font-weight: 700; color: var(--ink-2); text-decoration: none; border-radius: 22px;
}
.lang:active, .lang:hover { background: var(--surface-2); }

.search { position: relative; flex: 1; min-width: 0; display: flex; align-items: center; margin: 0; height: 100%; }
.search input {
  width: 100%; height: 100%; border: 0; outline: none; background: transparent;
  font: inherit; font-size: 16px; /* 16px prevents iOS zoom-on-focus */
  color: var(--ink); padding: 0 36px 0 4px; -webkit-appearance: none; appearance: none;
}
.search input::-webkit-search-cancel-button { display: none; }
.search input::placeholder { color: var(--ink-3); }
.search-clear {
  position: absolute; right: 0; border: 0; background: var(--surface-2); color: var(--ink-2);
  width: 32px; height: 32px; border-radius: 16px; font-size: 20px; line-height: 1; cursor: pointer;
}
.search-results {
  position: absolute; top: calc(100% + 8px); left: -54px; right: -56px;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  max-height: min(65vh, 480px); overflow-y: auto; overscroll-behavior: contain; padding: 6px 0;
}
.search-results[hidden], .search-clear[hidden] { display: none; }
.sr-head { padding: 10px 16px 4px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-3); }
.sr-item {
  display: flex; gap: 12px; align-items: center; width: 100%; min-height: 52px; padding: 8px 16px;
  border: 0; background: none; text-align: left; cursor: pointer;
}
.sr-item[aria-selected="true"], .sr-item:hover { background: var(--surface-2); }
.sr-icon { flex: none; width: 32px; height: 32px; border-radius: 16px; display: grid; place-items: center; background: var(--surface-2); font-size: 15px; }
.sr-icon.is-lot { background: var(--brand); color: var(--brand-ink); font-weight: 800; }
.sr-text { min-width: 0; display: flex; flex-direction: column; }
.sr-name { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-sub { font-size: 13px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sr-empty { padding: 12px 16px; font-size: 14px; color: var(--ink-3); }

/* ---------- vehicle chips ---------- */
.vehicles {
  position: fixed; z-index: 3; top: calc(var(--topbar-h) + 18px + var(--safe-t)); left: 10px; right: 10px;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0 6px;
}
.vehicles::-webkit-scrollbar { display: none; }
.vehicles button {
  flex: none; height: 38px; border: 0; background: var(--surface); box-shadow: var(--shadow);
  padding: 0 14px; border-radius: 19px; cursor: pointer; font-size: 14px; font-weight: 600; color: var(--ink-2);
}
.vehicles button[aria-checked="true"] { background: var(--brand); color: var(--brand-ink); }

/* ---------- bottom sheet (phones) / side panel (desktop) ---------- */
.sheet {
  position: fixed; z-index: 2; left: 0; right: 0; bottom: 0;
  background: var(--surface); border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: 0 -2px 16px rgba(16, 24, 40, .18);
  display: flex; flex-direction: column;
  height: var(--sheet-h); transition: height .25s cubic-bezier(.2, .8, .2, 1);
  padding-bottom: var(--safe-b);
}
.sheet.dragging { transition: none; }
.sheet-handle {
  flex: none; display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 8px;
  width: 100%; min-height: 56px; padding: 6px 16px 10px;
  border: 0; background: none; text-align: left; cursor: grab;
  touch-action: none; /* we handle vertical drags ourselves */
}
.grip { grid-column: 1 / -1; justify-self: center; width: 40px; height: 5px; border-radius: 3px; background: #cfd4da; margin-bottom: 8px; }
.sheet-title { font-weight: 700; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-count { font-size: 13px; color: var(--ink-3); white-space: nowrap; }
.sheet.is-detail .sheet-title {
  font-size: 19px; line-height: 1.25; white-space: normal;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.sheet-body { flex: 1; overflow-y: auto; overscroll-behavior: contain; border-top: 1px solid var(--line); -webkit-overflow-scrolling: touch; }

.locate { padding: 10px 16px; border-bottom: 1px solid var(--line); background: var(--brand-soft); }
.locate[hidden] { display: none; }
.locate-msg { margin: 0 0 8px; font-size: 13px; color: var(--ink-2); line-height: 1.4; }
.locate-msg:only-child, .locate-msg:has(+ [hidden]) { margin: 0; }
.locate-btn { width: 100%; border: 0; cursor: pointer; min-height: 44px; }
.locate-btn[hidden] { display: none; }

/* ---------- list ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list .empty { padding: 18px 16px; color: var(--ink-3); font-size: 14px; }
.item {
  display: grid; grid-template-columns: auto 1fr auto; grid-template-rows: auto auto; gap: 2px 12px; align-items: center;
  width: 100%; min-height: 64px; padding: 10px 16px; border: 0; border-bottom: 1px solid var(--line);
  background: none; text-align: left; cursor: pointer;
}
.item:active, .item:hover, .item:focus-visible { background: var(--surface-2); outline: none; }
.item-icon {
  grid-row: 1 / span 2; width: 34px; height: 34px; border-radius: 17px; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand); font-weight: 800; font-size: 16px;
}
.item-name { grid-column: 2; font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { grid-column: 2; font-size: 13px; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-price { grid-column: 3; grid-row: 1 / span 2; text-align: right; }
.price { display: block; font-weight: 800; font-size: 16px; color: var(--brand); white-space: nowrap; }
.price small { font-weight: 600; font-size: 12px; color: var(--ink-3); }
.price-sub { display: block; font-size: 12px; color: var(--ink-3); white-space: nowrap; }
.price-none { font-size: 12px; color: var(--ink-3); }
.price-none.big { font-size: 14px; margin: 0 0 16px; }

/* ---------- detail ---------- */
.detail { padding: 12px 16px 28px; }
.detail .back {
  border: 0; background: var(--surface-2); border-radius: 18px; height: 36px; padding: 0 14px;
  font-size: 14px; font-weight: 600; cursor: pointer; margin-bottom: 12px;
}
.detail h2 { margin: 0 0 4px; font-size: 21px; line-height: 1.25; }
.detail .addr { margin: 0 0 12px; color: var(--ink-2); font-size: 14px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 14px; }
.badge { font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 12px; background: var(--surface-2); color: var(--ink-2); }
.badge.ok { background: var(--brand-soft); color: var(--brand); }
.rates { display: grid; gap: 8px; margin-bottom: 16px; }
.rate {
  display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; align-items: center;
  padding: 10px 14px; border-radius: 12px; background: var(--surface-2);
}
.rate.current { background: var(--brand-soft); }
.rate-v { grid-row: 1 / span 2; font-weight: 600; font-size: 15px; }
.rate-h { font-weight: 800; font-size: 18px; color: var(--brand); text-align: right; white-space: nowrap; }
.rate-h small { font-size: 12px; font-weight: 600; color: var(--ink-3); }
.rate-m { font-size: 12px; color: var(--ink-3); text-align: right; }
.actions { display: flex; gap: 8px; margin-bottom: 18px; }
.btn {
  flex: 1; display: inline-flex; justify-content: center; align-items: center; gap: 6px;
  min-height: 48px; padding: 0 12px; border-radius: 24px; font-weight: 700; font-size: 15px; text-decoration: none;
  background: var(--surface-2); color: var(--ink);
}
.btn.primary { background: var(--brand); color: var(--brand-ink); }
.detail h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-3); margin: 18px 0 6px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 16px; margin: 0; font-size: 14px; }
.kv dt { color: var(--ink-2); }
.kv dd { margin: 0; font-weight: 600; }
.note { font-size: 12px; color: var(--ink-3); margin-top: 16px; }

/* ---------- map controls ---------- */
.maplibregl-ctrl-group { border-radius: 12px !important; box-shadow: var(--shadow) !important; }
/* Locate button rides just above the sheet as a round floating button. */
.maplibregl-ctrl-bottom-right {
  bottom: calc(var(--sheet-h) + 6px); transition: bottom .25s cubic-bezier(.2, .8, .2, 1);
}
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-group { border-radius: 26px !important; }
.maplibregl-ctrl-bottom-right .maplibregl-ctrl-group button { width: 52px; height: 52px; border-radius: 26px; }
.maplibregl-ctrl-bottom-left { bottom: calc(var(--sheet-h) + 6px); transition: bottom .25s cubic-bezier(.2, .8, .2, 1); }
.sheet.dragging ~ .maplibregl-ctrl-bottom-right { transition: none; }
.maplibregl-ctrl-top-right { display: none; } /* phones: pinch to zoom */

/* ---------- desktop ---------- */
@media (min-width: 820px) {
  :root { --sheet-h: 0px; }
  .topbar { right: auto; width: 400px; }
  .vehicles { left: 430px; right: auto; top: 18px; }
  .search-results { left: -54px; right: -56px; }
  .sheet {
    top: calc(var(--topbar-h) + 20px); left: 10px; bottom: 10px; right: auto; width: 400px; height: auto !important;
    border-radius: var(--radius); box-shadow: var(--shadow); transition: none;
  }
  .grip { display: none; }
  .sheet-handle { cursor: default; padding-top: 12px; min-height: 0; touch-action: auto; }
  .maplibregl-ctrl-top-right { display: block; top: 10px; }
  .maplibregl-ctrl-bottom-right { bottom: 24px; }
  .maplibregl-ctrl-bottom-left { left: 420px; bottom: 0; }
  .maplibregl-ctrl-group button { width: 40px; height: 40px; }
  .maplibregl-ctrl-bottom-right .maplibregl-ctrl-group button { width: 44px; height: 44px; }
}

.noscript { position: fixed; inset: auto 16px 16px; background: var(--surface); padding: 12px; border-radius: 10px; }
