/* PowerParcels AI — design system. "TRL Enterprise Light": white / grey / black, red accents.
   The topbar stays near-black (brand anchor) and the map stays dark; everything else is light. */
:root {
  --canvas: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --inset: #eef0f3;
  --line: #e5e8ec;
  --line-2: #d4d9df;
  --ink: #1a1e24;
  --ink-2: #3f4650;
  --muted: #667085;
  --muted-2: #98a2b3;
  --red: #d92632;
  --red-hi: #b91c26;
  --red-tint: #fdeeef;
  --red-line: #f3c2c6;
  --ok: #1a7f4e;
  --ok-tint: #e8f5ee;
  --ok-line: #bfe3cf;
  --warn: #a16207;
  --warn-tint: #fdf3e0;
  --topbar-bg: #14161a;
  --topbar-line: #2a2e35;
  --topbar-raised: #1f2329;
  --topbar-line-2: #383e47;
  --map-bg: #eceef1; /* CARTO Positron (light) basemap */
  --shadow-1: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-2: 0 4px 16px rgba(16, 24, 40, .10);
  --shadow-3: 0 24px 64px rgba(16, 24, 40, .22);
  --topbar-h: 54px;
  --side-w: 216px;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--canvas); color: var(--ink); font-size: 14px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1,h2,h3,h4 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #cfd5db; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #b9c0c9; }
::-webkit-scrollbar-track { background: transparent; }

/* icons */
.icn { display: inline-flex; width: 16px; height: 16px; flex: 0 0 auto; vertical-align: -3px; }
.icn svg { width: 100%; height: 100%; display: block; }

/* ---------- shell ---------- */
#app { height: 100vh; display: flex; flex-direction: column; }
#topbar {
  height: var(--topbar-h); flex: 0 0 auto; display: flex; align-items: center; gap: 16px;
  padding: 0 16px; background: var(--topbar-bg); border-bottom: 1px solid var(--topbar-line);
  color: #f2f4f7;
}
#layout { flex: 1 1 auto; display: flex; min-height: 0; }
#sidebar {
  width: var(--side-w); flex: 0 0 auto; background: #fafbfc;
  border-right: 1px solid var(--line); padding: 12px 10px 10px; overflow-y: auto;
  display: flex; flex-direction: column;
}
/* isolate: trap Leaflet's internal high z-indexes inside #view so map canvases
   never paint over the drawer/modal/topbar (which live outside #view). */
#view { flex: 1 1 auto; min-width: 0; overflow: auto; position: relative; isolation: isolate; z-index: 0; }

.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; letter-spacing: -0.02em; color: #fff; }
.brand .mark {
  width: 24px; height: 24px; border-radius: 6px; background: var(--red);
  display: grid; place-items: center; color: #fff;
}
.brand .mark svg { width: 13px; height: 13px; }
.brand small { color: var(--muted-2); font-weight: 500; letter-spacing: 0; }

/* topbar controls live on the dark bar — style them deliberately */
#topbar input, #topbar select {
  background: var(--topbar-raised); border: 1px solid var(--topbar-line-2); color: #e9ebee;
}
#topbar input::placeholder { color: #7c8490; }
#topbar input:focus, #topbar select:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(217, 38, 50, .25); }
#topbar .muted { color: #9aa1ac; }

