:root {
  --ink: #18242b;
  --muted: #68757a;
  --paper: #f5f0e6;
  --card: #fffdf8;
  --line: #d9d4c9;
  --red: #b24737;
  --red-dark: #873226;
  --mint: #cfe3d7;
  --yellow: #efd889;
  --shadow: 0 18px 55px rgba(24, 36, 43, .1);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; color: var(--ink); background: var(--paper); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; color: inherit; }
button, select, input[type="range"] { cursor: pointer; }
a { color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

.site-header { min-height: 78px; padding: 14px clamp(18px, 4vw, 56px); display: flex; align-items: center; justify-content: space-between; gap: 24px; color: #fffaf0; background: var(--ink); }
.brand { display: inline-flex; align-items: center; gap: 12px; text-decoration: none; }
.brand-mark { display: grid; place-items: center; width: 42px; height: 42px; border-radius: 50% 50% 46% 54% / 52% 45% 55% 48%; color: #fffaf0; background: var(--red); font-family: Georgia, serif; font-size: 24px; font-weight: 700; transform: rotate(-4deg); }
.brand strong, .brand small { display: block; }
.brand strong { font-family: Georgia, "Times New Roman", serif; font-size: 21px; letter-spacing: .01em; }
.brand small { margin-top: 1px; color: #afbdc2; font-size: 12px; }
.header-meta { display: flex; align-items: center; gap: 18px; color: #b7c2c6; font-size: 13px; }
.profile-button { padding: 10px 14px; color: #fffaf0; background: transparent; border: 1px solid #526169; border-radius: 999px; }
.profile-button:hover { border-color: #fffaf0; }
.refresh-button { padding: 10px 14px; color: var(--ink); background: #fffaf0; border: 1px solid #fffaf0; border-radius: 999px; font-weight: 750; }
.refresh-button:hover { background: #fff; }
.refresh-button:disabled { cursor: default; opacity: .72; }

main { max-width: 1440px; margin: 0 auto; padding: 0 clamp(18px, 4vw, 56px) 72px; }
.summary { display: flex; align-items: end; justify-content: space-between; gap: 24px; padding: 38px 0 26px; border-bottom: 1px solid var(--line); }
.eyebrow { margin: 0 0 7px; color: var(--red); font-size: 11px; font-weight: 800; letter-spacing: .15em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(31px, 4vw, 54px); font-weight: 500; line-height: 1; letter-spacing: -.035em; }
.search-box { width: min(420px, 38vw); }
.search-box input { width: 100%; padding: 14px 18px; background: #fffaf0; border: 1px solid var(--line); border-radius: 999px; outline: none; }
.search-box input:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(178, 71, 55, .13); }

.workspace { display: grid; grid-template-columns: 285px minmax(0, 1fr); gap: clamp(24px, 4vw, 54px); padding-top: 26px; }
.filters { position: sticky; top: 18px; align-self: start; display: grid; gap: 20px; padding-bottom: 30px; }
.filter-heading { display: flex; align-items: center; justify-content: space-between; }
.filter-heading h2 { margin: 0; font-family: Georgia, serif; font-size: 22px; }
.filter-heading button { padding: 0; color: var(--red); background: none; border: 0; }
.filters > label, .filters legend { font-size: 12px; font-weight: 750; }
.filters select { width: 100%; margin-top: 8px; padding: 10px; background: #fffaf0; border: 1px solid var(--line); border-radius: 9px; }
.range-row { display: grid; grid-template-columns: 1fr 58px; align-items: center; gap: 9px; margin-top: 9px; }
.range-row output { text-align: right; font-size: 12px; }
.filters fieldset { display: grid; gap: 10px; padding: 0; border: 0; }
.filters legend { margin-bottom: 10px; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13px; font-weight: 500; }
.check input { width: 16px; height: 16px; accent-color: var(--red); }
.requirement-filters { display: grid; gap: 10px; }
.filter-chips { display: flex; flex-wrap: wrap; gap: 7px; }
.filter-chip { min-height: 32px; padding: 6px 10px; color: var(--muted); background: rgba(255,253,248,.72); border: 1px solid var(--line); border-radius: 999px; font-size: 11px; font-weight: 700; line-height: 1.2; text-align: left; }
.filter-chip[data-state="include"] { color: #244237; background: var(--mint); border-color: #a7c9b6; }
.filter-chip[data-state="include"]::before { content: "+ "; }
.filter-chip[data-state="exclude"] { color: #7b2f24; background: #f4ddd8; border-color: #d9a79e; }
.filter-chip[data-state="exclude"]::before { content: "− "; }
.source-chip[data-state="include"]::before { content: "✓ "; }
.district-chips { max-height: 206px; overflow: auto; padding-right: 4px; }

.results-toolbar { min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 15px; color: var(--muted); font-size: 12px; }
.results-toolbar p { margin: 0; }
.results-toolbar label { display: flex; align-items: center; gap: 8px; }
.results-toolbar select { padding: 8px 30px 8px 10px; background: transparent; border: 1px solid var(--line); border-radius: 8px; }
.listing-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.listing-card { overflow: hidden; background: var(--card); border: 1px solid #ded9cf; border-radius: var(--radius); box-shadow: 0 8px 28px rgba(24,36,43,.055); transition: transform .18s ease, box-shadow .18s ease; }
.listing-card:hover { transform: translateY(-3px); box-shadow: var(--shadow); }
.listing-image-link { position: relative; display: block; aspect-ratio: 16 / 9; overflow: hidden; background: #d8ddd9; }
.listing-image { width: 100%; height: 100%; object-fit: cover; transition: transform .3s ease; }
.listing-image-link.no-image::before { content: "W"; position: absolute; inset: 0; display: grid; place-items: center; color: rgba(255,255,255,.72); background: linear-gradient(135deg, #8a9b97, #52646a); font-family: Georgia, serif; font-size: 54px; }
.listing-card:hover .listing-image { transform: scale(1.018); }
.source-badge { position: absolute; top: 12px; left: 12px; padding: 5px 8px; color: #fff; background: rgba(24,36,43,.82); backdrop-filter: blur(8px); border-radius: 6px; font-size: 10px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.listing-body { padding: 19px; }
.price-line { display: flex; align-items: baseline; gap: 8px; }
.price { font-family: Georgia, serif; font-size: 27px; font-weight: 500; }
.price-note { color: var(--muted); font-size: 11px; }
.listing-body h2 { margin: 11px 0 5px; font-size: 17px; line-height: 1.32; }
.listing-title { text-decoration: none; }
.listing-title:hover { color: var(--red); }
.location { margin-bottom: 14px; color: var(--muted); font-size: 12px; }
.facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin: 0 0 14px; }
.fact { padding: 9px 10px; background: #f3eee5; border-radius: 8px; }
.fact dt { color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.fact dd { margin: 3px 0 0; font-size: 12px; font-weight: 650; }
.requirements { min-height: 27px; display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.tag { padding: 5px 7px; color: #33433c; background: var(--mint); border-radius: 5px; font-size: 10px; font-weight: 700; }
.tag.attention { color: #604d11; background: var(--yellow); }
.tag.caution { color: #fff8e9; background: #8b4b35; }
.tag.eligible { color: #275640; background: #cbe8d5; }
.requirement-note { margin: -7px 0 16px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.listing-actions { display: flex; align-items: center; gap: 14px; }
.primary-button, .secondary-button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 10px 15px; border-radius: 10px; font-weight: 750; text-decoration: none; }
.primary-button { color: #fff; background: var(--red); border: 1px solid var(--red); }
.primary-button:hover { background: var(--red-dark); }
.secondary-button { background: #fffaf0; border: 1px solid var(--line); }
.contact-button { flex: 1; }
.source-link { color: var(--muted); font-size: 12px; }
.empty-state { padding: 80px 20px; text-align: center; color: var(--muted); }
.empty-state h2 { color: var(--ink); font-family: Georgia, serif; }

.dialog { width: min(680px, calc(100vw - 30px)); max-height: calc(100vh - 32px); padding: 0; color: var(--ink); background: var(--card); border: 0; border-radius: 20px; box-shadow: 0 30px 100px rgba(0,0,0,.3); }
.dialog::backdrop { background: rgba(15,24,29,.68); backdrop-filter: blur(4px); }
.dialog form { display: grid; gap: 18px; padding: 25px; }
.dialog-head { display: flex; align-items: start; justify-content: space-between; gap: 20px; }
.dialog-head h2 { margin: 0; font-family: Georgia, serif; font-size: 29px; font-weight: 500; }
.icon-button { width: 38px; height: 38px; padding: 0; background: #f1ece3; border: 0; border-radius: 50%; font-size: 24px; line-height: 1; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.dialog label { display: grid; gap: 6px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .04em; text-transform: uppercase; }
.dialog input, .dialog textarea { width: 100%; padding: 11px 12px; color: var(--ink); background: #fff; border: 1px solid var(--line); border-radius: 9px; letter-spacing: 0; text-transform: none; resize: vertical; }
.dialog .primary-button { justify-self: end; }
.contact-route { padding: 12px 14px; background: #edf1ed; border-radius: 10px; font-size: 13px; line-height: 1.5; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.site-footer { max-width: 1440px; margin: 0 auto; padding: 24px clamp(18px, 4vw, 56px) 36px; display: flex; justify-content: space-between; gap: 20px; color: var(--muted); border-top: 1px solid var(--line); font-size: 11px; }
.site-footer p { margin: 0; }
.site-footer a { color: var(--red); }
.refresh-status { max-width: 620px; text-align: right; }

.listing-detail-page main { max-width: 1180px; }
.detail-back { display: inline-flex; margin: 28px 0 18px; color: var(--red); font-size: 13px; font-weight: 700; text-decoration: none; }
.detail-shell { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(300px, .8fr); gap: clamp(24px, 5vw, 60px); }
.detail-shell.no-image { grid-template-columns: minmax(0, 760px); justify-content: center; }
.detail-image { width: 100%; max-height: 620px; object-fit: cover; background: #d8ddd9; border-radius: var(--radius); }
.detail-panel { align-self: start; display: grid; gap: 20px; padding: 24px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.detail-panel h1 { font-size: clamp(30px, 4vw, 48px); line-height: 1.04; }
.detail-price { margin: 0; font-family: Georgia, serif; font-size: 31px; }
.detail-location { margin: -12px 0 0; color: var(--muted); font-size: 13px; }
.detail-facts { grid-template-columns: repeat(2, minmax(0,1fr)); }
.detail-description { color: #435157; font-size: 14px; line-height: 1.65; }
.detail-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.detail-actions .refresh-listing-button { grid-column: 1 / -1; }
.detail-refresh-status { margin: -10px 0 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.detail-error { padding: 80px 20px; text-align: center; }

@media (max-width: 880px) {
  .workspace { grid-template-columns: 1fr; }
  .filters { position: static; grid-template-columns: repeat(2, minmax(0,1fr)); padding: 18px; background: rgba(255,253,248,.72); border: 1px solid var(--line); border-radius: 15px; }
  .filter-heading { grid-column: 1 / -1; }
  .listing-grid { grid-template-columns: 1fr; }
  .detail-shell { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .site-header { align-items: flex-start; }
  .header-meta { align-items: flex-end; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
  .header-meta > span { width: 100%; text-align: right; }
  .summary { align-items: stretch; flex-direction: column; padding-top: 28px; }
  .search-box { width: 100%; }
  .filters { grid-template-columns: 1fr; }
  .results-toolbar { align-items: flex-start; }
  .results-toolbar label { align-items: flex-end; flex-direction: column; gap: 4px; }
  .form-grid { grid-template-columns: 1fr; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions > * { width: 100%; }
  .detail-actions { grid-template-columns: 1fr; }
  .detail-actions .refresh-listing-button { grid-column: auto; }
  .site-footer { align-items: flex-start; flex-direction: column; }
  .refresh-status { text-align: left; }
}

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; } }
