:root {
  --bg: #f6f3ee; --panel: #fffdf9; --panel-2: #f1ece4; --ink: #1d2433; --ink-2: #4a5265; --muted: #8a8f9c;
  --line: #e4ddd2; --accent: #a6782f; --accent-ink: #fff; --accent-soft: #f3e7d2;
  --good: #2f7d57; --good-soft: #e2f1e8; --warn: #b7791f; --warn-soft: #faefd9; --bad: #b23b3b; --bad-soft: #f8e3e1;
  --info: #31588f; --info-soft: #e3ebf7; --shadow: 0 1px 2px rgba(29,36,51,.06), 0 4px 16px rgba(29,36,51,.06);
  --radius: 12px; --serif: "Fraunces", Georgia, serif; --sans: "Inter", -apple-system, system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12151c; --panel: #1a1e27; --panel-2: #222734; --ink: #ece8e1; --ink-2: #b9bcc6; --muted: #7d8291;
    --line: #2c3240; --accent: #d1a052; --accent-ink: #1a1408; --accent-soft: #3a2f1d;
    --good: #5fbf8b; --good-soft: #1d3328; --warn: #e0a547; --warn-soft: #3a2f1a; --bad: #e57373; --bad-soft: #3d2222;
    --info: #7fa6e0; --info-soft: #1e2a3d; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--ink); font: 14px/1.5 var(--sans); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; margin: 0 0 .4em; }
h1 { font-size: 28px; } h2 { font-size: 21px; } h3 { font-size: 16px; }
a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: 12.5px; } .num { font-variant-numeric: tabular-nums; }

.app { display: grid; grid-template-columns: 228px 1fr; min-height: 100vh; }
.nav { position: sticky; top: 0; height: 100vh; padding: 20px 14px; border-right: 1px solid var(--line); background: var(--panel); display: flex; flex-direction: column; gap: 18px; }
.brand { display: flex; gap: 10px; align-items: center; padding: 0 6px; }
.brand .mark { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font: 600 19px var(--serif); }
.brand b { font: 600 18px var(--serif); display: block; line-height: 1.1; } .brand small { color: var(--muted); font-size: 11.5px; }
.nav nav { display: flex; flex-direction: column; gap: 2px; }
.nav nav a { padding: 8px 12px; border-radius: 8px; color: var(--ink-2); text-decoration: none; cursor: pointer; font-weight: 500; display: flex; justify-content: space-between; align-items: center; }
.nav nav a:hover { background: var(--panel-2); }
.nav nav a.active { background: var(--accent-soft); color: var(--ink); }
.badge { background: var(--accent); color: var(--accent-ink); border-radius: 99px; font-size: 11px; padding: 0 7px; }
.scanbox { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 12px; background: var(--panel-2); border-radius: var(--radius); }
.bar { height: 4px; background: var(--line); border-radius: 4px; overflow: hidden; } .bar i { display: block; height: 100%; width: 0; background: var(--accent); transition: width .4s; }

main { padding: 28px 32px 60px; min-width: 0; }
.view { display: none; } .view.active { display: block; }

.btn { border: 1px solid var(--line); background: var(--panel); color: var(--ink); border-radius: 8px; padding: 7px 13px; font: 500 13px var(--sans); cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--accent); } .btn:disabled { opacity: .55; cursor: wait; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; } .btn.small { padding: 4px 9px; font-size: 12px; } .btn.block { width: 100%; }
.btn.danger { color: var(--bad); }
input, select, textarea { font: 13.5px var(--sans); color: var(--ink); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.chk { display: inline-flex; gap: 6px; align-items: center; color: var(--ink-2); font-size: 13px; cursor: pointer; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); align-content: start; }
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 14px; margin: 18px 0 22px; }
.kpi .v { font: 600 30px var(--serif); line-height: 1.1; } .kpi .l { color: var(--muted); font-size: 12.5px; }
.cols { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 18px; }
.head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; flex-wrap: wrap; }

