*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #242836;
  --border: #2e3345;
  --text: #e8eaed;
  --text-muted: #9aa0b0;
  --accent: #6c63ff;
  --accent-dim: rgba(108, 99, 255, 0.15);
  --danger: #ff6b6b;
  --warning: #ffa94d;
  --success: #51cf66;
  --info: #339af0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

/* --- Header --- */
header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.02em;
}

.logo span { color: var(--accent); }

.tagline {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: none;
}

@media (min-width: 640px) {
  .tagline { display: block; }
}

.back-link {
  font-size: 0.78rem;
  color: var(--text-muted);
  text-decoration: none;
  transition: color 0.2s;
}

.back-link:hover { color: var(--accent); }

/* --- Search bar --- */
#search-bar {
  position: fixed;
  top: 48px;
  left: 0;
  right: 0;
  z-index: 190;
  padding: 0.5rem 1rem;
  background: rgba(15, 17, 23, 0.92);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.search-wrap {
  max-width: 600px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0 0.75rem;
  transition: border-color 0.2s;
}

.search-wrap:focus-within {
  border-color: var(--accent);
}

.search-icon { flex-shrink: 0; }

#address-input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text);
  font-size: 0.9rem;
  padding: 0.6rem 0.75rem;
  outline: none;
}

#address-input::placeholder { color: var(--text-muted); }

#search-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 0.4rem 1rem;
  font-size: 0.82rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

#search-btn:hover { background: #7b73ff; }

.search-results {
  max-width: 600px;
  margin: 0.35rem auto 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.search-results.hidden { display: none; }

.search-result-item {
  padding: 0.6rem 0.85rem;
  font-size: 0.85rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.search-result-item:last-child { border-bottom: none; }

.search-result-item:hover { background: var(--surface-2); }

.search-result-item .match-addr {
  color: var(--text);
}

.search-result-item .match-city {
  color: var(--text-muted);
  font-size: 0.78rem;
}

/* --- Main layout --- */
#app {
  position: fixed;
  top: 96px; /* header + search */
  left: 0;
  right: 0;
  bottom: 0;
}

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

/* --- Panel --- */
.panel {
  position: absolute;
  top: 0;
  right: 0;
  width: 380px;
  max-width: 100%;
  height: 100%;
  background: var(--bg);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  z-index: 100;
  transition: transform 0.25s ease;
}

.panel.hidden {
  transform: translateX(100%);
}

.panel-close {
  position: absolute;
  top: 0.5rem;
  right: 0.75rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 10;
  line-height: 1;
  padding: 0.25rem;
}

.panel-close:hover { color: var(--text); }

.panel-address {
  padding: 1.25rem 1.25rem 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text);
  padding-right: 2.5rem;
}

/* --- Summary cards --- */
.panel-summary {
  padding: 0 1.25rem;
}

.panel-summary.hidden { display: none; }

.summary-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 0.6rem;
}

.summary-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.85rem;
  text-align: center;
}

.summary-label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}

.summary-value {
  font-size: 1.25rem;
  font-weight: 700;
}

/* Risk coloring */
.risk-high { color: var(--danger); }
.risk-medium { color: var(--warning); }
.risk-low { color: var(--success); }
.risk-info { color: var(--info); }

/* --- Detail sections --- */
.panel-details { padding: 0.5rem 1.25rem 2rem; }
.panel-details.hidden { display: none; }

.detail-section {
  margin-bottom: 1.5rem;
}

.detail-section h3 {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem;
}

.detail-item {
  background: var(--surface);
  border-radius: 6px;
  padding: 0.65rem 0.75rem;
}

.detail-item.full-width {
  grid-column: 1 / -1;
}

.detail-item .d-label {
  font-size: 0.68rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.detail-item .d-value {
  font-size: 0.92rem;
  font-weight: 500;
  margin-top: 0.15rem;
}

/* Broadband table */
.broadband-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}

.broadband-table th {
  text-align: left;
  padding: 0.5rem 0.6rem;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-weight: 500;
}

.broadband-table td {
  padding: 0.45rem 0.6rem;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

.broadband-table tr:last-child td { border-bottom: none; }

/* --- Loading --- */
.panel-loading {
  padding: 3rem 1.25rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.panel-loading.hidden { display: none; }

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 0.75rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* --- Layer controls --- */
.layer-controls {
  position: absolute;
  top: 0.75rem;
  left: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  z-index: 50;
}

.layer-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
}

.layer-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}

.layer-btn.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* --- Legend --- */
.legend {
  position: absolute;
  bottom: 2rem;
  left: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  z-index: 50;
  min-width: 140px;
}

.legend.hidden { display: none; }

.legend-title {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.3rem;
  font-size: 0.78rem;
  color: var(--text);
}

.legend-item:last-child { margin-bottom: 0; }

.legend-swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* --- Footer --- */
footer {
  display: none; /* hidden when map is fullscreen */
}

/* --- Mobile adjustments --- */
@media (max-width: 640px) {
  .panel {
    width: 100%;
    top: auto;
    bottom: 0;
    height: 55%;
    border-left: none;
    border-top: 1px solid var(--border);
    border-radius: 16px 16px 0 0;
  }

  .panel.hidden {
    transform: translateY(100%);
  }

  .layer-controls {
    top: 0.5rem;
    left: 0.5rem;
  }

  .legend {
    bottom: 1rem;
    left: 0.5rem;
  }
}

/* --- Map marker --- */
.map-marker {
  width: 24px;
  height: 24px;
  background: var(--accent);
  border: 3px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}
