/* Harborview Homesearch — shared styles (client + admin). Mobile-first, no framework. */
:root {
  --brand: #1f4e79;
  --brand-ink: #ffffff;
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #16202a;
  --muted: #5b6b7a;
  --line: #e2e6ea;
  --ok: #1d7a4f;
  --warn: #b26a00;
  --err: #b3261e;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
a { color: var(--brand); }
button { font: inherit; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---- layout ---- */
.app { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; padding-top: calc(12px + env(safe-area-inset-top, 0px));
  background: var(--brand); color: var(--brand-ink);
}
.topbar h1 { font-size: 17px; font-weight: 600; margin: 0; flex: 1; letter-spacing: 0.01em; }
.topbar .sub { font-size: 12px; opacity: 0.85; display: block; font-weight: 400; }
.topbar button { background: rgba(255,255,255,0.15); color: inherit; border: 0; border-radius: 10px; padding: 8px 12px; }
.main { flex: 1; width: 100%; max-width: 760px; margin: 0 auto; padding: 14px 14px 0; }

/* ---- criteria chip ---- */
.chip {
  display: flex; align-items: center; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 12px 8px 14px; margin-bottom: 12px; font-size: 14px; color: var(--muted);
}
.chip .chip-text { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip .chip-text b { color: var(--ink); font-weight: 600; }
.chip button { border: 0; background: var(--brand); color: #fff; border-radius: 999px; padding: 6px 12px; font-size: 13px; }

/* ---- messages ---- */
.thread { display: flex; flex-direction: column; gap: 10px; padding-bottom: 12px; }
.msg { max-width: 92%; padding: 10px 14px; border-radius: var(--radius); white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.user { align-self: flex-end; background: var(--brand); color: var(--brand-ink); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.assistant.error { border-color: #f1c7c4; background: #fff5f4; }
.msg.system { align-self: center; background: transparent; color: var(--muted); font-size: 13px; text-align: center; }
.msg .text { margin: 0; }
.msg .text + .card, .card + .text, .card + .card { margin-top: 10px; }
.meta { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* ---- working line ---- */
.working { align-self: flex-start; display: flex; flex-direction: column; gap: 6px; padding: 10px 14px; background: var(--card); border: 1px dashed var(--line); border-radius: var(--radius); font-size: 14px; color: var(--muted); max-width: 92%; }
.working .line { display: flex; align-items: center; gap: 8px; }
.working .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--brand); animation: pulse 1.1s ease-in-out infinite; flex: none; }
.working .elapsed { font-variant-numeric: tabular-nums; }
.working .hint { font-size: 12px; }
@keyframes pulse { 0%, 100% { opacity: 0.25; transform: scale(0.85); } 50% { opacity: 1; transform: scale(1); } }

/* ---- listing card ---- */
.card { border: 1px solid var(--line); border-radius: 12px; padding: 12px; background: #fbfcfd; white-space: normal; }
.card .addr { font-weight: 600; font-size: 15px; color: var(--brand); text-decoration: none; display: block; line-height: 1.35; }
.card .addr:not([href]) { color: var(--ink); }
.card .price { font-size: 17px; font-weight: 700; margin-top: 4px; }
.card .facts { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 6px; font-size: 13px; color: var(--muted); }
.card .facts span b { color: var(--ink); font-weight: 600; }
.card .status { margin-top: 6px; font-size: 13px; }
.card .status.coming { color: var(--warn); }
.card .status.active { color: var(--ok); }
.card .notes { margin-top: 8px; font-size: 13px; color: var(--ink); white-space: pre-wrap; }
.card .mls { margin-top: 8px; font-size: 13px; color: var(--muted); font-style: italic; }
.card .open { margin-top: 8px; font-size: 13px; }

/* ---- composer ---- */
.composer {
  position: sticky; bottom: 0; z-index: 4;
  background: linear-gradient(to top, var(--bg) 70%, rgba(246,247,249,0));
  padding: 10px 14px calc(10px + var(--safe-bottom));
}
.composer form { display: flex; gap: 8px; max-width: 760px; margin: 0 auto; }
.composer textarea {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; font: inherit; font-size: 16px; background: var(--card); max-height: 120px; min-height: 46px;
}
.composer button { border: 0; background: var(--brand); color: #fff; border-radius: 14px; padding: 0 16px; font-weight: 600; min-width: 64px; }
.composer button:disabled { opacity: 0.5; }
.composer .note { font-size: 12px; color: var(--muted); text-align: center; margin: 6px 0 0; }

/* ---- sheets / dialogs ---- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,0.35); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--card); width: 100%; max-width: 560px; border-radius: 18px 18px 0 0; padding: 18px 18px calc(18px + var(--safe-bottom)); box-shadow: 0 -8px 30px rgba(0,0,0,0.15); }
.sheet h2 { margin: 0 0 12px; font-size: 18px; }
.sheet label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
.sheet input, .sheet textarea, .sheet select { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font: inherit; font-size: 16px; }
.sheet .row { display: flex; gap: 10px; }
.sheet .row > * { flex: 1; }
.sheet .actions { display: flex; gap: 10px; margin-top: 16px; }
.btn { border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; background: var(--brand); color: #fff; cursor: pointer; }
.btn.secondary { background: #eef1f4; color: var(--ink); }
.btn.danger { background: #fbe9e7; color: var(--err); }
.btn.small { padding: 8px 12px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: 0.5; cursor: default; }

/* ---- auth / landing ---- */
.landing { max-width: 420px; margin: 8vh auto 0; padding: 0 18px; text-align: center; }
.landing .mark { width: 72px; height: 72px; border-radius: 20px; background: var(--brand); display: inline-flex; align-items: center; justify-content: center; color: #fff; font-size: 34px; font-weight: 700; margin-bottom: 14px; }
.landing h1 { font-size: 22px; margin: 0 0 6px; }
.landing p { color: var(--muted); margin: 0 0 18px; }
.landing form { display: flex; flex-direction: column; gap: 10px; text-align: left; }
.landing input { border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font: inherit; font-size: 16px; }
.landing .msg-line { font-size: 14px; color: var(--muted); min-height: 1.4em; }
.landing .msg-line.err { color: var(--err); }

/* ---- install hint ---- */
.install { position: fixed; left: 12px; right: 12px; bottom: calc(84px + var(--safe-bottom)); z-index: 15; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; box-shadow: 0 10px 30px rgba(0,0,0,0.15); display: flex; gap: 12px; align-items: flex-start; max-width: 560px; margin: 0 auto; }
.install .icon { width: 44px; height: 44px; border-radius: 12px; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex: none; }
.install .body { flex: 1; font-size: 14px; }
.install .body b { display: block; margin-bottom: 2px; }
.install .steps { display: flex; align-items: center; gap: 6px; margin-top: 8px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.install .steps svg { width: 20px; height: 20px; vertical-align: middle; }
.install .close { border: 0; background: transparent; font-size: 20px; line-height: 1; color: var(--muted); padding: 0 4px; }
.install .actions { margin-top: 8px; display: flex; gap: 8px; }

/* ---- toast ---- */
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(96px + var(--safe-bottom)); background: var(--ink); color: #fff; padding: 10px 14px; border-radius: 12px; font-size: 14px; z-index: 30; max-width: 90vw; }

/* ---- admin ---- */
.tabs { display: flex; gap: 6px; padding: 10px 0 6px; overflow-x: auto; }
.tabs a { flex: none; text-decoration: none; padding: 8px 14px; border-radius: 999px; background: var(--card); border: 1px solid var(--line); color: var(--ink); font-size: 14px; }
.tabs a.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.tabs .badge { display: inline-block; min-width: 18px; padding: 0 6px; border-radius: 9px; background: var(--err); color: #fff; font-size: 12px; text-align: center; margin-left: 6px; }
.list { display: flex; flex-direction: column; gap: 8px; }
.item { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; gap: 10px; align-items: flex-start; text-decoration: none; color: inherit; }
.item .grow { flex: 1; min-width: 0; }
.item .title { font-weight: 600; }
.item .sub { font-size: 13px; color: var(--muted); margin-top: 2px; overflow-wrap: anywhere; }
.item .right { text-align: right; font-size: 12px; color: var(--muted); flex: none; }
.pill { display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px; background: #eef1f4; color: var(--muted); }
.pill.active { background: #e3f4ea; color: var(--ok); }
.pill.invited { background: #fff3e0; color: var(--warn); }
.pill.disabled { background: #fbe9e7; color: var(--err); }
.pill.showing_request { background: #fbe9e7; color: var(--err); }
.pill.agent_question { background: #fff3e0; color: var(--warn); }
.pill.search_summary { background: #e8eef7; color: var(--brand); }
.section { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; margin-bottom: 10px; }
.section h3 { margin: 0 0 8px; font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; font-size: 14px; }
.kv .k { color: var(--muted); }
.stat { display: flex; gap: 10px; flex-wrap: wrap; }
.stat .box { flex: 1; min-width: 120px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.stat .box .n { font-size: 22px; font-weight: 700; }
.stat .box .l { font-size: 12px; color: var(--muted); }
.transcript { display: flex; flex-direction: column; gap: 8px; }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0 12px; }
.empty { color: var(--muted); text-align: center; padding: 30px 10px; font-size: 14px; }
.fab { position: fixed; right: 16px; bottom: calc(16px + var(--safe-bottom)); z-index: 10; border-radius: 999px; padding: 14px 18px; box-shadow: 0 8px 24px rgba(0,0,0,0.2); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table td, .table th { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; }
.table td:first-child, .table th:first-child { text-align: left; }

.fine { font-size: 13px; }
.inline { display: inline; }
.notes-line { margin-top: 8px; }