.topbar-spacer { flex: 1 1 auto; }
.gsearch { position: relative; width: 320px; max-width: 34vw; }
.gsearch input { width: 100%; padding-left: 33px; padding-right: 40px; }
.gsearch .sic { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: #7c8490; pointer-events: none; display: inline-flex; }
.gsearch .sic .icn { width: 14px; height: 14px; }
.gsearch kbd {
  position: absolute; right: 9px; top: 50%; transform: translateY(-50%); pointer-events: none;
  font-family: var(--mono); font-size: 10.5px; color: #7c8490; border: 1px solid var(--topbar-line-2);
  border-radius: 4px; padding: 1px 5px; line-height: 1.4;
}

/* topbar bell */
.bellbtn { position: relative; background: transparent; border: 0; color: #9aa1ac; cursor: pointer; padding: 7px; border-radius: 8px; display: inline-flex; }
.bellbtn:hover { background: var(--topbar-raised); color: #e9ebee; }
.bellbtn .bdg {
  position: absolute; top: 2px; right: 2px; background: var(--red); color: #fff; font-size: 9.5px;
  font-weight: 700; border-radius: 8px; min-width: 14px; height: 14px; line-height: 14px; text-align: center; padding: 0 3px;
}
.bellwrap { position: relative; }
/* Bell dropdown — anchored panel (pattern mirrors kbRelay's NotificationBell). */
.notif-dropdown {
  position: absolute; right: 0; top: calc(100% + 10px); z-index: 70;
  width: 340px; max-width: 90vw; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line-2); border-radius: var(--radius);
  box-shadow: var(--shadow-3); overflow: hidden;
}
.notif-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 13px; border-bottom: 1px solid var(--line);
  font-weight: 650; font-size: 12.5px;
}
.notif-markall { background: transparent; border: 0; color: var(--red); font: inherit; font-size: 11.5px; font-weight: 600; cursor: pointer; padding: 2px; }
.notif-markall:hover { text-decoration: underline; }
.notif-list { max-height: 55vh; overflow-y: auto; }
.notif-empty { color: var(--muted); font-size: 12.5px; padding: 18px 14px; text-align: center; }
.alert-row { display: flex; gap: 10px; padding: 10px 13px; border-bottom: 1px solid var(--line); font-size: 12.5px; color: var(--ink-2); align-items: flex-start; border-left: 3px solid transparent; }
.alert-row.unread { border-left-color: var(--red); background: #fffafa; }
.alert-row:last-child { border-bottom: 0; }
.alert-row .act-ic { width: 26px; height: 26px; border-radius: 7px; background: var(--red-tint); color: var(--red); display: grid; place-items: center; flex: 0 0 auto; }
.alert-row .t { color: var(--muted-2); font-size: 11px; margin-top: 2px; }
.gsearch .results {
  position: absolute; top: 40px; left: 0; right: 0; background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--radius); z-index: 60;
  max-height: 320px; overflow: auto; box-shadow: var(--shadow-3); color: var(--ink);
}
.gsearch .results .row { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid var(--line); }
.gsearch .results .row:last-child { border-bottom: 0; }
.gsearch .results .row:hover { background: var(--surface-2); }

.pill-role {
  display: inline-flex; align-items: center; gap: 8px; background: var(--topbar-raised);
  border: 1px solid var(--topbar-line-2); border-radius: 999px; padding: 4px 9px 4px 12px; cursor: pointer;
}
.pill-role:hover { border-color: #4a515c; }
.pill-role .car { color: #7c8490; display: inline-flex; }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--red); color: #fff;
  display: grid; place-items: center; font-size: 11px; font-weight: 700; }

/* nav */
.nav-group { margin: 4px 2px 16px; }
.nav-group .t { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted-2); padding: 4px 12px 8px; font-weight: 650; }
.nav-item {
  display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 8px;
  color: var(--ink-2); cursor: pointer; font-weight: 550; margin: 2px 0; font-size: 13.5px;
}
.nav-item:hover { background: var(--inset); color: var(--ink); }
.nav-item.active { background: var(--red-tint); color: var(--ink); font-weight: 650; }
.nav-item.active .ic { color: var(--red); }
.nav-item .ic { width: 18px; display: inline-flex; justify-content: center; color: var(--muted); }
.nav-item:hover .ic { color: var(--ink-2); }
.nav-item.active:hover { background: var(--red-tint); }

/* organization block pinned toward the sidebar foot */
.org-block { margin-top: auto; padding: 14px 12px 12px; border-top: 1px solid var(--line); }
.org-block .t { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted-2); font-weight: 650; }
.org-block .nm { font-weight: 650; margin-top: 5px; font-size: 13.5px; }
.org-block .chip { margin-top: 9px; }
.chip.ok { color: var(--ok); border-color: var(--ok-line); background: var(--ok-tint); }

/* AI copilot card — bottom of the sidebar */
.copilot-card {
  margin: 10px 2px 2px; padding: 13px 13px 12px; background: var(--surface);
  border: 1px solid var(--line-2); border-radius: var(--radius); box-shadow: var(--shadow-1);
}
.copilot-card .hd { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 13px; }
.copilot-card .hd .icn { color: var(--red); }
.copilot-card .sub { color: var(--muted); font-size: 11.5px; margin-top: 5px; line-height: 1.45; }
.copilot-card .btn { width: 100%; margin-top: 11px; color: var(--red); border-color: var(--red-line); }
.copilot-card .btn:hover { background: var(--red-tint); border-color: var(--red-line); color: var(--red-hi); }

