/* ============================================================
   MLSPoppy — mobile-first premium UI
   ============================================================ */
:root {
  --ink: #0f1b2d;
  --ink-2: #1c2c44;
  --paper: #f7f5f0;
  --card: #ffffff;
  --line: #e6e1d6;
  --muted: #6b7688;
  --text: #172033;
  --gold: #c9a24b;
  --gold-deep: #a9822f;
  --accent: #1F6FDB; /* MLSPoppy sapphire */
  --accent-deep: #1a56ad;
  --danger: #c0432f;
  --ok: #2f8f5b;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(15, 27, 45, 0.10);
  --shadow-sm: 0 2px 10px rgba(15, 27, 45, 0.06);
  /* No serif faces anywhere — display text uses the sans stack, weighted up. */
  --serif: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--sans);
  color: var(--text);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 0.9rem; margin: 0.5rem 0 0; }
[hidden] { display: none !important; }
em { font-style: italic; color: var(--text); }

/* ---- Buttons ---- */
button { font-family: inherit; cursor: pointer; }
.btn-primary {
  background: var(--ink);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 0.85rem 1.4rem;
  font-size: 1rem;
  font-weight: 600;
  transition: transform 0.08s ease, background 0.2s ease;
}
.btn-primary:hover { background: var(--ink-2); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.6; cursor: default; }
.btn-ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 0.5rem 0.9rem;
  font-size: 0.9rem;
  font-weight: 500;
}
.btn-ghost:hover { border-color: var(--muted); }

/* ---- Top bar ---- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--ink);
  color: #fff;
  padding: env(safe-area-inset-top) 0 0;
}
.topbar-inner {
  max-width: 1120px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.75rem 1rem;
}
.brand-row { display: flex; align-items: center; gap: 0.6rem; }
.topbar-title { font-weight: 600; letter-spacing: 0.01em; }
.topbar-actions { display: flex; gap: 0.5rem; }
.topbar .btn-ghost { color: #fff; border-color: rgba(255,255,255,0.25); }
.topbar .btn-ghost:hover { border-color: rgba(255,255,255,0.6); }

.brand-mark {
  width: 56px; height: 56px; border-radius: 14px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: var(--ink); font-weight: 800; font-size: 1.3rem; letter-spacing: 0.02em;
  box-shadow: var(--shadow-sm);
}
.brand-mark.small { width: 34px; height: 34px; border-radius: 9px; font-size: 0.85rem; }

/* MLSPoppy hummingbird mark */
.brand-bird { width: 72px; height: 72px; display: block; }
.brand-bird.small { width: 36px; height: 36px; }
.login-card .brand-bird { margin: 0 auto 0.7rem; }
.tm-sup { font-size: 0.5em; vertical-align: super; letter-spacing: 0; opacity: 0.75; }

/* ---- Login ---- */
.login-body {
  min-height: 100vh; display: grid; place-items: center;
  background: radial-gradient(120% 120% at 50% 0%, #1c2c44 0%, var(--ink) 60%);
  padding: 1.5rem;
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--card); border-radius: 22px; padding: 2rem 1.6rem;
  box-shadow: var(--shadow);
}
.login-card .brand { text-align: center; margin-bottom: 1.5rem; }
.login-card .brand-mark { margin: 0 auto 0.9rem; }
.login-card h1 { margin: 0; font-size: 1.4rem; }
.login-card form { display: flex; flex-direction: column; gap: 0.5rem; }
.login-card label { font-size: 0.85rem; font-weight: 600; color: var(--muted); }
.login-card input {
  padding: 0.85rem 1rem; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 12px; background: #fbfaf7;
}
.login-card input:focus { outline: 2px solid var(--gold); border-color: var(--gold); }
.login-card .btn-primary { margin-top: 0.6rem; }
/* What app is this? — stated under the name so the page identifies itself. */
.login-card .app-what { margin: 0.35rem 0 0.15rem; font-size: 0.95rem; color: var(--ink); }
.login-card .muted { font-size: 0.82rem; margin: 0.15rem 0 0; }
.login-card .pw-label-row { display: flex; align-items: baseline; justify-content: space-between; }
.link-btn {
  background: none; border: none; padding: 0; font: inherit; font-size: 0.82rem; font-weight: 600;
  color: var(--gold-deep); cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}