.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; }
.filters #fText { flex: 1 1 260px; } .filters #fMax { width: 130px; }
.areabar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 10px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.areabar #fAreaSel { font-weight: 600; }
#nearBox { display: inline-flex; flex-wrap: wrap; gap: 8px; align-items: center; flex: 1 1 420px; }
#nearBox.hidden { display: none; }
#fNear { flex: 1 1 240px; }
#view-map #map { height: calc(100vh - 190px); }
.lotgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 14px; margin-top: 12px; }
.lot { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; display: flex; flex-direction: column; transition: transform .12s, box-shadow .12s; }
.lot:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.lot .img { height: 150px; background: var(--panel-2) center/cover no-repeat; position: relative; }
.lot .img .tags { position: absolute; left: 8px; top: 8px; display: flex; gap: 5px; flex-wrap: wrap; }
.lot .star { position: absolute; right: 8px; top: 6px; background: rgba(0,0,0,.35); color: #fff; border: 0; border-radius: 99px; width: 30px; height: 30px; font-size: 16px; cursor: pointer; }
.lot .star.on { color: #ffcf5a; }
.lot .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.lot .price { font: 600 19px var(--serif); } .lot .title { font-weight: 500; line-height: 1.35; }
.lot .meta { color: var(--muted); font-size: 12.5px; display: flex; gap: 10px; flex-wrap: wrap; margin-top: auto; padding-top: 6px; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px; font-size: 11.5px; font-weight: 600; background: var(--panel-2); color: var(--ink-2); }
.pill.good { background: var(--good-soft); color: var(--good); } .pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.bad { background: var(--bad-soft); color: var(--bad); } .pill.info { background: var(--info-soft); color: var(--info); }
.pill.accent { background: var(--accent); color: var(--accent-ink); }
.score { font: 600 13px var(--sans); min-width: 34px; text-align: center; }

.list { display: flex; flex-direction: column; }
.row { display: flex; gap: 12px; align-items: center; padding: 10px 2px; border-bottom: 1px solid var(--line); cursor: pointer; }
.row:last-child { border-bottom: 0; } .row:hover { background: var(--panel-2); }
.row .thumb { width: 54px; height: 42px; border-radius: 6px; background: var(--panel-2) center/cover; flex: none; }
.row .grow { flex: 1; min-width: 0; } .row .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.feed .ev { padding: 7px 0; border-bottom: 1px dashed var(--line); font-size: 13px; } .feed .ev:last-child { border: 0; }
.feed .ev .k { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.datecol { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; }
.datechip { flex: none; min-width: 78px; text-align: center; border: 1px solid var(--line); border-radius: 10px; padding: 8px; background: var(--panel); cursor: pointer; }
.datechip b { display: block; font: 600 20px var(--serif); } .datechip span { font-size: 11px; color: var(--muted); }

#map { height: calc(100vh - 56px); border-radius: var(--radius); border: 1px solid var(--line); }

.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(230px, 1fr); gap: 12px; overflow-x: auto; min-height: 70vh; }
.col { background: var(--panel-2); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.col h3 { font-size: 14px; display: flex; justify-content: space-between; margin: 2px 4px 4px; }
.col.drop { outline: 2px dashed var(--accent); }
.kcard { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px; cursor: grab; font-size: 13px; }
.kcard .p { font: 600 15px var(--serif); }

.chatwrap { max-width: 860px; display: flex; flex-direction: column; height: calc(100vh - 88px); }
.chathead { display: flex; justify-content: space-between; align-items: center; }
.chatlog { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; padding: 8px 2px; }
.msg { padding: 11px 14px; border-radius: 12px; max-width: 88%; white-space: pre-wrap; line-height: 1.55; }
.msg.user { align-self: flex-end; background: var(--accent-soft); }
.msg.assistant { align-self: flex-start; background: var(--panel); border: 1px solid var(--line); }
.msg.thinking { color: var(--muted); font-style: italic; }
.chatform { display: flex; gap: 8px; margin-top: 10px; } .chatform textarea { flex: 1; resize: vertical; }
.suggest { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.suggest button { font-size: 12px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; font-weight: 600; color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; padding: 8px 8px; border-bottom: 1px solid var(--line); }
td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
td .err { color: var(--bad); font-size: 11.5px; max-width: 280px; }

.drawer { position: fixed; inset: 0; pointer-events: none; z-index: 1000; }
.drawer-bg { position: absolute; inset: 0; background: rgba(15,18,25,.35); opacity: 0; transition: opacity .2s; }
.drawer-panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(880px, 100%); background: var(--bg); transform: translateX(100%); transition: transform .25s ease; overflow-y: auto; box-shadow: -10px 0 40px rgba(0,0,0,.15); }
.drawer.open { pointer-events: auto; } .drawer.open .drawer-bg { opacity: 1; } .drawer.open .drawer-panel { transform: none; }
.dhead { position: relative; }
.dhero { height: 220px; background: var(--panel-2) center/cover; }
.dclose { position: absolute; right: 14px; top: 14px; background: rgba(0,0,0,.45); color: #fff; border: 0; width: 34px; height: 34px; border-radius: 99px; font-size: 18px; cursor: pointer; }
.dbody { padding: 20px 26px 40px; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin: 14px 0; }
.fact { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
.fact .l { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; } .fact .v { font-weight: 600; }
.tracker { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 20px 0 16px; overflow-x: auto; }
.tabs button { background: none; border: 0; padding: 9px 12px; font: 500 13.5px var(--sans); color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs button.active { color: var(--ink); border-bottom-color: var(--accent); }
.verdict { display: flex; gap: 16px; align-items: center; padding: 16px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--line); }
.ring { --p: 0; width: 72px; height: 72px; border-radius: 50%; flex: none; display: grid; place-items: center; background: conic-gradient(var(--c, var(--accent)) calc(var(--p) * 1%), var(--line) 0); }
.ring span { width: 58px; height: 58px; border-radius: 50%; background: var(--panel); display: grid; place-items: center; font: 600 20px var(--serif); }
.ranges { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; margin: 14px 0; }
.range { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.range .mid { font: 600 18px var(--serif); } .range .lh { font-size: 12px; color: var(--muted); } .range .b { font-size: 12px; color: var(--ink-2); margin-top: 4px; }
ul.clean { padding-left: 18px; margin: 6px 0 14px; } ul.clean li { margin: 4px 0; }
.risk { border-left: 3px solid var(--line); padding: 6px 10px; margin: 6px 0; background: var(--panel); border-radius: 0 8px 8px 0; }
.risk.high { border-color: var(--bad); } .risk.medium { border-color: var(--warn); } .risk.low { border-color: var(--good); }
.calc { display: grid; grid-template-columns: 260px 1fr; gap: 18px; }
.calc label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.kv { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px dashed var(--line); } .kv.total { font-weight: 600; border-bottom: 2px solid var(--line); }
.bigbid { font: 600 34px var(--serif); color: var(--accent); }
.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty h3 { color: var(--ink); }
.desc { white-space: pre-wrap; font-size: 13px; color: var(--ink-2); max-height: 520px; overflow-y: auto; background: var(--panel); padding: 14px; border-radius: 10px; border: 1px solid var(--line); }
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 26px; text-align: center; color: var(--muted); cursor: pointer; }
.dropzone.over { border-color: var(--accent); background: var(--accent-soft); }
.formgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px 16px; }
.formgrid label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--ink-2); }
.section { margin-bottom: 22px; }
.areas .arow { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; transition: transform .25s; z-index: 2000; max-width: 90vw; }
.toast.show { transform: translateX(-50%); }
.spin { display: inline-block; width: 13px; height: 13px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: s .8s linear infinite; vertical-align: -2px; }
@keyframes s { to { transform: rotate(360deg); } }
.leaflet-popup-content { font: 13px var(--sans); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .nav { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px 16px; gap: 10px; }
  .nav nav { flex-direction: row; flex-wrap: wrap; } .scanbox { margin: 0; width: 100%; }
  main { padding: 18px 16px 50px; }
  .kpis { grid-template-columns: repeat(2, minmax(0,1fr)); } .cols, .calc { grid-template-columns: 1fr; }
  .dbody { padding: 16px; }
}

body:not(.is-admin) .admin-only { display: none !important; }

/* sidebar account box: long names and emails truncate instead of overflowing */
.nav, .scanbox { min-width: 0; }
#userBox { display: grid; grid-template-columns: minmax(0, 1fr); grid-template-areas: "who" "email" "out"; gap: 1px; padding-bottom: 10px; border-bottom: 1px solid var(--line); font-size: 12.5px; }
#userBox .who { grid-area: who; display: flex; align-items: center; gap: 6px; min-width: 0; }
#userBox .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
#userBox .pill { flex: none; }
#userBox .email { grid-area: email; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#userBox #signOut { grid-area: out; justify-self: start; border: 0; background: none; padding: 4px 0 0; color: var(--accent); font-size: 12px; cursor: pointer; }
#userBox #signOut:hover { text-decoration: underline; }
#scanStatus { overflow-wrap: anywhere; }

/* narrow screens: wide tables scroll inside their card; suggestion chips wrap */
.card { min-width: 0; }
.card:has(> table), .card:has(> details table) { overflow-x: auto; }
.suggest button { white-space: normal; text-align: left; }
#peopleBox .card, #view-sources .card { overflow-x: auto; }