/* copilot chat (in the drawer) */
.chat { display: flex; flex-direction: column; gap: 10px; }
.chat .msg { display: flex; gap: 9px; align-items: flex-start; }
.chat .msg .who { width: 26px; height: 26px; border-radius: 7px; background: var(--red-tint); color: var(--red); display: grid; place-items: center; flex: 0 0 auto; margin-top: 1px; }
.chat .msg.user { flex-direction: row-reverse; }
.chat .msg.user .who { background: var(--inset); color: var(--muted); }
.chat .bubble { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; font-size: 12.5px; line-height: 1.55; color: var(--ink-2); max-width: 85%; }
.chat .msg.user .bubble { background: var(--red-tint); border-color: var(--red-line); color: var(--ink); }
.chat .bubble b { color: var(--ink); }
.sugg { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.sugg button { text-align: left; background: var(--surface); border: 1px solid var(--line-2); border-radius: 8px; padding: 8px 11px; font: inherit; font-size: 12.5px; color: var(--ink-2); cursor: pointer; }
.sugg button:hover { border-color: var(--red-line); background: var(--red-tint); color: var(--ink); }

/* ---------- controls ---------- */
input, select, textarea {
  background: var(--surface); border: 1px solid var(--line-2); color: var(--ink);
  border-radius: 8px; padding: 7px 10px; font: inherit; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--red); box-shadow: 0 0 0 3px rgba(217, 38, 50, .10); }
input::placeholder { color: var(--muted-2); }
label.fld { display: block; font-size: 12px; color: var(--muted); margin: 10px 0 4px; font-weight: 550; }

.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  background: var(--surface); border: 1px solid var(--line-2); color: var(--ink-2);
  border-radius: 8px; padding: 8px 13px; font: inherit; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow-1); white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: #b9c0c9; color: var(--ink); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-hi); border-color: var(--red-hi); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--muted); }
.btn.ghost:hover { background: var(--inset); color: var(--ink); border-color: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.sm .icn { width: 14px; height: 14px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn .icn { width: 15px; height: 15px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; font-size: 11.5px; font-weight: 600;
  padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line-2); color: var(--muted);
  background: var(--surface); white-space: nowrap;
}
.chip.red { color: var(--red-hi); border-color: var(--red-line); background: var(--red-tint); }
.chip.dot::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.chip.plain { border-color: transparent; background: var(--inset); }

/* ---------- layout helpers ---------- */
.page { padding: 22px 24px 44px; }
.page-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 18px; }
.page-head .grow { flex: 1 1 auto; }
.page-head h1 { font-size: 20px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 3px; }
.row { display: flex; gap: 12px; }
.wrap { flex-wrap: wrap; }
.grid { display: grid; gap: 12px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.tabnum { font-variant-numeric: tabular-nums; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-1); }
.card.pad { padding: 16px; }
.card h3 { font-size: 13.5px; }
.section-t { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted-2); margin: 0 0 8px; font-weight: 650; }

/* key/value pseudo-table — the standard way to show attribute data */
.props { width: 100%; }
.props .pr {
  display: flex; justify-content: space-between; align-items: baseline; gap: 18px;
  padding: 8px 2px; border-bottom: 1px solid var(--line); font-size: 13px;
}
.props .pr:last-child { border-bottom: 0; }
.props .pk { color: var(--muted); flex: 0 0 auto; }
.props .pv { font-weight: 600; color: var(--ink); text-align: right; font-variant-numeric: tabular-nums; min-width: 0; overflow-wrap: anywhere; }
.props.cols2 { display: grid; grid-template-columns: 1fr 1fr; column-gap: 32px; }
.props.cols2 .pr:nth-last-child(2):nth-child(odd) { border-bottom: 0; }

/* KPI tiles — glyph + title line, then number, then metric line */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-1); }
.kpi .hd { display: flex; align-items: center; gap: 9px; }
.kpi .ic { width: 30px; height: 30px; border-radius: 8px; background: var(--red-tint); color: var(--red); display: grid; place-items: center; flex: 0 0 auto; }
.kpi .ic .icn { width: 15px; height: 15px; }
.kpi .k { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 650; line-height: 1.3; }
.kpi .v { font-size: 24px; font-weight: 700; margin-top: 9px; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }
.kpi .v small { font-size: 13px; font-weight: 650; color: var(--muted); margin-left: 3px; letter-spacing: 0; }
.kpi .d { margin-top: 6px; font-size: 11.5px; color: var(--muted-2); display: flex; align-items: center; gap: 5px; font-weight: 550; }
.kpi .d.up { color: var(--ok); }
.kpi .d .icn { width: 13px; height: 13px; }

