/* Care Equation client platform v2 (07-10-2026). Light surface, one accent, semantic colours only with a word beside them.
   Type scale: 22 / 16 / 14 / 12.5 / 11.5. Nothing below 11.5px. */
:root {
  --bg: #f4f5f7; --surface: #ffffff; --line: #e3e6ea; --line2: #eef0f3; --hover: #f7f8fa;
  --ink: #1a1f26; --ink2: #566070; --ink3: #8a93a0;
  --accent: #1a1f26; --accent-ink: #ffffff;
  --gold: #b8912f; --gold-ink: #7a5d12; --gold-soft: #fbf6e8; --gold-line: #e8d9ad;
  --above: #c2410c; --above-soft: #fdf0ea; --below: #1d4ed8; --below-soft: #eaf0fd; --within: #6b7280; --within-soft: #f1f2f4;
  --good: #15803d; --good-soft: #eaf6ee; --warn: #b45309; --warn-soft: #fdf3e4; --bad: #b91c1c; --bad-soft: #fdecec;
  --good2: #3f8f5a; --good2-soft: #f1f9f3; --bad2: #c2574f; --bad2-soft: #fdf1f0;
  --radius: 10px; --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.08);
  --shadow-lg: 0 10px 40px rgba(16,24,40,.18);
  --rail: 232px; --topbar: 56px;
  font-size: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { overflow-x: hidden; } /* no fixed height here: the document must stay the scroller */
body { background: var(--bg); color: var(--ink); font: 14px/1.5 Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-font-smoothing: antialiased; }
a { color: var(--ink); }
h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }
h1 { font-size: 22px; } h2 { font-size: 16px; } h3 { font-size: 14px; }
.num, td.r, th.r, .kpi .v { font-variant-numeric: tabular-nums; }
button, select, input { font: inherit; color: inherit; }
::selection { background: var(--gold-line); }

