:root {
    --brand: #191919;
    --brand-dark: #0d0d0d;
    --accent: #8195bd;
    --accent-dark: #5a6f96;
    --listed-bar: #a8b8d8;
    --ink: #1f2227;
    --gray: #5c636e;
    --line: #e3e0db;
    --paper: #faf8f5;
    --card: #ffffff;
    --cta: #5a6f96;
    --track: #eee9e2;
    --totals-bg: #f6f3ee;
    --chip-bg: #f0ece6;
    --grid: #eee9e2;
    --bar-pended: #191919;
    --cool: #3b7dad;
    --warm: #c0392b;
  }
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body { font-family: "Avenir Next", Avenir, "Segoe UI", Helvetica, Arial, sans-serif; background: var(--paper); color: var(--ink); }

  /* ---------- password gate ---------- */
  #gate { position: fixed; inset: 0; background: var(--brand-dark); display: flex; align-items: center; justify-content: center; z-index: 100; }
  .gate-box { background: var(--card); border-radius: 10px; padding: 42px 46px; width: 360px; text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.4); }
  .gate-box .brand { font-size: 13px; letter-spacing: 3px; color: var(--accent-dark); font-weight: 700; text-transform: uppercase; }
  .gate-box h1 { font-size: 21px; margin: 8px 0 4px; }
  .gate-box p { font-size: 13px; color: var(--gray); margin-bottom: 20px; }
  .gate-box input { width: 100%; padding: 11px 13px; border: 1px solid var(--line); border-radius: 6px; font-size: 15px; margin-bottom: 12px; }
  .gate-box input:focus { outline: 2px solid var(--brand); border-color: transparent; }
  .gate-box button { width: 100%; padding: 11px; background: var(--brand); color: #fff; border: none; border-radius: 6px; font-size: 15px; font-weight: 600; cursor: pointer; }
  .gate-box button:hover { background: #3a3f47; }
  #gateErr { color: var(--warm); font-size: 13px; margin-top: 10px; display: none; }

  /* ---------- app shell ---------- */
  #app { display: none; }
  header { background: var(--card); color: var(--ink); padding: 18px 28px; border-bottom: 1px solid var(--line); }
  .head-logo { height: 52px; }
  .head-inner { max-width: 1180px; margin: 0 auto; display: flex; flex-wrap: wrap; align-items: center; gap: 14px; }
  .head-brand .eyebrow { font-size: 11px; letter-spacing: 3px; text-transform: uppercase; color: var(--accent-dark); font-weight: 700; }
  .head-brand h1 { font-size: 23px; font-weight: 700; }
  .head-controls { margin-left: auto; display: flex; align-items: center; gap: 10px; }
  .head-controls select { padding: 9px 12px; border-radius: 6px; border: 1px solid var(--line); font-size: 14px; background: var(--card); color: var(--ink); cursor: pointer; }
  .head-controls .btn-print { background: var(--brand); color: #fff; border: none; border-radius: 6px; padding: 10px 16px; font-size: 13px; cursor: pointer; }

  /* ---------- agent (Kena) branding ribbon ---------- */
  .agent-ribbon { background: var(--card); border-bottom: 1px solid var(--line); }
  .agent-ribbon-inner { max-width: 1180px; margin: 0 auto; padding: 11px 28px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
  .agent-ribbon img.ar-photo { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; border: 2px solid var(--accent); flex-shrink: 0; }
  .ar-eyebrow { font-size: 10px; letter-spacing: 2px; text-transform: uppercase; color: var(--gray); }
  .ar-name { font-weight: 800; font-size: 15px; line-height: 1.15; }
  .ar-title { font-size: 12px; color: var(--gray); }
  .ar-contact { margin-left: auto; display: flex; gap: 8px 18px; flex-wrap: wrap; font-size: 13px; }
  .ar-contact a { color: var(--accent-dark); font-weight: 700; text-decoration: none; white-space: nowrap; }
  .ar-contact a:hover { text-decoration: underline; }
  .ar-cta { background: var(--cta); color: #fff !important; padding: 9px 16px; border-radius: 7px; font-weight: 700; text-decoration: none !important; white-space: nowrap; }
  .ar-cta:hover { background: var(--accent); }
  @media (max-width: 620px) { .ar-contact { margin-left: 0; width: 100%; } }

  /* ---------- call-to-action band ---------- */
  .cta-band { background: var(--brand); color: #fff; }
  .cta-inner { max-width: 1180px; margin: 0 auto; padding: 26px 28px; display: flex; align-items: center; gap: 20px; flex-wrap: wrap; }
  .cta-photo { width: 64px; height: 64px; border-radius: 50%; object-fit: cover; border: 2px solid var(--accent); flex-shrink: 0; }
  .cta-text { flex: 1 1 360px; }
  .cta-text h2 { font-size: 19px; margin-bottom: 4px; }
  .cta-text p { font-size: 14px; color: #d8dbe1; line-height: 1.45; }
  .cta-btn { background: var(--cta); color: #fff; padding: 13px 26px; border-radius: 8px; font-size: 15px; font-weight: 800; text-decoration: none; white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.25); }
  .cta-btn:hover { background: #93a6ca; }

  nav.tabs { background: var(--brand-dark); }
  .tabs-inner { max-width: 1180px; margin: 0 auto; display: flex; flex-wrap: wrap; }
  .tabs .tab-div { width: 1px; background: rgba(255,255,255,.18); margin: 8px 8px; }
  .tabs button { background: none; border: none; color: rgba(255,255,255,.7); padding: 13px 20px; font-size: 14px; font-weight: 600; cursor: pointer; border-bottom: 3px solid transparent; }
  .tabs button.active { color: #fff; border-bottom-color: var(--accent); }
  .tabs button:hover { color: #fff; }

  main { max-width: 1180px; margin: 0 auto; padding: 26px 28px 60px; }
  .view { display: none; }
  .view.active { display: block; }

  /* ---------- overview ---------- */
  .county-strip { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px 24px; display: flex; flex-wrap: wrap; gap: 30px; align-items: center; margin-bottom: 22px; }
  .county-strip .cs-title { font-size: 13px; text-transform: uppercase; letter-spacing: 2px; color: var(--gray); font-weight: 700; }
  .cs-stat { text-align: center; }
  .cs-stat .v { font-size: 26px; font-weight: 700; }
  .cs-stat .l { font-size: 12px; color: var(--gray); }
  .cs-stat .delta { font-size: 12px; font-weight: 600; }

  .cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px; }
  .card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 20px 22px; cursor: pointer; transition: box-shadow .15s, transform .15s; position: relative; overflow: hidden; }
  .card:hover { box-shadow: 0 8px 24px rgba(0,0,0,.1); transform: translateY(-2px); }
  .card .accent { position: absolute; top: 0; left: 0; right: 0; height: 5px; }
  .card h3 { font-size: 17px; margin-bottom: 12px; }
  .card .ratio-row { display: flex; align-items: baseline; gap: 10px; margin-bottom: 12px; }
  .card .ratio { font-size: 38px; font-weight: 800; line-height: 1; }
  .card .ratio-cap { font-size: 12px; color: var(--gray); max-width: 130px; line-height: 1.3; }
  .card .delta { font-size: 13px; font-weight: 700; margin-left: auto; }
  .card .counts { display: flex; gap: 0; border-top: 1px solid var(--line); padding-top: 12px; }
  .card .counts div { flex: 1; text-align: center; }
  .card .counts .v { font-size: 19px; font-weight: 700; }
  .card .counts .l { font-size: 11px; color: var(--gray); text-transform: uppercase; letter-spacing: 1px; }
  .card .meter { height: 7px; border-radius: 4px; background: var(--track); margin: 4px 0 14px; overflow: hidden; }
  .card .meter > div { height: 100%; border-radius: 4px; }
  .card .view-link { font-size: 12px; color: var(--accent-dark); font-weight: 700; margin-top: 12px; display: inline-block; }

  .legend { margin-top: 22px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 20px; font-size: 13px; color: var(--gray); display: flex; flex-wrap: wrap; gap: 18px; align-items: center; }
  .legend .chip { display: inline-flex; align-items: center; gap: 6px; font-weight: 600; }
  .legend .dot { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }

  .panel { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 22px 24px; margin-top: 22px; }
  .panel h2 { font-size: 17px; margin-bottom: 4px; }
  .panel .sub { font-size: 13px; color: var(--gray); margin-bottom: 16px; }
  .chart-wrap { position: relative; height: 300px; }

  /* ---------- area detail ---------- */
  .area-head { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-bottom: 18px; }
  .area-head select { padding: 9px 12px; border-radius: 6px; border: 1px solid var(--line); font-size: 15px; font-weight: 600; background: var(--card); cursor: pointer; }
  .area-stats { display: flex; gap: 26px; margin-left: auto; }
  .area-stats .cs-stat .v { font-size: 22px; }

  table.bands { width: 100%; border-collapse: collapse; font-size: 14px; }
  table.bands th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--gray); padding: 8px 10px; border-bottom: 2px solid var(--line); }
  table.bands th.num, table.bands td.num { text-align: right; }
  table.bands td { padding: 8px 10px; border-bottom: 1px solid var(--line); }
  table.bands tr:last-child td { border-bottom: none; }
  table.bands tr.totals td { font-weight: 800; border-top: 2px solid var(--ink); background: var(--totals-bg); }
  .bar-cell { width: 38%; min-width: 220px; }
  .dualbar { display: flex; height: 16px; border-radius: 3px; overflow: hidden; background: var(--track); }
  .dualbar .listed { background: var(--listed-bar); }
  .dualbar .pended { background: var(--bar-pended); }
  .ratio-pill { display: inline-block; min-width: 62px; text-align: center; padding: 3px 8px; border-radius: 20px; font-weight: 700; font-size: 13px; color: #fff; }

  .trend { display: inline-flex; align-items: center; gap: 4px; font-weight: 800; font-size: 13px; padding: 3px 10px; border-radius: 20px; white-space: nowrap; }
  .trend.up { background: #e2f1e7; color: #1d7a3e; }
  .trend.down { background: #fae8e6; color: #c0392b; }
  .trend.flat { background: #eeeae4; color: var(--gray); }
  .trend.sm { padding: 1px 7px; font-size: 11px; margin-left: 6px; }

  .card-top { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
  .card-top h3 { margin-bottom: 0; }
  .lvl-chip { margin-left: auto; color: #fff; font-size: 11px; font-weight: 800; letter-spacing: 1px; text-transform: uppercase; padding: 4px 11px; border-radius: 20px; white-space: nowrap; }
  .gauge { position: relative; display: flex; height: 8px; border-radius: 4px; margin: 16px 0 3px; }
  .gauge-seg:first-child { border-radius: 4px 0 0 4px; }
  .gauge-seg:last-child { border-radius: 0 4px 4px 0; }
  .gauge-marker { position: absolute; top: -8px; width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 7px solid var(--ink); transform: translateX(-50%); }
  .gauge-labels { display: flex; font-size: 9px; color: var(--gray); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px; }
  .gauge-labels span { text-align: center; }
  .stmt { font-size: 13px; color: var(--ink); line-height: 1.45; margin-bottom: 10px; }
  .spark { width: 100%; height: 42px; display: block; }
  .spark-cap { font-size: 10px; color: var(--gray); text-transform: uppercase; letter-spacing: 1px; margin: 3px 0 12px; }
  .cs-state { flex-basis: 100%; display: flex; align-items: center; gap: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
  .cs-state .lvl-chip { margin-left: 0; }
  .cs-state .stmt { margin-bottom: 0; }
  .area-brief { display: flex; flex-wrap: wrap; align-items: center; gap: 18px; margin-top: 0; }
  .area-brief .brief-text { flex: 1 1 320px; }
  .area-brief .brief-text .stmt { margin: 8px 0 0; font-size: 14px; }
  .area-brief .brief-spark { flex: 1 1 260px; max-width: 360px; }

  .table-legend { font-size: 12px; color: var(--gray); margin: 12px 2px 0; display: flex; gap: 16px; }
  .table-legend .dot { width: 11px; height: 11px; border-radius: 3px; display: inline-block; margin-right: 5px; vertical-align: -1px; }

  footer { text-align: center; font-size: 12px; color: var(--gray); padding: 0 20px 40px; }

  /* ---------- segmented toggles ---------- */
  .seg { display: inline-flex; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: var(--card); flex-wrap: wrap; }
  .seg button { background: none; border: none; padding: 8px 14px; font-size: 13px; font-weight: 600; color: var(--gray); cursor: pointer; }
  .seg button.active { background: var(--brand); color: #fff; }
  .panel-head { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 16px; }
  .panel-head h2 { margin-bottom: 0; }
  .panel-head .seg { margin-left: auto; }

  /* ---------- price benchmark bars ---------- */
  .bench { display: flex; flex-direction: column; gap: 9px; }
  .bench-row { display: grid; grid-template-columns: 140px 1fr 96px; align-items: center; gap: 12px; }
  .bench-row .bn { font-size: 13px; font-weight: 700; }
  .bench-row .bn small { display: block; font-weight: 500; color: var(--gray); font-size: 11px; }
  .bench-track { background: var(--track); border-radius: 5px; height: 22px; }
  .bench-fill { height: 100%; border-radius: 5px; min-width: 2px; transition: width .4s; }
  .bench-row .bv { font-size: 14px; font-weight: 800; text-align: right; }
  .bench-row.ref .bench-track { background: repeating-linear-gradient(45deg,var(--track),var(--track) 6px,var(--line) 6px,var(--line) 12px); }
  .bench-note { font-size: 12px; color: var(--gray); margin-top: 14px; line-height: 1.5; }

  /* ---------- price / metric cards ---------- */
  .pcards { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
  .pcard { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px 20px; position: relative; overflow: hidden; }
  .pcard .accent { position: absolute; top: 0; left: 0; right: 0; height: 5px; }
  .pcard h3 { font-size: 16px; margin-bottom: 8px; }
  .pcard .big { font-size: 30px; font-weight: 800; line-height: 1; }
  .pcard .big small { font-size: 13px; font-weight: 600; color: var(--gray); }
  .pcard .sub2 { font-size: 13px; color: var(--gray); margin: 5px 0 4px; }
  .pcard .vsrow { display: flex; gap: 7px; flex-wrap: wrap; margin: 10px 0 4px; }
  .vs-pill { font-size: 11px; font-weight: 700; padding: 3px 9px; border-radius: 20px; background: var(--chip-bg); color: var(--ink); }
  .vs-pill b { color: var(--accent-dark); }

  /* ---------- interactive map ---------- */
  .map-panel { background: var(--card); border: 1px solid var(--line); border-radius: 10px; margin-top: 22px; overflow: hidden; }
  .map-head { display: flex; align-items: center; gap: 12px; padding: 16px 22px; cursor: pointer; user-select: none; }
  .map-head h2 { font-size: 17px; }
  .map-head .chev { margin-left: auto; transition: transform .2s; font-size: 14px; color: var(--gray); }
  .map-panel.collapsed .chev { transform: rotate(-90deg); }
  .map-body { padding: 0 22px 22px; display: grid; grid-template-columns: 1.5fr 1fr; gap: 22px; align-items: start; }
  .map-panel.collapsed .map-body { display: none; }
  .map-controls { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 4px; }
  #leafMap { height: 470px; border-radius: 8px; overflow: hidden; border: 1px solid var(--line); z-index: 0; }
  #leafMap .leaflet-tile { opacity: 1 !important; }
  .leaflet-container { font-family: "Avenir Next", Avenir, "Segoe UI", sans-serif; background: #eef2f4; }
  .maplabel { background: none; border: none; box-shadow: none; padding: 0; font-weight: 700; font-size: 12px; color: #fff;
    text-shadow: 0 1px 2px rgba(0,0,0,.55), 0 0 2px rgba(0,0,0,.45); text-align: center; line-height: 1.15; }
  .maplabel::before { display: none; }
  .maplabel b { font-size: 12.5px; }
  .maplabel small { font-weight: 700; font-size: 11px; }
  .map-legend { display: flex; align-items: center; gap: 0; font-size: 11px; color: var(--gray); margin-top: 8px; }
  .map-legend .sw { width: 26px; height: 12px; }
  .map-detail { border: 1px solid var(--line); border-radius: 10px; padding: 16px 18px; background: var(--paper); }
  .map-detail h3 { font-size: 17px; margin-bottom: 2px; }
  .map-detail .md-sub { font-size: 12px; color: var(--gray); margin-bottom: 12px; }
  .md-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
  .md-stat .l { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--gray); }
  .md-stat .v { font-size: 18px; font-weight: 800; }

  @media (max-width: 760px) {
    .map-body { grid-template-columns: 1fr; }
  }
  @media (max-width: 700px) {
    .head-controls { margin-left: 0; width: 100%; }
    .area-stats { margin-left: 0; width: 100%; justify-content: space-between; }
    .bar-cell { display: none; }
    .bench-row { grid-template-columns: 110px 1fr 80px; }
  }
  @media print {
    #gate, nav.tabs, .head-controls, .view-link, .ar-cta, .cta-band, footer .no-print { display: none !important; }
    .view { display: block !important; page-break-after: always; }
    body { background: #fff; }
    .card:hover { transform: none; box-shadow: none; }
  }


/* ===== THEME: Soft (v2) ===== */
body[data-theme="soft"] {
  --paper: #f4f3ef; --card: #ffffff; --ink: #3c4250; --gray: #7c8390; --line: #e7e2d9;
  --brand: #5d6b86; --brand-dark: #4c5871; --accent: #9bb4cf; --accent-dark: #6f88ad;
  --cta: #6f88ad; --listed-bar: #c6d2e2; --track: #ece7df; --totals-bg: #f3f1ec; --chip-bg: #eef0f2; --grid: #ece7df; --bar-pended: #5d6b86;
}
/* ===== THEME: Dark (v3) ===== */
body[data-theme="dark"] {
  --paper: #12141a; --card: #1e222b; --ink: #eceef2; --gray: #9aa3b1; --line: #2c313c;
  --brand: #0c0d11; --brand-dark: #08090c; --accent: #8aa0d8; --accent-dark: #a9bbe6;
  --cta: #4a5d86; --listed-bar: #46546e; --track: #2c313c; --totals-bg: #262b34; --chip-bg: #2a2f39; --grid: #2c313c; --bar-pended: #c9ccd2;
}
body[data-theme="dark"] .head-logo { filter: invert(1) brightness(1.7); }
body[data-theme="dark"] .gate-box img { filter: invert(1) brightness(1.7); }
body[data-theme="dark"] .gate-box input { background: var(--card); color: var(--ink); }
body[data-theme="dark"] .leaflet-container { background: #20242d; }

/* ===== theme/version switcher ===== */
.theme-switch { display: inline-flex; gap: 5px; align-items: center; }
.theme-switch a { font-size: 12px; font-weight: 700; color: var(--gray); text-decoration: none; padding: 5px 9px; border-radius: 6px; border: 1px solid var(--line); }
.theme-switch a:hover { color: var(--ink); }
.theme-switch a.on { background: var(--brand); color: #fff; border-color: var(--brand); }
