:root {
  --red: #d93a3a;
  --yellow: #e6b422;
  --green: #2f9e44;
  --purple: #7c3aed;
  --gray: #4a5058;
  --ink: #1b1d1e;
  --mute: #5a6067;
  --bg: #fafbfc;
  --rule: #e3e6ea;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
/* Use dynamic viewport height on browsers that support it so iOS Safari's
   address-bar collapse/expand doesn't leave the map overflowing or gapping. */
@supports (height: 100dvh) {
  html, body { height: 100dvh; }
}
body { display: flex; flex-direction: column; }

header {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; border-bottom: 1px solid var(--rule); background: #fff;
}
header h1 { font-size: 15px; margin: 0; font-weight: 600; }

.search { position: relative; flex: 1; max-width: 520px; }
.search input {
  width: 100%; padding: 7px 10px; font-size: 14px;
  border: 1px solid var(--rule); border-radius: 6px; outline: none;
}
.search input:focus { border-color: #4a90e2; }
#results {
  position: absolute; top: 100%; left: 0; right: 0; margin: 4px 0 0;
  padding: 0; list-style: none; background: #fff;
  border: 1px solid var(--rule); border-radius: 6px;
  box-shadow: 0 6px 16px rgba(0,0,0,0.08);
  max-height: 320px; overflow-y: auto; z-index: 1001;
}
#results li {
  padding: 8px 10px; font-size: 13px; cursor: pointer;
  border-bottom: 1px solid var(--rule);
}
#results li:last-child { border-bottom: none; }
#results li:hover, #results li[aria-selected="true"] { background: #f2f6fb; }
#results .acct { color: var(--mute); font-size: 11px; margin-left: 8px; }

