:root {
  --bg: #0b1220;
  --panel: #0f172a;
  --panel-2: #111827;
  --accent: #22d3ee;
  --accent-2: #f59e0b;
  --muted: #9ca3af;
  --text: #f8fafc;
  --border: #1f2937;
  --radius: 14px;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  font-family: "Space Grotesk", "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(circle at 20% 20%, rgba(34, 211, 238, 0.12), transparent 35%),
    radial-gradient(circle at 80% 0%, rgba(245, 158, 11, 0.12), transparent 35%),
    var(--bg);
  color: var(--text);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  width: 100vw;
  height: 100svh;
  overflow: hidden;
  background: var(--bg);
}

solar-app {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 100svh;
}

.app {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.map-full {
  position: relative;
  width: 100%;
  height: 100%;
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: #000;
}

#map {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
}

.overlay-stack {
  position: absolute;
  top: calc(16px + env(safe-area-inset-top, 0px));
  left: calc(16px + env(safe-area-inset-left, 0px));
  right: calc(16px + env(safe-area-inset-right, 0px));
  max-width: 560px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 600;
  pointer-events: none;
}

.overlay-stack > * {
  pointer-events: auto;
}

header {
  padding: 18px 20px;
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.1), rgba(255, 255, 255, 0.02));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
}

h1 {
  margin: 0 0 6px;
  font-size: 26px;
}

p {
  margin: 4px 0 0;
  color: var(--muted);
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.panel.info {
  max-height: 70vh;
  overflow-y: auto;
}

.status-toast {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 12px;
  background: rgba(15, 23, 42, 0.92);
  border: 1px solid var(--border);
  color: var(--muted);
  font-size: 14px;
  box-shadow: var(--shadow);
  width: fit-content;
}

.spinner-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: radial-gradient(circle at center, rgba(15, 23, 42, 0.35), rgba(15, 23, 42, 0.6));
  z-index: 900;
  pointer-events: none;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(34, 211, 238, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

.spinner-text {
  color: var(--text);
  font-weight: 600;
  letter-spacing: 0.02em;
}

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

.map-actions {
  position: absolute;
  bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  right: calc(12px + env(safe-area-inset-right, 0px));
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 700;
  pointer-events: none;
}

.roof-btn {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(15, 23, 42, 0.92);
  color: var(--text);
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  pointer-events: auto;
}

.roof-btn.ping {
  position: relative;
  animation: roof-ping 1.2s ease-out infinite;
}

.roof-btn.ping::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 14px;
  border: 2px solid rgba(34, 211, 238, 0.6);
  opacity: 0.75;
  animation: roof-pulse 1.2s ease-out infinite;
  pointer-events: none;
}

.roof-btn:hover {
  background: rgba(34, 211, 238, 0.14);
  color: var(--accent);
}

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

.hint {
  padding: 8px 10px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.9);
  color: var(--muted);
  border: 1px solid var(--border);
  font-size: 13px;
  box-shadow: var(--shadow);
  pointer-events: auto;
}

.status {
  font-size: 14px;
  color: var(--muted);
  margin-top: 8px;
}

.small-info {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.chip {
  background: rgba(34, 211, 238, 0.12);
  color: var(--accent);
  padding: 6px 10px;
  border-radius: 999px;
  border: 1px solid rgba(34, 211, 238, 0.25);
  font-size: 13px;
}

.card {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
}

.card h3 {
  margin: 0 0 4px;
}

.card p {
  margin: 2px 0;
}
.card img {
  display: block;
  width: 100%;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(245, 158, 11, 0.14);
  color: var(--accent-2);
  font-weight: 600;
}

.legend {
  display: none;
}

.leaflet-interactive.roof-polygon {
  cursor: pointer;
  filter: drop-shadow(0 0 6px rgba(239, 68, 68, 0.35));
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 16px;
  z-index: 1200;
}

.modal-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  max-width: 960px;
  width: 100%;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 16px 16px 0;
}

.modal-header h2 {
  margin: 6px 0 0;
  font-size: 22px;
}

.modal-body {
  padding: 0 16px 16px;
  overflow-y: auto;
  display: grid;
  gap: 12px;
}

.modal-body img {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.close {
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
}

.close:hover {
  background: rgba(34, 211, 238, 0.08);
  color: var(--accent);
}

.pill.small {
  padding: 4px 8px;
  font-size: 12px;
}

.leaflet-control-container .leaflet-control-attribution {
  display: none !important;
}

@media (max-width: 900px) {
  .overlay-stack {
    left: calc(12px + env(safe-area-inset-left, 0px));
    right: calc(12px + env(safe-area-inset-right, 0px));
    max-width: none;
    gap: 10px;
  }

  .panel.info {
    max-height: 55vh;
  }

  #map > div.leaflet-control-container > div.leaflet-top.leaflet-left > div {
    display: none;
  }

  .map-actions {
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    right: calc(10px + env(safe-area-inset-right, 0px));
  }

  .roof-btn {
    width: auto;
  }

  .legend {
    left: 10px;
    right: 10px;
    width: auto;
  }
}

@keyframes roof-ping {
  0% {
    transform: scale(1);
    box-shadow: 0 10px 30px rgba(34, 211, 238, 0.5);
  }
  40% {
    transform: scale(1.07);
    box-shadow: 0 16px 44px rgba(34, 211, 238, 0.7);
  }
  100% {
    transform: scale(1);
    box-shadow: 0 10px 30px rgba(34, 211, 238, 0.35);
  }
}

@keyframes roof-pulse {
  0% {
    transform: scale(0.95);
    opacity: 0.8;
  }
  60% {
    transform: scale(1.15);
    opacity: 0.2;
  }
  100% {
    transform: scale(1.2);
    opacity: 0;
  }
}
