:root {
  --bg: #0A0F0D;
  --panel: #111A16;
  --panel-2: #16231D;
  --line: #24362C;
  --line-2: #2F4639;
  --text: #EDEAE0;
  --muted: #9AA89F;
  --gold: #C8A96A;
  --gold-2: #E2C98F;
  --green: #2F5D45;
  --green-2: #3F7A5B;
  --russet: #B5562B;
  --ok: #72C495;
  --warn: #DDAA48;
  --bad: #D86A4E;
  --info: #7FA8C9;
  --radius: 14px;
  --sans: 'Inter', system-ui, -apple-system, Segoe UI, sans-serif;
  --serif: 'Cormorant Garamond', Georgia, serif;
  --mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--sans); }
a { color: var(--gold); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select { font: inherit; color: inherit; }
code { font-family: var(--mono); font-size: 12.5px; color: var(--gold-2); }

.shell { display: grid; grid-template-columns: 248px 1fr; min-height: 100vh; }
.side { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 22px; padding: 22px 16px; background: linear-gradient(180deg, #0D1512, #0A0F0D); border-right: 1px solid var(--line); }
.brand { display: flex; gap: 12px; align-items: center; padding: 0 6px; }
.brand-name { font-weight: 300; letter-spacing: .18em; font-size: 14px; }
.brand-name b { font-weight: 700; color: var(--gold); }
.brand-sub { font-family: var(--mono); font-size: 10px; letter-spacing: .24em; color: var(--muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav button { display: flex; align-items: center; gap: 10px; text-align: left; background: none; border: 0; border-radius: 10px; padding: 10px 12px; color: var(--muted); cursor: pointer; }
.nav button:hover { background: var(--panel); color: var(--text); }
.nav button.active { background: var(--panel-2); color: var(--text); box-shadow: inset 2px 0 0 var(--gold); }
.ico { width: 18px; text-align: center; color: var(--gold); }
.side-foot { margin-top: auto; display: grid; gap: 8px; }
.pill { font-size: 12px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel); }
.pill.ok { border-color: #2c5a40; color: var(--ok); }
.pill.warn { border-color: #5a4a22; color: var(--warn); }
.tiny { font-size: 11.5px; color: var(--muted); }
.small { font-size: 13px; }
.muted { color: var(--muted); }

.main { padding: 28px clamp(16px, 3vw, 40px) 60px; max-width: 1480px; width: 100%; }
.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.head { display: flex; justify-content: space-between; gap: 20px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 20px; }
.eyebrow { font-family: var(--mono); font-size: 11px; letter-spacing: .16em; text-transform: uppercase; color: var(--gold); margin: 0 0 6px; }
h1 { font-family: var(--serif); font-weight: 600; font-size: clamp(30px, 4vw, 42px); line-height: 1.05; margin: 0; }
h2 { font-size: 15px; font-weight: 600; margin: 0; letter-spacing: .01em; }
h3 { font-size: 14px; margin: 0; }
.lede { color: var(--muted); max-width: 760px; margin: 8px 0 0; }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; min-width: 0; }
.card-h { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.grid2 > .card, .grid3 > .card { margin-bottom: 0; }
.grid2, .grid3 { margin-bottom: 16px; }
.stack { display: grid; gap: 12px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text); padding: 9px 16px; border-radius: 10px; cursor: pointer; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: var(--gold); text-decoration: none; }
.btn.gold { background: var(--gold); color: #17140D; border-color: var(--gold); }
.btn.gold:hover { background: var(--gold-2); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 12.5px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.chip { display: inline-block; font-size: 11px; padding: 3px 9px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line-2); color: var(--muted); white-space: nowrap; }
.chip.high { color: #FFD8CC; background: #4A2116; border-color: #7A3826; }
.chip.medium { color: #F5E2B8; background: #3D3218; border-color: #6A5524; }
.chip.low { color: #CFE0D5; background: #1C3326; border-color: #2E4B39; }
.chip.ok { color: var(--ok); }
.chip.err { color: var(--bad); }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.kpi { background: linear-gradient(160deg, var(--panel-2), var(--panel)); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; }
.kpi .v { font-family: var(--serif); font-size: 38px; font-weight: 600; line-height: 1; color: var(--gold-2); }
.kpi .l { color: var(--muted); font-size: 12.5px; margin-top: 6px; }

.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.timeline li { display: grid; grid-template-columns: 92px 1fr; gap: 12px; }
.timeline time { font-family: var(--mono); font-size: 12px; color: var(--gold); padding-top: 2px; }
.timeline p { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.actions { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.actions li { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); font-size: 13.5px; }
.feed { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.feed li { display: grid; grid-template-columns: 96px 1fr; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.feed time { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.feed .fmt { font-size: 11px; color: var(--gold); text-transform: uppercase; letter-spacing: .08em; }

.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.tbl th { text-align: left; font-weight: 500; color: var(--muted); font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--line-2); white-space: nowrap; }
.tbl td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:hover td { background: #131F1A; }
.mono { font-family: var(--mono); font-size: 12px; }

label { display: grid; gap: 5px; font-size: 12.5px; color: var(--muted); min-width: 0; }
label.inline { display: inline-flex; align-items: center; gap: 8px; }
input, select { background: #0D1512; border: 1px solid var(--line-2); border-radius: 9px; padding: 9px 11px; color: var(--text); min-width: 0; width: 100%; }
input[type=checkbox] { width: auto; accent-color: var(--gold); }
input[type=range] { padding: 0; accent-color: var(--gold); }
input:focus, select:focus { outline: 2px solid rgba(200, 169, 106, .45); outline-offset: 1px; border-color: var(--gold); }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 12px; }
.row > label { flex: 1 1 150px; }
.row > .grow, .filters > .grow { flex: 3 1 240px; }
.row.end { justify-content: flex-end; margin-bottom: 0; }
.filters { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.filters > label { flex: 1 1 150px; }
fieldset.checks { border: 1px solid var(--line-2); border-radius: 10px; padding: 8px 12px 10px; margin: 0 0 12px; display: flex; flex-wrap: wrap; gap: 6px 16px; flex: 2 1 260px; }
fieldset.checks legend { font-size: 12px; color: var(--muted); padding: 0 6px; }
fieldset.checks label { display: inline-flex; align-items: center; gap: 7px; color: var(--text); font-size: 13px; }
.row fieldset.checks { margin: 0; }
.seg { display: inline-flex; gap: 4px; padding: 4px; border: 1px solid var(--line-2); border-radius: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.seg button { border: 0; background: none; padding: 8px 14px; border-radius: 9px; color: var(--muted); cursor: pointer; }
.seg button.on { background: var(--green); color: var(--text); }
.quick { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.quick button { border: 1px solid var(--line-2); background: none; border-radius: 8px; padding: 7px 10px; cursor: pointer; color: var(--muted); }
.quick button:hover { color: var(--text); border-color: var(--gold); }
.search-form [class^="m-"], .search-form [class*=" m-"] { display: none; }
.search-form[data-mode="authority"] .m-authority,
.search-form[data-mode="postcode"] .m-postcode,
.search-form[data-mode="point"] .m-point { display: grid; }
output { color: var(--gold); font-family: var(--mono); }

.status-line { min-height: 22px; margin: 4px 2px 12px; font-size: 13px; color: var(--muted); }
.status-line.err { color: var(--bad); }
.results-grid { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; align-items: start; }
.results-grid .map-card { position: sticky; top: 16px; }
.insight-card { max-height: 640px; overflow: auto; }
.results-grid > .card { margin-bottom: 0; }
.map-card { padding: 0; overflow: hidden; position: relative; }
.map { height: 460px; width: 100%; background: #0D1512; }
.map-legend { position: absolute; z-index: 500; left: 10px; bottom: 10px; background: rgba(10, 15, 13, .85); border: 1px solid var(--line-2); border-radius: 9px; padding: 6px 10px; font-size: 11.5px; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }
.dot.approved { background: var(--ok); } .dot.refused { background: var(--bad); } .dot.pending { background: var(--warn); } .dot.other { background: #8F9A94; }
.ring { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--gold); }
.insight-card { display: grid; gap: 14px; align-content: start; }
.gauge { display: flex; align-items: center; gap: 16px; }
.gauge .num { font-family: var(--serif); font-size: 52px; font-weight: 600; line-height: 1; color: var(--gold-2); }
.bar { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--green-2), var(--gold)); }
.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stat { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 17px; }
.stat span { font-size: 11.5px; color: var(--muted); }
.mini { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.mini td, .mini th { padding: 5px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.mini th { color: var(--muted); font-weight: 500; }

.results { display: grid; gap: 10px; }
.app { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: #0F1814; cursor: pointer; }
.app:hover, .app.hl { border-color: var(--gold); }
.app .ref { font-family: var(--mono); font-size: 12px; color: var(--gold); }
.app .addr { font-weight: 600; }
.app .desc { color: var(--muted); font-size: 13.5px; grid-column: 1 / -1; }
.app .meta { display: flex; gap: 6px; flex-wrap: wrap; grid-column: 1 / -1; align-items: center; font-size: 12px; color: var(--muted); }
.app .links { display: flex; gap: 12px; font-size: 12.5px; }
.st { font-size: 11px; padding: 3px 9px; border-radius: 99px; font-weight: 600; }
.st.Approved { background: #183A27; color: var(--ok); } .st.Refused { background: #43201A; color: #F0A08A; }
.st.Pending { background: #3D3218; color: var(--warn); } .st.Withdrawn, .st.Referred, .st.Other { background: #222B27; color: #B9C3BD; }
.pager { display: flex; justify-content: center; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.export { display: flex; gap: 6px; flex-wrap: wrap; }

.alert { border: 1px solid var(--line); border-left: 3px solid var(--line-2); border-radius: 12px; background: var(--panel); padding: 16px 18px; }
.alert.high { border-left-color: var(--russet); } .alert.medium { border-left-color: var(--gold); } .alert.low { border-left-color: var(--green-2); }
.alert h3 { font-size: 15px; margin: 6px 0; }
.alert .meta { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.alert p { margin: 6px 0; font-size: 13.5px; }
.alert .act { background: var(--panel-2); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-top: 8px; }
.alert details { margin-top: 8px; font-size: 13px; }
.alert summary { cursor: pointer; color: var(--gold); }
.diff { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 8px; }
.diff div { background: #0D1512; border: 1px solid var(--line); border-radius: 9px; padding: 10px; font-size: 12.5px; max-height: 220px; overflow: auto; }
.diff .b { border-color: #5A2A1E; } .diff .a { border-color: #22543A; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); border: 1px dashed var(--line-2); border-radius: var(--radius); }

.preset { display: grid; gap: 12px; align-content: start; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag { display: inline-flex; align-items: center; gap: 6px; background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 99px; padding: 4px 6px 4px 10px; font-size: 12.5px; }
.tag button { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 0 4px; }
.topic-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; }
.topic-grid label { display: flex; align-items: center; gap: 6px; color: var(--text); font-size: 12.5px; }

.flow { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; align-items: stretch; }
.node { border: 1px solid var(--line-2); border-radius: 12px; padding: 14px; background: var(--panel-2); position: relative; }
.node b { display: block; color: var(--gold-2); margin-bottom: 4px; }
.node span { font-size: 12.5px; color: var(--muted); }
.node.core { background: var(--green); border-color: var(--green-2); }
.node.core b { color: #fff; }
.health-card .v { font-size: 15px; font-weight: 600; margin-top: 6px; }
.health-card .v.ok { color: var(--ok); } .health-card .v.warn { color: var(--warn); }
.contracts { padding-left: 18px; margin: 0; display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
.log { background: #0D1512; border: 1px solid var(--line); border-radius: 10px; padding: 12px; font: 12px/1.45 var(--mono); max-height: 320px; overflow: auto; white-space: pre-wrap; }

.drawer { position: fixed; inset: 0; background: rgba(0, 0, 0, .55); z-index: 2000; display: flex; justify-content: flex-end; }
.drawer[hidden] { display: none; }
.drawer-in { width: min(720px, 100%); height: 100%; overflow: auto; background: var(--panel); border-left: 1px solid var(--line-2); padding: 26px; position: relative; }
.x { position: absolute; right: 16px; top: 12px; font-size: 26px; background: none; border: 0; color: var(--muted); cursor: pointer; }
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%); background: var(--panel-2); border: 1px solid var(--gold); padding: 10px 16px; border-radius: 10px; z-index: 3000; font-size: 13.5px; max-width: 90vw; }
.toast[hidden] { display: none; }
.spinner { display: inline-block; width: 14px; height: 14px; border: 2px solid var(--line-2); border-top-color: var(--gold); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -2px; }
@keyframes spin { to { transform: rotate(360deg); } }

.leaflet-container { font-family: var(--sans); background: #0D1512; }
.leaflet-popup-content-wrapper, .leaflet-popup-tip { background: var(--panel); color: var(--text); border: 1px solid var(--line-2); }
.leaflet-popup-content { font-size: 12.5px; margin: 12px 14px; }
.leaflet-control-layers, .leaflet-bar a { background: var(--panel) !important; color: var(--text) !important; border-color: var(--line-2) !important; }
.leaflet-control-attribution { background: rgba(10, 15, 13, .75) !important; color: var(--muted) !important; }
.leaflet-control-attribution a { color: var(--gold) !important; }

@media (max-width: 1100px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid3, .flow { grid-template-columns: 1fr 1fr; }
  .results-grid { grid-template-columns: 1fr; }
}
@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: sticky; z-index: 1000; height: auto; flex-direction: column; gap: 10px; padding: 12px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav { flex-direction: row; overflow-x: auto; scrollbar-width: none; }
  .nav button { white-space: nowrap; padding: 8px 10px; }
  .side-foot { display: none; }
  .main { padding: 20px 16px 48px; }
  .grid2, .grid3, .flow { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 10px; }
  .map { height: 340px; }
  .diff { grid-template-columns: 1fr; }
  .timeline li, .feed li { grid-template-columns: 1fr; gap: 2px; }
}

/* overflow guards */
.main, .side, .nav { min-width: 0; }
fieldset { min-width: 0; }
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .head-actions .btn { flex: 1 1 auto; }
  .seg { display: flex; }
  .seg button { flex: 1 1 auto; }
  .tbl { font-size: 12.5px; }
  .drawer-in { padding: 20px 16px; }
}