.legend { font-size: 12px; color: var(--mute); display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.legend-item { white-space: nowrap; }
.legend-label { color: var(--mute); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  vertical-align: middle; margin-right: 3px; }
.dot.red    { background: var(--red); }
.dot.yellow { background: var(--yellow); }
.dot.green  { background: var(--green); }
.dot.purple { background: var(--purple); }
.dot.gray   { background: var(--gray); }

.info-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px; padding: 0; margin-left: 2px;
  background: #fff; color: var(--mute);
  border: 1px solid var(--rule); border-radius: 50%;
  font-size: 12px; font-weight: 600; line-height: 1;
  cursor: pointer;
}
.info-btn:hover { background: #f2f6fb; color: var(--ink); border-color: #c3cad2; }
.info-btn[aria-expanded="true"] { background: #1b6fe6; color: #fff; border-color: #1b6fe6; }

.intro-nudge {
  background: none; border: none; padding: 0 2px; margin: 0;
  font: inherit; color: #1b6fe6; font-size: 12px;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
.intro-nudge:hover { text-decoration: underline; }

.info-popover {
  position: fixed; top: 52px; right: 16px; z-index: 1002;
  max-width: 420px; padding: 18px 20px;
  background: #fff; border: 1px solid var(--rule); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.10);
  font-size: 13px; line-height: 1.55; color: var(--ink);
}
.info-popover section { margin-bottom: 14px; }
.info-popover section + section { padding-top: 14px; border-top: 1px solid var(--rule); }
.info-popover h3 { margin: 0 0 6px; font-size: 14px; font-weight: 600; color: var(--ink); }
.info-popover p { margin: 6px 0; }
.info-popover ul, .info-popover ol { padding-left: 0; margin: 8px 0; list-style: none; counter-reset: howto; }
.info-popover li { margin: 6px 0; padding-left: 0; }
.info-popover ol li { padding-left: 22px; position: relative; counter-increment: howto; }
.info-popover ol li::before {
  content: counter(howto);
  position: absolute; left: 0; top: 0;
  width: 16px; height: 16px; border-radius: 50%;
  background: #eef2f7; color: var(--ink);
  font-size: 10px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}
.info-popover li strong { color: var(--ink); }
.info-popover a { color: #1b6fe6; }
.info-popover ol .dot { margin: 0 1px; }
.info-disclaimer { margin-top: 14px !important; padding-top: 10px;
  border-top: 1px solid var(--rule);
  font-size: 11px; color: var(--mute); }
.info-relative {
  margin-top: 10px !important; padding: 8px 10px;
  background: #f3eefe; border-left: 3px solid var(--purple);
  font-size: 12px; color: var(--ink); border-radius: 4px;
}
.info-close {
  margin-top: 6px; padding: 6px 12px;
  background: #fff; color: var(--mute);
  border: 1px solid var(--rule); border-radius: 5px;
  font-size: 12px; font-weight: 600; cursor: pointer;
}
.info-close:hover { background: #f2f6fb; color: var(--ink); }

@media (max-width: 720px) {
  /* Stack the header so search gets a full row.
     Row 1: title + (optional nudge) + ?
     Row 2: search (full width)
     Inline legend is hidden — the ? popover is the color reference on phones. */
  header {
    flex-wrap: wrap;
    gap: 8px 10px;
    padding: 8px 12px;
  }
  header h1 { flex: 1 1 auto; font-size: 14px; }
  .search {
    order: 3;
    flex: 1 1 100%;
    width: 100%;
    max-width: none;
  }
  .legend {
    order: 2;
    flex: 0 0 auto;
    gap: 6px;
    margin-left: auto;
  }
  .legend-item { display: none; }
  .intro-nudge { font-size: 11px; }
  .info-popover {
    top: 92px;
    right: 8px; left: 8px;
    max-width: none;
  }
}

main { flex: 1; position: relative; }
#map { position: absolute; top: 0; left: 0; right: 0; bottom: 0; }

/* Map-overlay legend (bottom-left). Always visible — five color rows
   stacked, no header, no toggle. */
.legend-control {
  background: #fff;
  padding: 6px 10px 8px;
  font-size: 12px;
  color: var(--ink);
  line-height: 1.3;
  min-width: 170px;
}
.legend-control .legend-row {
  display: grid;
  grid-template-columns: 12px auto 1fr;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}
.legend-control .legend-row .dot {
  width: 12px; height: 12px; margin: 0;
}
.legend-control .legend-desc {
  color: var(--mute); font-size: 11px;
  white-space: nowrap;
  text-align: right;
}

.locate-control .locate-btn {
  display: flex; align-items: center; justify-content: center;
  width: 30px; height: 30px;
  background: #fff; color: var(--ink);
  cursor: pointer;
}
.locate-control .locate-btn:hover { background: #f2f6fb; color: #1b6fe6; }
.locate-control.loading .locate-btn { color: #1b6fe6; }
.locate-control.loading .locate-btn svg { animation: locate-pulse 1s ease-in-out infinite; }
@keyframes locate-pulse { 50% { opacity: 0.35; } }

.locate-toast {
  position: fixed; left: 50%; bottom: 72px; transform: translateX(-50%);
  z-index: 2000; max-width: calc(100vw - 32px);
  padding: 10px 14px;
  background: #1b1d1e; color: #fff;
  border-radius: 8px;
  font-size: 13px; line-height: 1.4;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.20);
}

footer {
  padding: 8px 16px; font-size: 12px; color: var(--mute);
  border-top: 1px solid var(--rule); background: #fff; text-align: center;
}

.parcel-popup { font-size: 13px; line-height: 1.45; }
.parcel-popup .addr { font-weight: 600; margin-bottom: 2px; }
.parcel-popup .owner { font-size: 12px; color: var(--mute); margin-bottom: 4px; }
.parcel-popup .pct { font-weight: 600; }
.parcel-popup .pct.red    { color: var(--red); }
.parcel-popup .pct.yellow { color: #a57a00; }
.parcel-popup .pct.green  { color: var(--green); }
.parcel-popup .pct.purple { color: var(--purple); }
.parcel-popup .pct.gray   { color: var(--gray); }
.parcel-popup a.download {
  display: inline-block; margin-top: 6px; padding: 5px 9px;
  background: #1b6fe6; color: #fff; border-radius: 5px;
  text-decoration: none; font-weight: 600; font-size: 12px;
}
.parcel-popup a.download:hover { background: #155fc6; }

/* Mobile bottom sheet — shown instead of Leaflet popup on touch/narrow views.
   Fixed at the bottom, doesn't move with the map, has room for content,
   explicit close button, finger won't occlude the text. */
.parcel-sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1500;
  padding: 24px 20px 24px;
  background: #fff;
  border-top-left-radius: 14px; border-top-right-radius: 14px;
  box-shadow: 0 -6px 20px rgba(0, 0, 0, 0.14);
  transform: translateY(100%);
  transition: transform 0.22s ease-out;
  max-height: 60vh; overflow-y: auto;
  font-size: 15px; line-height: 1.45; color: var(--ink);
}
.parcel-sheet.open { transform: translateY(0); }
/* Bucket-color accent strip across the top — catches the eye and
   reinforces the signal the user just tapped. */
.parcel-sheet::before {
  content: "";
  position: absolute; top: 0; left: 0; right: 0;
  height: 5px;
  border-top-left-radius: 14px; border-top-right-radius: 14px;
  background: var(--gray);
}
.parcel-sheet.red::before    { background: var(--red); }
.parcel-sheet.yellow::before { background: var(--yellow); }
.parcel-sheet.green::before  { background: var(--green); }
.parcel-sheet.purple::before { background: var(--purple); }
.parcel-sheet.gray::before   { background: var(--gray); }
/* Pull-handle pill — standard mobile affordance for a draggable/
   dismissible sheet. Purely visual here; dismissal is via close button
   or tap-on-map. */
.parcel-sheet::after {
  content: "";
  position: absolute; top: 10px; left: 50%;
  transform: translateX(-50%);
  width: 36px; height: 4px;
  border-radius: 2px;
  background: #d0d5db;
}
.parcel-sheet .sheet-close {
  position: absolute; top: 16px; right: 10px;
  width: 32px; height: 32px; padding: 0;
  background: none; border: none;
  font-size: 22px; line-height: 1; color: var(--mute);
  cursor: pointer; border-radius: 50%;
}
.parcel-sheet .sheet-close:hover,
.parcel-sheet .sheet-close:active { background: #f2f6fb; color: var(--ink); }
.parcel-sheet .sheet-addr { font-weight: 600; font-size: 17px; padding-right: 36px; margin-bottom: 2px; }
.parcel-sheet .sheet-owner { font-size: 13px; color: var(--mute); margin-bottom: 6px; }
.parcel-sheet .sheet-meta { font-size: 13px; color: var(--mute); margin-bottom: 6px; }
.parcel-sheet .sheet-pct { font-weight: 600; margin: 4px 0 14px; }
.parcel-sheet .sheet-pct.red    { color: var(--red); }
.parcel-sheet .sheet-pct.yellow { color: #a57a00; }
.parcel-sheet .sheet-pct.green  { color: var(--green); }
.parcel-sheet .sheet-pct.purple { color: var(--purple); }
.parcel-sheet .sheet-pct.gray   { color: var(--gray); }
.parcel-sheet .sheet-action {
  display: block; text-align: center;
  padding: 12px 16px; border-radius: 8px;
  text-decoration: none; font-weight: 600; font-size: 15px;
}
.parcel-sheet .sheet-action.download { background: #1b6fe6; color: #fff; }
.parcel-sheet .sheet-action.download:active { background: #155fc6; }

/* ============================================================
   REPORT PAGE — screen layout, then @media print at the bottom.
   Served at report.html?a=<account>; rendered by report.js.
   ============================================================ */
body.report-page { background: var(--bg); }

.report-toolbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  background: #fff; border-bottom: 1px solid var(--rule);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}
.toolbar-btn {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid var(--rule);
  background: #fff; color: var(--ink);
  border-radius: 6px;
  font-size: 13px; font-weight: 600;
  text-decoration: none; cursor: pointer;
  font-family: inherit;
}
.toolbar-btn:hover { background: #f2f6fb; border-color: #c3cad2; }
.toolbar-btn.print {
  background: #1b6fe6; color: #fff; border-color: #1b6fe6;
}
.toolbar-btn.print:hover { background: #155fc6; border-color: #155fc6; }

.report {
  max-width: 820px; margin: 0 auto; padding: 24px 20px 48px;
  font-size: 14px; line-height: 1.5; color: var(--ink);
}
.report-sheet {
  background: #fff;
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 40px 48px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.report .legal-notice {
  font-style: italic; font-size: 12px; color: var(--mute);
  margin: 0 0 20px; padding-bottom: 14px;
  border-bottom: 1px solid var(--rule);
}

/* Verdict banner — immediate file/don't-file signal at the top of Page 1.
   Big label + small subtitle, tinted by bucket. Deliberately attention-
   grabbing for the "FILE" / "DO NOT FILE" variants; muted for skip. */
.report .verdict-banner {
  display: flex; align-items: baseline; gap: 14px;
  margin: 0 0 20px;
  padding: 14px 18px;
  border-radius: 6px;
  border-left: 6px solid var(--gray);
  background: #f4f6f8;
}
.report .verdict-label {
  font-size: 22px; font-weight: 800; letter-spacing: 0.5px;
  white-space: nowrap;
}
.report .verdict-subtitle {
  font-size: 13px; color: var(--ink); line-height: 1.4;
}
.report .verdict-banner.verdict-red {
  background: #fde8e8; border-left-color: var(--red);
}
.report .verdict-banner.verdict-red .verdict-label { color: var(--red); }
.report .verdict-banner.verdict-yellow {
  background: #fff5d6; border-left-color: var(--yellow);
}
.report .verdict-banner.verdict-yellow .verdict-label { color: #8a6500; }
.report .verdict-banner.verdict-green {
  background: #e8f5ec; border-left-color: var(--green);
}
.report .verdict-banner.verdict-green .verdict-label { color: var(--green); }
.report .verdict-banner.verdict-purple {
  background: #f3eefe; border-left-color: var(--purple);
}
.report .verdict-banner.verdict-purple .verdict-label { color: var(--purple); }
.report .verdict-banner.verdict-gray {
  background: #f1f3f5; border-left-color: var(--gray);
}
.report .verdict-banner.verdict-gray .verdict-label { color: var(--gray); }

@media (max-width: 560px) {
  .report .verdict-banner { flex-direction: column; gap: 4px; padding: 12px 14px; }
  .report .verdict-label { font-size: 18px; }
}

.report .report-title {
  margin: 0 0 2px; font-size: 22px; font-weight: 700;
}
.report .report-subtitle {
  margin: 0 0 18px; font-size: 13px; color: var(--mute);
}
.report h2 {
  margin: 20px 0 8px; font-size: 15px; font-weight: 700;
  padding-bottom: 4px; border-bottom: 1px solid var(--rule);
}
.report h3 {
  margin: 16px 0 6px; font-size: 14px; font-weight: 700;
}
.report p { margin: 8px 0; }
.report a { color: #1b6fe6; }

.report .bottomline {
  margin: 14px 0 20px;
  padding: 14px 16px;
  background: #F4F7FB;
  border-left: 3px solid #1b6fe6;
  border-radius: 4px;
  font-size: 15px; line-height: 1.5;
}

/* Facts table */
.report table.facts {
  width: 100%; border-collapse: collapse;
  font-size: 13px;
}
.report table.facts th,
.report table.facts td {
  padding: 6px 10px;
  text-align: left; vertical-align: middle;
  border-bottom: 1px solid var(--rule);
}
.report table.facts tr:last-child th,
.report table.facts tr:last-child td { border-bottom: none; }
.report table.facts th { font-weight: 600; width: 38%; }

/* Comp table */
.report table.comps {
  width: 100%; border-collapse: collapse;
  font-size: 13px; margin: 10px 0 12px;
}
.report table.comps thead th {
  background: #EEEEEE; font-weight: 600;
  padding: 8px 10px; text-align: left;
  border-bottom: 1px solid #000;
}
.report table.comps th.col-num,
.report table.comps th.col-year { text-align: center; }
.report table.comps th.col-sqft,
.report table.comps th.col-psf,
.report table.comps th.col-value { text-align: right; }

.report table.facts .psf-inline {
  color: var(--mute); font-weight: 400; font-size: 12px;
}
.report table.comps tbody td,
.report table.comps tfoot td {
  padding: 6px 10px; border-bottom: 1px solid var(--rule);
}
.report table.comps td.num { text-align: right; font-variant-numeric: tabular-nums; }
.report table.comps .subject-row td {
  background: #FFF7E6; font-weight: 600;
}
.report table.comps tfoot tr.summary td {
  background: #F4F7FB;
  font-weight: 600;
}

/* Comp-spread confidence badge (next to "Median $/sqft of 5 comps").
   Reads as a tiny pill so it doesn't dominate the median number itself. */
.report .conf-badge {
  display: inline-block; margin-left: 8px;
  padding: 1px 7px; border-radius: 999px;
  font-size: 10px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.04em; vertical-align: middle;
  border: 1px solid currentColor;
  cursor: help;
}
.report .conf-badge.conf-tight    { color: var(--green); background: #ecf9ef; }
.report .conf-badge.conf-moderate { color: #a57a00;     background: #fff8e1; }
.report .conf-badge.conf-wide     { color: var(--red);   background: #fdecec; }

/* Purple "do not file" warning box (replaces hearing script for under-
   assessed parcels). High-contrast border + background so it can't be
   skimmed past — this is a safety message. */
.report .purple-warning {
  margin: 12px 0 18px;
  padding: 14px 18px;
  background: #f3eefe;
  border-left: 4px solid var(--purple);
  border-radius: 4px;
  color: var(--ink);
}
.report .purple-warning p { margin: 6px 0; }
.report .purple-warning p:first-child { margin-top: 0; font-size: 15px; }
.report .purple-warning p:last-child { margin-bottom: 0; font-size: 12px; color: var(--mute); }
.report table.comps tfoot tr.summary:first-child td {
  border-top: 1px solid #000;
}
.report table.comps tfoot tr.summary.over td:last-child { color: #C03030; }
.report table.comps tfoot tr.summary.under td:last-child { color: var(--green); }

/* Gray-parcel "no comps" notice takes the place of the comp table */
#gray-notice p { margin: 10px 0; }

/* Deadline banner (Page 2) */
.report .deadline-banner {
  margin: 12px 0 18px;
  padding: 14px 16px;
  background: #FFF8E1;
  border: 1px solid #E6B422;
  border-radius: 5px;
  font-size: 14px;
}

/* Rebuttals table */
.report table.rebuttals {
  width: 100%; border-collapse: collapse;
  font-size: 13px; margin: 10px 0 14px;
}
.report table.rebuttals thead th {
  background: #EEEEEE; font-weight: 600;
  padding: 8px 10px; text-align: left;
  border-bottom: 1px solid #000;
}
.report table.rebuttals td {
  padding: 8px 10px; vertical-align: top;
  border-bottom: 1px solid var(--rule);
}
.report table.rebuttals td:first-child {
  width: 38%; font-style: italic;
}

/* What-not-to-argue + disclaimer lists */
.report ul.not-to-argue,
.report ul.disclaimer-list {
  list-style: none; padding: 0; margin: 8px 0;
}
.report ul.not-to-argue li,
.report ul.disclaimer-list li {
  padding: 6px 0 6px 18px;
  position: relative;
  font-size: 13px; line-height: 1.5;
}
.report ul.not-to-argue li::before,
.report ul.disclaimer-list li::before {
  content: "•"; position: absolute; left: 4px; color: var(--mute);
}

/* Hearing script ordered list */
.report ol.script {
  padding: 0 0 0 24px; margin: 10px 0;
}
.report ol.script li {
  margin: 10px 0; font-size: 14px;
}

.report .report-footer {
  margin-top: 24px; padding-top: 14px;
  border-top: 1px solid var(--rule);
  font-size: 12px; color: var(--mute); text-align: center;
  font-style: italic;
}

/* Error state (bad ?a= or missing data) */
.report-error {
  max-width: 560px; margin: 60px auto; padding: 30px 32px;
  background: #fff; border: 1px solid var(--rule); border-radius: 8px;
  text-align: center;
}
.report-error h1 { font-size: 20px; margin: 0 0 10px; }
.report-error a { color: #1b6fe6; }

@media (max-width: 720px) {
  .report { padding: 12px 8px 40px; }
  .report-sheet { padding: 22px 18px; border-radius: 6px; }
  .report-toolbar { padding: 8px 12px; }
  .report .report-title { font-size: 18px; }
  .report table.facts th { width: 42%; }
  .report table.comps { font-size: 12px; }
  .report table.comps thead th,
  .report table.comps tbody td,
  .report table.comps tfoot td { padding: 5px 6px; }
  .report table.rebuttals td:first-child { width: 40%; }
}

/* ============================================================
   PRINT: hide chrome, page-break between Page 1 and Page 2,
   tighten margins to fit one sheet per section of LETTER paper.
   ============================================================ */
@media print {
  body.report-page { background: #fff; }
  .report-toolbar { display: none; }
  .report {
    max-width: none; margin: 0; padding: 0;
    font-size: 11pt; line-height: 1.35;
  }
  .report-sheet {
    border: none; box-shadow: none; margin: 0;
    padding: 0;
    page-break-after: always;
    break-after: page;
  }
  .report-sheet:last-of-type {
    page-break-after: auto;
    break-after: auto;
  }
  .report-sheet.page-1 { page-break-inside: avoid; }
  .report h2, .report h3 { page-break-after: avoid; }
  .report table { page-break-inside: avoid; }
  .report .legal-notice {
    border-bottom: 1px solid #999; font-size: 9pt;
  }
  .report .verdict-banner {
    background: #fff !important;
    border: 1px solid #000; border-left-width: 4px !important;
    border-left-color: #000 !important;
    page-break-inside: avoid;
  }
  .report .verdict-banner .verdict-label { color: #000 !important; }
  .report .bottomline {
    background: #fff; border-left: 2px solid #000;
    padding: 8px 10px; font-size: 11pt;
  }
  .report .deadline-banner {
    background: #fff; border: 1px solid #999;
  }
  .report table.comps .subject-row td { background: #eee; }
  .report table.comps tfoot tr.summary td { background: #f4f4f4; }
  .report table.comps tfoot tr.summary.over td:last-child { color: #000; font-weight: 700; }
  .report table.comps tfoot tr.summary.under td:last-child { color: #000; font-weight: 700; }
  .report .conf-badge {
    background: #fff !important; color: #000 !important;
    border: 1px solid #000;
  }
  .report .purple-warning {
    background: #fff; border: 2px solid #000; border-left-width: 4px;
    color: #000;
  }
  a { color: #000; text-decoration: none; }
  @page { margin: 0.75in; }
}
