:root {
  /* Guardian Recovery brand (guardianrecovery.com) */
  --navy: #002635;        /* deep overlay navy */
  --navy-2: #004860;      /* brand dark teal */
  --teal: #006f93;        /* brand primary */
  --teal-soft: #e4f0f5;
  --gold: #ffa800;        /* brand gold */
  --ink: #2b3a42;
  --muted: #64707a;
  --line: #e3e7e4;
  --bg: #f6f7f3;          /* brand cream tint */
  --card: #ffffff;
  --green: #2f9e63;
  --red: #c0392b;
  --amber: #b7791f;
  --purple: #6d5aa8;
  --orange: #d97b29;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 38, 53, .08), 0 8px 24px rgba(0, 38, 53, .07);
  --sidebar-w: 380px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--ink);
  background: var(--bg);
  overflow: hidden;
}

/* ---------- header ---------- */
header {
  position: relative;
  z-index: 1200;
  height: 62px;
  background: #fff;
  color: var(--navy-2);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 20px;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(0, 38, 53, .06);
}
.brand { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-logo { display: flex; align-items: center; flex: none; }
.brand-logo img { height: 34px; width: auto; display: block; }
.brand-divider { width: 1px; height: 30px; background: var(--line); flex: none; }
.brand h1 { font-size: 15.5px; font-weight: 600; margin: 0; letter-spacing: .2px; white-space: nowrap; color: var(--navy-2); }
.brand .sub { font-size: 11.5px; color: var(--muted); margin-top: 1px; white-space: nowrap; }
.header-spacer { flex: 1; }
.admissions {
  font-size: 12.5px; color: var(--muted); text-align: right; line-height: 1.35; white-space: nowrap;
}
.admissions a { color: var(--teal); font-weight: 700; text-decoration: none; }
.admissions a:hover { color: var(--gold); }

/* ---------- layout ---------- */
.app { display: flex; height: calc(100% - 62px); }

/* ---------- sidebar ---------- */
aside {
  width: var(--sidebar-w);
  flex: none;
  background: var(--card);
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  z-index: 1100;
}
.controls { padding: 14px 16px 10px; border-bottom: 1px solid var(--line); }
.search-row { position: relative; margin-bottom: 10px; }
.search-row svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
#search {
  width: 100%; padding: 9px 12px 9px 34px;
  border: 1px solid var(--line); border-radius: 9px;
  font: inherit; font-size: 13.5px; color: var(--ink);
  background: var(--bg); outline: none;
}
#search:focus { border-color: var(--teal); background: #fff; box-shadow: 0 0 0 3px rgba(0,111,147,.12); }

