:root {
  --bg: #070a0f;
  --surface: #0f1621;
  --surface2: #17202e;
  --border: #232e3f;
  --text: #e9edf3;
  --muted: #8b95a5;
  --amber: #f5a623;
  --blue: #6ea8ff;
  --green: #37d67a;
  --red: #ff5d5d;
  --purple: #b07aff;
  --gray: #8b95a5;
  --radius: 12px;
  --topbar-h: 58px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); overflow: hidden;
}
button { font: inherit; }
.hidden { display: none !important; }

/* ---------- login ---------- */
.login {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 700px at 70% -10%, #14203a 0%, var(--bg) 60%);
  z-index: 100; padding: 20px;
}
.login-card {
  width: 400px; max-width: 100%; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px; padding: 36px;
}
.brand { font-weight: 800; letter-spacing: .06em; font-size: 20px; white-space: nowrap; }
.brand span { color: var(--amber); }
.brand small { display: block; color: var(--muted); font-weight: 500; letter-spacing: .2em; font-size: 10px; margin-top: 2px; }
.login-card h1 { font-size: 17px; font-weight: 600; margin: 26px 0 18px; color: var(--text); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 6px; letter-spacing: .04em; }
.field input, .field textarea, .field select {
  width: 100%; padding: 13px 14px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 15px; outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--blue); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 18px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface2); color: var(--text); cursor: pointer; font-size: 14px;
  min-height: 44px; text-decoration: none; user-select: none;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--amber); border-color: var(--amber); color: #14100a; font-weight: 700; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); }
.btn.small { padding: 7px 12px; min-height: 34px; font-size: 13px; border-radius: 8px; }
.btn.block { width: 100%; }
.btn.ghost { background: transparent; }
.error-msg { color: var(--red); font-size: 13px; min-height: 18px; margin: 8px 0; }

/* ---------- app shell ---------- */
#app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.topbar {
  height: var(--topbar-h); display: flex; align-items: center; gap: 14px;
  padding: 0 14px; padding-top: env(safe-area-inset-top);
  background: rgba(11, 15, 22, .92); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border); z-index: 30; flex: none;
}
.topbar .brand { font-size: 16px; }
.search { position: relative; flex: 1; max-width: 520px; }
.search input {
  width: 100%; padding: 11px 14px 11px 38px; border-radius: 10px; font-size: 15px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text); outline: none;
}
.search input:focus { border-color: var(--blue); }
.search::before {
  content: ""; position: absolute; left: 13px; top: 50%; width: 14px; height: 14px;
  transform: translateY(-55%); pointer-events: none;
  background: no-repeat center / contain url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="%238b95a5" stroke-width="2.4"><circle cx="11" cy="11" r="7"/><path d="M20 20l-4-4"/></svg>');
}
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 60;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; max-height: 50vh; overflow-y: auto; box-shadow: 0 18px 50px rgba(0,0,0,.5);
}
.search-item { padding: 12px 14px; cursor: pointer; border-bottom: 1px solid var(--border); }
.search-item:last-child { border-bottom: none; }
.search-item:hover, .search-item:active { background: var(--surface2); }
.search-item .addr { font-weight: 600; font-size: 14px; }
.search-item .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.topbar-right { display: flex; gap: 8px; margin-left: auto; align-items: center; }

.view, #mapView { position: absolute; inset: 0; top: var(--topbar-h); }
.view { overflow-y: auto; -webkit-overflow-scrolling: touch; }
#map { position: absolute; inset: 0; }
.maplibregl-canvas { outline: none; }

