/* Viet Weather PWA — mobile-first responsive CSS */

/* Reset & base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #1a73e8;
  --primary-dark: #1557b0;
  --danger: #d93025;
  --bg: #f8f9fa;
  --surface: #ffffff;
  --text: #202124;
  --text-secondary: #5f6368;
  --border: #dadce0;
  --shadow: 0 2px 8px rgba(0,0,0,0.12);
  --radius: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

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

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Map */
#map-container {
  flex: 1;
  position: relative;
  min-height: 0;
}

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

/* Search */
#search-bar {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 10px;
  z-index: 1000;
  max-width: 400px;
}

#search-input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  outline: none;
}

#search-input:focus {
  border-color: var(--primary);
}

#search-results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
  max-height: 200px;
  overflow-y: auto;
  display: none;
}

#search-results.show {
  display: block;
}

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

.search-result-item:hover {
  background: #e8f0fe;
}

.search-result-item .name {
  font-weight: 500;
}

.search-result-item .admin {
  color: var(--text-secondary);
  font-size: 12px;
}

/* Radar toggle */
#radar-toggle {
  position: absolute;
  top: 60px;
  right: 10px;
  z-index: 1000;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  font-size: 13px;
  box-shadow: var(--shadow);
}

#radar-toggle.active {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}

#desktop-controls {
  display: none;
}

/* Attribution */
#attribution {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255,255,255,0.92);
  padding: 4px 8px;
  font-size: 10px;
  text-align: center;
  z-index: 1000;
  color: var(--text-secondary);
}

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

/* Panels */
.panel {
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0,0,0,0.08);
  max-height: 60vh;
  overflow-y: auto;
  z-index: 900;
}

.panel.hidden {
  display: none;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.panel-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.btn-icon {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px 8px;
  line-height: 1;
}

/* Bottom bar */
#bottom-bar {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 900;
}

.btn-main {
  flex: 1;
  padding: 10px 8px;
  border: 1px solid var(--primary);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--primary);
  font-size: 13px;
  cursor: pointer;
  text-align: center;
  font-weight: 500;
}

.btn-main:hover {
  background: #e8f0fe;
}

.btn-main:active {
  background: #d2e3fc;
}

/* Current summary */
#current-summary {
  display: flex;
  gap: 12px;
  padding: 12px 16px;
  overflow-x: auto;
}

.summary-card {
  flex: 0 0 auto;
  min-width: 140px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.summary-card .point-name {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
}

.summary-card .temp {
  font-size: 28px;
  font-weight: 300;
  line-height: 1;
  margin-bottom: 4px;
}

.summary-card .detail {
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.4;
}

.summary-card .source-tag {
  font-size: 10px;
  color: var(--primary);
  margin-top: 4px;
}

/* Hourly section */
#hourly-section {
  padding: 0 16px 16px;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
}

.tab {
  flex: 1;
  padding: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  cursor: pointer;
  font-size: 13px;
  border-radius: var(--radius) var(--radius) 0 0;
  font-weight: 500;
}

.tab.active {
  background: var(--surface);
  border-bottom-color: var(--surface);
  color: var(--primary);
}

#hourly-table {
  overflow-x: auto;
}

.hourly-grid {
  display: grid;
  grid-template-columns: 80px repeat(24, 70px);
  gap: 1px;
  background: var(--border);
  border: 1px solid var(--border);
  font-size: 11px;
}

.hourly-grid .header {
  background: var(--bg);
  padding: 6px 4px;
  font-weight: 600;
  text-align: center;
  white-space: nowrap;
}

.hourly-grid .cell {
  background: var(--surface);
  padding: 5px 3px;
  text-align: center;
  white-space: nowrap;
}

.hourly-grid .cell.highlight {
  background: #fff8e1;
}

.hourly-grid .row-label {
  background: var(--bg);
  padding: 6px 4px;
  font-weight: 500;
  text-align: right;
  white-space: nowrap;
}

/* Source status */
#source-status {
  padding: 12px 16px;
  font-size: 12px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}

