* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
#map { width: 100vw; height: 100vh; }

/* ============================================================ */
/* ★★★ BASE STYLES (สำหรับ PC) ★★★ */
/* ============================================================ */

/* ปุ่ม SVG ด้านขวาบน */
.controls-top-right {
  position: fixed;
  top: 80px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

.btn-svg {
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #ccc;
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  width: 44px;
  height: 44px;
}
.btn-svg:hover { background: #f0f0f0; box-shadow: 0 4px 12px rgba(0,0,0,0.2); }
.btn-svg.active { background: #e3f2fd; border-color: #1976d2; }
.btn-svg svg { width: 24px; height: 24px; }

/* ปุ่มด้านซ้าย */
.controls-left {
  position: fixed;
  top: 80px;
  left: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
}

/* Animation ด้านล่าง */
.controls-bottom {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 255, 255, 0.95);
  padding: 15px 25px;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  gap: 15px;
  z-index: 1000;
  min-width: 500px;
  max-width: 90vw;
}

.time-display {
  font-size: 22px;
  font-weight: bold;
  color: #1976d2;
  min-width: 80px;
  font-variant-numeric: tabular-nums;
}

.btn {
  background: #1976d2;
  color: white;
  border: none;
  padding: 10px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.2s;
  white-space: nowrap;
}
.btn:hover { background: #1565c0; }

.timeline {
  flex: 1;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: #ddd;
  border-radius: 3px;
  min-width: 100px;
}
.timeline::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  background: #1976d2;
  border-radius: 50%;
  cursor: pointer;
}

.status { font-size: 12px; color: #666; min-width: 60px; }

/* ชื่อสถานี */
.station-label {
  background: rgba(255,255,255,0.8);
  border: 1px solid #d32f2f;
  border-radius: 4px;
  padding: 1px 4px;
  font-size: 11px;
  font-weight: bold;
  color: #d32f2f;
}

/* Legend dBZ */
.legend {
  position: fixed;
  bottom: 100px;
  left: 20px;
  background: rgba(255, 255, 255, 0.95);
  padding: 10px 12px;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  z-index: 1000;
  font-size: 10px;
  max-height: calc(100vh - 200px);
  overflow-y: auto;
}
.legend-title {
  font-weight: bold;
  font-size: 11px;
  margin-bottom: 6px;
  color: #333;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}
.legend-close {
  background: none;
  border: none;
  font-size: 14px;
  cursor: pointer;
  color: #999;
  padding: 0 2px;
  line-height: 1;
}
.legend-close:hover { color: #d32f2f; }
.legend-row {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-bottom: 1px;
  line-height: 1.1;
}
.legend-color {
  width: 20px;
  height: 10px;
  border-radius: 1px;
  border: 1px solid rgba(0,0,0,0.1);
}
.legend-label {
  color: #555;
  font-variant-numeric: tabular-nums;
  font-size: 10px;
}

.legend-toggle-btn {
  position: fixed;
  bottom: 100px;
  left: 20px;
  background: rgba(255,255,255,0.95);
  border: none;
  padding: 8px 12px;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  cursor: pointer;
  font-size: 12px;
  z-index: 999;
  display: none;
}

/* Opacity Slider */
.opacity-control {
  position: fixed;
  bottom: 30px;
  left: 20px;
  background: rgba(255, 255, 255, 0.95);
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-family: sans-serif;
}
.opacity-control label {
  font-weight: 600;
  color: #333;
  white-space: nowrap;
}
.opacity-control input[type="range"] {
  width: 100px;
  height: 4px;
  -webkit-appearance: none;
  background: #ddd;
  border-radius: 2px;
}
.opacity-control input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: #1976d2;
  border-radius: 50%;
  cursor: pointer;
}
#opacity-value {
  font-variant-numeric: tabular-nums;
  color: #1976d2;
  font-weight: 600;
  min-width: 35px;
  text-align: right;
}

/* Summary Panel */
.summary-panel {
  position: fixed;
  top: 80px;
  left: 80px;
  width: 400px;
  max-height: calc(100vh - 200px);
  background: rgba(255, 255, 255, 0.98);
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.2);
  z-index: 1000;
  display: none;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, sans-serif;
}
.summary-title-bar {
  background: linear-gradient(135deg, #9c27b0, #673ab7);
  color: white;
  padding: 12px 16px;
  font-weight: bold;
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.summary-close {
  background: none;
  border: none;
  color: white;
  font-size: 18px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.summary-content {
  padding: 16px;
  max-height: calc(100vh - 280px);
  overflow-y: auto;
  font-size: 13px;
  color: #333;
  line-height: 1.6;
}
.summary-header {
  font-weight: bold;
  font-size: 14px;
  color: #9c27b0;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 2px solid #e1bee7;
}
.summary-body p { margin-bottom: 10px; }
.station-list { list-style: none; padding: 0; margin: 10px 0; }
.station-list li {
  padding: 8px;
  margin-bottom: 6px;
  background: #f5f5f5;
  border-radius: 6px;
  border-left: 4px solid #9c27b0;
}
.dbz-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  color: white;
  font-weight: bold;
  font-size: 11px;
  margin-right: 6px;
}
.level-text { font-size: 12px; color: #666; }
.alert-box {
  background: #fff3e0;
  border-left: 4px solid #ff9800;
  padding: 10px;
  border-radius: 6px;
  margin-top: 12px;
  font-size: 12px;
  line-height: 1.7;
}
.alert-box b { color: #e65100; }
.alert-box.danger {
  background: #ffebee;
  border-left: 4px solid #d32f2f;
  color: #b71c1c;
}
.alert-box.danger b { color: #c62828; }
.alert-box.warning {
  background: #fff8e1;
  border-left: 4px solid #ff9800;
  color: #e65100;
}
.alert-box.warning b { color: #ef6c00; }
.hint {
  background: #e3f2fd;
  border-left: 4px solid #1976d2;
  padding: 8px;
  border-radius: 6px;
  font-size: 12px;
  color: #1565c0;
}
.loading { text-align: center; color: #999; padding: 20px; }
.error {
  background: #ffebee;
  border-left: 4px solid #d32f2f;
  padding: 10px;
  border-radius: 6px;
  color: #c62828;
  font-size: 12px;
}
.circle-label {
  background: rgba(255,255,255,0.9);
  border: 1px solid #999;
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 11px;
  font-weight: bold;
  color: #333;
}
.radius-label { background: transparent !important; border: none !important; }
.place-popup .leaflet-popup-content-wrapper {
  background: rgba(255, 255, 255, 0.95);
  border-radius: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.2);
  padding: 0;
}
.place-popup .leaflet-popup-content { margin: 6px 10px; font-size: 12px; }
.place-popup .leaflet-popup-tip { display: none; }
.rain-arrow { background: transparent !important; border: none !important; }
.rain-arrow div { font-family: sans-serif; line-height: 1; }
.leaflet-control-attribution {
  font-size: 9px !important;
  background: rgba(255,255,255,0.7) !important;
}

/* ============================================================ */
/* ★★★ RESPONSIVE — สำหรับมือถือ (จอเล็ก < 768px) ★★★ */
/* ============================================================ */
@media (max-width: 768px) {
  /* ปุ่มขวาบน — เล็กลง */
  .controls-top-right {
    top: 10px;
    right: 10px;
    gap: 6px;
  }
  .btn-svg {
    width: 40px;
    height: 40px;
    padding: 6px;
  }
  .btn-svg svg { width: 20px; height: 20px; }

  /* ปุ่มซ้าย — เล็กลง */
  .controls-left {
    top: 10px;
    left: 10px;
    gap: 6px;
  }

  /* Legend — เล็กลง + เลื่อน */
  .legend {
    bottom: 120px;
    left: 10px;
    padding: 8px 10px;
    font-size: 9px;
    max-height: calc(100vh - 250px);
  }
  .legend-title { font-size: 10px; }
  .legend-color { width: 16px; height: 8px; }
  .legend-label { font-size: 9px; }
  .legend-close { font-size: 12px; }

  /* ปุ่มแสดง Legend */
  .legend-toggle-btn {
    bottom: 120px;
    left: 10px;
    padding: 6px 10px;
    font-size: 11px;
  }

  /* Opacity Slider — เล็กลง */
  .opacity-control {
    bottom: 130px;
    left: 10px;
    padding: 8px 10px;
    font-size: 11px;
  }
  .opacity-control input[type="range"] { width: 60px; }
  #opacity-value { min-width: 30px; }

  /* Animation ด้านล่าง — ปรับให้เต็มความกว้าง */
  .controls-bottom {
    bottom: 10px;
    left: 10px;
    right: 10px;
    transform: none;
    padding: 10px 12px;
    gap: 8px;
    min-width: auto;
    max-width: none;
    width: calc(100vw - 20px);
  }
  .time-display { font-size: 16px; min-width: 50px; }
  .btn { padding: 8px 12px; font-size: 12px; }
  .timeline { height: 4px; min-width: 40px; }
  .status { font-size: 10px; min-width: 40px; }

  /* Summary Panel — เต็มจอ */
  .summary-panel {
    top: 10px;
    left: 10px;
    right: 10px;
    width: auto;
    max-height: calc(100vh - 120px);
  }
  .summary-title-bar { padding: 10px 14px; font-size: 13px; }
  .summary-content { padding: 12px; font-size: 12px; max-height: calc(100vh - 200px); }
  .summary-header { font-size: 13px; }

  /* ปุ่มใน Popup */
  .leaflet-popup-content { font-size: 12px; }
  .station-label { font-size: 9px; padding: 0 3px; }
}

/* ★★★ สำหรับมือถือจอเล็กมาก (< 400px) ★★★ */
@media (max-width: 400px) {
  .btn-svg { width: 36px; height: 36px; }
  .btn-svg svg { width: 18px; height: 18px; }
  .time-display { font-size: 14px; min-width: 44px; }
  .timeline { min-width: 30px; }
  .legend { font-size: 8px; padding: 6px 8px; }
  .legend-color { width: 14px; height: 7px; }
  .legend-label { font-size: 8px; }
  .opacity-control { font-size: 10px; padding: 6px 8px; }
}

/* ★★★ สำหรับ iPad/Tablet (768-1024px) ★★★ */
@media (min-width: 769px) and (max-width: 1024px) {
  .summary-panel { width: 350px; }
  .legend { max-height: calc(100vh - 250px); }
}

/* ★★★ Opacity Slider (แบบ inline ใน controls-bottom) ★★★ */
.opacity-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  padding-left: 10px;
  border-left: 1px solid #ddd;
}
.opacity-inline label {
  font-weight: 600;
  color: #333;
  white-space: nowrap;
}
.opacity-inline input[type="range"] {
  width: 70px;
  height: 4px;
  -webkit-appearance: none;
  background: #ddd;
  border-radius: 2px;
}
.opacity-inline input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  background: #1976d2;
  border-radius: 50%;
  cursor: pointer;
}
.opacity-inline #opacity-value {
  font-variant-numeric: tabular-nums;
  color: #1976d2;
  font-weight: 600;
  min-width: 30px;
  text-align: right;
}

/* ============================================================ */
/* ★★★ RESPONSIVE — มือถือ (จอเล็ก < 768px) ★★★ */
/* ============================================================ */
@media (max-width: 768px) {
  /* ปุ่มขวาบน — เล็กลง + อยู่บน Layer Control */
  .controls-top-right {
    top: 60px;           /* ← เลื่อนลงมา ไม่ทับ Layer Control */
    right: 10px;
    gap: 6px;
  }
  .btn-svg {
    width: 40px;
    height: 40px;
    padding: 6px;
  }
  .btn-svg svg { width: 20px; height: 20px; }

  /* ปุ่มซ้าย — เล็กลง */
  .controls-left {
    top: 60px;
    left: 10px;
    gap: 6px;
  }

  /* Legend — เล็กลง + เลื่อนขึ้น (ไม่ทับ Animation) */
  .legend {
    bottom: 130px;       /* ← เลื่อนขึ้น ให้พ้น Animation */
    left: 10px;
    padding: 8px 10px;
    font-size: 9px;
    max-height: calc(100vh - 280px);
  }
  .legend-title { font-size: 10px; }
  .legend-color { width: 16px; height: 8px; }
  .legend-label { font-size: 9px; }
  .legend-close { font-size: 12px; }

  /* ปุ่มแสดง Legend */
  .legend-toggle-btn {
    bottom: 130px;
    left: 10px;
    padding: 6px 10px;
    font-size: 11px;
  }

  /* Animation ด้านล่าง — ปรับให้เต็มความกว้าง */
  .controls-bottom {
    bottom: 10px;
    left: 10px;
    right: 10px;
    transform: none;
    padding: 10px 12px;
    gap: 8px;
    min-width: auto;
    max-width: none;
    width: calc(100vw - 20px);
    flex-wrap: wrap;     /* ← ให้ห่อได้ถ้าจอแคบ */
  }
  .time-display { font-size: 16px; min-width: 50px; }
  .btn { padding: 8px 12px; font-size: 12px; }
  .timeline { height: 4px; min-width: 40px; flex: 1; }
  .status { font-size: 10px; min-width: 40px; }

  /* Opacity Slider — เล็กลง */
  .opacity-inline {
    font-size: 10px;
    padding-left: 6px;
    gap: 4px;
    width: 100%;          /* ← ขึ้นบรรทัดใหม่ */
    justify-content: center;
    border-left: none;
    border-top: 1px solid #ddd;
    padding-top: 6px;
    margin-top: 4px;
  }
  .opacity-inline input[type="range"] { width: 80px; }
  .opacity-inline #opacity-value { min-width: 28px; }

  /* Summary Panel — เต็มจอ */
  .summary-panel {
    top: 10px;
    left: 10px;
    right: 10px;
    width: auto;
    max-height: calc(100vh - 120px);
  }
  .summary-title-bar { padding: 10px 14px; font-size: 13px; }
  .summary-content { padding: 12px; font-size: 12px; max-height: calc(100vh - 200px); }
  .summary-header { font-size: 13px; }

  /* ปุ่มใน Popup */
  .leaflet-popup-content { font-size: 12px; }
  .station-label { font-size: 9px; padding: 0 3px; }
}

/* ★★★ มือถือจอเล็กมาก (< 400px) ★★★ */
@media (max-width: 400px) {
  .btn-svg { width: 36px; height: 36px; }
  .btn-svg svg { width: 18px; height: 18px; }
  .time-display { font-size: 14px; min-width: 44px; }
  .timeline { min-width: 30px; }
  .legend { font-size: 8px; padding: 6px 8px; }
  .legend-color { width: 14px; height: 7px; }
  .legend-label { font-size: 8px; }
  .opacity-inline { font-size: 9px; padding: 4px 0 0 0; }
  .opacity-inline input[type="range"] { width: 60px; }
}