.filter-label { font-size: 10.5px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--muted); margin: 10px 0 6px; }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  border: 1px solid var(--line); background: #fff; color: var(--ink);
  font: inherit; font-size: 12px; font-weight: 500;
  padding: 4.5px 11px; border-radius: 999px; cursor: pointer;
  transition: all .12s ease;
}
.pill:hover { border-color: var(--teal); color: var(--teal); }
.pill.on { background: var(--navy-2); border-color: var(--navy-2); color: #fff; }
.selects { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.selects select {
  width: 100%; padding: 7px 9px; font: inherit; font-size: 12.5px;
  border: 1px solid var(--line); border-radius: 8px; color: var(--ink); background: #fff;
}
.count-row { display: flex; align-items: center; justify-content: space-between; margin-top: 11px; }
#count { font-size: 12px; color: var(--muted); }
#reset { background: none; border: none; color: var(--teal); font: inherit; font-size: 12px; font-weight: 600; cursor: pointer; padding: 0; }
#reset:hover { text-decoration: underline; }

.list { flex: 1; overflow-y: auto; padding: 10px 12px 20px; }
.state-group { margin-bottom: 4px; }
.state-head {
  font-size: 11px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase;
  color: var(--muted); padding: 10px 6px 6px;
}
.fcard {
  background: #fff; border: 1px solid var(--line); border-radius: var(--radius);
  padding: 11px 13px; margin-bottom: 8px; cursor: pointer;
  transition: border-color .12s, box-shadow .12s, transform .12s;
}
.fcard:hover { border-color: #b9c6d8; box-shadow: var(--shadow); }
.fcard.active { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(0,111,147,.14), var(--shadow); }
.fcard-top { display: flex; align-items: flex-start; gap: 9px; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; margin-top: 4px; }
.fcard h3 { font-size: 13.5px; font-weight: 600; margin: 0; line-height: 1.3; }
.fcard .loc { font-size: 12px; color: var(--muted); margin-top: 2px; }
.fcard .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 7px; }
.chip {
  font-size: 10.5px; font-weight: 600; padding: 2.5px 7px; border-radius: 5px;
  background: var(--teal-soft); color: #00516b;
}
.chip.mh { background: #ece8f7; color: #55458f; }
.chip.beds { background: #fff3da; color: #8a5b00; }
.chip.pop { background: #eef2f7; color: #4a5b74; }

/* ---------- map ---------- */
.map-wrap { position: relative; flex: 1; }
#map { position: absolute; inset: 0; background: #dde5ee; }

.legend {
  position: absolute; right: 14px; bottom: 24px; z-index: 1000;
  background: rgba(255,255,255,.95); backdrop-filter: blur(6px);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow);
  padding: 10px 13px; font-size: 12px;
}
.legend h4 { margin: 0 0 7px; font-size: 10.5px; font-weight: 700; letter-spacing: .7px; text-transform: uppercase; color: var(--muted); }
.legend .row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.legend .row:last-child { margin-bottom: 0; }

/* marker */
.pin { filter: drop-shadow(0 2px 3px rgba(9,17,32,.35)); }
.pin svg { display: block; }
.leaflet-popup-content-wrapper { border-radius: 10px; box-shadow: var(--shadow); }
.leaflet-popup-content { margin: 12px 16px; font-family: inherit; }
.pop-name { font-weight: 600; font-size: 13.5px; margin-bottom: 2px; }
.pop-city { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.pop-link { font-size: 12px; font-weight: 600; color: var(--teal); cursor: pointer; }

/* ---------- detail panel ---------- */
.detail {
  position: absolute; top: 14px; right: 14px; bottom: 24px; width: 400px; max-width: calc(100% - 28px);
  z-index: 1050;
  background: #fff; border: 1px solid var(--line); border-radius: 14px; box-shadow: 0 12px 40px rgba(9,17,32,.22);
  display: flex; flex-direction: column;
  transform: translateX(calc(100% + 28px));
  transition: transform .22s ease;
}
.detail.open { transform: none; }
.detail-head {
  padding: 16px 18px 13px; border-bottom: 1px solid var(--line);
  display: flex; align-items: flex-start; gap: 10px;
}
.detail-head .dot { margin-top: 6px; }
.detail-head h2 { font-size: 16.5px; font-weight: 650; margin: 0; line-height: 1.25; }
.detail-head .loc { font-size: 12.5px; color: var(--muted); margin-top: 3px; }
#close-detail {
  margin-left: auto; flex: none; background: var(--bg); border: 1px solid var(--line);
  width: 28px; height: 28px; border-radius: 8px; cursor: pointer; color: var(--muted);
  display: grid; place-items: center; font-size: 14px; line-height: 1;
}
#close-detail:hover { color: var(--ink); border-color: #b9c6d8; }
.detail-body { flex: 1; overflow-y: auto; padding: 14px 18px 20px; }

.sec { margin-bottom: 16px; }
.sec h4 { font-size: 10.5px; font-weight: 700; letter-spacing: .8px; text-transform: uppercase; color: var(--muted); margin: 0 0 7px; }
.sec .val { font-size: 13px; line-height: 1.5; }
.sec .val a { color: var(--teal); text-decoration: none; font-weight: 550; }
.sec .val a:hover { text-decoration: underline; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat {
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
}
.stat .n { font-size: 19px; font-weight: 700; color: var(--navy-2); line-height: 1.1; }
.stat .l { font-size: 11px; color: var(--muted); margin-top: 2px; }
.loc-chips { display: flex; flex-wrap: wrap; gap: 5px; }
.loc-chip {
  font-size: 11.5px; font-weight: 550; padding: 4px 9px; border-radius: 7px;
  background: var(--teal-soft); color: #00516b; border: 1px solid rgba(0,111,147,.25);
}
.loc-chip.mh { background: #ece8f7; color: #55458f; border-color: rgba(109,90,168,.3); }
.loc-chip.housing { background: #eaf6ee; color: #21744a; border-color: rgba(47,158,99,.3); }
.note { font-size: 12px; color: var(--muted); background: var(--bg); border-left: 3px solid var(--gold); border-radius: 0 8px 8px 0; padding: 8px 11px; line-height: 1.5; }

.ins-search { width: 100%; padding: 7px 10px; font: inherit; font-size: 12.5px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 8px; }
.ins-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.ins-table th {
  text-align: left; font-size: 10px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: var(--muted); padding: 5px 7px; border-bottom: 1px solid var(--line);
}
.ins-table td { padding: 6.5px 7px; border-bottom: 1px solid #eef2f6; vertical-align: top; line-height: 1.45; }
.ins-table th:nth-child(1), .ins-table td:nth-child(1) { width: 45%; }
.ins-table tr:last-child td { border-bottom: none; }
.payor { font-weight: 570; }
.mini { font-size: 10.5px; color: var(--muted); }

.empty { text-align: center; color: var(--muted); font-size: 13px; padding: 30px 10px; }

/* mobile */
.menu-btn { display: none; }
@media (max-width: 860px) {
  .app { position: relative; }
  aside {
    position: absolute; inset: 0 auto 0 0; width: min(86vw, 360px);
    transform: translateX(-100%); transition: transform .2s ease;
    box-shadow: 0 0 40px rgba(9,17,32,.3);
  }
  aside.open { transform: none; }
  .menu-btn {
    display: grid; place-items: center;
    background: #fff; color: var(--navy-2); border: 1px solid var(--line);
    width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
    position: absolute; top: 14px; left: 14px; z-index: 1060; box-shadow: var(--shadow);
  }
  .detail { width: auto; left: 14px; }
  .admissions .line2 { display: none; }
}