#source-status .ok { color: #188038; }
#source-status .error { color: var(--danger); }

/* Config panel */
.config-body {
  padding: 16px;
}

.config-row {
  margin-bottom: 12px;
}

.config-row label {
  display: block;
  margin-bottom: 4px;
  font-weight: 500;
  font-size: 13px;
}

.config-row input[type="number"] {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
}

#points-list {
  margin-bottom: 12px;
}

.point-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 6px;
  font-size: 13px;
}

.point-item .remove-point {
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 4px;
  padding: 4px 8px;
  cursor: pointer;
  font-size: 12px;
}

#config-status {
  font-size: 12px;
  color: var(--primary);
  min-height: 20px;
}

/* Loading */
.loading {
  text-align: center;
  padding: 20px;
  color: var(--text-secondary);
}

/* Marker popup custom */
.leaflet-popup-content {
  font-family: var(--font);
  font-size: 13px;
}

.point-popup .name {
  font-weight: 600;
  margin-bottom: 4px;
}

.point-popup .coords {
  font-size: 11px;
  color: var(--text-secondary);
}

.point-popup button {
  margin-top: 6px;
  padding: 4px 10px;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

/* Responsive: desktop */
@media (min-width: 768px) {
  #app {
    flex-direction: row;
  }

  #map-container {
    flex: 1;
  }

  #bottom-bar {
    display: none;
  }

  #dashboard {
    width: 380px;
    max-height: 100vh;
    border-left: 1px solid var(--border);
    border-top: none;
  }

  #dashboard.hidden {
    display: none;
  }

  #config-panel {
    width: 380px;
    max-height: 100vh;
    border-left: 1px solid var(--border);
    border-top: none;
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
  }

  #search-bar {
    max-width: 360px;
  }

  #desktop-controls {
    display: flex;
    gap: 6px;
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1000;
  }

  #desktop-controls button {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    box-shadow: var(--shadow);
    cursor: pointer;
    font-size: 13px;
  }

  .summary-card {
    min-width: 160px;
  }

  /* Desktop sidebar toggle */
  #sidebar-toggle {
    display: flex;
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 1001;
  }

  #sidebar-toggle button {
    padding: 8px 14px;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 13px;
    box-shadow: var(--shadow);
    margin-left: 6px;
  }
}

/* Air Quality cards */
#aq-summary {
  display: flex;
  gap: 12px;
  padding: 0 16px 12px;
  overflow-x: auto;
}

.aq-card {
  flex: 0 0 auto;
  min-width: 220px;
  padding: 12px;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.aq-card .point-name {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 8px;
}

.aq-aqi-row {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
}

.aq-aqi-item {
  flex: 1;
  padding: 8px 6px;
  border-radius: 6px;
  text-align: center;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}

.aq-aqi-item .aq-index {
  display: block;
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 2px;
}

.aq-aqi-item .aq-label {
  display: block;
  font-size: 11px;
  font-weight: 500;
}

.aq-pollutants {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px 8px;
}

.aq-p {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  padding: 2px 0;
}

.aq-p .label {
  font-weight: 500;
  color: var(--text);
}

.aq-p .value {
  color: var(--text-secondary);
}

/* Air Quality hourly section */
#aq-hourly-section {
  padding: 0 16px 16px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  padding: 10px 0 8px;
  color: var(--text);
}

#aq-hourly-table {
  overflow-x: auto;
  margin-bottom: 6px;
}

.aq-grid {
  grid-template-columns: 80px repeat(24, 64px);
  font-size: 10px;
}

#aq-attribution {
  font-size: 10px;
  color: var(--text-secondary);
  text-align: center;
  padding: 4px 0;
}

/* Two default points should be comparable without a horizontal scroll in the
   desktop sidebar. On a phone cards remain scrollable rather than cramped. */
@media (min-width: 768px) {
  #aq-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow-x: visible;
  }

  .aq-card {
    min-width: 0;
    padding: 10px;
  }

  .aq-aqi-row {
    gap: 4px;
  }

  .aq-aqi-item {
    padding: 6px 2px;
  }

  .aq-aqi-item .aq-index {
    font-size: 13px;
  }

  .aq-aqi-item .aq-label {
    font-size: 9px;
  }

  .aq-pollutants {
    grid-template-columns: 1fr;
  }
}

