/* =============================================
   styles.css — all visual styles for Transparency Map
   HOW TO RUN: npx serve . then open http://localhost:3000
============================================= */

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

:root {
  --bg:      #0d0d14;
  --panel:   #13131f;
  --border:  rgba(255,255,255,0.07);
  --accent:  #4361ee;
  --accent2: #7b92ff;
  --text:    #e8e8f0;
  --muted:   #6b6b88;
  --danger:  #ff4d6d;
  --font:    'DM Sans', sans-serif;
  --mono:    'DM Mono', monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overflow: hidden;
}

/* ── TOP BAR ─────────────────────────────── */
#topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 1000;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  background: rgba(13,13,20,0.85);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
}

#logo {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

#logo .dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  animation: pulse 2.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.8); }
}

#logo span { font-size: 15px; font-weight: 600; letter-spacing: 0.04em; }
#logo em   { font-style: normal; color: var(--accent2); }

/* ── SEARCH ──────────────────────────────── */
#search-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  max-width: 420px;
  margin: 0 32px;
}

#search-input {
  flex: 1;
  height: 38px;
  padding: 0 14px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  outline: none;
  transition: border-color 0.2s, background 0.2s;
}

#search-input::placeholder { color: var(--muted); text-transform: none; letter-spacing: 0; }
#search-input:focus { border-color: var(--accent); background: rgba(67,97,238,0.08); }

#search-btn {
  height: 38px;
  padding: 0 18px;
  background: var(--accent);
  border: none;
  border-radius: 8px;
  color: #fff;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  white-space: nowrap;
}

#search-btn:hover    { background: var(--accent2); }
#search-btn:active   { transform: scale(0.97); }
#search-btn:disabled { background: var(--muted); cursor: not-allowed; }

/* ── MAP ─────────────────────────────────── */
#map {
  position: fixed;
  top: 64px; left: 0; right: 0; bottom: 0;
}

/* ── WELCOME OVERLAY ─────────────────────── */
#welcome {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 500;
  text-align: center;
  pointer-events: none;
  animation: fadeIn 0.8s ease both;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translate(-50%, -48%); }
  to   { opacity: 1; transform: translate(-50%, -50%); }
}

#welcome .icon { font-size: 48px; margin-bottom: 16px; display: block; filter: drop-shadow(0 0 20px rgba(67,97,238,0.6)); }
#welcome h1    { font-size: 22px; font-weight: 600; margin-bottom: 10px; }
#welcome p     { font-size: 14px; color: var(--muted); max-width: 300px; line-height: 1.6; }
#welcome .hint {
  display: inline-block;
  margin-top: 18px;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 12px;
  font-family: var(--mono);
  color: var(--accent2);
  letter-spacing: 0.06em;
}

/* ── SPINNER ─────────────────────────────── */
#spinner {
  display: none;
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 600;
  text-align: center;
}

#spinner.active { display: block; }

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

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

@keyframes floodPulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(1.3); }
}
#spinner p { font-size: 13px; color: var(--text); font-family: var(--mono); }

/* ── ERROR TOAST ─────────────────────────── */
#error-toast {
  display: none;
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 2000;
  background: #1e0a10;
  border: 1px solid var(--danger);
  border-radius: 10px;
  padding: 12px 20px;
  font-size: 13px;
  color: var(--danger);
  font-family: var(--mono);
  box-shadow: 0 8px 32px rgba(255,77,109,0.2);
  white-space: nowrap;
}

#error-toast.active {
  display: block;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(10px); }
  to   { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ── PANELS (shared styles) ──────────────── */
.panel {
  position: fixed;
  z-index: 1000;
  background: rgba(19,19,31,0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
}

.panel-title {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 12px;
}

/* ── LAYER PANEL ─────────────────────────── */
#layer-panel {
  display: none;
  top: 80px;
  left: 16px;
  min-width: 220px;
}

#layer-panel.active {
  display: block;
  animation: panelIn 0.4s ease;
}

/* Make layer-panel use shared panel styles */
#layer-panel { position: fixed; z-index: 1000; background: rgba(19,19,31,0.92); backdrop-filter: blur(12px); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; }