/* ---------- shell */
.shell { display: flex; min-height: 100vh; }
.rail { width: var(--rail); flex: 0 0 var(--rail); background: var(--surface); border-right: 1px solid var(--line); position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; }
.rail .brand { display: flex; align-items: center; gap: 10px; padding: 16px 18px 14px; border-bottom: 1px solid var(--line2); }
.rail .brand img { height: 30px; width: 30px; }
.rail .brand .nm { font-weight: 700; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase; }
.rail .brand .tg { font-size: 11px; color: var(--ink3); letter-spacing: 0.04em; }
.rail nav { padding: 10px 10px; flex: 1; }
.rail .sec { font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink3); padding: 12px 10px 6px; }
.rail a.item { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 8px; color: var(--ink2); text-decoration: none; font-size: 13.5px; position: relative; }
.rail a.item i { width: 16px; text-align: center; color: var(--ink3); font-size: 13px; }
.rail a.item:hover { background: var(--hover); color: var(--ink); }
.rail a.item.active { background: #f0f2f5; color: var(--ink); font-weight: 600; }
.rail a.item.active::before { content: ''; position: absolute; left: -10px; top: 8px; bottom: 8px; width: 3px; border-radius: 2px; background: var(--gold); }
.rail a.item.active i { color: var(--gold-ink); }
.rail .foot { padding: 12px 14px 16px; border-top: 1px solid var(--line2); font-size: 12px; color: var(--ink2); }
.rail .foot .who { font-weight: 600; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail .foot .tier { color: var(--ink3); }
.rail .foot button { margin-top: 8px; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { height: var(--topbar); background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 28px; position: sticky; top: 0; z-index: 50; }
.topbar .crumb { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.topbar .crumb h1 { font-size: 17px; }
.topbar .crumb .org { color: var(--ink3); font-size: 13px; }
.topbar .right { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--ink3); }
.content { padding: 22px 28px 60px; max-width: 1480px; width: 100%; }
@media (max-width: 1100px) { :root { --rail: 64px; } .rail .brand .nm, .rail .brand .tg, .rail a.item span, .rail .sec, .rail .foot { display: none; } .rail a.item { justify-content: center; padding: 10px; } .rail a.item.active::before { display: none; } .content { padding: 16px; } }

/* ---------- page head and controls */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .lead { font-size: 13px; color: var(--ink2); max-width: 760px; }
.controls { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.ctl label { display: block; font-size: 11.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink3); margin-bottom: 4px; }
select, input[type=text], input[type=number], input[type=search] { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 7px 10px; font-size: 13px; min-width: 160px; color: var(--ink); }
select:focus, input:focus { outline: 2px solid var(--gold-line); border-color: var(--gold); }
.btn { display: inline-flex; align-items: center; gap: 7px; border-radius: var(--radius-sm); padding: 8px 14px; font-size: 13px; font-weight: 600; cursor: pointer; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); white-space: nowrap; }
.btn:hover { opacity: .92; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.ghost { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--hover); opacity: 1; }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn i { font-size: 12px; }
.link { color: var(--ink); text-decoration: underline; text-decoration-color: var(--gold-line); cursor: pointer; }
.link:hover { text-decoration-color: var(--gold); }

/* ---------- cards, KPIs, insights */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.card h2 { margin-bottom: 2px; }
.card .basis { font-size: 12.5px; color: var(--ink3); margin-bottom: 12px; }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 12px; box-shadow: var(--shadow); min-height: 96px; display: flex; flex-direction: column; }
.kpi .k { font-size: 11.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink3); }
.kpi .v { font-size: 26px; font-weight: 650; line-height: 1.15; margin: 4px 0 2px; color: var(--ink); }
.kpi .v small { font-size: 14px; font-weight: 500; color: var(--ink2); margin-left: 4px; }
.kpi .s { font-size: 12.5px; color: var(--ink2); }
.kpi .s.more { margin-top: auto; }
.insight { border-left: 3px solid var(--gold); background: var(--gold-soft); padding: 10px 14px; border-radius: 0 var(--radius-sm) var(--radius-sm) 0; font-size: 14px; margin-bottom: 8px; }
.insight b { font-weight: 650; }
.insights { margin-bottom: 14px; }
.note { font-size: 12.5px; color: var(--ink3); }
.muted { color: var(--ink3); }
.empty { padding: 28px; text-align: center; color: var(--ink3); font-size: 13px; }
.loading { padding: 22px; color: var(--ink3); font-size: 13px; display: flex; align-items: center; gap: 10px; }
.loading i { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.skel { background: linear-gradient(90deg, #eef0f3 25%, #f6f7f9 50%, #eef0f3 75%); background-size: 400% 100%; animation: shimmer 1.4s infinite; border-radius: 6px; }
@keyframes shimmer { 0% { background-position: 100% 0 } 100% { background-position: 0 0 } }

/* ---------- tables */
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t th { text-align: left; font-size: 11.5px; letter-spacing: 0.05em; text-transform: uppercase; color: var(--ink3); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; font-weight: 600; user-select: none; background: var(--surface); position: sticky; top: 0; }
table.t th.sort { cursor: pointer; } table.t th.sort:hover { color: var(--ink); }
table.t td { padding: 9px 10px; border-bottom: 1px solid var(--line2); vertical-align: middle; }
table.t tr.row { cursor: pointer; } table.t tr.row:hover td { background: var(--hover); }
table.t tr.sel td { background: var(--gold-soft); }
table.t tr.you td { background: var(--gold-soft); font-weight: 600; }
table.t tr.ref td { color: var(--ink2); font-style: normal; background: #fafbfc; }
table.t tr.grp td { color: var(--ink2); font-weight: 600; padding-top: 14px; border-bottom: 1px solid var(--line); font-size: 12px; letter-spacing: 0.04em; text-transform: uppercase; }
table.t .r { text-align: right; }
table.t .n { color: var(--ink3); }
table.t .sub { display: block; font-size: 11.5px; color: var(--ink3); font-weight: 400; letter-spacing: 0; text-transform: none; }
table.t.compact td { padding: 6px 8px; font-size: 12.5px; } table.t.compact th { padding: 6px 8px; }
table.t th.wrap { white-space: normal; line-height: 1.25; }
table.t td.lead-col { min-width: 190px; }
table.t th.wrap { max-width: 90px; }
.tbl-wrap { overflow: auto; max-height: 70vh; }
.tbl-wrap.flat { max-height: none; }

/* ---------- semantic pills, bars */
.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 10px; border: 1px solid transparent; white-space: nowrap; line-height: 1.4; }
.pill.above { color: var(--above); background: var(--above-soft); }
.pill.below { color: var(--below); background: var(--below-soft); }
.pill.within { color: var(--within); background: var(--within-soft); }
.pill.none { color: var(--ink3); background: var(--within-soft); }
.pill.good { color: var(--good); background: var(--good-soft); }
.pill.warn { color: var(--warn); background: var(--warn-soft); }
.pill.bad { color: var(--bad); background: var(--bad-soft); }
.pill.good2 { color: var(--good2); background: var(--good2-soft); }
.pill.bad2 { color: var(--bad2); background: var(--bad2-soft); }
.pill.you { color: var(--gold-ink); background: var(--gold-soft); border-color: var(--gold-line); }
.gap.above { color: var(--above); } .gap.below { color: var(--below); } .gap.within { color: var(--ink2); }
.pos-bar { display: inline-flex; height: 8px; width: 120px; border-radius: 4px; overflow: hidden; background: var(--line); vertical-align: middle; }
.pos-bar b { display: block; height: 100%; }
.pos-bar .a { background: var(--above); } .pos-bar .w { background: #c6ccd4; } .pos-bar .b { background: var(--below); }
.range { position: relative; height: 16px; width: 150px; display: inline-block; vertical-align: middle; }
.range .track { position: absolute; left: 0; right: 0; top: 7px; height: 2px; background: var(--line); }
.range .band { position: absolute; top: 5px; height: 6px; background: #cfd4db; border-radius: 3px; }
.range .med { position: absolute; top: 2px; width: 1.5px; height: 12px; background: var(--ink2); }
.range .you { position: absolute; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: var(--gold); margin-left: -5px; box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--gold-line); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--ink2); margin-top: 8px; align-items: center; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 5px; vertical-align: -1px; }
.legend i.sq { border-radius: 2px; }
.stack { display: flex; height: 10px; border-radius: 5px; overflow: hidden; background: var(--line); }
.stack b { display: block; height: 100%; }
.mbar { position: relative; height: 10px; width: 160px; display: inline-block; vertical-align: middle; background: var(--line2); border-radius: 3px; }
.mbar .zero { position: absolute; top: -2px; bottom: -2px; width: 1px; background: var(--ink3); }
.mbar .neg { position: absolute; top: 2px; height: 6px; background: var(--bad); border-radius: 3px 0 0 3px; }
.mbar .pos { position: absolute; top: 2px; height: 6px; background: var(--good); border-radius: 0 3px 3px 0; }
.mbar .band { position: absolute; top: 0; height: 10px; background: rgba(180,83,9,.12); }
.stars { color: var(--gold); letter-spacing: 1px; font-size: 12px; white-space: nowrap; }
.stars .off { color: var(--line); }

/* ---------- map + side panel */
.split { display: grid; grid-template-columns: minmax(0, 7fr) minmax(360px, 5fr); gap: 14px; }
@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } }
.map { height: 560px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: #eef0f2; }
.leaflet-container { position: relative; z-index: 0; isolation: isolate; } /* keep map panes under the top bar and drawer */
.panel { height: 560px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); padding: 10px 12px; scrollbar-width: thin; }
.panel .back { color: var(--ink2); cursor: pointer; font-size: 12.5px; display: inline-block; margin-bottom: 6px; }
.panel .back:hover { color: var(--ink); }
.rank-row { padding: 9px 8px; border-bottom: 1px solid var(--line2); cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; }
.rank-row:hover, .rank-row.sel { background: var(--gold-soft); }
.rank-row .nm { font-weight: 600; font-size: 13px; }
.rank-row .sm { grid-column: 1 / span 2; font-size: 12px; color: var(--ink3); }
.leaflet-container { font: inherit; }
.leaflet-container a.leaflet-popup-close-button { color: var(--ink3); }
.leaflet-bar a { background: var(--surface); color: var(--ink); border-bottom-color: var(--line); }
.leaflet-control-attribution { font-size: 10px; background: rgba(255,255,255,.8); }
.pop .leaflet-popup-content-wrapper { border-radius: 8px; box-shadow: var(--shadow-lg); border: 1px solid var(--line); }
.pop .leaflet-popup-content { margin: 10px 12px; font-size: 12.5px; line-height: 1.4; min-width: 240px; }
.pop .ttl { font-weight: 650; font-size: 13.5px; }
.pop .sub { color: var(--ink2); font-size: 12px; }
.pop table { border-collapse: collapse; width: 100%; margin-top: 6px; }
.pop td { padding: 2px 4px; border-bottom: 1px solid var(--line2); }
.pop td.r { text-align: right; white-space: nowrap; }
.pop a { color: var(--gold-ink); }
.tip { font-size: 12px; }
.ho-icon { background: var(--gold); color: #fff; font-weight: 650; font-size: 11px; padding: 3px 8px; border-radius: 10px; white-space: nowrap; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.site-icon { width: 14px; height: 14px; background: var(--gold); border: 2px solid #fff; border-radius: 3px; box-shadow: 0 0 0 1px var(--gold-ink); }

/* ---------- drawer */
.drawer-backdrop { position: fixed; inset: 0; background: rgba(16,24,40,.35); z-index: 1900; display: none; }
.drawer-backdrop.open { display: block; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(820px, 94vw); background: var(--surface); z-index: 2000; transform: translateX(100%); transition: transform .22s ease, visibility 0s linear .22s; visibility: hidden; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; }
.drawer.open { transform: none; visibility: visible; transition: transform .22s ease; }
.drawer .drawer-close { position: absolute; top: 12px; right: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 50%; width: 32px; height: 32px; cursor: pointer; color: var(--ink2); z-index: 2; }
.drawer .drawer-close:hover { background: var(--hover); color: var(--ink); }
.drawer-body { overflow-y: auto; padding: 22px 26px 40px; flex: 1; }
.drawer-body h2 { font-size: 18px; margin-bottom: 2px; }
.drawer-body .sub { color: var(--ink2); font-size: 13px; margin-bottom: 14px; }
.drawer-body .card { box-shadow: none; }
.modal-overlay { display: none; } /* legacy id kept for the Support at Home module; routed to the drawer */

/* ---------- Prime chat */
.chat { display: grid; grid-template-rows: 1fr auto; height: calc(100vh - var(--topbar) - 44px); min-height: 520px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.chat > div:first-child { display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
.chat-log { flex: 1 1 auto; overflow-y: auto; min-height: 0; padding: 22px 26px; display: flex; flex-direction: column; gap: 14px; }
.msg { max-width: 820px; line-height: 1.55; font-size: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--gold-soft); border: 1px solid var(--gold-line); border-radius: 12px 12px 2px 12px; padding: 10px 14px; }
.msg.bot { display: flex; gap: 12px; align-items: flex-start; }
.msg.bot img { width: 26px; height: 26px; margin-top: 3px; flex: 0 0 26px; }
.msg.bot .body { background: #fafbfc; border: 1px solid var(--line); border-radius: 2px 12px 12px 12px; padding: 12px 16px; }
.msg .tools { display: block; margin-top: 8px; font-size: 11.5px; color: var(--ink3); }
.msg .err { color: var(--bad); }
.msg a { color: var(--gold-ink); }
.typing { color: var(--ink3); font-size: 12.5px; display: flex; gap: 8px; align-items: center; font-style: italic; }
.typing .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--gold); display: inline-block; animation: bounce 1.2s infinite; }
.typing .dot:nth-child(2) { animation-delay: .2s } .typing .dot:nth-child(3) { animation-delay: .4s }
@keyframes bounce { 0%, 60%, 100% { transform: translateY(0) } 30% { transform: translateY(-5px) } }
.chat-in { border-top: 1px solid var(--line); padding: 12px 16px; display: flex; gap: 10px; align-items: center; background: var(--surface); }
.chat-in input { flex: 1; min-width: 0; padding: 10px 14px; font-size: 14px; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 26px 14px; }
.chip { font-size: 12.5px; border: 1px solid var(--line); background: var(--surface); border-radius: 16px; padding: 6px 12px; cursor: pointer; color: var(--ink2); }
.chip:hover { border-color: var(--gold); color: var(--ink); }

/* ---------- misc */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 900px) { .grid2 { grid-template-columns: 1fr; } }
.dl-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.dl { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; display: flex; flex-direction: column; gap: 8px; }
.dl .t { font-weight: 600; } .dl .d { font-size: 12.5px; color: var(--ink2); flex: 1; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tab { padding: 9px 14px; font-size: 13.5px; color: var(--ink2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--ink); border-bottom-color: var(--gold); font-weight: 600; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; font-size: 13px; }
.kv .k { color: var(--ink3); }
.sr-only { position: absolute; left: -9999px; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px; z-index: 200; box-shadow: var(--shadow-lg); }
