:root {
  --bg: #1f2933;
  --panel-bg: rgba(255, 255, 255, 0.97);
  --shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  --red: #e5484d;
  --yellow: #ffc53d;
  --green: #30a46c;
  --radius: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; }
body { background: var(--bg); -webkit-tap-highlight-color: transparent; }
.hidden { display: none !important; }
.muted { color: #667; font-size: 13px; margin: 0 0 4px; }
.error { color: var(--red); font-size: 13px; }

/* Map fills the viewport */
#map { position: absolute; inset: 0; }

/* Drawing overlay sits above the map; pointer-events toggled per tool. */
#draw-canvas {
  position: absolute;
  inset: 0;
  /* A <canvas>'s width/height attributes act as presentational size hints; with
     only inset:0 they over-constrain layout and the canvas stays 300x150 in the
     top-left. Explicit 100% overrides that so the overlay fills the viewport. */
  width: 100%;
  height: 100%;
  z-index: 5;
  touch-action: none;
  pointer-events: none;
}

/* ---- Login ---- */
.login {
  position: absolute; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #2b3a4a, #1f2933);
  padding: env(safe-area-inset-top) 16px;
}
.login-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 28px; width: min(360px, 92vw); display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card label { display: flex; flex-direction: column; font-size: 13px; gap: 4px; color: #334; }
.login-card input {
  padding: 11px 12px; border: 1px solid #cbd2d9; border-radius: 9px; font-size: 16px;
}
.login-card button {
  margin-top: 6px; padding: 12px; border: 0; border-radius: 9px;
  background: var(--green); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer;
}

/* ---- Toolbar ---- */
.toolbar {
  position: absolute; z-index: 10;
  top: calc(env(safe-area-inset-top) + 10px); left: 10px;
  display: flex; flex-direction: column; gap: 8px;
}
.tool-group {
  display: flex; gap: 4px; padding: 4px;
  background: var(--panel-bg); border-radius: var(--radius); box-shadow: var(--shadow);
}
.toolbar button {
  width: 44px; height: 44px; border: 0; border-radius: 9px; background: transparent;
  font-size: 20px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background 0.12s;
}
.toolbar button:hover { background: #eef1f4; }
.toolbar button.active { background: #d7e3ff; box-shadow: inset 0 0 0 2px #4c7dff; }
.color { position: relative; }
.color::after {
  content: ""; width: 24px; height: 24px; border-radius: 50%;
  background: var(--c); box-shadow: inset 0 0 0 1px rgba(0,0,0,0.15);
}
.color.active { box-shadow: inset 0 0 0 2px #1f2933; }
.pen[data-pen="region"] { font-size: 26px; }
.pencil-toggle {
  display: flex; align-items: center; gap: 5px; font-size: 12px; color: #334;
  padding: 0 8px; white-space: nowrap; cursor: pointer;
}
.draw-only.dim { opacity: 0.35; pointer-events: none; }

.layers { flex-direction: column; gap: 2px; padding: 8px; }
.layers label {
  display: flex; align-items: center; gap: 6px; font-size: 12px; color: #334;
  cursor: pointer; white-space: nowrap;
}
.layers input { margin: 0; }

/* ---- Properties panel ---- */
.panel {
  position: absolute; z-index: 10; top: 0; right: 0; height: 100%;
  width: min(360px, 90vw);
  background: var(--panel-bg); box-shadow: var(--shadow);
  display: flex; transition: transform 0.2s ease;
}
.panel.collapsed { transform: translateX(100%); }
.panel-inner {
  display: flex; flex-direction: column; width: 100%;
  padding: calc(env(safe-area-inset-top) + 12px) 14px 12px;
  overflow: hidden;
}
.panel-toggle {
  position: absolute; left: -34px; top: 12px; width: 34px; height: 44px;
  border: 0; border-radius: 10px 0 0 10px; background: var(--panel-bg);
  box-shadow: var(--shadow); cursor: pointer; font-size: 18px;
}
.panel-show {
  position: absolute; z-index: 10; top: calc(env(safe-area-inset-top) + 12px); right: 0;
  border: 0; border-radius: 10px 0 0 10px; padding: 10px 12px;
  background: var(--panel-bg); box-shadow: var(--shadow); cursor: pointer; font-weight: 600;
}
.panel-head { display: flex; align-items: baseline; justify-content: space-between; }
.panel-head h2 { margin: 0 0 8px; font-size: 18px; }
.who { font-size: 12px; color: #667; }
#add-form { display: flex; gap: 6px; align-items: stretch; }
#add-input {
  flex: 1; resize: none; padding: 9px 10px; border: 1px solid #cbd2d9;
  border-radius: 9px; font-size: 15px; font-family: inherit;
}
#add-btn { border: 0; border-radius: 9px; padding: 0 14px; background: var(--green); color: #fff; font-weight: 600; cursor: pointer; }
.add-status { font-size: 12px; color: #667; min-height: 16px; margin: 6px 2px; }

.prop-list { list-style: none; margin: 6px 0 0; padding: 0; overflow-y: auto; flex: 1; -webkit-overflow-scrolling: touch; }
.prop-card {
  display: flex; gap: 10px; padding: 9px; border-radius: 10px; cursor: pointer;
  border: 1px solid #e2e6ea; margin-bottom: 8px; background: #fff;
}
.prop-card:hover { border-color: #b9c2cc; }
.prop-card img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; background: #e6eaee; flex-shrink: 0; }
.prop-card .body { flex: 1; min-width: 0; }
.prop-card .addr { font-weight: 600; font-size: 14px; line-height: 1.25; word-break: break-word; }
.prop-card .prices { font-size: 13px; margin-top: 3px; display: flex; gap: 10px; flex-wrap: wrap; }
.prop-card .list-price { color: #1f2933; }
.prop-card .est-price { color: var(--green); }
.prop-card .meta { font-size: 11px; color: #889; margin-top: 3px; }
.prop-card a { color: #4c7dff; font-size: 12px; }
.prop-card .row-actions { display: flex; gap: 8px; margin-top: 6px; }
.prop-card button.link { background: none; border: 0; color: #4c7dff; cursor: pointer; font-size: 12px; padding: 0; }
.prop-card button.danger { color: var(--red); }
.prop-card input.edit {
  width: 100%; font-size: 13px; padding: 4px 6px; border: 1px solid #cbd2d9; border-radius: 6px; margin-top: 4px;
}
.prop-card .bb { font-size: 12px; margin-top: 2px; color: #556; }
.prop-card .bb-edit { display: flex; gap: 6px; margin-top: 4px; }
.prop-card .bb-edit input.edit { width: 50%; margin-top: 0; }

/* property thread popup */
.prop-thread .pt-head { margin-bottom: 6px; }
.prop-thread .pt-addr { font-weight: 700; font-size: 14px; line-height: 1.2; }
.prop-thread .pt-meta { font-size: 12px; color: #667; margin-top: 2px; }

/* ---- Map markers ---- */
/* Note marker: bubble (icon + preview) above a downward tip; the tip apex is
   the anchor point, so it points exactly at the note's location. */
.note-marker {
  display: flex; flex-direction: column; align-items: center; cursor: pointer;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}
.note-bubble {
  display: inline-flex; align-items: center; gap: 5px; max-width: 180px; white-space: nowrap;
  background: #ffc53d; color: #3a2f10; border-radius: 10px; padding: 3px 9px;
  font-size: 12px; font-weight: 600;
}
.note-bubble .nb-text { overflow: hidden; text-overflow: ellipsis; }
.note-tip {
  width: 0; height: 0; margin-top: -1px;
  border-left: 7px solid transparent; border-right: 7px solid transparent;
  border-top: 9px solid #ffc53d;
}

.note-pop.thread .thread-list { max-height: 210px; overflow-y: auto; margin-bottom: 8px; }
.note-pop .msg { padding: 6px 0; border-bottom: 1px solid #eee; }
.note-pop .msg:last-child { border-bottom: 0; }
.note-pop .msg-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.note-pop .msg-author { font-weight: 700; font-size: 13px; color: #1f2933; }
.note-pop .msg-time { font-size: 10px; color: #889; flex: 0 0 auto; }
.note-pop .msg-text { font-size: 14px; white-space: pre-wrap; word-break: break-word; margin-top: 1px; }

/* Property marker: a content-sized bubble with a triangle tip that points to
   the exact location (anchored at the tip). */
.prop-marker {
  display: flex; flex-direction: column; align-items: center; cursor: pointer;
  filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
}
.pm-bubble {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  background: #fff; border: 2px solid #4c7dff; border-radius: 10px; padding: 3px 7px;
  max-width: 220px;
}
.pm-tip {
  width: 0; height: 0; margin-top: -1px;
  border-left: 7px solid transparent; border-right: 7px solid transparent;
  border-top: 9px solid #4c7dff;
}
.prop-marker.steep .pm-bubble { border-color: #d97706; }
.prop-marker.steep .pm-tip { border-top-color: #d97706; }
.prop-marker.very-steep .pm-bubble { border-color: var(--red); }
.prop-marker.very-steep .pm-tip { border-top-color: var(--red); }
.pm-bubble img { width: 30px; height: 30px; border-radius: 5px; object-fit: cover; background: #e6eaee; }
.pm-prices { font-size: 11px; line-height: 1.15; }
.pm-list { font-weight: 700; }
.pm-est { color: var(--green); }
.pm-steep { font-size: 10px; font-weight: 700; color: #d97706; }
.prop-marker.very-steep .pm-steep { color: var(--red); }
.pm-bb { font-size: 10px; color: #556; }
.pm-msg { font-size: 10px; color: #4c7dff; }

.prop-card.steep { border-left: 4px solid #d97706; }
.prop-card.very-steep { border-left: 4px solid var(--red); }
.prop-card .slope { font-size: 12px; margin-top: 2px; color: #889; }
.prop-card .loud { font-size: 12px; margin-top: 2px; color: #889; }
.prop-card.steep .slope { color: #d97706; font-weight: 600; }
.prop-card.very-steep .slope { color: var(--red); font-weight: 600; }

/* Comment editor popup */
.note-pop textarea {
  width: 240px; height: 90px; border: 1px solid #cbd2d9; border-radius: 8px;
  padding: 8px; font-size: 15px; font-family: inherit; resize: vertical;
}
.note-pop .pop-actions { display: flex; justify-content: space-between; margin-top: 6px; }
.note-pop button { border: 0; border-radius: 7px; padding: 6px 12px; cursor: pointer; font-weight: 600; }
.note-pop .save { background: var(--green); color: #fff; }
.note-pop .del { background: #fbe9ea; color: var(--red); }
.note-pop .author { font-size: 11px; color: #889; margin-top: 4px; }

/* import bookmarklet */
.import-help {
  background: none; border: 0; color: #4c7dff; cursor: pointer; font-size: 12px;
  padding: 2px 0 8px; text-align: left;
}
.modal {
  position: absolute; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center;
  background: rgba(20, 26, 33, 0.55); padding: 16px;
}
.modal-card {
  background: #fff; border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px; width: min(440px, 94vw); position: relative;
}
.modal-card h2 { margin: 0 0 8px; font-size: 18px; }
.modal-close {
  position: absolute; top: 10px; right: 10px; border: 0; background: none; font-size: 16px; cursor: pointer; color: #667;
}
.bookmarklet {
  display: inline-block; background: var(--green); color: #fff; text-decoration: none;
  padding: 9px 14px; border-radius: 9px; font-weight: 600; cursor: grab;
}
.import-code {
  width: 100%; font-family: ui-monospace, Menlo, monospace; font-size: 11px;
  border: 1px solid #cbd2d9; border-radius: 8px; padding: 8px; resize: vertical; color: #334;
}
.copy-btn {
  margin-top: 6px; border: 0; border-radius: 8px; padding: 7px 12px; background: #eef1f4; cursor: pointer; font-weight: 600;
}

/* toast */
.toast {
  position: absolute; z-index: 30; bottom: 18px; left: 50%; transform: translateX(-50%);
  background: rgba(31, 41, 51, 0.94); color: #fff; padding: 9px 16px; border-radius: 20px;
  font-size: 13px; box-shadow: var(--shadow); max-width: 80vw; text-align: center;
}

/* connection dot */
.conn {
  position: absolute; z-index: 10; bottom: 8px; left: 10px; font-size: 13px;
  color: var(--green); text-shadow: 0 0 2px rgba(0,0,0,0.3); transition: color 0.2s;
}
.conn.down { color: var(--red); }

/* MapLibre attribution: keep it out of the way of the panel */
.maplibregl-ctrl-bottom-right { margin-right: 4px; }