/* tables */
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th, table.tbl td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
table.tbl th { color: var(--muted); font-weight: 650; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; cursor: pointer; user-select: none; position: sticky; top: 0; background: var(--surface); z-index: 1; box-shadow: inset 0 -1px 0 var(--line); }
table.tbl th.n, table.tbl td.n { text-align: right; }
table.tbl tbody tr { cursor: pointer; }
table.tbl tbody tr:hover { background: var(--surface-2); }

/* score badge — tinted, not saturated */
.score-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 40px;
  padding: 2px 8px; border-radius: 7px; font-weight: 700; font-size: 12.5px; font-variant-numeric: tabular-nums;
  border: 1px solid transparent; }
.score-badge.s-hi  { background: #e5f4ea; color: #187a41; border-color: #c4e5cf; }
.score-badge.s-good{ background: #eff6e2; color: #5c7a17; border-color: #d8e8b8; }
.score-badge.s-mid { background: #fdf3dd; color: #a16207; border-color: #f1dcae; }
.score-badge.s-low { background: #fdeceb; color: #c0362c; border-color: #f4c7c3; }

/* status chips — light tints */
.st { font-size: 11px; padding: 2px 8px; border-radius: 6px; border: 1px solid var(--line-2); color: var(--muted); font-weight: 600; white-space: nowrap; }
.st.brownfield { color: #8a5a19; border-color: #ead9bb; background: #faf3e8; }
.st.former_power_station { color: #6d3f9e; border-color: #ded0ec; background: #f6f0fb; }
.st.greenfield { color: #1f7a3d; border-color: #c8e6d1; background: #ecf7f0; }

/* ---------- drawer ---------- */
#drawer-root { position: fixed; inset: 0; pointer-events: none; z-index: 80; }
#drawer-root.open { pointer-events: auto; }
.drawer-scrim { position: absolute; inset: 0; background: #10141a; opacity: 0; transition: opacity .18s; }
#drawer-root.open .drawer-scrim { opacity: .4; }
.drawer {
  position: absolute; top: 0; right: 0; height: 100%; width: 520px; max-width: 94vw;
  background: var(--surface); border-left: 1px solid var(--line); transform: translateX(100%);
  transition: transform .2s ease; display: flex; flex-direction: column; box-shadow: var(--shadow-3);
}
#drawer-root.open .drawer { transform: none; }
.drawer .dh { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.drawer .dh .grow { min-width: 0; overflow-wrap: anywhere; } /* long titles wrap instead of overflowing the close button */
.drawer .db { flex: 1 1 auto; overflow: auto; padding: 16px; }
.drawer .df { border-top: 1px solid var(--line); padding: 12px 16px; display: flex; gap: 10px; background: var(--surface-2); border-radius: 0 0 0 var(--radius); }
.iconbtn { background: transparent; border: 0; color: var(--muted); cursor: pointer; padding: 6px; border-radius: 7px; display: inline-flex; }
.iconbtn:hover { background: var(--inset); color: var(--ink); }

/* modal */
#modal-root { position: fixed; inset: 0; z-index: 90; display: none; place-items: center; }
#modal-root.open { display: grid; }
#modal-root .scrim { position: absolute; inset: 0; background: rgba(16, 20, 26, .45); }
.modal { position: relative; width: 460px; max-width: 92vw; background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 20px; box-shadow: var(--shadow-3); }

/* toast */
#toast-root { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 120; display: flex; flex-direction: column; gap: 8px; }
.toast { background: var(--surface); border: 1px solid var(--line-2); border-left: 3px solid var(--red);
  padding: 10px 14px; border-radius: 8px; box-shadow: var(--shadow-2); font-size: 13px; animation: tin .2s; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }

/* meters / bars — flat fills, no gradients */
.meter { height: 6px; background: var(--inset); border-radius: 4px; overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--red); border-radius: 4px; opacity: .85; }

/* AI Site Analyst panel — the product's signature moment */
.ai-panel { border: 1px solid var(--line-2); border-radius: var(--radius); padding: 14px 15px; background: var(--surface); box-shadow: var(--shadow-1); }
.ai-panel .hd { display: flex; gap: 11px; align-items: flex-start; }
.ai-panel .ai-icon { width: 34px; height: 34px; border-radius: 8px; background: var(--red-tint); color: var(--red); display: grid; place-items: center; flex: 0 0 auto; }
.ai-panel .ai-icon .icn { width: 17px; height: 17px; }
.ai-panel .ttl { font-weight: 650; font-size: 13.5px; }
.ai-panel .sub { color: var(--muted); font-size: 12px; margin-top: 1px; line-height: 1.45; }
.ai-panel .meta { color: var(--muted-2); font-size: 11.5px; }

/* report — reads like an analyst document */
.report h2 { font-size: 18px; margin-bottom: 2px; }
.report .rec { display: inline-flex; align-items: center; gap: 8px; font-weight: 650; font-size: 13px;
  padding: 8px 14px; border-radius: 8px; background: var(--ok-tint); color: var(--ok); border: 1px solid var(--ok-line); }
.report section { border-top: 1px solid var(--line); padding: 15px 0; }
.report section h3 { font-size: 13.5px; margin-bottom: 2px; }
.report section .metrics { display: grid; grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 8px; margin: 10px 0; }
.report .m { background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px; padding: 8px 11px; font-size: 12px; }
.report .m > span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 2px; }
.report .m b { display: block; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.report .body-t { color: var(--ink-2); font-size: 13px; margin-top: 4px; line-height: 1.55; }
.cite { font-size: 12px; color: var(--ink-2); background: var(--surface-2); border: 1px solid var(--line);
  border-left: 3px solid var(--red); border-radius: 6px; padding: 8px 12px; margin: 8px 0; line-height: 1.5; }
.cite b { color: var(--ink); }
.draft { white-space: pre-wrap; font-size: 12.5px; background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 8px; padding: 13px 14px; line-height: 1.6; color: var(--ink-2); }

/* pipeline board */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; }
.board .col { flex: 0 0 232px; background: #f1f3f5; border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; max-height: 100%; }
.board .col > .h { padding: 9px 11px 7px; font-size: 12px; font-weight: 650; display: flex; justify-content: space-between; align-items: center; color: var(--ink-2); }
.board .col .cards { padding: 8px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 40px; }
.tcard { background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; cursor: grab; box-shadow: var(--shadow-1); }
.tcard:hover { border-color: var(--line-2); box-shadow: var(--shadow-2); }
.tcard.drag { opacity: .4; }
.board .col.drop-hover { outline: 2px dashed var(--red-line); outline-offset: -2px; background: var(--red-tint); }
.tcard .nm { font-weight: 600; font-size: 12.5px; }
.tcard .mt { color: var(--muted); font-size: 11.5px; margin-top: 3px; display: flex; justify-content: space-between; }

/* map — light Positron basemap (white / cool slate) to match the layout */
.map { width: 100%; height: 100%; background: var(--map-bg); }
.leaflet-container { background: var(--map-bg); font: inherit; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-2); }
.explore-grid { display: grid; grid-template-columns: 236px 1fr; height: 100%; }
.explore-main { display: grid; grid-template-rows: 55% 45%; min-height: 0; }
.filter-rail { border-right: 1px solid var(--line); background: #fafbfc; overflow-y: auto; padding: 14px 14px 20px; }
.result-head { display: flex; align-items: center; gap: 12px; padding: 8px 14px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); background: var(--surface); }
.result-body { overflow: auto; background: var(--surface); }
.range-val { font-size: 12px; color: var(--muted); float: right; font-variant-numeric: tabular-nums; }
input[type=range] { width: 100%; accent-color: var(--red); padding: 0; border: 0; background: transparent; box-shadow: none; }
input[type=range]:focus { box-shadow: none; }

.legend { display: flex; gap: 12px; align-items: center; font-size: 11.5px; color: var(--muted); }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; margin-right: 4px; vertical-align: -1px; }

.funnel .bar { display: flex; align-items: center; gap: 10px; margin: 7px 0; }
.funnel .lab { width: 120px; font-size: 12.5px; color: var(--muted); }
.funnel .track { flex: 1; height: 18px; background: var(--inset); border-radius: 5px; overflow: hidden; }
.funnel .track > i { display: block; height: 100%; background: var(--red); border-radius: 5px 0 0 5px; opacity: .85; }
.funnel .n { width: 28px; text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; font-size: 12.5px; }

.empty { color: var(--muted); font-size: 13px; padding: 28px; text-align: center; }
.spinner { width: 22px; height: 22px; border: 3px solid var(--line-2); border-top-color: var(--red); border-radius: 50%; animation: spin .7s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg); } }
.activity-item { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 12.5px; color: var(--ink-2); align-items: flex-start; }
.activity-item:last-child { border-bottom: 0; }
.activity-item .act-ic { width: 26px; height: 26px; border-radius: 7px; background: var(--inset); color: var(--muted); display: grid; place-items: center; flex: 0 0 auto; margin-top: 1px; }
.activity-item .t { color: var(--muted-2); font-size: 11px; margin-top: 1px; }

/* list rows (dashboard top parcels, saved screens, …) */
.list-row { display: flex; align-items: center; gap: 10px; padding: 8px 2px; border-bottom: 1px solid var(--line); cursor: pointer; border-radius: 4px; }
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--surface-2); }

/* ---------- responsive (≤820px phone/tablet; desktop above is untouched) ---------- */
.mobile-only { display: none !important; }
.hamb { background: transparent; border: 0; color: #cfd4db; cursor: pointer; padding: 7px; border-radius: 8px; }
.hamb:hover { background: var(--topbar-raised); color: #fff; }
#side-scrim, .rail-scrim { display: none; }

@media (max-width: 820px) {
  .mobile-only { display: inline-flex !important; }

  /* topbar compresses; every control stays reachable */
  #topbar { gap: 8px; padding: 0 10px; }
  .gsearch { flex: 1 1 auto; width: auto; min-width: 0; }
  .gsearch kbd { display: none; }
  .model-wrap .lbl { display: none; }
  .model-wrap select { max-width: 138px; }
  .pill-role { padding: 4px 8px 4px 4px; gap: 4px; }
  .pill-role .who { display: none; }

  /* sidebar becomes a left slide-over (nav + org + Meridian intact) */
  #sidebar {
    position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: 268px; z-index: 66;
    transform: translateX(-105%); transition: transform .2s ease;
  }
  body.side-open #sidebar { transform: none; box-shadow: var(--shadow-3); }
  body.side-open #side-scrim { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(16, 20, 26, .45); z-index: 65; }

  /* pages + the big two-column rows stack */
  .page { padding: 14px 14px 40px; }
  .layout-row { flex-direction: column; }
  .layout-row > * { min-width: 0 !important; width: 100%; flex: 1 1 auto !important; }
  .card.pad { overflow-x: auto; } /* wide tables (e.g. team) scroll inside their card */
  #view .grid { grid-template-columns: 1fr !important; }
  .kpis { grid-template-columns: repeat(2, 1fr); }

  /* explore: single column (map over results); filter rail is a slide-over */
  .explore-grid { grid-template-columns: 1fr; }
  .explore-main { grid-template-rows: 46% 54%; }
  /* stop the wide results table's intrinsic min-width from propagating up */
  .explore-main, .explore-main > *, .result-body { min-width: 0; }
  /* z-index must clear Leaflet's internal panes (~400-1000) — the rail lives
     inside #view's isolated stacking context, so this can't leak over the
     drawer/modal/topbar which sit outside #view. */
  .filter-rail {
    position: fixed; top: var(--topbar-h); bottom: 0; left: 0; width: 300px; max-width: 86vw; z-index: 1200;
    transform: translateX(-105%); transition: transform .2s ease;
  }
  .explore-grid.rail-open .filter-rail { transform: none; box-shadow: var(--shadow-3); }
  .explore-grid.rail-open .rail-scrim { display: block; position: fixed; inset: var(--topbar-h) 0 0 0; background: rgba(16, 20, 26, .45); z-index: 1190; }
  .result-head { flex-wrap: wrap; row-gap: 6px; }
  .result-body table.tbl { min-width: 720px; } /* keep all columns; horizontal scroll */
  .result-body, .board { -webkit-overflow-scrolling: touch; }
}

@media (max-width: 540px) {
  html, body { overflow-x: hidden; } /* backstop: never let content expand the layout viewport */
  #topbar { gap: 6px; }
  .brand { gap: 0; }
  .brand > span:not(.mark), .brand small { display: none; } /* mark only on phones */
  .model-wrap select { max-width: 112px; font-size: 12.5px; }
  .gsearch { min-width: 70px; }
  .legend { display: none; }
  .kpi .v { font-size: 21px; }
  .page-head { flex-wrap: wrap; }
  .page-head h1 { font-size: 18px; }
  .notif-dropdown { position: fixed; top: calc(var(--topbar-h) + 6px); left: 8px; right: 8px; width: auto; max-width: none; }
}

/* print — the report packet becomes the page */
@media print {
  #topbar, #sidebar, .btn, #toast-root { display: none !important; }
  body { background: #fff; }
  #view { overflow: visible; }
  .page { padding: 0; }
  .card { border: 0; box-shadow: none; }
}
