:root {
  --bg: #110a0c;
  --surface: #1c1215;
  --surface2: #291a1e;
  --border: #3a2228;
  --text: #f0e4e6;
  --text-muted: #a88b90;
  --accent: #8b2232;
  --accent-dim: #6b1a28;
  --green: #4ade80;
  --orange: #fb923c;
  --red: #f87171;
  --glass: rgba(28, 18, 21, 0.90);
  --glass-border: rgba(58, 34, 40, 0.7);
  --panel-radius: 16px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
}

/* Full-screen map */
#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

/* ─── Search Bar (inside left panel) ─── */
#search-bar {
  position: relative;
  z-index: 20;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid var(--glass-border);
  border-radius: var(--panel-radius) var(--panel-radius) 0 0;
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 8px;
}

.search-icon {
  color: var(--text-muted);
  flex-shrink: 0;
}

#search-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 14px;
  padding: 12px 0;
  outline: none;
}

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

#search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  margin-top: 0;
  background: var(--surface);
  border: 1px solid var(--glass-border);
  border-top: none;
  border-radius: 0 0 12px 12px;
  overflow: hidden;
  max-height: 300px;
  overflow-y: auto;
  z-index: 30;
}

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

.search-result {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.search-result:last-child { border-bottom: none; }
.search-result:hover { background: rgba(139, 34, 50, 0.15); }

.search-result-name { font-weight: 600; color: var(--text); }
.search-result-detail { color: var(--text-muted); font-size: 12px; margin-top: 2px; }

/* ─── Layer Selector ─── */
#layer-selector {
  position: absolute;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  display: flex;
  flex-direction: row;
  gap: 4px;
  background: var(--glass);
  backdrop-filter: blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: 12px;
  padding: 6px;
}

.layer-btn {
  width: 48px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 6px 4px 4px;
  transition: all 0.2s;
}

.layer-label {
  font-size: 9px;
  line-height: 1;
  letter-spacing: 0.02em;
}

.layer-btn:hover { color: var(--text); background: rgba(255,255,255,0.06); }
.layer-btn.active { color: var(--accent); background: rgba(139, 34, 50, 0.18); }

/* ─── Weather Panel (left floating card, always visible) ─── */
#weather-panel {
  position: absolute;
  top: 16px;
  left: 16px;
  bottom: 16px;
  width: 340px;
  z-index: 25;
  background: var(--glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--panel-radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* weather-close button removed — panel is always visible */

#weather-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
}

/* Weather panel content */
.wp-location { font-size: 18px; font-weight: 700; margin-bottom: 2px; }
.wp-coords { font-size: 12px; color: var(--text-muted); margin-bottom: 16px; }

.wp-hero {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.wp-temp {
  font-size: 48px;
  font-weight: 700;
  letter-spacing: -2px;
  line-height: 1;
}

.wp-conditions { font-size: 14px; color: var(--text-muted); }
.wp-highlow { font-size: 13px; color: var(--text-muted); margin-top: 2px; }

.wp-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.wp-grid-item {
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  padding: 10px 12px;
}

.wp-grid-label {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.wp-grid-value {
  font-size: 15px;
  font-weight: 600;
}

/* AQI badge */
.wp-aqi {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 16px;
}

.wp-aqi-number {
  font-size: 20px;
  font-weight: 700;
}

/* Precipitation graph */
.wp-precip-graph {
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 16px;
}
.wp-precip-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.wp-precip-dry {
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
  padding: 6px 0;
}
.wp-precip-peak {
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
  margin-bottom: 2px;
}
.wp-precip-bars {
  display: flex;
  align-items: flex-end;
  gap: 3px;
  height: 48px;
}
.wp-precip-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
}
.wp-precip-bar-label {
  font-size: 9px;
  color: var(--text-muted);
  margin-bottom: 2px;
  line-height: 1;
}
.wp-precip-bar {
  width: 100%;
  border-radius: 3px 3px 1px 1px;
  min-width: 0;
}
.wp-precip-axis {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Nowcast */
.wp-nowcast {
  font-size: 13px;
  padding: 8px 12px;
  background: rgba(139, 34, 50, 0.12);
  border-radius: 10px;
  margin-bottom: 16px;
  color: var(--accent);
}

/* Forecast strip */
.wp-forecast-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.wp-forecast {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.wp-forecast::-webkit-scrollbar { height: 4px; }
.wp-forecast::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.wp-day {
  flex-shrink: 0;
  width: 72px;
  background: rgba(255,255,255,0.04);
  border-radius: 10px;
  padding: 10px 6px;
  text-align: center;
  font-size: 12px;
}

.wp-day-name { font-weight: 600; margin-bottom: 4px; }
.wp-day-icon { font-size: 20px; margin-bottom: 4px; }
.wp-day-temps { font-weight: 600; }
.wp-day-temps span { color: var(--text-muted); font-weight: 400; }
.wp-day-precip { color: var(--text-muted); font-size: 11px; margin-top: 2px; }

/* Chat toggle hidden — drawer always visible */
#chat-toggle { display: none; }

/* ─── Chat Drawer (right floating card, always visible) ─── */
#chat-drawer {
  position: absolute;
  top: 16px;
  right: 16px;
  bottom: 16px;
  width: 380px;
  z-index: 30;
  background: var(--glass);
  backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--panel-radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 15px;
  flex-shrink: 0;
  border-radius: var(--panel-radius) var(--panel-radius) 0 0;
}


#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#chat-form {
  padding: 12px 16px;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
}

.input-wrap {
  display: flex;
  gap: 8px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}

#chat-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 14px;
  padding: 8px 10px;
  outline: none;
}

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