@keyframes panelIn {
  from { opacity: 0; transform: translateY(-8px); }
  to   { opacity: 1; transform: translateY(0); }
}

.layer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.layer-row:last-child { border-bottom: none; }

.layer-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.layer-count {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--muted);
  background: rgba(255,255,255,0.06);
  padding: 2px 8px;
  border-radius: 10px;
  min-width: 28px;
  text-align: center;
}

/* Toggle switch */
.toggle { position: relative; width: 36px; height: 20px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,0.1);
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ── LEGEND ──────────────────────────────── */
#legend {
  display: none;
  position: fixed;
  bottom: 28px;
  left: 16px;
  z-index: 1000;
  background: rgba(19,19,31,0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  min-width: 200px;
}

#legend.active { display: block; animation: panelIn 0.4s ease; }

.legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text);
  margin-bottom: 6px;
}

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

.legend-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,0.4);
}

.legend-diamond {
  width: 10px; height: 10px;
  flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,0.4);
  transform: rotate(45deg);
}

.legend-square {
  width: 10px; height: 10px;
  border-radius: 2px;
  flex-shrink: 0;
  border: 1.5px solid rgba(255,255,255,0.4);
}

/* ── SUMMARY CARD ────────────────────────── */
#summary-card {
  display: none;
  position: fixed;
  top: 80px;
  right: 16px;
  z-index: 1000;
  background: rgba(19,19,31,0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 18px;
  min-width: 240px;
  max-width: 280px;
}

#summary-card.active {
  display: block;
  animation: panelIn 0.5s ease;
}