/* ── Precipitation Timeline (Windy-style) ──────────────────────────── */

#timeline-panel {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 950;
  background: rgba(20, 22, 28, 0.94);
  color: #e0e0e0;
  padding: 6px 10px 10px;
  font-size: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  user-select: none;
}

#timeline-panel.hidden {
  display: none;
}

.timeline-empty {
  text-align: center;
  padding: 8px;
  color: #999;
  font-size: 12px;
}

.timeline-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 6px;
}

.timeline-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: #e0e0e0;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 14px;
  cursor: pointer;
  min-width: 32px;
  text-align: center;
  line-height: 1.2;
}

.timeline-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.timeline-btn:active {
  background: rgba(255, 255, 255, 0.3);
}

.timeline-time {
  position: relative;
  font-weight: 700;
  font-size: 13px;
  color: #1d1d1d;
  margin-left: 6px;
  padding: 5px 10px;
  border-radius: 5px;
  background: #e1a600;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
  white-space: nowrap;
}

.timeline-time::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -5px;
  width: 10px;
  height: 10px;
  background: #e1a600;
  transform: translateX(-50%) rotate(45deg);
  z-index: -1;
}

.timeline-slider-row {
  margin-bottom: 4px;
}

.timeline-scale {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 2px 5px;
  color: #aeb4bd;
  font-size: 10px;
  letter-spacing: 0.01em;
}

.timeline-scale .scale-radar { flex: 1; }
.timeline-scale .scale-forecast { flex: 1; text-align: right; }

.timeline-split-marker {
  padding: 0 6px;
  color: #ffaa00;
  font-weight: 700;
  font-size: 11px;
  text-shadow: 0 0 6px rgba(255, 170, 0, 0.35);
  white-space: nowrap;
}

#timeline-slider {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  /* Default fallback; JS overrides with --radar-pct / --fcst-pct gradient */
  --radar-pct: 40%;
  --fcst-pct: 60%;
  background: linear-gradient(to right,
    rgba(0, 180, 80, 0.55) 0%,
    rgba(0, 180, 80, 0.55) var(--radar-pct),
    rgba(77, 166, 255, 0.45) var(--radar-pct),
    rgba(77, 166, 255, 0.45) 100%
  );
  border-radius: 3px;
  outline: none;
  cursor: pointer;
}

#timeline-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #4da6ff;
  border: 2px solid #fff;
  cursor: pointer;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

#timeline-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #4da6ff;
  border: 2px solid #fff;
  cursor: pointer;
}

.timeline-source-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
}

.timeline-source {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
}

.timeline-source.src-radar {
  background: rgba(0, 180, 80, 0.25);
  color: #4cff88;
}

.timeline-source.src-forecast {
  background: rgba(77, 166, 255, 0.25);
  color: #80c4ff;
}

.timeline-source.src-nowcast {
  background: rgba(255, 170, 0, 0.25);
  color: #ffaa00;
}

.timeline-legend {
  font-size: 10px;
  color: #aaa;
  display: flex;
  align-items: center;
  gap: 3px;
}

.legend-swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  border: 1px solid rgba(255,255,255,0.3);
}

.legend-swatch.legend-hatch {
  background: repeating-linear-gradient(
    -45deg,
    rgba(100,140,200,0.25),
    rgba(100,140,200,0.25) 2px,
    transparent 2px,
    transparent 4px
  );
  border: 1px solid rgba(100,140,200,0.4);
}

/* No-precipitation model warning */
.timeline-no-precip {
  text-align: center;
  padding: 4px 8px;
  margin-top: 4px;
  font-size: 11px;
  color: #aeb4bd;
  font-style: italic;
  border-top: 1px solid rgba(255,255,255,0.1);
}

/* Make the timeline panel not overlap the attribution bar */
#attribution {
  z-index: 940;
}