.link-btn:hover { color: var(--ink); }
.login-card .forgot-btn { margin-top: 0.9rem; align-self: center; }
/* After a failed attempt the way out should be impossible to miss. */
.login-card .forgot-btn.nudge { color: var(--danger); animation: forgot-pulse 1.2s ease-in-out 2; }
@keyframes forgot-pulse { 50% { opacity: 0.35; } }
.recovery-panel {
  margin-top: 1.1rem; padding: 0.9rem 1rem; border: 1px solid var(--line); border-radius: 12px;
  background: #fbfaf7; font-size: 0.86rem; line-height: 1.45;
}
.recovery-panel p { margin: 0 0 0.6rem; }
.recovery-panel p:last-child { margin-bottom: 0; }
.recovery-panel .small { font-size: 0.78rem; }
.recovery-panel code { font-size: 0.8rem; background: #f0ece2; padding: 0.1rem 0.3rem; border-radius: 4px; }

/* ---- Ask view ---- */
.ask-view { min-height: calc(100vh - 60px); display: grid; place-items: center; padding: 1.5rem 1rem 3rem; }
.ask-hero { text-align: center; max-width: 560px; width: 100%; }
.ask-title { font-family: var(--serif); font-weight: 700; font-size: clamp(1.8rem, 6vw, 2.6rem); margin: 0.2rem 0 0.6rem; line-height: 1.1; }
.ask-sub { font-size: 1rem; margin: 0 auto 2rem; max-width: 460px; }

.mic {
  position: relative;
  width: 108px; height: 108px; border-radius: 50%;
  border: none; margin: 0.5rem auto 0.8rem;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--ink), var(--ink-2));
  color: #fff; box-shadow: var(--shadow);
  transition: transform 0.1s ease;
}
.mic:active { transform: scale(0.96); }
.mic-ring {
  position: absolute; inset: -6px; border-radius: 50%;
  border: 3px solid var(--gold); opacity: 0;
}
.mic.listening { background: linear-gradient(135deg, var(--accent), var(--accent-deep)); }
.mic.listening .mic-ring { animation: pulse 1.4s ease-out infinite; opacity: 1; }
@keyframes pulse {
  0% { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(1.35); opacity: 0; }
}
.mic-status { font-size: 0.95rem; min-height: 1.4em; margin: 0 0 1.6rem; }

.text-fallback { display: flex; gap: 0.5rem; max-width: 460px; margin: 0 auto 1.6rem; }
.text-fallback input {
  flex: 1; padding: 0.8rem 1rem; font-size: 1rem;
  border: 1px solid var(--line); border-radius: 12px; background: var(--card);
}
.text-fallback input:focus { outline: 2px solid var(--gold); border-color: var(--gold); }
.text-fallback .btn-primary { padding: 0.8rem 1.1rem; }

