@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=IBM+Plex+Mono:wght@300;400;500;600&display=swap');

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

:root {
  --bg:      #0c1017;
  --surface: rgba(14, 18, 28, 0.96);
  --border:  #1e2738;
  --accent:  #4fffb0;
  --accent-dim: rgba(79, 255, 176, 0.12);
  --muted:   #4e6178;
  --text:    #d0dae6;
  --dim:     #7d92a8;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --panel-width: 320px;
  --results-width: 300px;
  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'IBM Plex Mono', 'Fira Code', monospace;
}

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

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ─── HEADER ─── */
#header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 1001;
  flex-shrink: 0;
}

#header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent), 0 0 20px rgba(79,255,176,0.25);
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

#header h1 {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--accent);
}

#header-meta {
  font-size: 12px;
  font-family: var(--font-mono);
  letter-spacing: 0.1em;
  color: var(--muted);
  text-transform: uppercase;
}

/* ─── MAP ─── */
#map-wrap {
  position: relative;
  flex: 1;
  min-height: 0;
}

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

/* ─── LEFT PANEL (Controls) ─── */
#panel {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 1000;
  width: var(--panel-width);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 80px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4), 0 2px 8px rgba(0,0,0,0.2);
}

#panel-scroll {
  overflow-y: auto;
  flex: 1;
  padding: 4px;
}

#panel-scroll::-webkit-scrollbar { width: 5px; }
#panel-scroll::-webkit-scrollbar-track { background: transparent; }
#panel-scroll::-webkit-scrollbar-thumb {
  background: var(--muted);
  border-radius: 3px;
}

/* ─── RIGHT PANEL (Results) ─── */
#results-panel {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 1000;
  width: var(--results-width);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  backdrop-filter: blur(20px);
  display: none;              /* hidden until results arrive */
  flex-direction: column;
  max-height: calc(100vh - 80px);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4), 0 2px 8px rgba(0,0,0,0.2);
  animation: slideInRight 0.3s ease;
}

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

#results-panel.visible {
  display: flex;
}

#results-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

#results-close {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 20px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
  line-height: 1;
}

#results-close:hover {
  color: var(--text);
  background: rgba(255,255,255,0.06);
}

#results-panel-scroll {
  overflow-y: auto;
  flex: 1;
  padding: 4px;
}

#results-panel-scroll::-webkit-scrollbar { width: 5px; }
#results-panel-scroll::-webkit-scrollbar-track { background: transparent; }
#results-panel-scroll::-webkit-scrollbar-thumb {
  background: var(--muted);
  border-radius: 3px;
}

/* ─── SECTIONS ─── */
.psec {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.psec:first-child {
  border-radius: var(--radius-md) var(--radius-md) 0 0;
}

.psec:last-child {
  border-bottom: none;
  border-radius: 0 0 var(--radius-md) var(--radius-md);
}

.sec-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--dim);
  margin-bottom: 14px;
}

/* ─── SLIDER ─── */
.slider-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.slider-label {
  font-size: 13px;
  color: var(--text);
  font-family: var(--font-mono);
}

.slider-val {
  font-size: 16px;
  color: var(--accent);
  font-weight: 600;
  font-family: var(--font-mono);
}

input[type=range] {
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  height: 4px;
  background: var(--border);
  outline: none;
  cursor: pointer;
  border-radius: 2px;
}

input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(79,255,176,0.5), 0 2px 6px rgba(0,0,0,0.3);
  cursor: pointer;
  transition: transform 0.15s ease;
}

input[type=range]::-webkit-slider-thumb:hover {
  transform: scale(1.15);
}

input[type=range]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  box-shadow: 0 0 8px rgba(79,255,176,0.5), 0 2px 6px rgba(0,0,0,0.3);
  cursor: pointer;
}

/* ─── RINGS ─── */
#rings-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.ring-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.02);
  transition: background 0.15s ease;
}

.ring-row:hover {
  background: rgba(255,255,255,0.04);
}

.ring-toggle {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.15s;
}

.ring-toggle:hover { transform: scale(1.1); }
.ring-toggle.off { opacity: .25; }

.ring-min-input {
  flex: 1;
  background: transparent;
  border: none;
  border-bottom: 1.5px solid var(--border);
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--text);
  padding: 4px 6px;
  outline: none;
  width: 0;
  transition: border-color 0.2s ease;
}

.ring-min-input:focus {
  border-bottom-color: var(--accent);
}

.ring-unit {
  font-size: 12px;
  color: var(--dim);
  flex-shrink: 0;
  font-family: var(--font-mono);
}

.ring-color-input {
  width: 26px;
  height: 20px;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  padding: 0;
  background: none;
  flex-shrink: 0;
}

.ring-del {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
  padding: 2px 4px;
  flex-shrink: 0;
  transition: color 0.15s, transform 0.15s;
  border-radius: 4px;
}

.ring-del:hover {
  color: #ff5c6e;
  transform: scale(1.1);
}

.btn-add-ring {
  width: 100%;
  padding: 10px 12px;
  background: transparent;
  border: 1.5px dashed var(--muted);
  border-radius: var(--radius-sm);
  color: var(--dim);
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.btn-add-ring:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* ─── UPLOAD ─── */
#drop-zone {
  border: 1.5px dashed var(--muted);
  border-radius: var(--radius-md);
  padding: 18px 14px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  position: relative;
}

#drop-zone:hover,
#drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

#drop-zone input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

#drop-zone-label {
  font-size: 12px;
  letter-spacing: 0.06em;
  color: var(--dim);
  line-height: 1.7;
}