/* ---------- home ---------- */
.home-wrap { max-width: 1100px; margin: 0 auto; padding: 26px 18px 80px; }
.home-hero { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.home-hero h1 { margin: 0 0 4px; font-size: 26px; }
.home-hero .sub { color: var(--muted); font-size: 13.5px; }
.home-hero .btn { margin-left: auto; }
.ds-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.ds-tile { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; overflow: hidden; cursor: pointer; transition: border-color .15s; }
.ds-tile:hover { border-color: var(--muted); }
.ds-cover { aspect-ratio: 16/8; background: #000; }
.ds-cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ds-body { padding: 14px 16px 16px; }
.ds-body .t { font-weight: 700; font-size: 17px; }
.ds-body .m { color: var(--muted); font-size: 13px; margin-top: 4px; }
.ds-actions { display: flex; gap: 8px; margin-top: 14px; }
.ds-actions .btn { flex: 1; }

/* ---------- reports ---------- */
.reports-head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin-bottom: 14px; }
.reports-head h1 { margin: 0 0 2px; font-size: 22px; }
.reports-head .sub { color: var(--muted); font-size: 13px; }
.reports-search { margin-bottom: 18px; }
.house-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; }
.house-card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; cursor: pointer; transition: border-color .15s; }
.house-card:hover { border-color: var(--muted); }
.hc-thumb { position: relative; aspect-ratio: 4/3; background: #000; }
.hc-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.hc-thumb .n { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.65); color: #fff; font-size: 11px; padding: 2px 7px; border-radius: 6px; }
.hc-body { padding: 10px 12px 12px; }
.hc-body .t { font-weight: 600; font-size: 13.5px; display: flex; align-items: center; gap: 7px; }
.hc-body .dot { width: 9px; height: 9px; min-width: 9px; border-radius: 50%; display: inline-block; }
.hc-meta { color: var(--muted); font-size: 11.5px; margin-top: 3px; }
.prop-line { font-size: 13.5px; color: var(--text); line-height: 1.5; margin-bottom: 4px; }

/* ---------- damage screening ---------- */
.filters-row { display: flex; gap: 14px; margin-top: 10px; flex-wrap: wrap; align-items: center; }
.damage-filters { display: flex; gap: 8px; flex-wrap: wrap; }
.damage-filters .chip.active { border-color: var(--amber); color: var(--amber); }
.dmg-badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 700;
  border: 1.5px solid; background: rgba(11,15,22,.75); letter-spacing: .03em;
}
.hc-thumb .dmg-badge { position: absolute; left: 6px; top: 6px; }
.dmg-badge.big { font-size: 13px; padding: 6px 14px; margin-bottom: 10px; }
.dmg-panel { margin-bottom: 6px; }
.dmg-note { font-size: 13px; color: var(--text); margin: 6px 0; line-height: 1.45; }
.dmg-disclaimer { font-size: 11px; color: var(--muted); margin-top: 8px; font-style: italic; }
.map-float {
  position: absolute; top: 12px; left: 12px; z-index: 15;
  background: rgba(11,15,22,.85); backdrop-filter: blur(8px);
}
.map-float.active-mode { border-color: var(--amber); color: var(--amber); }

/* ---------- house detail as modal (reports view) ---------- */
.house-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 55; }
.panel.modal-mode {
  position: fixed; left: 50%; top: 50%; right: auto; bottom: auto;
  transform: translate(-50%, -50%);
  width: min(680px, 94vw); max-height: 86vh; z-index: 60;
}