.examples { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: center; }
.chip {
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: 0.5rem 0.9rem; font-size: 0.85rem;
  transition: border-color 0.2s, background 0.2s;
}
.chip:hover { border-color: var(--gold); background: #fffdf7; }

/* ---- Clarify view ---- */
.clarify-view, .report-view, .loading-view { max-width: 1120px; margin: 0 auto; padding: 1.25rem 1rem 4rem; }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.5rem; box-shadow: var(--shadow-sm); max-width: 620px; margin: 1rem auto; }
.eyebrow { text-transform: uppercase; letter-spacing: 0.12em; font-size: 0.72rem; font-weight: 700; color: var(--gold-deep); margin: 0 0 0.4rem; }
.panel-title { font-family: var(--serif); font-weight: 700; font-size: 1.5rem; margin: 0 0 0.4rem; }
.questions { display: flex; flex-direction: column; gap: 1.25rem; margin: 1.4rem 0; }
.q-block label.q-text { display: block; font-weight: 600; margin-bottom: 0.55rem; }
.q-block .q-why { font-size: 0.82rem; color: var(--muted); margin: -0.35rem 0 0.55rem; }
.q-options { display: flex; flex-wrap: wrap; gap: 0.45rem; margin-bottom: 0.5rem; }
.opt {
  border: 1px solid var(--line); background: #fbfaf7; border-radius: 999px;
  padding: 0.45rem 0.85rem; font-size: 0.88rem; color: var(--text);
}
.opt.selected { background: var(--ink); color: #fff; border-color: var(--ink); }
.q-block input.q-free {
  width: 100%; padding: 0.7rem 0.9rem; border: 1px solid var(--line);
  border-radius: 10px; font-size: 0.95rem; background: #fbfaf7;
}
.q-block input.q-free:focus { outline: 2px solid var(--gold); border-color: var(--gold); }
.clarify-actions { display: flex; justify-content: space-between; gap: 0.75rem; margin-top: 0.5rem; }

/* ---- Loading ---- */
.loading-view { display: grid; place-items: center; min-height: 50vh; gap: 1rem; }
.spinner {
  width: 46px; height: 46px; border-radius: 50%;
  border: 4px solid var(--line); border-top-color: var(--gold);
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Agent brand banner ---- */
.agent-banner {
  display: flex; align-items: center; gap: 1.4rem;
  background: linear-gradient(180deg, #ffffff 0%, #fbfaf7 100%);
  border: 1px solid var(--line); border-top: 4px solid var(--gold);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 1rem 1.5rem; margin-bottom: 1.3rem;
}
.agent-photo {
  height: 118px; width: auto; object-fit: contain; flex-shrink: 0;
  align-self: flex-end;
}
.agent-names { font-family: var(--serif); font-size: 1.65rem; font-weight: 600; color: var(--ink); line-height: 1.1; }
.agent-tag {
  color: var(--gold-deep); font-weight: 700; font-size: 0.82rem;
  letter-spacing: 0.06em; text-transform: uppercase; margin-top: 0.25rem;
}
.agent-group { color: var(--muted); font-size: 0.86rem; margin-top: 0.3rem; }
.agent-contact { display: flex; flex-wrap: wrap; gap: 0.25rem 1.1rem; margin-top: 0.55rem; font-size: 0.86rem; color: var(--text); }
.agent-contact .ac-item { position: relative; }
.agent-contact .ac-item + .ac-item::before {
  content: ""; position: absolute; left: -0.58rem; top: 0.15rem; bottom: 0.15rem;
  width: 1px; background: var(--line);
}
.agent-contact b { color: var(--ink); }

@media (max-width: 560px) {
  .agent-banner { flex-direction: column; text-align: center; align-items: center; gap: 0.6rem; padding: 1rem; }
  .agent-photo { height: 150px; align-self: center; }
  .agent-contact { justify-content: center; }
  .agent-contact .ac-item + .ac-item::before { display: none; }
}

/* ---- Report header ---- */
.back-btn { margin-bottom: 0.9rem; font-weight: 600; }
.report-header { margin-bottom: 1rem; }
.report-title {
  outline: none; border-radius: 8px; padding: 2px 8px; margin-left: -8px;
  transition: background 0.15s, box-shadow 0.15s; cursor: text;
}
.report-title:hover { background: rgba(201, 162, 75, 0.10); }
.report-title:focus { background: #fffdf5; box-shadow: inset 0 0 0 2px var(--gold); }
.edit-hint { color: var(--gold-deep); font-size: 0.78rem; white-space: nowrap; }
.corr-note { color: var(--accent); font-weight: 600; }

/* ---- Gold primary action (Save as PDF) ---- */
.btn-gold {
  background: linear-gradient(135deg, var(--gold), var(--gold-deep));
  color: var(--ink); border: none; border-radius: 10px;
  padding: 0.5rem 1rem; font-size: 0.9rem; font-weight: 700; font-family: inherit;
  cursor: pointer; box-shadow: var(--shadow-sm); white-space: nowrap;
  transition: filter 0.15s, transform 0.05s;
}
.btn-gold:hover { filter: brightness(1.06); }
.btn-gold:active { transform: translateY(1px); }
.btn-gold:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---- Send to ShowPoppy ---- */
.btn-showpoppy {
  background: var(--accent); color: #fff; border: none; border-radius: 10px;
  padding: 0.5rem 0.95rem; font-size: 0.9rem; font-weight: 600; font-family: inherit;
}
.btn-showpoppy:hover { background: #245c58; }
.btn-showpoppy:disabled { opacity: 0.6; }

/* ---- PDF choice menu ---- */
.pdf-menu { position: relative; display: inline-block; }
.pdf-choices {
  position: absolute; right: 0; top: calc(100% + 6px);
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); padding: 0.35rem; z-index: 30; min-width: 168px;
}
.pdf-choices button {
  display: block; width: 100%; text-align: left; background: transparent; border: none;
  padding: 0.55rem 0.7rem; border-radius: 8px; font-size: 0.9rem; color: var(--text);
}
.pdf-choices button:hover { background: #f3f0e8; }
.report-header h1 { font-family: var(--serif); font-weight: 700; font-size: clamp(1.5rem, 5vw, 2.1rem); margin: 0 0 0.25rem; }
.report-header .report-meta { color: var(--muted); font-size: 0.9rem; }

/* ---- Answer banner (for "how many" count questions) ---- */
.answer-banner {
  background: linear-gradient(135deg, var(--ink), var(--ink-2)); color: #fff;
  border-radius: var(--radius); padding: 1.4rem 1.6rem; margin-bottom: 1.25rem;
  font-family: var(--serif); font-size: clamp(1.3rem, 3.6vw, 2rem); line-height: 1.3;
  box-shadow: var(--shadow-sm);
}
.answer-banner .count-num { color: var(--gold); font-weight: 700; }
.answer-sub { font-family: var(--sans); font-size: 0.98rem; margin-top: 0.7rem; color: rgba(255, 255, 255, 0.82); }
.answer-sub b { color: var(--gold); font-weight: 700; }
.answer-asof { font-family: var(--sans); font-size: 0.8rem; margin-top: 0.6rem; color: rgba(255, 255, 255, 0.6); }
.oh-answer { font-family: var(--sans); font-size: 0.95rem; margin-top: 0.35rem; color: rgba(255,255,255,0.9); }
/* Client-friendly shareable text panel */
.friendly-panel { background: var(--card); border: 1px solid var(--line); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 1rem 1.2rem 1.1rem; margin-bottom: 1.25rem; box-shadow: var(--shadow-sm); }
.fp-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; font-family: var(--sans); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted); font-weight: 700; margin-bottom: 0.7rem; }
.fp-share { text-transform: none; letter-spacing: 0; font-size: 0.85rem; padding: 0.4rem 0.85rem; }
.fp-text { font-family: var(--sans); font-size: 0.96rem; line-height: 1.5; white-space: pre-wrap; color: var(--text); margin: 0; }
.oh-answer.yes b { color: var(--gold); }
.oh-answer.no { color: rgba(255,255,255,0.7); }
.comm-box { margin-top: 0.95rem; padding-top: 0.8rem; border-top: 1px solid rgba(255, 255, 255, 0.16); }
.comm-label { font-family: var(--sans); font-size: 0.7rem; letter-spacing: 0.05em; text-transform: uppercase; color: rgba(255, 255, 255, 0.6); margin-bottom: 0.55rem; }
.comm-row { display: flex; flex-wrap: wrap; gap: 1.1rem 2.2rem; }
.comm-split { font-family: var(--sans); font-size: 0.75rem; color: rgba(255, 255, 255, 0.72); margin-bottom: 0.1rem; }
.comm-amt { font-family: var(--serif); font-size: 1.4rem; font-weight: 700; color: var(--gold); line-height: 1.1; }

/* ---- Stat bar ---- */
.stat-bar {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.75rem;
  margin-bottom: 1.25rem;
}
.stat {
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 0.9rem 1rem; box-shadow: var(--shadow-sm);
}
.stat .stat-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.stat .stat-value { font-family: var(--serif); font-size: 1.35rem; font-weight: 600; margin-top: 0.2rem; }
.stat.hero { grid-column: span 2; background: linear-gradient(135deg, var(--ink), var(--ink-2)); color: #fff; border: none; }
.stat.hero .stat-label { color: rgba(255,255,255,0.7); }
.stat.hero .stat-value { color: var(--gold); font-size: 1.7rem; }

/* ---- Report toolbar ---- */
.report-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.75rem; margin-bottom: 1rem; flex-wrap: wrap;
}
.view-toggle { display: inline-flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg { border: none; background: transparent; padding: 0.5rem 0.95rem; font-size: 0.9rem; font-weight: 500; color: var(--muted); }
.seg.active { background: var(--ink); color: #fff; }
.toolbar-right { display: flex; align-items: center; gap: 0.6rem; }
.sort-label { font-size: 0.82rem; color: var(--muted); display: flex; align-items: center; gap: 0.35rem; }
.sort-label select { padding: 0.45rem 0.5rem; border: 1px solid var(--line); border-radius: 9px; background: var(--card); font-size: 0.85rem; }

/* ---- Column/title builder overlay ---- */
.layout-overlay {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(15, 27, 45, 0.55);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 1.5rem 1rem; overflow-y: auto;
}
.layout-modal {
  background: var(--paper); border-radius: 20px; box-shadow: var(--shadow);
  width: 100%; max-width: 720px; padding: 1.25rem 1.25rem 1.5rem; margin: auto 0;
}
.lb-modal-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.lb-modal-head h2 { font-family: var(--serif); font-weight: 700; font-size: 1.5rem; margin: 0; }
.lb-intro { font-size: 0.9rem; margin: 0.35rem 0 1rem; }
.ask-columns-btn { margin-top: 1.6rem; }
.lb-add-row { margin-bottom: 0.6rem; }
.lb-dropdown { width: 100%; padding: 0.7rem 0.8rem; font-size: 0.95rem; }

/* ---- Layout builder ---- */
.layout-builder {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm); padding: 1rem 1.1rem 1.2rem; margin-bottom: 0;
}
.lb-row { margin-bottom: 0.9rem; }
.lb-row:last-child { margin-bottom: 0; }
.lb-head { display: flex; align-items: baseline; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.5rem; }
.lb-title { font-weight: 700; font-size: 0.9rem; }
.lb-hint { font-size: 0.75rem; color: var(--muted); }
.chip-track {
  display: flex; flex-wrap: wrap; gap: 0.45rem; min-height: 44px;
  padding: 0.5rem; border-radius: 12px; background: #fbfaf7; border: 1px dashed var(--line);
}
.active-track { border-color: var(--gold); background: #fffdf5; }
.col-chip {
  display: inline-flex; align-items: center; gap: 0.4rem;
  background: var(--ink); color: #fff; border-radius: 999px;
  padding: 0.4rem 0.5rem 0.4rem 0.7rem; font-size: 0.85rem; font-weight: 600;
  touch-action: none; user-select: none; cursor: grab;
}
.col-chip .grip { opacity: 0.6; font-size: 0.8rem; letter-spacing: -2px; }
.col-chip .rm {
  border: none; background: rgba(255,255,255,0.18); color: #fff; cursor: pointer;
  width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center;
  font-size: 0.7rem; line-height: 1;
}
.col-chip .rm:hover { background: var(--danger); }
.col-chip.dragging { opacity: 0.45; cursor: grabbing; }
.col-chip.drop-target { outline: 2px dashed var(--gold); outline-offset: 2px; }
.palette-chip {
  background: var(--card); border: 1px solid var(--line); color: var(--text);
  border-radius: 999px; padding: 0.4rem 0.8rem; font-size: 0.85rem; cursor: pointer;
}
.palette-chip:hover { border-color: var(--gold); background: #fffdf7; }
.palette-chip::before { content: "＋ "; color: var(--gold-deep); font-weight: 700; }
.lb-saved-controls { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.4rem; }
.lb-select, .lb-name {
  padding: 0.5rem 0.6rem; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); font-size: 0.88rem; font-family: inherit;
}
.lb-name { flex: 1; min-width: 140px; }
.lb-select { min-width: 160px; }
.lb-spacer { flex: 1 1 12px; }
.lb-save { padding: 0.5rem 1rem; }

/* ---- Cards ---- */
.cards-grid { display: grid; grid-template-columns: 1fr; gap: 1rem; }
.listing {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  overflow: hidden; box-shadow: var(--shadow-sm); display: flex; flex-direction: column;
  transition: transform 0.1s ease, box-shadow 0.2s ease;
}
.listing:hover { box-shadow: var(--shadow); }
.listing.is-clickable { cursor: pointer; }
.listing.is-clickable:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--gold); }
.listing-photo { position: relative; aspect-ratio: 16 / 10; background: #e9e5db; overflow: hidden; }
.listing-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.listing-photo .no-photo { width: 100%; height: 100%; display: grid; place-items: center; color: var(--muted); font-size: 0.85rem; }
.badge {
  position: absolute; top: 0.6rem; left: 0.6rem;
  background: rgba(15,27,45,0.88); color: #fff; font-size: 0.72rem; font-weight: 600;
  padding: 0.28rem 0.6rem; border-radius: 999px; letter-spacing: 0.02em;
}
.badge.dom { left: auto; right: 0.6rem; background: rgba(201,162,75,0.95); color: var(--ink); }
.badge.oh-badge {
  top: auto; bottom: 0.6rem; left: 0.6rem; right: auto;
  background: var(--accent); color: #fff; letter-spacing: 0.04em;
}
.badge.role-badge {
  top: auto; bottom: 0.6rem; left: 0.6rem; right: auto;
  background: var(--accent); color: #fff; letter-spacing: 0.03em;
}
.listing-oh {
  margin-top: 0.55rem; font-size: 0.86rem; font-weight: 700; color: var(--accent);
  background: rgba(47,111,107,0.10); border: 1px solid rgba(47,111,107,0.25);
  border-radius: 8px; padding: 0.35rem 0.6rem; display: inline-block;
}
.fact.dist { color: var(--gold-deep); font-weight: 600; }
.listing-body { padding: 0.9rem 1rem 1.1rem; }
.listing-price { font-family: var(--serif); font-size: 1.4rem; font-weight: 600; }
.listing-sold { font-family: var(--sans, inherit); font-size: 0.8rem; font-weight: 600; color: var(--gold-deep); letter-spacing: 0.02em; margin-top: 0.1rem; }
.listing-addr { font-weight: 600; margin-top: 0.15rem; }
.listing-sub { color: var(--muted); font-size: 0.88rem; }
.listing-facts { display: flex; flex-wrap: wrap; gap: 0.4rem 0.9rem; margin-top: 0.7rem; font-size: 0.88rem; }
.listing-facts .fact b { font-weight: 700; }
.listing-foot { margin-top: 0.7rem; padding-top: 0.6rem; border-top: 1px solid var(--line); font-size: 0.78rem; color: var(--muted); display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.listing-info { flex: 0 0 auto; border: 1px solid var(--gold); background: rgba(201, 162, 75, 0.1); color: var(--gold-deep); font-weight: 600; font-size: 0.78rem; padding: 0.28rem 0.62rem; border-radius: 999px; cursor: pointer; white-space: nowrap; transition: background 0.15s; }
.listing-info:hover { background: var(--gold); color: #fff; }
th.info-col, td.info-col { width: 1%; padding-left: 0.4rem; padding-right: 0.4rem; text-align: center; }
.row-info { border: 1px solid var(--line); background: var(--card); color: var(--gold-deep); font-size: 0.95rem; line-height: 1; width: 1.7rem; height: 1.7rem; border-radius: 50%; cursor: pointer; transition: background 0.15s, color 0.15s; }
.row-info:hover { background: var(--gold); color: #fff; border-color: var(--gold); }

/* ---- Agent roster / leaderboard tables ---- */
.agents-wrap { margin-top: 0.5rem; }
.agents-note { color: var(--muted); font-size: 0.86rem; margin-bottom: 0.7rem; padding: 0.55rem 0.75rem; background: rgba(201, 162, 75, 0.08); border-left: 3px solid var(--gold); border-radius: 0 8px 8px 0; }
.agents-table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow-sm); }
.agents-table thead th { background: var(--ink); color: #fff; font-family: var(--sans); font-size: 0.74rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; text-align: left; padding: 0.7rem 0.85rem; }
.agents-table th.num, .agents-table td.num { text-align: right; }
/* Click a column title to sort; clicking the same one again flips the direction. */
.agents-table th.sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.agents-table th.sortable:hover { background: var(--ink-2); }
.agents-table th .arrow { color: var(--gold); font-size: 0.7rem; }
.agents-table th.ag-rank, .agents-table td.ag-rank { text-align: center; width: 2.4rem; color: var(--gold-deep); font-weight: 700; }
.agents-table tbody td { padding: 0.62rem 0.85rem; border-top: 1px solid var(--line); font-size: 0.92rem; }
.agents-table tbody tr:nth-child(even) { background: #faf8f3; }
.agents-table .ag-name { font-weight: 600; color: var(--ink); }
.agents-table .ag-link { font: inherit; font-weight: 600; color: var(--gold-deep); background: none; border: none; padding: 0; cursor: pointer; text-align: left; text-decoration: underline; text-decoration-color: rgba(201, 162, 75, 0.45); text-underline-offset: 2px; }
.agents-table .ag-link:hover { color: var(--ink); text-decoration-color: var(--gold); }
.agents-table .ag-hot { font-weight: 700; color: var(--gold-deep); }

/* ---- Full-property detail view ---- */
.detail-wrap { margin-top: 0.5rem; }
.detail-property { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 1.4rem 1.5rem 1.6rem; margin-bottom: 1.5rem; }
.dp-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; padding-bottom: 1rem; border-bottom: 2px solid var(--gold); }
.dp-addr { font-family: var(--serif); font-size: 1.7rem; font-weight: 600; line-height: 1.15; color: var(--ink); }
.dp-sub { color: var(--muted); margin-top: 0.2rem; }
.dp-priceblock { text-align: right; }
.dp-price { font-family: var(--serif); font-size: 1.8rem; font-weight: 700; color: var(--gold-deep); }
.dp-pricemeta { font-size: 0.8rem; color: var(--muted); margin-top: 0.15rem; }
.dp-status { font-weight: 700; color: var(--ink); }
.dp-sold { color: var(--gold-deep); font-weight: 600; }
.dp-mls { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; }
.dp-gallery { margin: 1.1rem 0 0.4rem; }
.dp-main { width: 100%; max-height: 460px; object-fit: cover; border-radius: 12px; background: var(--paper); }
.dp-thumbs { display: flex; gap: 0.5rem; overflow-x: auto; padding: 0.6rem 0 0.2rem; }
.dp-thumbs img { width: 92px; height: 66px; object-fit: cover; border-radius: 8px; cursor: pointer; opacity: 0.6; border: 2px solid transparent; flex: 0 0 auto; transition: opacity 0.15s; }
.dp-thumbs img:hover { opacity: 0.9; }
.dp-thumbs img.active { opacity: 1; border-color: var(--gold); }
.dp-tour { display: inline-block; margin: 0.3rem 0 0.6rem; color: var(--accent); font-weight: 600; text-decoration: none; }
.dp-tour:hover { text-decoration: underline; }
.dp-sections { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.1rem 1.8rem; margin-top: 1rem; }
.dp-section { break-inside: avoid; }
.dp-h { font-family: var(--sans); font-size: 0.72rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase; color: var(--gold-deep); margin: 0 0 0.5rem; padding-bottom: 0.35rem; border-bottom: 1px solid var(--line); }
.dp-grid { display: flex; flex-direction: column; gap: 0.35rem; }
.dp-row { display: flex; justify-content: space-between; gap: 1rem; font-size: 0.9rem; line-height: 1.35; }
.dp-k { color: var(--muted); flex: 0 0 auto; }
.dp-v { color: var(--text); text-align: right; font-weight: 500; }
/* ---- Agent dossier: collapsible sections so one agent doesn't fill the screen ---- */
.ad-head { padding-bottom: 0.9rem; border-bottom: 2px solid var(--gold); margin-bottom: 1rem; }
.ad-name { margin: 0; font-size: 1.45rem; }
.ad-idline { margin-top: 0.3rem; font-size: 0.92rem; color: var(--muted); }
/* .answer-asof is white-on-dark inside the banner; on the light header it needs its own color. */
.ad-head .answer-asof { color: var(--muted); margin-top: 0.35rem; }
.ad-drop {
  border: 1px solid var(--line); border-radius: var(--radius); background: var(--card);
  box-shadow: var(--shadow-sm); margin-bottom: 0.7rem; overflow: hidden;
}
.ad-drop > summary {
  display: flex; align-items: baseline; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap;
  padding: 0.85rem 1rem; cursor: pointer; user-select: none; list-style: none;
}
.ad-drop > summary::-webkit-details-marker { display: none; }
.ad-drop > summary:hover { background: #fbfaf7; }
.ad-drop > summary::before {
  content: '▸'; color: var(--gold-deep); font-size: 0.8rem; margin-right: 0.15rem;
  transition: transform 0.15s ease; display: inline-block;
}
.ad-drop[open] > summary::before { transform: rotate(90deg); }
.ad-drop[open] > summary { border-bottom: 1px solid var(--line); }
.ad-title { font-weight: 700; font-size: 1rem; flex: 1 1 auto; }
.ad-sum { color: var(--gold-deep); font-weight: 600; font-size: 0.92rem; text-align: right; }
.ad-body { padding: 0.9rem 1rem 1.1rem; }
.ad-body .answer-banner { margin: 0; }
.ad-body .dp-sections { margin-top: 0.4rem; }
.ad-foot { margin: 0.6rem 0 0; font-size: 0.82rem; }
.ad-txfilter { margin-bottom: 0.7rem; }
.ad-txfilter .muted { font-weight: 500; }
.ad-idsplit { margin-top: 0.9rem; padding-top: 0.7rem; border-top: 1px solid var(--line); }
.ad-idsplit-h .dp-k, .ad-idsplit-h .dp-v { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--gold-deep); }
.ad-actions { margin: 0.9rem 0 0; }
.ad-link {
  font: inherit; font-weight: 600; font-size: 0.92rem; color: var(--gold-deep);
  background: none; border: none; padding: 0; cursor: pointer;
  text-decoration: underline; text-decoration-color: rgba(201, 162, 75, 0.45); text-underline-offset: 3px;
}
.ad-link:hover { color: var(--ink); text-decoration-color: var(--gold); }
.ad-listings { box-shadow: none; }
.ad-listings .dl-status { font-weight: 600; color: var(--gold-deep); white-space: nowrap; }
.ad-listings .info-col { width: 2rem; text-align: center; }
/* Drill-down links inside the dark answer banner need the bright gold to read. */
.answer-banner .ad-actions { margin: 0.8rem 0 0; font-size: 1rem; }
.answer-banner .ad-link { color: var(--gold); text-decoration-color: rgba(201, 162, 75, 0.6); }
.answer-banner .ad-link:hover { color: #fff; }
/* A count answer's drill-down: the collapsible provides the card frame, so the
   table wrapper drops its own (no double border), and the body scrolls the table. */
.table-wrap:has(> .count-drill) { background: none; border: none; box-shadow: none; overflow: visible; }
.count-drill .ad-body { padding: 0; overflow-x: auto; }
/* Printing an agent sheet must not hide content behind collapsed arrows. */
@media print {
  .ad-drop { break-inside: avoid; box-shadow: none; }
  .ad-drop > summary::before { content: ''; }
  .ad-drop .ad-body { display: block !important; }
}
.dp-remarks-sec { margin-top: 1.2rem; }
.dp-remarks { font-size: 0.95rem; line-height: 1.6; color: var(--text); white-space: pre-line; }
@media (max-width: 640px) {
  .dp-head { flex-direction: column; }
  .dp-priceblock { text-align: left; }
  .dp-sections { grid-template-columns: 1fr; }
}

/* ---- Table ---- */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
table { border-collapse: collapse; width: 100%; font-size: 0.88rem; min-width: 720px; }
thead th {
  text-align: left; padding: 0.7rem 0.85rem; background: #fbfaf7;
  border-bottom: 2px solid var(--line); font-weight: 700; white-space: nowrap;
  position: sticky; top: 0; cursor: pointer; user-select: none;
}
thead th .arrow { color: var(--gold-deep); font-size: 0.7rem; }
tbody td { padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
tbody tr:hover { background: #fdfcf9; }
/* Sales / leases selector in the report toolbar. */
.tx-filter { display: inline-flex; align-items: center; gap: 0.4rem; font-size: 0.82rem; font-weight: 600; color: var(--muted); }
.tx-filter select {
  font: inherit; font-weight: 600; color: var(--ink); padding: 0.35rem 0.5rem;
  border: 1px solid var(--line); border-radius: 9px; background: var(--card); cursor: pointer;
}
.tx-filter select:focus { outline: 2px solid var(--gold); }
/* Rows that open the property sheet — the ⓘ alone is too small a target. */
tbody tr.is-clickable { cursor: pointer; }
.agents-table tbody tr.is-clickable:hover { background: #f6f2e8; }
td.num, th.num { text-align: right; }

/* ---- Empty / toast ---- */
.empty { text-align: center; color: var(--muted); padding: 3rem 1rem; }
.toast {
  position: fixed; left: 50%; bottom: 1.5rem; transform: translateX(-50%);
  background: var(--danger); color: #fff; padding: 0.8rem 1.2rem; border-radius: 12px;
  box-shadow: var(--shadow); z-index: 50; max-width: 90vw; font-size: 0.9rem;
}

/* ---- Tablet / desktop ---- */
@media (min-width: 640px) {
  .stat-bar { grid-template-columns: repeat(4, 1fr); }
  .stat.hero { grid-column: span 2; }
  .cards-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 960px) {
  .cards-grid { grid-template-columns: repeat(3, 1fr); }
}

/* ---- Print / PDF ---- */
/* ---- Print / PDF: a client-ready, email-able market report ---- */
.print-footer { display: none; }

@media print {
  @page { size: Letter; margin: 0.5in 0.5in 0.72in; }
  html, body { background: #fff !important; }
  /* Print the brand colors, not just black on white. */
  * { -webkit-print-color-adjust: exact !important; print-color-adjust: exact !important; }

  /* Hide app chrome and on-screen-only affordances. */
  .topbar, #newReportBtn, .report-toolbar, #errorToast, .back-btn, .edit-hint,
  #layoutOverlay, .listing-info, .row-info, th.info-col, td.info-col,
  .dp-thumbs, .dp-tour { display: none !important; }

  .report-view { padding: 0 !important; max-width: none !important; margin: 0 !important; }
  .report-title { box-shadow: none !important; background: none !important; padding: 0 !important; margin-left: 0 !important; }

  /* Letterhead — compact, keeps the gold rule + portrait; stays with the report. */
  .agent-banner {
    break-inside: avoid; break-after: avoid; box-shadow: none;
    border: 1px solid var(--line); border-top: 3px solid var(--gold);
    padding: 0.5rem 0.9rem; margin-bottom: 0.55rem; gap: 1rem;
  }
  .agent-photo { height: 84px; }
  .agent-names { font-size: 1.32rem; }
  .agent-tag { font-size: 0.68rem; margin-top: 0.08rem; }
  .agent-group { font-size: 0.72rem; margin-top: 0.12rem; }
  .agent-contact { font-size: 0.72rem; margin-top: 0.28rem; gap: 0.2rem 0.9rem; }

  .report-header { margin-bottom: 0.5rem; break-after: avoid; }
  .report-header h1 { font-size: 1.55rem; }
  .report-header .report-meta { font-size: 0.72rem; }

  /* Navy hero answer block (how many / when) prints in full color. */
  .answer-banner { break-inside: avoid; box-shadow: none; padding: 1.1rem 1.3rem; }

  /* Stat bar — compact tiles so the first row of homes lands on page 1. */
  .stat-bar { grid-template-columns: repeat(4, 1fr) !important; gap: 0.4rem; break-inside: avoid; margin-bottom: 0.6rem; }
  .stat { padding: 0.5rem 0.62rem !important; box-shadow: none !important; border: 1px solid var(--line); }
  .stat .stat-value { font-size: 1.02rem !important; }
  .stat.hero { grid-column: span 2; }
  .stat.hero .stat-value { font-size: 1.24rem !important; }

  /* Cards — two per row, each kept whole; keep the first row with the header. */
  body[data-pdf="table"] #cardsWrap,
  body[data-pdf="answer"] #cardsWrap { display: none !important; }
  body[data-pdf="cards"] #tableWrap,
  body[data-pdf="detail"] #tableWrap,
  body[data-pdf="answer"] #tableWrap { display: none !important; }
  body[data-pdf="cards"] #cardsWrap,
  body[data-pdf="both"] #cardsWrap {
    display: grid !important; grid-template-columns: 1fr 1fr !important; gap: 0.45rem !important;
  }
  body[data-pdf="table"] #tableWrap,
  body[data-pdf="both"] #tableWrap { display: block !important; box-shadow: none; }
  body[data-pdf="both"] #tableWrap { margin-top: 0.55rem; }

  .listing { break-inside: avoid; box-shadow: none; border: 1px solid var(--line); }
  .listing-photo { aspect-ratio: auto !important; height: 2in !important; }
  .listing-body { padding: 0.55rem 0.72rem 0.72rem !important; }
  .listing-price { font-size: 1.15rem !important; }
  .listing-facts { margin-top: 0.4rem; font-size: 0.78rem; }
  .listing-foot { margin-top: 0.5rem; }

  /* Table — repeat the header on every page, keep rows intact. */
  #tableWrap table { font-size: 0.72rem; }
  #tableWrap thead { display: table-header-group; }
  #tableWrap tr { break-inside: avoid; }
  #tableWrap th { background: var(--ink) !important; color: #fff !important; }

  /* Agent roster / leaderboard sheet. */
  .agents-table { font-size: 0.74rem; box-shadow: none; }
  .agents-table thead { display: table-header-group; }
  .agents-table tbody tr { break-inside: avoid; }
  .agents-table thead th { background: var(--ink) !important; color: #fff !important; }
  .agents-note { break-inside: avoid; }

  /* Single-property detail sheet. */
  .detail-property { break-inside: avoid; box-shadow: none; border: 1px solid var(--line); padding: 0.9rem 1rem; }
  .dp-main { max-height: 3.4in !important; }
  .dp-section { break-inside: avoid; }

  /* On a CLIENT listing report (one you'd send to a client), never expose other
     agents' info in the PDF: hide the detail Agents section and the List Agent /
     List Office table columns. Agent-centric reports (a report ABOUT an agent)
     keep everything — the whole point is that agent's data. */
  body[data-report-kind="client"] .dp-agents,
  body[data-report-kind="client"] .agentcol { display: none !important; }

  /* Gold-ruled footer, repeated on every page of the PDF. */
  .print-footer {
    display: block; position: fixed; bottom: 0; left: 0; right: 0;
    border-top: 1px solid var(--gold); padding: 0.28rem 0;
    font-family: var(--sans); font-size: 0.62rem; letter-spacing: 0.03em;
    color: var(--muted); text-align: center; background: #fff;
  }
}
