:root {
  --ink: #111111;
  --muted: #595959;
  --line: #d9d9d9;
  --line-soft: #ebebeb;
  --bg: #ffffff;
  --bg-soft: #f5f5f5;
  --radius: 2px;
  --topbar-h: 56px;
  --bottomnav-h: 0px;          /* set to real height on mobile */
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg); color: var(--ink);
  font-size: 16px; line-height: 1.5;
  display: flex; flex-direction: column;
}
a { color: var(--ink); }

/* ---------- header ---------- */
#topbar {
  display: flex; align-items: center; gap: 22px;
  padding: 0 20px; height: var(--topbar-h); background: #fff;
  border-bottom: 1px solid var(--ink); position: sticky; top: 0; z-index: 1100;
}
.homebtn {
  display: flex; align-items: center; gap: 8px; text-decoration: none;
  font-weight: 700; font-size: 15px; color: var(--ink);
  padding: 6px 10px 6px 6px; border: 1px solid transparent;
}
.homebtn:hover { border-color: var(--ink); }
.homebtn svg { width: 22px; height: 22px; }
#nav { display: flex; gap: 20px; align-items: center; flex: 1; }
#nav a { color: var(--ink); text-decoration: none; font-weight: 600; font-size: 15px; padding: 4px 0; border-bottom: 2px solid transparent; }
#nav a.active, #nav a:hover { border-bottom-color: var(--ink); }
#nav a.btn-primary { border-bottom: none; color: #fff; }
#userbox { display: flex; gap: 16px; align-items: center; font-size: 14px; }
#userbox a { color: var(--ink); text-decoration: none; font-weight: 600; }
#userbox a:hover { text-decoration: underline; }
.badge {
  background: var(--ink); color: #fff; border-radius: 9px;
  font-size: 11px; padding: 1px 7px; margin-left: 4px;
}

main { flex: 1; padding-bottom: var(--bottomnav-h); }

/* ---------- bottom nav (mobile) ---------- */
#bottomnav { display: none; }