/* ---------- panels ---------- */
.panel {
  position: absolute; top: calc(var(--topbar-h) + 12px); bottom: 12px; width: 380px;
  background: rgba(15, 22, 33, .97); border: 1px solid var(--border); border-radius: var(--radius);
  z-index: 20; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
}
.panel.left { left: 12px; }
.panel.right { right: 12px; }
.panel-head {
  padding: 16px 18px 12px; border-bottom: 1px solid var(--border);
  display: flex; align-items: flex-start; gap: 10px; flex: none;
}
.panel-head h2 { margin: 0; font-size: 18px; line-height: 1.25; flex: 1; }
.panel-head .sub { color: var(--muted); font-size: 12.5px; margin-top: 4px; }
.icon-btn {
  background: var(--surface2); color: var(--muted); border: 1px solid var(--border);
  width: 36px; height: 36px; min-width: 36px; border-radius: 9px; cursor: pointer; font-size: 15px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { color: var(--text); }
.panel-body { padding: 14px 18px 18px; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }

/* dataset cards */
.ds-card {
  display: flex; gap: 12px; padding: 10px; border: 1px solid var(--border); border-radius: 12px;
  margin-bottom: 10px; cursor: pointer; background: var(--surface2); align-items: center;
}
.ds-card:hover { border-color: var(--muted); }
.ds-card img { width: 84px; height: 62px; object-fit: cover; border-radius: 8px; background: #000; flex: none; }
.ds-card .t { font-weight: 700; font-size: 14.5px; }
.ds-card .m { color: var(--muted); font-size: 12.5px; margin-top: 3px; }

/* house panel */
.status-chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0 4px; }
.chip {
  padding: 9px 14px; border-radius: 999px; border: 1.5px solid var(--border);
  background: var(--surface2); color: var(--text); font-size: 13px; cursor: pointer; min-height: 38px;
  display: inline-flex; align-items: center; gap: 7px;
}
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.chip.active { border-color: currentColor; }
.chip[data-s="interested"] .dot { background: var(--amber); }
.chip[data-s="knocked"] .dot { background: var(--gray); }
.chip[data-s="appointment"] .dot { background: var(--purple); }
.chip[data-s="sold"] .dot { background: var(--green); }
.chip[data-s="not_interested"] .dot { background: var(--red); }
.chip[data-s="interested"].active { color: var(--amber); }
.chip[data-s="knocked"].active { color: var(--gray); }
.chip[data-s="appointment"].active { color: var(--purple); }
.chip[data-s="sold"].active { color: var(--green); }
.chip[data-s="not_interested"].active { color: var(--red); }
.note-row { display: flex; gap: 8px; margin-top: 10px; }
.note-row textarea { flex: 1; min-height: 44px; max-height: 120px; resize: vertical; font-size: 14px; }
.section-label { font-size: 11px; letter-spacing: .12em; color: var(--muted); margin: 18px 0 8px; font-weight: 700; }
.photo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.photo-grid .ph { position: relative; border-radius: 10px; overflow: hidden; cursor: pointer; background: #000; aspect-ratio: 4/3; border: 1px solid var(--border); }
.photo-grid .ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-grid .ph .n {
  position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.65); color: #fff;
  font-size: 11px; padding: 2px 7px; border-radius: 6px;
}
.house-actions { display: flex; gap: 8px; margin-top: 16px; }

/* ---------- legend ---------- */
#legend {
  position: absolute; left: 12px; bottom: 12px; z-index: 15; display: flex; gap: 6px; flex-wrap: wrap;
  background: rgba(11,15,22,.85); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px;
  backdrop-filter: blur(8px); max-width: 70vw;
}
#legend .lg { display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; color: var(--muted); margin-right: 6px; }
#legend .lg i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

/* ---------- photo viewer ---------- */
.viewer { position: fixed; inset: 0; background: #000; z-index: 80; }
#osd { position: absolute; inset: 0; }
.viewer .icon-btn { position: absolute; z-index: 85; width: 46px; height: 46px; font-size: 20px; background: rgba(20,26,36,.8); }
#viewerClose { top: max(14px, env(safe-area-inset-top)); right: 14px; }
#viewerPrev { left: 10px; top: 50%; transform: translateY(-50%); }
#viewerNext { right: 10px; top: 50%; transform: translateY(-50%); }
#viewerCaption {
  position: absolute; bottom: max(16px, env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%);
  background: rgba(11,15,22,.85); border: 1px solid var(--border); color: var(--text);
  padding: 9px 16px; border-radius: 999px; font-size: 13.5px; z-index: 85; white-space: nowrap; max-width: 90vw;
  overflow: hidden; text-overflow: ellipsis;
}
.viewer-msg { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: var(--muted); z-index: 82; }

/* ---------- measure tool ---------- */
.measure-bar {
  position: absolute; top: max(14px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  z-index: 86; display: flex; gap: 8px; align-items: center;
  background: rgba(11,15,22,.88); border: 1px solid var(--border); border-radius: 12px; padding: 7px 9px;
  backdrop-filter: blur(8px); max-width: 94vw; flex-wrap: wrap; justify-content: center;
}
.meas-controls { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: center; }
.meas-controls .chip { min-height: 34px; padding: 6px 12px; font-size: 12.5px; }
.meas-controls .chip.active { border-color: var(--amber); color: var(--amber); }
.meas-pitch {
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 8px; font-size: 13px;
}
#measReadout { font-size: 13px; color: var(--amber); font-weight: 700; min-width: 70px; text-align: center; }

.meas-list { margin-bottom: 4px; }
.meas-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-size: 13px; padding: 7px 0; border-bottom: 1px solid var(--border);
}
.meas-row.total { font-weight: 700; color: var(--amber); border-bottom: none; }
.meas-row.auto { color: var(--blue); }
.meas-del {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 13px;
  padding: 4px 8px; border-radius: 6px;
}
.meas-del:hover { color: var(--red); }

