:root {
  --bg: #f6f7f9; --card: #fff; --text: #17202e; --muted: #5d6878; --line: #dde2e8;
  --accent: #1f5fa8; --accent-text: #fff; --ok: #e6f4ea; --ok-text: #1d5b2c; --err: #fdecea; --err-text: #8a1c12;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #11151b; --card: #1a2029; --text: #e6e9ee; --muted: #9aa4b2; --line: #2c3440;
    --accent: #5b9be0; --accent-text: #0b1220; --ok: #173222; --ok-text: #9ad7aa; --err: #3a1714; --err-text: #f2a79f;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 -apple-system, "Segoe UI", Roboto, sans-serif; }
main { max-width: 1200px; margin: 0 auto; padding: 16px; }
a { color: var(--accent); }
h1 { font-size: 1.5rem; margin: 0.5rem 0 1rem; }
h1 small { color: var(--muted); font-weight: 400; font-size: 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 0.5rem; }
small { color: var(--muted); }

nav.top { display: flex; gap: 16px; align-items: center; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
nav.top .brand { font-weight: 700; text-decoration: none; color: var(--text); }
nav.top .spacer { flex: 1; }
nav.top .who { color: var(--muted); }
nav.top form { margin: 0; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; margin-bottom: 16px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.narrow { max-width: 420px; margin: 10vh auto 0; }

label { display: block; margin-bottom: 10px; font-weight: 600; }
input, select, textarea { font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; width: 100%; font-weight: 400; margin-top: 3px; }
input[type="checkbox"], input[type="file"] { width: auto; }
button, .btn { font: inherit; font-weight: 600; background: var(--accent); color: var(--accent-text); border: 0; border-radius: 6px; padding: 9px 16px; cursor: pointer; text-decoration: none; display: inline-block; }
button.link { background: none; color: var(--accent); padding: 0; font-weight: 400; text-decoration: underline; }
.btn.secondary { background: transparent; color: var(--accent); border: 1px solid var(--accent); }

.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.filters input, .filters select { width: auto; margin: 0; }
.bulk { margin-bottom: 8px; display: flex; gap: 8px; align-items: center; }
.bulk select { width: auto; margin: 0; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 0.85rem; color: var(--muted); font-weight: 600; }
td.owners { max-width: 280px; font-size: 0.9rem; }
tr.inactive { opacity: 0.5; }

.tag, .status { font-size: 0.8rem; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); white-space: nowrap; }
.tag-short_sale { border-color: var(--accent); color: var(--accent); }
.status-responded, .status-appointment, .status-scanned { background: var(--ok); color: var(--ok-text); border-color: transparent; }
.status-do_not_mail, .status-dead { color: var(--muted); }

.ok { background: var(--ok); color: var(--ok-text); padding: 10px 12px; border-radius: 8px; }
.error { background: var(--err); color: var(--err-text); padding: 10px 12px; border-radius: 8px; }
.empty { color: var(--muted); }
dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; }
.qr svg { width: 160px; height: 160px; background: #fff; border-radius: 6px; }
.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li { padding: 6px 0; border-bottom: 1px solid var(--line); }
.timeline time { color: var(--muted); font-size: 0.85rem; }

/* homeowner page */
.ho { max-width: 680px; margin: 0 auto; }
.ho-head { display: flex; flex-direction: column; margin: 8px 0 24px; }
.ho-head .brand { font-weight: 700; font-size: 1.15rem; }
.ho .lead-in { font-size: 1.05rem; }
.ho-options { display: grid; gap: 12px; margin: 20px 0; }
.ho-options section, .ho-agent { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.ho-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.ho-form { margin-top: 16px; }
.hp { position: absolute; left: -9999px; }
.stop { text-align: center; margin: 12px 0; }
.ho-footer { color: var(--muted); font-size: 0.85rem; border-top: 1px solid var(--line); margin-top: 24px; padding-top: 12px; }

/* letters + map */
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row .grow { flex: 1; min-width: 220px; }
.row label { margin-bottom: 10px; }
.bulk .sep { width: 1px; height: 24px; background: var(--line); margin: 0 6px; }
.letter-links .btn { margin: 4px 4px 0 0; font-size: 0.85rem; padding: 6px 10px; }
#map { height: 68vh; min-height: 360px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 10px; }
#leadmap { height: 260px; border: 1px solid var(--line); border-radius: 10px; margin-bottom: 16px; }
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 0.85rem; color: var(--muted); margin-bottom: 16px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; }
textarea { font-family: Georgia, serif; line-height: 1.5; }

/* settings + add property */
.title-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.narrow-form { max-width: 640px; }
.card h2 + p small { display: block; margin-bottom: 8px; }
.card h2 { margin-top: 12px; }
.photo-row { display: flex; gap: 16px; align-items: center; margin-bottom: 12px; }
.me-photo { width: 96px; height: 96px; border-radius: 50%; object-fit: cover; border: 1px solid var(--line); flex: none; }
.me-photo.empty { display: grid; place-items: center; font-size: 0.8rem; color: var(--muted); background: var(--bg); }

/* letter editor: looks like the printed page */
.editor { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; margin-bottom: 14px; background: var(--card); }
.toolbar-ed { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; padding: 8px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); z-index: 1; }
.toolbar-ed button { background: transparent; color: var(--text); border: 1px solid transparent; border-radius: 6px; padding: 5px 9px; min-width: 34px; font-weight: 600; }
.toolbar-ed button:hover { border-color: var(--line); background: var(--bg); }
.toolbar-ed .t-italic { font-style: italic; } .toolbar-ed .t-underline { text-decoration: underline; }
.toolbar-ed .tsep { width: 1px; height: 22px; background: var(--line); margin: 0 4px; }
.toolbar-ed select { width: auto; margin: 0 0 0 auto; }
.paper { background: #e9ecf1; padding: 24px 12px; }
.letter-body { max-width: 6.7in; min-height: 5in; margin: 0 auto; background: #fff; color: #111; padding: 0.6in 0.6in; box-shadow: 0 2px 10px rgba(0,0,0,.12);
  font: 11pt/1.45 Georgia, "Times New Roman", serif; outline: none; }
.letter-body p { margin: 0 0 0.6em; }
.letter-body h2 { font: 600 15pt/1.3 Georgia, serif; margin: 0.4em 0 0.4em; color: #0f2050; }
.letter-body ul, .letter-body ol { margin: 0 0 0.6em; padding-left: 1.4em; }
.letter-body font[size="2"] { font-size: 9pt; } .letter-body font[size="5"] { font-size: 14pt; }
button.link.danger { color: #c0392b; margin: 4px 0 16px; }
.actions-cell { white-space: nowrap; }

/* letters and postcards: design uploads and the postcard message box */
.row-gap { display: inline-flex; gap: 8px; flex-wrap: wrap; }
.upload h2 { margin-top: 0; }
.art-row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.art-thumb { width: 120px; border: 1px solid var(--line); background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.1); }
.art-thumb.wide { width: 200px; }
.art-status { margin: 8px 0 0; font-weight: 600; }
label.check { display: flex; gap: 8px; align-items: center; font-weight: 400; }
label.check input { width: auto; margin: 0; }
/* the postcard's message column at its printed width, shown 1.6x so it's comfortable to edit */
.pc-paper { overflow-x: auto; }
.letter-body.pc-text { zoom: 1.6; width: 2.32in; max-width: none; min-height: 2.3in; padding: 0.12in 0.14in; font: 8.5pt/1.35 Georgia, "Times New Roman", serif;
  background: linear-gradient(#fff 2.18in, transparent 2.18in, transparent calc(2.18in + 1px), #fff calc(2.18in + 1px)), repeating-linear-gradient(90deg, #c33 0 4px, transparent 4px 8px);
  background-size: 100% 100%, 100% 1px; background-position: 0 0, 0 2.18in; background-repeat: no-repeat; }
.letter-body.pc-text p { margin: 0 0 0.45em; }
.letter-body.pc-text h2 { font-size: 11pt; }

/* ───────────── App shell (signed in): sidebar on a computer, top bar on a phone ───────────── */
:root { --side: #0f172a; --side-text: #cbd5e1; --side-on: #1e40af; --navy: #0f2050; --soft: #eef2f8; }
@media (prefers-color-scheme: dark) { :root { --soft: #1f2733; } }
body { font-family: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif; }
h1 { font: 600 1.75rem/1.2 "Fraunces", Georgia, serif; letter-spacing: -0.01em; }
h1 small { display: block; font: 400 0.95rem/1.4 "Inter", sans-serif; margin-top: 4px; }
.card { border-radius: 14px; padding: 20px; box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04); }
button, .btn { border-radius: 10px; }
input, select, textarea { border-radius: 8px; padding: 9px 11px; }
.muted { color: var(--muted); }

body.app nav.top { background: var(--side); color: var(--side-text); border: 0; padding: 12px 16px; gap: 12px;
  position: sticky; top: 0; z-index: 20; flex-wrap: wrap; }
body.app nav.top a { color: var(--side-text); text-decoration: none; }
nav.top .brand { color: #fff !important; font: 600 1.15rem/1.1 "Fraunces", Georgia, serif; display: flex; flex-direction: column; }
nav.top .brand span { font: 500 0.7rem "Inter", sans-serif; letter-spacing: 0.1em; text-transform: uppercase; color: #94a3b8; margin-top: 3px; }
nav.top .links { display: flex; gap: 4px; overflow-x: auto; order: 3; width: 100%; scrollbar-width: none; }
nav.top .links a { padding: 8px 14px; border-radius: 10px; white-space: nowrap; font-weight: 500; }
nav.top .links a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
nav.top .links a.on { background: var(--side-on); color: #fff; box-shadow: 0 6px 16px rgba(30, 64, 175, 0.35); }
nav.top .me { margin-left: auto; display: flex; align-items: center; gap: 12px; }
nav.top .who { display: flex; align-items: center; gap: 10px; }
nav.top .who span { display: none; color: #fff; font-weight: 600; font-size: 0.9rem; line-height: 1.2; }
nav.top .who small { display: block; color: #94a3b8; font-weight: 400; font-size: 0.75rem; }
nav.top button.link { color: #94a3b8; font-size: 0.85rem; }
.avatar { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: #1e40af; color: #fff;
  font: 600 0.8rem "Inter", sans-serif; font-style: normal; flex: none; }
.avatar.sm { width: 26px; height: 26px; font-size: 0.68rem; }

@media (min-width: 960px) {
  body.app { display: grid; grid-template-columns: 236px minmax(0, 1fr); min-height: 100vh; }
  body.app nav.top { flex-direction: column; align-items: stretch; height: 100vh; padding: 24px 16px; gap: 28px; flex-wrap: nowrap; }
  nav.top .brand { padding: 0 8px; }
  nav.top .links { flex-direction: column; order: 0; overflow: visible; }
  nav.top .links a { padding: 11px 14px; }
  nav.top .me { margin: auto 0 0; flex-direction: column; align-items: stretch; gap: 10px; border-top: 1px solid rgba(255, 255, 255, 0.08); padding-top: 16px; }
  nav.top .who span { display: block; }
  nav.top .me form { padding-left: 44px; }
  body.app main { padding: 32px 36px; max-width: 1280px; width: 100%; }
}

/* ───────────── Leads list ───────────── */
.filters { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.filters input[type="search"], .filters input[name="q"] { flex: 1 1 220px; }
.selbar { background: var(--soft); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; flex-wrap: wrap; margin-bottom: 14px; }
.selcount { font-weight: 600; color: var(--muted); min-width: 100px; }
.selcount.on { color: var(--accent); }
.table-wrap { border-radius: 14px; }
th { text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.72rem; padding: 12px 10px; background: var(--soft); }
td { padding: 12px 10px; vertical-align: middle; }
tbody tr:hover { background: var(--soft); }
tr.picked { background: var(--soft); }
td.addr a { font-weight: 600; color: var(--text); text-decoration: none; display: block; }
td.addr a:hover { color: var(--accent); }
td.addr small, td.activity small { display: block; font-size: 0.78rem; }
td.activity small { text-transform: uppercase; letter-spacing: 0.04em; font-size: 0.68rem; }
td.filed { white-space: nowrap; color: var(--muted); }
.agent-chip { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; font-weight: 500; }

/* status labels: same colors as the map dots */
.status, .tag { display: inline-block; font-size: 0.72rem; font-weight: 600; letter-spacing: 0.03em; text-transform: uppercase;
  padding: 3px 9px; border-radius: 999px; border: 0; background: var(--soft); color: var(--muted); white-space: nowrap; }
.status-new { background: #eef0f4; color: #5b6475; }
.status-mailed_1, .status-mailed_2, .status-mailed_3 { background: #e5edfb; color: #1d3f80; }
.status-scanned { background: #fff1db; color: #9a5b00; }
.status-responded, .status-appointment { background: #e3f5ea; color: #127a3e; }
.status-listed, .status-closed { background: #efe6f8; color: #5b2b94; }
.status-dead { background: #eef0f4; color: #8a94a6; }
.status-do_not_mail { background: #fde8e6; color: #b30c00; }
.tag-short_sale { background: #e5edfb; color: #1e40af; }
.tag-equity { background: #e3f5ea; color: #127a3e; }
.tag-reverse { background: #fff1db; color: #9a5b00; }
@media (prefers-color-scheme: dark) {
  .status, .tag { background: #253041 !important; color: #cbd5e1 !important; }
  .status-responded, .status-appointment, .tag-equity { color: #8fe0ad !important; }
  .status-scanned { color: #ffc46b !important; }
  .status-do_not_mail { color: #ff9a90 !important; }
  .status-mailed_1, .status-mailed_2, .status-mailed_3, .tag-short_sale { color: #9cc0ff !important; }
}

/* phone: each lead becomes a card */
@media (max-width: 720px) {
  .table-wrap.leads { background: transparent; border: 0; overflow: visible; }
  .table-wrap.leads table, .table-wrap.leads tbody { display: block; }
  .table-wrap.leads thead { display: none; }
  .table-wrap.leads tbody tr { display: grid; grid-template-columns: 28px 1fr auto; gap: 6px 10px; background: var(--card); border: 1px solid var(--line);
    border-radius: 14px; padding: 14px; margin-bottom: 10px; }
  .table-wrap.leads td { display: block; border: 0; padding: 0; }
  .table-wrap.leads td.pickcell { grid-row: 1 / span 2; }
  .table-wrap.leads td.addr { grid-column: 2 / 4; }
  .table-wrap.leads td[data-label] { grid-column: 2 / 4; display: flex; justify-content: space-between; gap: 12px; font-size: 0.9rem; }
  .table-wrap.leads td[data-label]::before { content: attr(data-label); color: var(--muted); font-size: 0.8rem; }
  .table-wrap.leads td.owners { max-width: none; }
  .table-wrap.leads td.activity { text-align: right; }
  .table-wrap.leads td.activity small { display: inline; margin-left: 6px; }
  .selbar select, .selbar button { flex: 1 1 auto; }
}

/* ───────────── Lead page ───────────── */
.lead-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px 20px; flex-wrap: wrap; margin-bottom: 18px; }
.lead-head h1 { margin: 0; }
.lead-head .chips { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.timeline li { display: flex; flex-direction: column; gap: 2px; padding: 10px 0 10px 18px; position: relative; border-bottom: 0; border-left: 2px solid var(--line); margin-left: 6px; }
.timeline li::before { content: ""; position: absolute; left: -7px; top: 15px; width: 12px; height: 12px; border-radius: 50%; background: var(--card); border: 2px solid #8a94a6; }
.timeline li.ev-scan::before, .timeline li.ev-callback::before { border-color: #127a3e; background: #127a3e; }
.timeline li.ev-mailed::before { border-color: #1e40af; }
.timeline li.ev-stop_mail::before { border-color: #d40e00; background: #d40e00; }
.timeline time { font-size: 0.78rem; }
@media (max-width: 720px) { .selbar .sep { display: none; } }