/* ---------- buttons & inputs ---------- */
.btn-primary, .btn-ghost, .btn-danger {
  border-radius: var(--radius); padding: 11px 20px; font-size: 15px;
  font-weight: 700; cursor: pointer; text-decoration: none; display: inline-block;
  font-family: inherit; line-height: 1.3; text-align: center;
}
.btn-primary { background: var(--ink); color: #fff; border: 1px solid var(--ink); }
.btn-primary:hover { background: #333; }
.btn-primary.small { padding: 8px 14px; font-size: 14px; }
.btn-ghost { background: #fff; color: var(--ink); border: 1px solid var(--ink); }
.btn-ghost:hover { background: var(--bg-soft); }
.btn-danger { background: #fff; color: #a4262c; border: 1px solid #a4262c; }
.btn-danger:hover { background: #fdf3f4; }
.linklike { background: none; border: none; font: inherit; text-decoration: underline; cursor: pointer; color: var(--muted); }
input, select, textarea {
  font: inherit; padding: 11px 12px; border: 1px solid var(--ink);
  border-radius: var(--radius); background: #fff; color: var(--ink); width: 100%;
}
input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible {
  outline: 3px solid #767676; outline-offset: 1px;
}
label { font-size: 14px; font-weight: 700; color: var(--ink); display: block; margin: 16px 0 5px; }
.checkline { display: flex; gap: 10px; align-items: center; font-size: 15px; margin: 8px 0; }
.checkline input { width: 20px; height: 20px; flex: none; accent-color: var(--ink); }
input[type=radio], input[type=checkbox] { accent-color: var(--ink); }

/* ---------- search layout ---------- */
.search-wrap { display: grid; grid-template-columns: 280px 1fr 42%; height: calc(100vh - var(--topbar-h)); }
#filters {
  overflow-y: auto; padding: 18px; background: #fff; border-right: 1px solid var(--line);
}
.filters-head { display: none; }
#filters details { border-top: 1px solid var(--line-soft); padding: 4px 0; }
#filters summary { font-weight: 700; font-size: 14.5px; cursor: pointer; padding: 8px 0; }
.price-row { display: flex; gap: 8px; }
#results { overflow-y: auto; padding: 20px; }
.result-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.result-head h2 { margin: 0; font-size: 18px; }
.result-head select { width: auto; padding: 8px 10px; }
#map-pane { position: relative; border-left: 1px solid var(--line); }
#map { position: absolute; inset: 0; }
.mob-toolbar { display: none; }

/* ---------- cards ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.card {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; text-decoration: none; color: var(--ink); display: block; position: relative;
}
.card:hover { border-color: var(--ink); }
.card.hl { outline: 3px solid var(--ink); }
.card img.cover { width: 100%; height: 150px; object-fit: cover; display: block; background: var(--bg-soft); }
.card .body { padding: 12px 14px 14px; }
.card .price { font-weight: 800; font-size: 17px; }
.card .price small { color: var(--muted); font-weight: 400; }
.card h4 { margin: 4px 0 6px; font-size: 15px; line-height: 1.35; }
.card .meta { color: var(--muted); font-size: 13.5px; }
.tag {
  display: inline-block; background: var(--bg-soft); color: var(--ink); font-size: 12px;
  font-weight: 600; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1px 8px; margin: 3px 4px 0 0;
}
.tag.green { background: #fff; border-color: var(--ink); font-weight: 700; }
.fav-btn {
  position: absolute; top: 8px; right: 8px; background: #fff;
  border: 1px solid var(--line); border-radius: var(--radius); width: 36px; height: 36px;
  font-size: 17px; cursor: pointer; line-height: 1;
}

/* ---------- detail ---------- */
.detail { max-width: 1060px; margin: 24px auto; padding: 0 20px 40px; }
.gallery { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; }
.gallery img.main { width: 100%; height: 360px; object-fit: cover; border-radius: var(--radius); }
.gallery .thumbs { display: grid; grid-template-rows: repeat(3, 1fr); gap: 8px; }
.gallery .thumbs img { width: 100%; height: 114px; object-fit: cover; border-radius: var(--radius); cursor: pointer; }
.detail h1 { font-size: 26px; line-height: 1.25; }
.detail-grid { display: grid; grid-template-columns: 1fr 330px; gap: 32px; margin-top: 22px; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; margin: 16px 0; }
.facts div { font-size: 15px; padding: 9px 0; border-bottom: 1px solid var(--line-soft); }
.facts b { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .02em; }
.amenity-cols { columns: 2; font-size: 15px; }
.amenity-cols div { margin: 5px 0; break-inside: avoid; }
.sidebox { border: 1px solid var(--ink); border-radius: var(--radius); padding: 20px; position: sticky; top: calc(var(--topbar-h) + 16px); background: #fff; }
.sidebox .price { font-size: 24px; font-weight: 800; }
.help-box { background: var(--bg-soft); border-left: 3px solid var(--ink); padding: 12px 14px; margin: 16px 0; font-size: 14.5px; }
#dmap { height: 280px; border: 1px solid var(--line); margin-top: 20px; }

/* ---------- forms / wizard ---------- */
.form-page { max-width: 720px; margin: 26px auto; padding: 0 18px 60px; }
.form-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; margin-bottom: 16px; }
.form-card h3 { margin: 0 0 4px; font-size: 19px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 14px; }
.amenity-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 14px; margin-top: 8px; }
#fmap { height: 300px; border: 1px solid var(--line); margin-top: 14px; }
.imgrow { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.imgrow .thumbwrap { position: relative; }
.imgrow img { width: 110px; height: 80px; object-fit: cover; border: 1px solid var(--line); border-radius: var(--radius); }
.imgrow button {
  position: absolute; top: -8px; right: -8px; background: var(--ink); color: #fff;
  border: none; border-radius: 50%; width: 24px; height: 24px; cursor: pointer; font-size: 12px;
}
.err { color: #a4262c; font-size: 14px; margin-top: 10px; white-space: pre-wrap; }

.form-sub { text-align: center; color: var(--muted); margin: -2px 0 18px; font-size: 15px; }
.steps { display: flex; justify-content: center; gap: 2px; margin: 0 0 20px; flex-wrap: wrap; }
.stepdot {
  display: flex; align-items: center; gap: 7px; border: 1px solid transparent; background: transparent;
  color: var(--muted); font: inherit; font-size: 13.5px; font-weight: 600; cursor: pointer;
  padding: 6px 11px; border-radius: var(--radius);
}
.stepdot span {
  width: 26px; height: 26px; border-radius: 50%; background: #fff; border: 1.5px solid var(--line);
  display: flex; align-items: center; justify-content: center; font-size: 13px; flex: none;
}
.stepdot.active { color: var(--ink); border-color: var(--ink); }
.stepdot.active span { background: var(--ink); color: #fff; border-color: var(--ink); }
.stepdot.done span { background: #fff; border-color: var(--ink); color: var(--ink); }
.stepdot:disabled { opacity: .4; cursor: default; }
.wizard-nav { display: flex; gap: 12px; margin-top: 16px; align-items: center; }
.step h3 { margin-top: 0; }
.step .stephint { color: var(--muted); font-size: 14.5px; margin: 2px 0 12px; }
.step details { border-top: 1px solid var(--line-soft); }
.pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill {
  border: 1px solid var(--ink); border-radius: var(--radius); padding: 10px 16px; cursor: pointer;
  font-size: 14.5px; font-weight: 600; background: #fff;
}
.pill:has(input:checked) { background: var(--ink); color: #fff; }
.pill input { display: none; }
.choice {
  display: flex; align-items: center; gap: 12px; border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; margin: 8px 0; cursor: pointer;
  background: #fff; font-size: 15px; font-weight: 600;
}
.choice:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.choice input { width: 20px; height: 20px; flex: none; }
.step details .cnt { color: var(--muted); font-size: 12.5px; font-weight: 600; }

/* ---------- auth ---------- */
.auth-page { max-width: 440px; margin: 50px auto; padding: 0 18px; }

/* ---------- swipe (legacy route) ---------- */
.swipe-page { max-width: 480px; margin: 20px auto; padding: 0 16px 40px; text-align: center; }
.swipe-card { background: #fff; border: 1px solid var(--ink); border-radius: var(--radius); overflow: hidden; text-align: left; transition: transform .25s, opacity .25s; }
.swipe-card img { width: 100%; height: 280px; object-fit: cover; display: block; }
.swipe-card .body { padding: 16px 18px; }
.swipe-card.out-left { transform: translateX(-120%) rotate(-9deg); opacity: 0; }
.swipe-card.out-right { transform: translateX(120%) rotate(9deg); opacity: 0; }
.swipe-actions { display: flex; justify-content: center; gap: 26px; margin: 18px 0 8px; }
.swipe-actions button { width: 60px; height: 60px; border-radius: 50%; border: 1px solid var(--ink); font-size: 24px; cursor: pointer; background: #fff; }
.swipe-yes { background: var(--ink) !important; color: #fff; }
.learned { font-size: 13px; color: var(--muted); margin-top: 14px; }

/* ---------- wizard (woonwijzer) ---------- */
.wizard-page { max-width: 600px; margin: 36px auto; padding: 0 18px 50px; text-align: center; }
.wizard-page h2 { font-size: 24px; }
.wizard-q {
  background: #fff; border: 1px solid var(--ink); border-radius: var(--radius);
  padding: 36px 28px; font-size: 21px; font-weight: 700; line-height: 1.4;
}
.wizard-buttons { display: flex; justify-content: center; gap: 12px; margin-top: 20px; flex-wrap: wrap; }
.wizard-buttons button { min-width: 110px; font-size: 16px; padding: 13px 22px; }
.wizard-meta { color: var(--muted); margin-top: 16px; font-size: 14px; }

/* ---------- chat ---------- */
.chat-wrap { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - var(--topbar-h) - var(--bottomnav-h)); }
#threadlist { border-right: 1px solid var(--line); overflow-y: auto; background: #fff; }
.thread { display: block; padding: 14px 16px; border-bottom: 1px solid var(--line-soft); text-decoration: none; color: var(--ink); }
.thread:hover, .thread.active { background: var(--bg-soft); }
.thread .who { font-weight: 700; }
.thread .snippet { color: var(--muted); font-size: 13.5px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.thread .ctx { font-size: 12.5px; color: var(--muted); text-decoration: underline; }
#chatpane { display: flex; flex-direction: column; min-width: 0; }
#chathead { padding: 13px 18px; border-bottom: 1px solid var(--line); background: #fff; font-weight: 700; display: flex; gap: 10px; align-items: center; }
.backlink { display: none; text-decoration: none; font-size: 22px; line-height: 1; padding: 0 6px; }
#chatmsgs { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 8px; background: var(--bg-soft); }
.bubble { max-width: 70%; padding: 9px 14px; border-radius: var(--radius); font-size: 15px; line-height: 1.4; border: 1px solid var(--line); }
.bubble.me { align-self: flex-end; background: var(--ink); color: #fff; border-color: var(--ink); }
.bubble.them { align-self: flex-start; background: #fff; }
.bubble time { display: block; font-size: 11px; opacity: .65; margin-top: 3px; }
#chatform { display: flex; gap: 10px; padding: 12px 16px; background: #fff; border-top: 1px solid var(--line); }

/* ---------- start overlay ---------- */
#startoverlay {
  position: fixed; inset: 0; background: rgba(17, 17, 17, .45);
  display: flex; align-items: center; justify-content: center; z-index: 2000; padding: 16px;
}
#startoverlay[hidden] { display: none; }
.start-card {
  background: #fff; border: 1px solid var(--ink); border-radius: var(--radius);
  max-width: 480px; width: 100%; padding: 30px 28px; position: relative;
}
.start-card h2 { margin: 0 0 4px; font-size: 24px; }
.start-card > p { margin: 0 0 18px; color: var(--muted); font-size: 16px; }
.start-close {
  position: absolute; top: 12px; right: 12px; background: #fff; border: 1px solid var(--line);
  border-radius: var(--radius); width: 38px; height: 38px; font-size: 16px; cursor: pointer;
}
.start-opt {
  display: block; border: 1px solid var(--ink); border-radius: var(--radius);
  padding: 16px 18px; margin: 10px 0; text-decoration: none; color: var(--ink);
}
.start-opt:hover { background: var(--bg-soft); }
.start-opt b { display: block; font-size: 17px; margin-bottom: 2px; }
.start-opt span { color: var(--muted); font-size: 14px; }
#startbrowse { margin-top: 10px; font-size: 14px; }

/* ---------- misc ---------- */
.page { max-width: 1060px; margin: 26px auto; padding: 0 20px 50px; }
.empty { text-align: center; color: var(--muted); padding: 56px 20px; font-size: 16px; }
#toast {
  position: fixed; bottom: calc(var(--bottomnav-h) + 20px); left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 12px 22px; border-radius: var(--radius);
  font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 2100;
  max-width: 92vw; text-align: center;
}
#toast.show { opacity: 1; }
.leaflet-popup-content { font-size: 14px; }
.leaflet-popup-content a { color: var(--ink); font-weight: 700; }
.mobile-only { display: none; }

/* ============================================================ mobile */
@media (max-width: 800px) {
  :root { --bottomnav-h: 62px; }
  .mobile-only { display: initial; }

  /* top bar: home + login only; main nav moves to bottom */
  #nav { display: none; }
  #topbar { gap: 10px; padding: 0 12px; }
  #userbox { margin-left: auto; gap: 12px; }
  #userbox a:not(:last-child):not([href="#/messages"]) { display: none; }

  /* bottom navigation */
  #bottomnav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: var(--bottomnav-h);
    background: #fff; border-top: 1px solid var(--ink); z-index: 1100;
  }
  #bottomnav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; text-decoration: none; color: var(--muted); font-size: 11.5px; font-weight: 700;
    position: relative;
  }
  #bottomnav a svg { width: 23px; height: 23px; }
  #bottomnav a.active { color: var(--ink); box-shadow: inset 0 3px 0 var(--ink); }
  #bottomnav .badge { position: absolute; top: 7px; right: calc(50% - 22px); }

  /* search: full-width list, map behind a toggle */
  .search-wrap { display: block; height: auto; min-height: calc(100vh - var(--topbar-h) - var(--bottomnav-h)); }
  .mob-toolbar {
    display: flex; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line);
    position: sticky; top: var(--topbar-h); background: #fff; z-index: 900; align-items: center;
  }
  .mob-toolbar .btn-ghost { padding: 9px 14px; font-size: 14px; }
  .seg { display: flex; flex: 1; max-width: 220px; margin-left: auto; border: 1px solid var(--ink); border-radius: var(--radius); overflow: hidden; }
  .seg button {
    flex: 1; border: none; background: #fff; font: inherit; font-weight: 700; font-size: 14px;
    padding: 9px 0; cursor: pointer; color: var(--ink);
  }
  .seg button.on { background: var(--ink); color: #fff; }

  #filters {
    display: none; position: fixed; inset: var(--topbar-h) 0 0 0; z-index: 1500;
    background: #fff; border-right: none; padding: 16px; overflow-y: auto;
  }
  .search-wrap.filters-open #filters { display: block; }
  .filters-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
  .filters-head b { font-size: 18px; }
  .filters-head button { background: #fff; border: 1px solid var(--ink); border-radius: var(--radius); width: 40px; height: 40px; font-size: 16px; cursor: pointer; }

  #results { padding: 14px 12px 24px; }
  .cards { grid-template-columns: 1fr; }
  .card img.cover { height: 190px; }

  #map-pane { display: none; }
  .search-wrap.mode-map #map-pane {
    display: block; position: fixed; left: 0; right: 0; border-left: none;
    top: calc(var(--topbar-h) + 57px); bottom: var(--bottomnav-h); z-index: 800;
  }
  .search-wrap.mode-map #results { display: none; }

  /* detail */
  .detail { margin: 14px auto; padding: 0 12px 30px; }
  .detail h1 { font-size: 21px; }
  .detail-grid, .gallery { grid-template-columns: 1fr; }
  .gallery img.main { height: 240px; }
  .gallery .thumbs { grid-template-rows: none; grid-template-columns: repeat(3, 1fr); }
  .gallery .thumbs img { height: 84px; }
  .sidebox { position: static; }
  .facts { grid-template-columns: 1fr; }
  .amenity-cols { columns: 1; }

  /* wizard / forms */
  .form-page { margin: 16px auto; padding: 0 12px 50px; }
  .form-card { padding: 18px 14px; }
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .grid2 > div, .grid3 > div { grid-column: auto !important; }
  .amenity-grid { grid-template-columns: 1fr; }
  .stepdot { padding: 6px 7px; font-size: 0; gap: 0; }
  .stepdot span { font-size: 13px; }
  .stepdot.active { font-size: 13px; gap: 7px; }
  .wizard-nav { position: sticky; bottom: calc(var(--bottomnav-h) + 10px); background: #fff; border: 1px solid var(--line); padding: 10px; }
  .wizard-nav .btn-primary, .wizard-nav .btn-ghost { flex: 1; }
  .wizard-nav div { display: none; }
  #fmap { height: 260px; }

  /* chat: list OR conversation */
  .chat-wrap { display: block; height: calc(100vh - var(--topbar-h) - var(--bottomnav-h)); }
  #threadlist { height: 100%; border-right: none; }
  #chatpane { height: 100%; }
  .chat-wrap:not(.has-thread) #chatpane { display: none; }
  .chat-wrap.has-thread #threadlist { display: none; }
  .chat-wrap.has-thread .backlink { display: inline; }
  .bubble { max-width: 86%; }

  .wizard-q { padding: 28px 18px; font-size: 19px; }
  .wizard-buttons button { flex: 1 1 100%; }
  .page { margin: 16px auto; padding: 0 12px 40px; }
}