/* ---------- toast ---------- */
#toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--surface2); border: 1px solid var(--border); color: var(--text);
  padding: 12px 20px; border-radius: 12px; z-index: 200; opacity: 0; transition: all .25s; pointer-events: none;
  font-size: 14px; box-shadow: 0 10px 40px rgba(0,0,0,.5); max-width: 90vw;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.err { border-color: var(--red); }

/* ---------- admin ---------- */
.admin-wrap { position: fixed; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.admin-main { max-width: 1080px; margin: 0 auto; padding: 24px 18px 80px; }
.tabs { display: flex; gap: 6px; margin: 18px 0; flex-wrap: wrap; }
.tab {
  padding: 10px 18px; border-radius: 999px; border: 1px solid var(--border); background: transparent;
  color: var(--muted); cursor: pointer; font-size: 14px; min-height: 42px;
}
.tab.active { background: var(--amber); border-color: var(--amber); color: #14100a; font-weight: 700; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; margin-bottom: 14px;
}
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card .sub { color: var(--muted); font-size: 12.5px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.row .field { flex: 1; min-width: 160px; margin-bottom: 0; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; letter-spacing: .04em; }
.badge.ready { background: rgba(55,214,122,.15); color: var(--green); }
.badge.importing { background: rgba(245,166,35,.15); color: var(--amber); }
.badge.new { background: rgba(110,168,255,.15); color: var(--blue); }
.badge.error { background: rgba(255,93,93,.15); color: var(--red); }
.progress { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; margin: 10px 0 4px; border: 1px solid var(--border); }
.progress i { display: block; height: 100%; background: var(--amber); border-radius: 99px; transition: width .4s; }
.access-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.access-grid label {
  display: inline-flex; gap: 8px; align-items: center; border: 1px solid var(--border); border-radius: 10px;
  padding: 9px 13px; cursor: pointer; font-size: 13.5px; background: var(--surface2); min-height: 40px;
}
.access-grid input { width: 17px; height: 17px; accent-color: var(--amber); }
table.stats { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.stats th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: .05em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
table.stats td { padding: 10px; border-bottom: 1px solid var(--border); }
.feed { font-size: 13px; }
.feed li { padding: 8px 0; border-bottom: 1px solid var(--border); list-style: none; color: var(--muted); }
.feed li b { color: var(--text); font-weight: 600; }
.feed { margin: 0; padding: 0; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; flex-wrap: wrap; }
.user-row:last-child { border: none; }
.user-row .grow { flex: 1; min-width: 140px; }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 12px; }

/* browse modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 150; display: flex; align-items: center; justify-content: center; padding: 18px; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; width: 560px; max-width: 100%; max-height: 80vh; display: flex; flex-direction: column; }
.modal-head { padding: 16px 18px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px; }
.modal-head h3 { margin: 0; font-size: 15px; flex: 1; word-break: break-all; }
.modal-body { overflow-y: auto; padding: 8px 0; flex: 1; }
.dir-item { padding: 11px 20px; cursor: pointer; display: flex; gap: 10px; align-items: center; font-size: 14px; }
.dir-item:hover { background: var(--surface2); }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; gap: 10px; align-items: center; }

/* ---------- tablet / narrow ---------- */
@media (max-width: 920px) {
  .topbar { flex-wrap: wrap; height: auto; padding-bottom: 10px; gap: 10px; }
  .topbar .search { order: 3; flex-basis: 100%; max-width: none; }
  #mapView, .view { top: 110px; }
  .panel, .panel.modal-mode { top: auto; bottom: 0; left: 0 !important; right: 0 !important; width: 100%;
    transform: none; max-height: 62vh; border-radius: 18px 18px 0 0; border-bottom: none;
    padding-bottom: env(safe-area-inset-bottom); }
  #legend { bottom: auto; top: 122px; left: 8px; }
  .photo-grid { grid-template-columns: 1fr 1fr 1fr; }
}
@media (max-width: 520px) {
  .photo-grid { grid-template-columns: 1fr 1fr; }
  .brand small { display: none; }
}
