:root {
  color-scheme: light;
  --bg: #eef2f7;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --ink: #111827;
  --muted: #64748b;
  --line: #d9e2ec;
  --brand: #155eef;
  --brand-dark: #0f3fb5;
  --good: #047857;
  --warning: #b45309;
  --shadow: 0 20px 45px rgba(15, 23, 42, 0.10);
  --radius: 22px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at top left, #dbeafe 0, transparent 32rem), var(--bg);
}

button,
input {
  font: inherit;
}

.app-header,
.app-footer {
  max-width: 1500px;
  margin: 0 auto;
  padding: 24px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--brand);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 6px;
  font-size: clamp(2rem, 4vw, 4.2rem);
  line-height: 0.95;
  letter-spacing: -0.05em;
}

h2 {
  margin-bottom: 16px;
  font-size: 1rem;
  letter-spacing: -0.02em;
}

.lede {
  max-width: 720px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1rem;
}

.header-actions,
.card-title-row,
.copy-grid,
.search-form {
  display: flex;
  gap: 10px;
}

.header-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button {
  border: 0;
  border-radius: 999px;
  padding: 11px 16px;
  color: #fff;
  background: var(--brand);
  font-weight: 800;
  cursor: pointer;
  transition: transform 150ms ease, background 150ms ease, opacity 150ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
  background: var(--brand-dark);
}

.button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.button-secondary {
  color: var(--brand);
  background: #e8f0ff;
}

.button-secondary:hover:not(:disabled) {
  color: #fff;
  background: var(--brand);
}

.button-ghost {
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
}

.button-small {
  padding: 8px 12px;
  font-size: 0.84rem;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 22px;
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 24px 24px;
}

.map-panel,
.card {
  background: rgba(255, 255, 255, 0.86);
  border: 1px solid rgba(217, 226, 236, 0.92);
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.map-panel {
  position: sticky;
  top: 16px;
  overflow: hidden;
  height: calc(100vh - 170px);
  min-height: 620px;
  border-radius: var(--radius);
}

.map {
  width: 100%;
  height: 100%;
}

.map-hint {
  position: absolute;
  left: 18px;
  bottom: 18px;
  z-index: 500;
  max-width: min(560px, calc(100% - 36px));
  padding: 10px 12px;
  border-radius: 999px;
  color: #0f172a;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.12);
  font-size: 0.86rem;
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  border-radius: var(--radius);
  padding: 18px;
}

.muted-card {
  color: var(--muted);
  background: rgba(248, 250, 252, 0.88);
}

.search-form input {
  min-width: 0;
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 11px 14px;
  background: #fff;
  outline: none;
}

.search-form input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(21, 94, 239, 0.12);
}

.status-line {
  min-height: 20px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 0.88rem;
}

.results,
.saved-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.result-item,
.saved-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 12px;
  text-align: left;
  color: var(--ink);
  background: var(--surface-2);
}

.result-item {
  cursor: pointer;
}

.result-item:hover {
  border-color: var(--brand);
}

.result-label,
.saved-label {
  display: block;
  font-weight: 800;
}

.result-meta,
.saved-meta {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.82rem;
}

.card-title-row {
  align-items: center;
  justify-content: space-between;
}

.data-grid {
  display: grid;
  gap: 10px;
  margin: 0;
}

.data-grid div {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface-2);
}

dt {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
  font-weight: 750;
}

.copy-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin-top: 14px;
}

.saved-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.saved-item .remove-button {
  border: 0;
  border-radius: 999px;
  padding: 7px 10px;
  color: #991b1b;
  background: #fee2e2;
  font-weight: 800;
  cursor: pointer;
}

.app-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.88rem;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .map-panel {
    position: relative;
    top: 0;
    height: 60vh;
    min-height: 420px;
  }

  .side-panel {
    grid-row: 2;
  }
}

@media (max-width: 720px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions,
  .search-form,
  .copy-grid {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr;
  }

  .app-shell,
  .app-header,
  .app-footer {
    padding-left: 14px;
    padding-right: 14px;
  }

  .data-grid div {
    grid-template-columns: 1fr;
  }

  .map-hint {
    border-radius: 16px;
  }
}


/* Local map engine: no Leaflet / no CDN dependency. */
.map {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  background: #dbeafe;
  cursor: grab;
  user-select: none;
  touch-action: none;
}

.map.is-dragging {
  cursor: grabbing;
}

.map-tile-pane,
.map-marker-pane {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.map-tile {
  position: absolute;
  width: 256px;
  height: 256px;
  border: 0;
  user-select: none;
  -webkit-user-drag: none;
}

.map-marker {
  position: absolute;
  z-index: 20;
  width: 22px;
  height: 22px;
  border: 3px solid #fff;
  border-radius: 999px 999px 999px 4px;
  background: var(--brand);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.28);
  transform: translate(-50%, -100%) rotate(-45deg);
}

.map-marker::after {
  content: "";
  position: absolute;
  inset: 4px;
  border-radius: 999px;
  background: #fff;
}

.map-marker.search-marker {
  width: 16px;
  height: 16px;
  background: #f97316;
  opacity: 0.9;
}

.map-marker.saved-marker {
  background: #047857;
}

.map-controls {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 30;
  display: grid;
  gap: 8px;
}

.map-control-button {
  width: 40px;
  height: 40px;
  border: 1px solid rgba(15, 23, 42, 0.16);
  border-radius: 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.12);
  font-size: 1.25rem;
  font-weight: 900;
  cursor: pointer;
}