#send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

#send-btn:hover { background: var(--accent-dim); }
#send-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* Message bubbles */
.message {
  max-width: 100%;
  line-height: 1.6;
  font-size: 13px;
}

.message.user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  padding: 8px 14px;
  border-radius: 14px 14px 4px 14px;
  max-width: 85%;
}

.message.bot {
  align-self: flex-start;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--border);
  padding: 12px 14px;
  border-radius: 4px 14px 14px 14px;
}

.message.bot p { margin-bottom: 6px; }
.message.bot p:last-child { margin-bottom: 0; }
.message.bot strong { color: var(--accent); }
.message.bot h3 { font-size: 14px; margin: 10px 0 4px; }
.message.bot h3:first-child { margin-top: 0; }
.message.bot ul, .message.bot ol { padding-left: 18px; margin-bottom: 6px; }
.message.bot li { margin-bottom: 3px; }
.message.bot code {
  background: var(--surface2);
  padding: 2px 5px;
  border-radius: 4px;
  font-size: 12px;
}
.message.bot hr {
  border: none;
  border-top: 1px solid var(--border);
  margin: 10px 0;
}
.message.bot table {
  border-collapse: collapse;
  margin: 6px 0;
  width: 100%;
}
.message.bot th, .message.bot td {
  border: 1px solid var(--border);
  padding: 4px 8px;
  text-align: left;
  font-size: 12px;
}
.message.bot th {
  background: var(--surface2);
  font-weight: 600;
}

/* Loading dots */
.message.bot.loading {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px 16px;
}

.loading-status {
  margin-left: 8px;
  font-size: 11px;
  color: var(--text-muted);
}

.dot {
  width: 5px;
  height: 5px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: bounce 1.4s infinite ease-in-out;
}

.dot:nth-child(2) { animation-delay: 0.2s; }
.dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ─── Map Legend ─── */
#map-legend {
  position: absolute;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  display: flex;
  gap: 8px;
  pointer-events: none;
  max-width: 90vw;
}

#map-legend.hidden { display: none; }

.legend-item {
  background: var(--glass);
  backdrop-filter: blur(8px);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  padding: 8px 12px;
  pointer-events: auto;
  min-width: 200px;
}

.legend-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text);
  margin-bottom: 6px;
}

.legend-unit {
  font-weight: 400;
  color: var(--text-muted);
  text-transform: none;
}

.legend-bar {
  height: 10px;
  border-radius: 4px;
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.legend-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 3px;
}

/* ─── Attribution ─── */
#attribution {
  position: absolute;
  bottom: 6px;
  left: 8px;
  z-index: 10;
  font-size: 10px;
  color: var(--text-muted);
  opacity: 0.6;
}