#drop-zone-label strong {
  display: block;
  font-size: 13px;
  color: var(--text);
  margin-bottom: 4px;
  font-weight: 600;
}

#origin-info {
  margin-top: 10px;
  font-size: 12px;
  color: var(--dim);
  line-height: 1.5;
}

.origin-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--accent-dim);
  border: 1px solid rgba(79,255,176,0.2);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  margin-top: 6px;
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
}

.origin-badge button {
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  padding: 0 2px;
  transition: color 0.15s;
}

.origin-badge button:hover { color: #ff5c6e; }

/* ─── STATUS ─── */
#status {
  font-size: 13px;
  letter-spacing: 0.02em;
  color: var(--dim);
  line-height: 1.7;
  min-height: 36px;
}

#status.ok   { color: var(--accent); }
#status.busy { color: #f5c842; }
#status.err  { color: #ff5c6e; }

.spin {
  display: inline-block;
  width: 12px;
  height: 12px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: rot 0.65s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

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

/* ─── BUTTONS ─── */
.action-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.btn {
  flex: 1;
  padding: 10px 8px;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--dim);
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

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

.btn.primary:hover:not(:disabled) {
  background: var(--accent);
  color: var(--bg);
  box-shadow: 0 0 16px rgba(79,255,176,0.3);
}

/* ─── HINT ─── */
#hint {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1000;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 22px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  pointer-events: none;
  transition: opacity 0.4s;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

#hint.hidden { opacity: 0; }

/* ─── LEAFLET OVERRIDES ─── */
.leaflet-control-zoom a {
  background: var(--surface) !important;
  border-color: var(--border) !important;
  color: var(--text) !important;
  font-family: var(--font-body) !important;
  font-size: 16px !important;
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
}

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

.leaflet-control-attribution {
  background: rgba(14,18,28,0.8) !important;
  color: var(--muted) !important;
  font-size: 10px !important;
  border-radius: var(--radius-sm) !important;
}

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

/* ─── ANALYSIS RESULTS ─── */
.analysis-results {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 12px;
}

.result-ring {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

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

.ring-title {
  font-size: 12px;
  font-weight: 600;
  padding-left: 10px;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stats-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-row {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 22px;
}

.stat-label {
  width: 76px;
  font-size: 11px;
  color: var(--dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stat-bar-wrap {
  flex: 1;
  height: 6px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.stat-bar {
  height: 100%;
  border-radius: 3px;
  transition: width 0.3s ease;
}

.stat-val {
  width: 26px;
  font-size: 12px;
  font-family: var(--font-mono);
  color: var(--accent);
  text-align: right;
  font-weight: 600;
}

/* ─── AMENITY ICONS (SVG-based, themed) ─── */
.amenity-icon {
  background: none !important;
  border: none !important;
}

.amenity-marker {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid;
  backdrop-filter: blur(4px);
  transition: transform 0.15s ease;
}

.amenity-marker:hover {
  transform: scale(1.2);
}

.amenity-marker svg {
  width: 12px;
  height: 12px;
}

.amenity-marker.cat-education {
  background: rgba(96, 165, 250, 0.2);
  border-color: rgba(96, 165, 250, 0.6);
  color: #60a5fa;
}

.amenity-marker.cat-health {
  background: rgba(248, 113, 113, 0.2);
  border-color: rgba(248, 113, 113, 0.6);
  color: #f87171;
}

.amenity-marker.cat-public {
  background: rgba(167, 139, 250, 0.2);
  border-color: rgba(167, 139, 250, 0.6);
  color: #a78bfa;
}

.amenity-marker.cat-groceries {
  background: rgba(251, 146, 60, 0.2);
  border-color: rgba(251, 146, 60, 0.6);
  color: #fb923c;
}

.amenity-marker.cat-parks {
  background: rgba(79, 255, 176, 0.2);
  border-color: rgba(79, 255, 176, 0.6);
  color: #4fffb0;
}

/* ─── CUSTOM POPUP ─── */
.leaflet-popup-content-wrapper {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-sm) !important;
  color: var(--text) !important;
  font-family: var(--font-body) !important;
  font-size: 12px !important;
  box-shadow: 0 4px 16px rgba(0,0,0,0.4) !important;
}

.leaflet-popup-tip {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
}

.leaflet-popup-content {
  margin: 10px 14px !important;
  line-height: 1.5 !important;
}

.leaflet-popup-content strong {
  color: var(--accent);
  font-weight: 600;
}

.leaflet-popup-close-button {
  color: var(--muted) !important;
  font-size: 18px !important;
  padding: 4px 8px 0 0 !important;
}

.leaflet-popup-close-button:hover {
  color: var(--text) !important;
}

/* ─── RESPONSIVE: Tablets ─── */
@media (max-width: 900px) {
  :root {
    --panel-width: 280px;
    --results-width: 260px;
  }

  #header h1 { font-size: 12px; }
  #header-meta { font-size: 10px; }
}

/* ─── RESPONSIVE: Mobile ─── */
@media (max-width: 600px) {
  :root {
    --panel-width: calc(100vw - 32px);
    --results-width: calc(100vw - 32px);
  }

  #panel {
    top: auto;
    bottom: 16px;
    left: 16px;
    right: 16px;
    max-height: 40vh;
  }

  #results-panel {
    top: 16px;
    left: 16px;
    right: 16px;
    max-height: 40vh;
  }

  #hint { display: none; }

  #header h1 { font-size: 11px; letter-spacing: 0.12em; }
  #header-meta { display: none; }

  .psec { padding: 14px 16px; }
  .sec-label { font-size: 10px; }
}