.map-control-button:hover {
  background: #fff;
}

.map-attribution {
  position: absolute;
  right: 12px;
  bottom: 12px;
  z-index: 30;
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.92);
  color: var(--muted);
  font-size: 0.72rem;
}

.map-attribution a {
  color: var(--brand);
  font-weight: 800;
  text-decoration: none;
}

.map-error {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 50;
  width: min(440px, calc(100% - 48px));
  transform: translate(-50%, -50%);
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.95);
  box-shadow: var(--shadow);
  color: var(--ink);
}

.map-error strong {
  display: block;
  margin-bottom: 6px;
}

/* Fibre overlay */
.fibre-card {
  border-color: rgba(37, 99, 235, 0.22);
}

.layer-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.25rem 0.55rem;
  background: #eff6ff;
  color: #1d4ed8;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.02em;
}

.layer-toggle {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.75rem;
  border: 1px solid #dbe3ef;
  border-radius: 1rem;
  background: #f8fafc;
  cursor: pointer;
}

.layer-toggle input {
  margin-top: 0.2rem;
}

.layer-toggle strong {
  display: block;
  color: #0f172a;
}

.layer-toggle small {
  display: block;
  margin-top: 0.15rem;
  color: #64748b;
  line-height: 1.25;
}

.fibre-details {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border: 1px solid #dbe3ef;
  border-radius: 1rem;
  background: #ffffff;
  color: #334155;
  font-size: 0.86rem;
  line-height: 1.45;
}

.fibre-details strong {
  color: #0f172a;
}

.fibre-details dl {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  gap: 0.35rem 0.7rem;
  margin: 0.65rem 0 0;
}

.fibre-details dt {
  color: #64748b;
  font-weight: 700;
}

.fibre-details dd {
  margin: 0;
  color: #0f172a;
  word-break: break-word;
}

.map-line-pane {
  position: absolute;
  inset: 0;
  z-index: 420;
  pointer-events: none;
  overflow: visible;
}

.map-polyline {
  fill: none;
  stroke: #dc2626;
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.72;
}

.map-polyline.co {
  stroke-dasharray: none;
}

.map-polyline.et {
  stroke-dasharray: 8 6;
}

.map-marker.fibre-marker {
  width: 13px;
  height: 13px;
  border: 2px solid #ffffff;
  background: #16a34a;
  box-shadow: 0 0 0 2px rgba(22, 163, 74, 0.28), 0 8px 18px rgba(15, 23, 42, 0.22);
  cursor: pointer;
  z-index: 520;
}

.map-marker.fibre-marker.asset-pm,
.map-marker.fibre-marker.asset-pmu {
  width: 18px;
  height: 18px;
  border-radius: 0.35rem;
  background: #dc2626;
  box-shadow: 0 0 0 2px rgba(220, 38, 38, 0.28), 0 8px 18px rgba(15, 23, 42, 0.25);
}

.map-marker.fibre-marker.asset-bpe {
  background: #2563eb;
  box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.28), 0 8px 18px rgba(15, 23, 42, 0.22);
}

.map-marker.fibre-marker.asset-pbo {
  background: #16a34a;
}

.map-marker.fibre-marker.asset-bi {
  border-radius: 0.25rem;
  background: #9333ea;
  box-shadow: 0 0 0 2px rgba(147, 51, 234, 0.28), 0 8px 18px rgba(15, 23, 42, 0.22);
}

.map-marker.fibre-marker.unverified {
  outline: 2px dashed rgba(245, 158, 11, 0.9);
  outline-offset: 2px;
}

/* Mobile map gestures */
.custom-map {
  touch-action: none;
  overscroll-behavior: contain;
}

.fibre-card .layer-toggle + .layer-toggle {
  margin-top: 0.55rem;
}

.fibre-card .layer-toggle input:checked + span strong {
  color: #1d4ed8;
}

.nearest-fibre {
  margin: 0.85rem 0 0;
  padding: 0.85rem;
  border: 1px solid #dbe3ef;
  border-radius: 1rem;
  background: #f8fafc;
  font-size: 0.88rem;
  line-height: 1.45;
}

.nearest-fibre strong {
  display: block;
  margin-bottom: 0.25rem;
  color: #0f172a;
}

.nearest-fibre span {
  display: block;
  color: #475569;
}

.nearest-fibre dl {
  display: grid;
  grid-template-columns: 6.8rem 1fr;
  gap: 0.35rem 0.65rem;
  margin: 0.65rem 0 0;
}

.nearest-fibre dt {
  color: #64748b;
  font-weight: 800;
}

.nearest-fibre dd {
  margin: 0;
  color: #0f172a;
  word-break: break-word;
}

/* Compact LR badges on fibre markers: local_lr/downstream_lr */
.map-marker.fibre-marker {
  pointer-events: auto;
}

.map-marker.fibre-marker[data-lr]::after {
  content: attr(data-lr);
  position: absolute;
  left: 12px;
  top: -10px;
  min-width: 1.65rem;
  padding: 0.08rem 0.28rem;
  border: 1px solid rgba(15, 23, 42, 0.18);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.94);
  color: #0f172a;
  font-size: 0.66rem;
  font-weight: 900;
  line-height: 1.15;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.16);
  pointer-events: none;
}

.map-marker.fibre-marker:hover::after {
  content: attr(data-label);
  z-index: 999;
  font-size: 0.72rem;
}