#attribution a {
  color: var(--text-muted);
  text-decoration: none;
}

#attribution a:hover { color: var(--text); }

/* ─── Scrollbars ─── */
#chat-messages::-webkit-scrollbar,
#weather-content::-webkit-scrollbar {
  width: 5px;
}

#chat-messages::-webkit-scrollbar-track,
#weather-content::-webkit-scrollbar-track {
  background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb,
#weather-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

/* ─── MapLibre Overrides ─── */
.maplibregl-popup-content {
  background: var(--surface) !important;
  color: var(--text) !important;
  border: 1px solid var(--border) !important;
  border-radius: 8px !important;
  padding: 10px 14px !important;
  font-family: inherit !important;
  font-size: 13px !important;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4) !important;
}

.maplibregl-popup-anchor-bottom .maplibregl-popup-tip {
  border-top-color: var(--surface) !important;
}

.maplibregl-popup-close-button {
  color: var(--text-muted) !important;
  font-size: 18px !important;
}

.maplibregl-ctrl-group {
  background: var(--glass) !important;
  border: 1px solid var(--glass-border) !important;
  border-radius: 10px !important;
  overflow: hidden;
}

.maplibregl-ctrl-group button {
  background: transparent !important;
  border-bottom: 1px solid var(--border) !important;
}

.maplibregl-ctrl-group button:last-child {
  border-bottom: none !important;
}

.maplibregl-ctrl-group button span {
  filter: invert(0.8);
}

/* Hidden on desktop */
#mobile-search, #mobile-sheet { display: none; }

/* ─── Mobile ─── */
@media (max-width: 900px) {
  #weather-panel { width: 280px; }
  #chat-drawer { width: 300px; }
}

@media (max-width: 640px) {
  /* Hide desktop panels */
  #weather-panel, #chat-drawer { display: none !important; }

  /* Floating search bar */
  #mobile-search {
    display: block;
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    z-index: 25;
  }

  #mobile-search #search-bar {
    background: var(--glass);
    backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-bottom: 1px solid var(--glass-border);
    border-radius: 12px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  }

  /* Bottom sheet */
  #mobile-sheet {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 30;
    background: var(--glass);
    backdrop-filter: blur(20px);
    border-top: 1px solid var(--glass-border);
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.3);
    flex-direction: column;
    height: 160px;
    transition: height 0.3s cubic-bezier(0.25, 1, 0.5, 1);
    overflow: hidden;
  }

  #mobile-sheet.sheet-peek { height: 160px; }
  #mobile-sheet.sheet-half { height: 52vh; }
  #mobile-sheet.sheet-full { height: 92vh; }

  .sheet-handle {
    display: flex;
    justify-content: center;
    padding: 10px 0 4px;
    cursor: grab;
    flex-shrink: 0;
    touch-action: none;
    -webkit-user-select: none;
    user-select: none;
  }

  .sheet-handle-bar {
    width: 36px;
    height: 4px;
    background: var(--text-muted);
    border-radius: 2px;
    opacity: 0.4;
  }

  .sheet-tabs {
    display: flex;
    padding: 0 12px 8px;
    gap: 4px;
    flex-shrink: 0;
  }

  .sheet-tab {
    flex: 1;
    padding: 7px;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.2s;
  }

  .sheet-tab.active {
    background: rgba(139, 34, 50, 0.18);
    color: var(--text);
    border-color: var(--accent-dim);
  }

  .sheet-body {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
  }

  .sheet-pane { display: block; height: 100%; }
  .sheet-pane.hidden { display: none !important; }

  #sheet-chat {
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  #sheet-chat.hidden { display: none !important; }

  #sheet-chat #chat-messages {
    flex: 1;
    overflow-y: auto;
  }

  #sheet-chat #chat-form {
    flex-shrink: 0;
  }

  /* Reposition layer selector to top-right */
  #layer-selector {
    top: 68px;
    right: 12px;
    bottom: auto;
    left: auto;
    transform: none;
    flex-direction: column;
  }

  #map-legend {
    bottom: 172px;
    flex-direction: column;
  }

  /* Shift map controls below search bar */
  .maplibregl-ctrl-top-left {
    top: 68px !important;
  }

  #attribution {
    bottom: 168px;
  }
}