.summary-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.summary-label {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.summary-postcode {
  font-size: 18px;
  font-weight: 600;
  font-family: var(--mono);
  color: var(--accent2);
  letter-spacing: 0.06em;
}

.summary-overall {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
  margin-top: 4px;
}

.summary-overall.good   { background: rgba(61,220,151,0.15);  color: #3ddc97; }
.summary-overall.medium { background: rgba(244,162,97,0.15);  color: #f4a261; }
.summary-overall.bad    { background: rgba(255,77,109,0.15);  color: #ff4d6d; }

.summary-rows { display: flex; flex-direction: column; gap: 8px; }

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.summary-row-left {
  display: flex;
  align-items: center;
  gap: 7px;
}

.summary-emoji    { font-size: 14px; }
.summary-row-name { font-size: 13px; color: var(--text); }

.summary-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 600;
  padding: 3px 9px;
  border-radius: 20px;
}

.summary-pill.good    { background: rgba(61,220,151,0.15);  color: #3ddc97; }
.summary-pill.medium  { background: rgba(244,162,97,0.15);  color: #f4a261; }
.summary-pill.bad     { background: rgba(255,77,109,0.15);  color: #ff4d6d; }
.summary-pill.neutral { background: rgba(107,107,136,0.15); color: #9b9bbb; }

.summary-count {
  font-weight: 400;
  opacity: 0.7;
  font-family: var(--mono);
}

.summary-footer {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 10px;
  color: var(--muted);
  font-family: var(--mono);
  text-align: center;
}

/* ── LOCATION CARD ───────────────────────── */
#location-card {
  display: none;
  position: fixed;
  bottom: 28px;
  right: 24px;
  z-index: 1000;
  background: rgba(19,19,31,0.92);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 20px;
  min-width: 220px;
}

#location-card.active { display: block; animation: panelIn 0.4s ease; }

#location-card .label {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

#location-card .postcode-display {
  font-size: 22px;
  font-weight: 600;
  font-family: var(--mono);
  color: var(--accent2);
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

#location-card .coords { font-size: 11px; font-family: var(--mono); color: var(--muted); }

/* ── POPUP STYLES ────────────────────────── */
.leaflet-popup-content-wrapper {
  background: var(--panel) !important;
  border: 1px solid var(--border) !important;
  border-radius: 10px !important;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5) !important;
  color: var(--text) !important;
  font-family: var(--font) !important;
}

.leaflet-popup-tip          { background: var(--panel) !important; }
.leaflet-popup-close-button { color: var(--muted) !important; }

.popup-name    { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.popup-type    { font-size: 11px; color: var(--muted); margin-bottom: 8px; text-transform: uppercase; letter-spacing: 0.08em; font-family: var(--mono); }
.popup-address { font-size: 11px; color: var(--muted); line-height: 1.5; font-family: var(--mono); margin-top: 8px; }

.popup-rating {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}

.popup-rating.green  { background: rgba(61,220,151,0.15);  color: #3ddc97; }
.popup-rating.yellow { background: rgba(168,224,99,0.15);  color: #a8e063; }
.popup-rating.orange { background: rgba(244,162,97,0.15);  color: #f4a261; }
.popup-rating.red    { background: rgba(255,77,109,0.15);  color: #ff4d6d; }
.popup-rating.grey   { background: rgba(107,107,136,0.15); color: #9b9bbb; }

/* ── LEAFLET OVERRIDES ───────────────────── */
.leaflet-container { background: var(--bg) !important; }

.leaflet-control-zoom {
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  overflow: hidden;
}

.leaflet-control-zoom a {
  background: var(--panel) !important;
  color: var(--text) !important;
  border-color: var(--border) !important;
}

.leaflet-control-zoom a:hover { background: var(--bg) !important; }

.leaflet-control-attribution {
  background: rgba(13,13,20,0.7) !important;
  color: var(--muted) !important;
  font-size: 10px !important;
}

.leaflet-control-attribution a { color: var(--muted) !important; }

/* ── RESPONSIVE ──────────────────────────── */
@media (max-width: 600px) {
  #search-wrap { max-width: none; margin: 0 12px; }
  #logo span   { display: none; }
  #topbar      { padding: 0 12px; gap: 8px; }
  #layer-panel { min-width: unset; }
  #legend      { display: none !important; }
}

/* ── LEGEND CHIPS (category filter toggles) ── */
.legend-section-title {
  font-size: 10px;
  font-family: var(--mono);
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 8px;
}

.legend-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text);
  padding: 5px 8px;
  margin-bottom: 3px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s, opacity 0.15s;
  border: 1px solid transparent;
}

.legend-chip:hover {
  background: rgba(255,255,255,0.06);
  border-color: var(--border);
}

.legend-chip.inactive {
  opacity: 0.35;
}

.legend-chip.inactive:hover {
  opacity: 0.55;
}

/* ── CRIME RANGE CONTROL ─────────────────── */
.crime-range-row {
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 0 8px;
  border-bottom: 1px solid var(--border);
}

/* Show once the layer panel is active (i.e. after first search) */
#layer-panel.active .crime-range-row {
  display: flex;
}

.crime-range-label {
  font-size: 11px;
  font-family: var(--mono);
  color: var(--muted);
  letter-spacing: 0.08em;
  flex-shrink: 0;
}

.crime-range-seg {
  display: flex;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.crime-range-btn {
  flex: 1;
  padding: 4px 8px;
  background: transparent;
  border: none;
  border-right: 1px solid var(--border);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 11px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}

.crime-range-btn:last-child {
  border-right: none;
}

.crime-range-btn:hover {
  background: rgba(255,255,255,0.07);
  color: var(--text);
}

.crime-range-btn.active {
  background: var(--accent);
  color: #fff;
}

.crime-range-btn:disabled {
  cursor: wait;
  opacity: 0.5;
}

/* ── LEGEND PENTAGON (schools) ───────────── */
.legend-pentagon {
  width: 12px;
  height: 11px;
  flex-shrink: 0;
}

/* ── MOBILE LAYOUT (max-width: 600px) ───────── */
@media (max-width: 600px) {

  /* Layer panel — full width, pinned below topbar */
  #layer-panel {
    top: 72px !important;
    left: 8px !important;
    right: 8px !important;
    min-width: unset !important;
    padding: 10px 12px !important;
  }

  /* Layers in a 2x2 grid */
  #layer-panel .layer-row {
    padding: 5px 0;
  }

  .layer-rows-grid {
    display: block;
  }

  /* Crime range row full width below grid */
  .crime-range-row {
    grid-column: 1 / -1;
  }

  /* Hide desktop summary card and location card */
  #summary-card  { display: none !important; }
  #location-card { display: none !important; }

  /* Mobile bottom bar */
  #mobile-bar {
    display: flex !important;
  }

  /* Legend stays hidden on mobile */
  #legend { display: none !important; }
}

/* ── MOBILE BOTTOM BAR ───────────────────────── */
#mobile-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: rgba(19,19,31,0.97);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 10px 14px 14px;
  flex-direction: column;
  gap: 8px;
}

.mobile-bar-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.mobile-bar-postcode {
  font-size: 18px;
  font-weight: 600;
  font-family: var(--mono);
  color: var(--accent2);
  letter-spacing: 0.06em;
}

.mobile-bar-verdict {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  white-space: nowrap;
}

.mobile-bar-verdict.good   { background: rgba(61,220,151,0.15);  color: #3ddc97; }
.mobile-bar-verdict.medium { background: rgba(244,162,97,0.15);  color: #f4a261; }
.mobile-bar-verdict.bad    { background: rgba(255,77,109,0.15);  color: #ff4d6d; }

.mobile-bar-scores {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 12px;
}

.mobile-bar-score {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11px;
  font-family: var(--mono);
}

.mobile-bar-score-label { color: var(--muted); }

.mobile-bar-score-pill {
  font-size: 10px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 10px;
}

.mobile-bar-score-pill.good    { background: rgba(61,220,151,0.15);  color: #3ddc97; }
.mobile-bar-score-pill.medium  { background: rgba(244,162,97,0.15);  color: #f4a261; }
.mobile-bar-score-pill.bad     { background: rgba(255,77,109,0.15);  color: #ff4d6d; }
.mobile-bar-score-pill.neutral { background: rgba(107,107,136,0.15); color: #9b9bbb; }

/* Push map content up on mobile so markers aren't hidden by bottom bar */
@media (max-width: 600px) {
  #map { bottom: 110px; }
}

/* ── PRICE MARKERS ───────────────────────── */
.price-marker {
  background: transparent !important;
  border: none !important;
}

/* ── COLLAPSIBLE LAYER PANEL ─────────────── */
.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
  user-select: none;
  margin-bottom: 0;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.panel-header:hover { opacity: 0.85; }

.panel-chevron {
  font-size: 14px;
  color: var(--muted);
  transition: transform 0.2s;
  line-height: 1;
}

.panel-chevron.collapsed { transform: rotate(-90deg); }

.layer-panel-body {
  overflow: hidden;
  transition: max-height 0.25s ease, opacity 0.2s ease;
  max-height: 600px;
  opacity: 1;
  margin-top: 10px;
}

.layer-panel-body.collapsed {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
}

/* On mobile the panel header already spans full width */
@media (max-width: 600px) {
  .panel-header { padding-bottom: 8px; }
}

/* Legend panel header sits flush with panel padding — no extra margin needed */
#legend .panel-header { margin-bottom: 0; }
#legend .layer-panel-body { margin-top: 8px; }

/* ── LEGEND SCROLLABLE BODY ──────────────── */
/* max-height keeps legend from growing up into the layer panel above.
   Layer panel starts at top:80px and is typically 180-220px tall,
   so we leave at least 320px of clearance from the top of the viewport. */
#legend .layer-panel-body {
  max-height: calc(100vh - 420px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

#legend .layer-panel-body::-webkit-scrollbar {
  width: 4px;
}

#legend .layer-panel-body::-webkit-scrollbar-track {
  background: transparent;
}

#legend .layer-panel-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}


/* ── LAYER PANEL ABOVE LEGEND ────────────── */
/* Layer panel gets higher z-index so it always renders on top if
   the legend somehow grows tall enough to reach it */
#layer-panel { z-index: 1001 !important; }

/* On desktop, cap legend so it never overlaps the layer panel.
   Layer panel is typically 200-260px tall from top:80px = ends ~340px from top.
   Legend bottom:28px, so max total legend height = viewport - 340px - 28px */
@media (min-width: 601px) {
  #legend {
    max-height: calc(100vh - 380px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  #legend.active { display: flex; }
  #legend .layer-panel-body {
    flex: 1;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
  }
}
