:root {
  --paper: #eef1f1;
  --surface: #ffffff;
  --ink: #16232c;
  --ink-2: #4b5a64;
  --ink-3: #7c8a92;
  --rule: #d8dfe1;
  --rule-2: #e8ecec;
  --accent: #1f5f9e;
  --focus: #2a78d6;
  --good: #0a7d0a;
  --warn: #a86b00;
  --bad: #c03232;
  --radius: 6px;
  --font: 'Barlow', system-ui, sans-serif;
  --font-num: 'Barlow Condensed', 'Barlow', system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.45 var(--font); color: var(--ink); background: var(--paper); -webkit-font-smoothing: antialiased; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.num { font-family: var(--font-num); font-variant-numeric: tabular-nums; }

/* Fibre colour code (TIA-598): the brand strip */
.fibre-strip { height: 5px; display: grid; grid-template-columns: repeat(12, 1fr); }
.fibre-strip i:nth-child(1) { background: #1f6fd1; } .fibre-strip i:nth-child(2) { background: #f07f1a; }
.fibre-strip i:nth-child(3) { background: #1f9a3c; } .fibre-strip i:nth-child(4) { background: #7a4a24; }
.fibre-strip i:nth-child(5) { background: #8a959b; } .fibre-strip i:nth-child(6) { background: #ffffff; box-shadow: inset 0 0 0 1px #d8dfe1; }
.fibre-strip i:nth-child(7) { background: #d63a3a; } .fibre-strip i:nth-child(8) { background: #1b1b1b; }
.fibre-strip i:nth-child(9) { background: #f4c81f; } .fibre-strip i:nth-child(10) { background: #7b4fc9; }
.fibre-strip i:nth-child(11) { background: #f29bb8; } .fibre-strip i:nth-child(12) { background: #33c3cf; }

/* ---------- buttons ---------- */
.btn { border: 1px solid var(--rule); background: var(--surface); border-radius: var(--radius); padding: 7px 12px; cursor: pointer; font-weight: 500; line-height: 1.2; }
.btn:hover { border-color: var(--ink-3); }
.btn:disabled { cursor: not-allowed; opacity: .5; }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #22343f; }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 9px; font-size: 13px; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--rule-2); }

/* ---------- map app layout ---------- */
.app { display: grid; grid-template-columns: 390px 1fr; height: 100vh; }
.panel { background: var(--surface); border-right: 1px solid var(--rule); display: flex; flex-direction: column; min-height: 0; z-index: 2; }
.brand { padding: 16px 20px 12px; }
.brand h1 { font: 600 22px/1.15 var(--font); margin: 10px 0 2px; letter-spacing: -.01em; }
.brand p { margin: 0; color: var(--ink-2); font-size: 14px; }
.weekbar { display: flex; align-items: center; gap: 10px; padding: 10px 20px; border-top: 1px solid var(--rule-2); border-bottom: 1px solid var(--rule-2); background: #f8faf9; }
.weekbar .week { font: 600 26px/1 var(--font-num); }
.weekbar .week small { font: 500 13px var(--font); color: var(--ink-2); margin-right: 4px; }
.weekbar .grow { flex: 1; }
.tabs { display: flex; gap: 2px; padding: 8px 14px 0; border-bottom: 1px solid var(--rule); }
.tabs button { border: 0; background: none; padding: 8px 10px 9px; cursor: pointer; color: var(--ink-2); font-weight: 500; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.tabs .count { font: 600 12px var(--font-num); background: var(--rule-2); border-radius: 9px; padding: 1px 6px; margin-left: 4px; }
.tab-body { flex: 1; overflow: auto; padding: 16px 20px 24px; }
.panel-foot { border-top: 1px solid var(--rule); padding: 10px 14px; display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--ink-2); }
.panel-foot .grow { flex: 1; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); display: inline-block; margin-right: 6px; }
.sync-dot.local { background: var(--warn); }
.sync-dot.error { background: var(--bad); }

#map { height: 100vh; background: #e4e8e7; }
.leaflet-container { font-family: var(--font); }
.leaflet-tile-pane { filter: grayscale(.85) contrast(.92) brightness(1.04); }

/* ---------- KPI block in panel ---------- */
.kpi-main { display: grid; grid-template-columns: 1fr 1fr; gap: 18px 16px; margin-bottom: 18px; }
.kpi .v { font: 600 34px/1 var(--font-num); letter-spacing: -.01em; }
.kpi .v small { font-size: 18px; color: var(--ink-3); font-weight: 500; }
.kpi .l { color: var(--ink-2); font-size: 13.5px; margin-top: 3px; }
.bar { height: 6px; background: var(--rule-2); border-radius: 3px; overflow: hidden; margin-top: 7px; }
.bar > i { display: block; height: 100%; background: var(--ink); border-radius: 3px; transition: width .4s ease; }
h2.sec { font: 600 15px/1.3 var(--font); margin: 22px 0 8px; }
h2.sec .hint { font-weight: 400; color: var(--ink-3); font-size: 13px; margin-left: 4px; }

/* stage ladder (homes funnel) */
.ladder { list-style: none; margin: 0; padding: 0; }
.ladder li { display: grid; grid-template-columns: 1fr 58px; gap: 2px 10px; padding: 6px 0; border-bottom: 1px solid var(--rule-2); font-size: 14px; }
.ladder li .n { text-align: right; font: 600 17px var(--font-num); }
.ladder li .bar { grid-column: 1 / -1; margin-top: 0; height: 4px; }
.ladder li .bar > i { background: var(--sw, var(--ink)); }

/* ---------- queues ---------- */
.queue { border: 1px solid var(--rule); border-radius: var(--radius); margin-bottom: 10px; }
.queue summary { list-style: none; cursor: pointer; padding: 10px 12px; display: grid; grid-template-columns: 1fr auto; gap: 0 10px; }
.queue summary::-webkit-details-marker { display: none; }
.queue summary b { font-weight: 600; }
.queue summary .n { font: 600 22px/1 var(--font-num); align-self: center; grid-row: 1 / 3; grid-column: 2; }
.queue summary .d { color: var(--ink-2); font-size: 13px; }
.queue .items { display: flex; flex-wrap: wrap; gap: 5px; padding: 0 12px 12px; }
.chip { border: 1px solid var(--rule); background: #f8faf9; border-radius: 4px; padding: 2px 7px; font: 500 13px var(--font-num); cursor: pointer; }
.chip:hover { border-color: var(--ink-2); }
.queue .more { font-size: 13px; color: var(--ink-3); align-self: center; }
.queue .qact { padding: 0 12px 12px; }

/* ---------- selection ---------- */
.empty { color: var(--ink-2); padding: 18px 0; }
.empty b { color: var(--ink); }
.sel-head .type { color: var(--ink-2); font-size: 13.5px; }
.sel-head h2 { font: 600 26px/1.1 var(--font-num); margin: 2px 0 2px; }
.sel-head .sub { color: var(--ink-2); }
.phase { display: inline-flex; align-items: center; gap: 7px; margin-top: 10px; padding: 4px 10px 4px 8px; border-radius: 14px; background: #f3f5f5; border: 1px solid var(--rule); font-weight: 500; font-size: 14px; }
.phase .sw { width: 10px; height: 10px; border-radius: 50%; background: var(--sw); }
.facts { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 14px 0 0; font-size: 14px; }
.facts dt { color: var(--ink-2); }
.facts dd { margin: 0; }

/* the chain: every link between POP and the home */
.chain { list-style: none; margin: 6px 0 0; padding: 0; position: relative; }
.chain li { position: relative; padding: 5px 0 5px 28px; font-size: 14px; display: flex; gap: 8px; align-items: baseline; }
.chain li::before { content: ''; position: absolute; left: 8px; top: 0; bottom: 0; width: 2px; background: var(--rule); }
.chain li:first-child::before { top: 50%; }
.chain li:last-child::before { bottom: 50%; }
.chain li.ok::before { background: #8cc68c; }
.chain .node { position: absolute; left: 2px; top: 9px; width: 14px; height: 14px; border-radius: 50%; background: var(--surface); border: 2px solid var(--ink-3); display: grid; place-items: center; font-size: 9px; font-weight: 700; color: #fff; }
.chain li.ok .node { background: var(--good); border-color: var(--good); }
.chain li.bad .node { background: var(--bad); border-color: var(--bad); }
.chain li.wip .node { border-color: #eda100; background: #fff3d3; }
.chain .what { flex: 1; }
.chain .what button { border: 0; background: none; padding: 0; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; text-decoration-color: #b8c8d8; }
.chain .st { color: var(--ink-2); font-size: 13px; text-align: right; }

.actions { display: grid; gap: 10px; margin-top: 8px; }
.action { border: 1px solid var(--rule); border-radius: var(--radius); padding: 10px 12px; }
.action.blocked { background: #fafbfb; }
.action .btn { width: 100%; text-align: left; }
.action ul { list-style: none; margin: 8px 0 0; padding: 0; font-size: 13.5px; }
.action li { display: flex; gap: 6px; color: var(--ink-2); }
.action li .i { width: 14px; flex: none; font-weight: 700; }
.action li.ok .i { color: var(--good); }
.action li.no .i { color: var(--bad); }
.action li.no { color: var(--ink); }
.impact { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 6px; }
.impact div { background: #f6f8f8; border-radius: var(--radius); padding: 8px 10px; }
.impact .v { font: 600 22px/1 var(--font-num); }
.impact .l { font-size: 12.5px; color: var(--ink-2); }
.minibar { display: flex; height: 10px; border-radius: 3px; overflow: hidden; gap: 2px; margin-top: 8px; background: var(--rule-2); }
.minibar i { display: block; height: 100%; }
.keylist { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 13px; color: var(--ink-2); margin-top: 6px; }
.keylist span::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 2px; background: var(--sw); margin-right: 5px; }

/* ---------- map overlays ---------- */
.map-tools { position: absolute; top: 12px; right: 12px; z-index: 500; display: flex; gap: 8px; align-items: flex-start; }
.search { position: relative; }
.search input { width: 250px; padding: 8px 11px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--surface); box-shadow: 0 1px 3px rgba(22, 35, 44, .12); }
.search ul { position: absolute; top: 40px; left: 0; right: 0; margin: 0; padding: 4px 0; list-style: none; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: 0 6px 16px rgba(22, 35, 44, .14); max-height: 300px; overflow: auto; }
.search li button { width: 100%; text-align: left; border: 0; background: none; padding: 6px 11px; cursor: pointer; display: flex; justify-content: space-between; gap: 8px; }
.search li button:hover, .search li button.on { background: #eef3f8; }
.search li small { color: var(--ink-3); }
.layers { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius); padding: 8px 12px; box-shadow: 0 1px 3px rgba(22, 35, 44, .12); font-size: 14px; }
.layers label { display: flex; gap: 7px; align-items: center; padding: 2px 0; cursor: pointer; }
.layers summary { cursor: pointer; font-weight: 500; }
.legend { position: absolute; right: 12px; bottom: 26px; z-index: 500; background: rgba(255, 255, 255, .95); border: 1px solid var(--rule); border-radius: var(--radius); padding: 10px 12px; font-size: 13px; box-shadow: 0 1px 3px rgba(22, 35, 44, .12); width: 270px; }
.legend h3 { font: 600 13px var(--font); margin: 0 0 4px; }
.legend h3:not(:first-child) { margin-top: 9px; }
.legend div { display: flex; align-items: center; gap: 8px; padding: 1px 0; color: var(--ink-2); }
.legend .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--sw); flex: none; border: 1.5px solid #fff; box-shadow: 0 0 0 1px rgba(0,0,0,.15); }
.legend .ln { width: 22px; height: 0; border-top: 4px solid var(--sw); flex: none; }
.legend .ln.dash { border-top-style: dashed; border-top-width: 3px; }
.legend .sq { width: 11px; height: 11px; border-radius: 2px; background: #fff; border: 3px solid var(--sw); flex: none; }
.legend .n { margin-left: auto; font: 600 13px var(--font-num); color: var(--ink); }
.dp-icon { width: 16px; height: 16px; border-radius: 3px; background: #fff; border: 4px solid var(--sw); box-shadow: 0 0 0 1px rgba(22, 35, 44, .35); }
.dp-icon.sel { box-shadow: 0 0 0 3px #ffd84d, 0 0 0 4px rgba(22,35,44,.5); }
.dp-label { font: 600 12px var(--font-num); color: var(--ink); background: rgba(255,255,255,.85); padding: 0 3px; border-radius: 2px; white-space: nowrap; transform: translate(12px, -18px); display: inline-block; }
.pop-icon { width: 30px; height: 30px; border-radius: 6px; background: var(--ink); color: #fff; display: grid; place-items: center; font: 700 11px var(--font-num); box-shadow: 0 0 0 3px #fff, 0 2px 6px rgba(0,0,0,.3); border-bottom: 5px solid var(--sw); }
.leaflet-tooltip.tt { font: 13px var(--font); padding: 5px 8px; border-radius: 4px; }

/* toast + modal */
.toast { position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px); opacity: 0; background: var(--ink); color: #fff; padding: 10px 16px; border-radius: var(--radius); z-index: 2000; transition: .25s ease; pointer-events: none; max-width: 90vw; font-size: 14.5px; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast b { font-weight: 600; color: #a8e6a8; }
dialog { border: 0; border-radius: 10px; padding: 0; width: min(440px, 92vw); box-shadow: 0 18px 50px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(22, 35, 44, .45); }
.dlg { padding: 20px 22px; }
.dlg h2 { margin: 0 0 4px; font: 600 20px var(--font); }
.dlg p { color: var(--ink-2); margin: 0 0 14px; font-size: 14px; }
.dlg label { display: block; font-weight: 500; font-size: 14px; margin-bottom: 4px; }
.dlg input[type=password], .dlg input[type=number] { width: 100%; padding: 8px 10px; border: 1px solid var(--rule); border-radius: var(--radius); }
.dlg .row { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.dlg .err { color: var(--bad); font-size: 13.5px; min-height: 20px; margin-top: 6px; }
.dlg .opt { display: flex; gap: 8px; align-items: center; margin-top: 10px; font-size: 14px; }
.dlg .opt input { width: 70px; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; grid-template-rows: 55vh 45vh; }
  .panel { order: 2; border-right: 0; border-top: 1px solid var(--rule); }
  #map { height: 55vh; }
  .brand { padding: 10px 16px 8px; } .brand h1 { font-size: 18px; margin-top: 6px; } .brand p { display: none; }
  .legend { display: none; }
  .search input { width: 170px; }
  .tab-body { padding: 12px 16px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
.leaflet-tooltip.dp-label-tt { display: none; background: rgba(255,255,255,.9); border: 0; box-shadow: none; padding: 0 4px; font: 600 12px var(--font-num); color: var(--ink); border-radius: 2px; }
.leaflet-tooltip.dp-label-tt::before { display: none; }
.show-dp-labels .leaflet-tooltip.dp-label-tt { display: block; }
.legend .ln.cable { border: 0; height: 7px; background: linear-gradient(var(--sw) 0 30%, #7ee07e 30% 70%, var(--sw) 70%); }
.leaflet-container:not(.show-dp-labels) .dp-icon { transform: scale(.72); }
.legend .ln.cable.part { background: linear-gradient(var(--sw) 0 30%, transparent 30% 70%, var(--sw) 70%), repeating-linear-gradient(90deg, #fff 0 4px, var(--sw) 4px 8px); }
