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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

#map {
  width: 100%;
  height: 100%;
  z-index: 0;
}

/* Map logo overlay — top-left on the map */
#mapLogo {
  position: fixed;
  top: 46px;
  left: 8px;
  z-index: 999;
  width: 96px;
  height: 96px;
  pointer-events: none;
  opacity: 0.9;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.4));
}

#mapLogo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* Push Leaflet controls below status bar (40px) + logo (104px) */
.leaflet-top {
  top: 150px !important;
}

/* Leaflet attribution styling — pinned to very bottom-right */
.leaflet-control-attribution {
  background: rgba(0, 0, 0, 0.55) !important;
  color: rgba(255, 255, 255, 0.75) !important;
  font-size: 11px !important;
  position: fixed !important;
  bottom: 0 !important;
  right: 0 !important;
  z-index: 1001 !important;
  padding: 2px 6px !important;
  border-radius: 4px 0 0 0 !important;
}

.leaflet-control-attribution a {
  color: rgba(255, 255, 255, 0.9) !important;
}

/* Status bar */
#statusBar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 40px;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  padding: 0 12px;
  gap: 8px;
  z-index: 1000;
  color: #fff;
  font-size: 14px;
}

#appLogo {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot.connected {
  background: #4caf50;
  box-shadow: 0 0 6px #4caf50;
}

.dot.disconnected {
  background: #f44336;
  animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

#alertCount {
  margin-inline-start: auto;
  font-weight: 600;
  direction: ltr;
}

/* Alert panel */
#alertPanel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 50vh;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(10px);
  border-radius: 16px 16px 0 0;
  z-index: 1002;
  color: #fff;
  transition: transform 0.3s ease, height 0.3s ease;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

#alertPanel.collapsed {
  transform: translateY(calc(100% - 44px));
}

#alertPanel.expanded {
  height: 85vh;
}

#panelContent {
  flex: 1;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.25) transparent;
}

#panelContent::-webkit-scrollbar { width: 6px; }
#panelContent::-webkit-scrollbar-track { background: transparent; }
#panelContent::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.25); border-radius: 3px; }
#panelContent::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.4); }

#panelHandle {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  padding: 8px 16px 6px;
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.handle-bar {
  width: 36px;
  height: 4px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.4);
  margin-bottom: 4px;
  flex-basis: 100%;
  /* center the bar */
  margin-left: auto;
  margin-right: auto;
}

#panelTitle {
  font-size: 13px;
  font-weight: 600;
  opacity: 0.8;
}

/* New alert badge */
.new-badge {
  background: #f44336;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  margin-inline-start: 6px;
  animation: badge-pulse 1.5s ease-in-out infinite;
}

@keyframes badge-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

#alertList {
  padding: 4px 12px 8px;
}

#alertList:empty::after {
  content: none;
}

/* ── History section ─────────────────────────── */
#historySection {
  display: none;
  padding: 0 12px 16px;
}

#alertPanel.expanded #historySection {
  display: block;
}

#historyDivider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 12px;
}

#historyDivider::before,
#historyDivider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: rgba(255, 255, 255, 0.15);
}

#historyDividerLabel {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  opacity: 0.5;
  white-space: nowrap;
}

#historySearchBox {
  margin-bottom: 10px;
}

#historySearchInput {
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  color: #fff;
  font-size: 16px;
  padding: 8px 12px;
  outline: none;
  box-sizing: border-box;
}

#historySearchInput::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

#historySearchInput:focus {
  border-color: rgba(255, 255, 255, 0.3);
  background: rgba(255, 255, 255, 0.12);
}

#historyList {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.history-item:active {
  background: rgba(255, 255, 255, 0.05);
}

.history-time {
  font-size: 11px;
  opacity: 0.45;
  min-width: 48px;
  text-align: end;
  font-variant-numeric: tabular-nums;
}

.history-empty {
  text-align: center;
  opacity: 0.4;
  font-size: 13px;
  padding: 20px 0;
}

.alert-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 14px;
}

.alert-item:last-child {
  border-bottom: none;
}

.alert-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.alert-dot.pre_alert { background: #ffd700; }
.alert-dot.alert { background: #f44336; animation: pulse-alert 1s infinite; }
.alert-dot.all_clear { background: #4caf50; }

@keyframes pulse-alert {
  0%, 100% { box-shadow: 0 0 0 0 rgba(244, 67, 54, 0.6); }
  50% { box-shadow: 0 0 0 6px rgba(244, 67, 54, 0); }
}

.alert-name {
  flex: 1;
  direction: rtl;
}

[dir="ltr"] .alert-name {
  direction: ltr;
}

.alert-name-en {
  font-size: 11px;
  opacity: 0.6;
  direction: ltr;
}

.alert-name-secondary {
  font-size: 11px;
  opacity: 0.6;
  direction: rtl;
}

.alert-time {
  font-size: 11px;
  opacity: 0.5;
  direction: ltr;
}

/* Legend */
#legend {
  position: fixed;
  bottom: 168px;
  right: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  border-radius: 8px 0 0 8px;
  padding: 6px 10px;
  z-index: 1000;
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  direction: ltr;
  align-items: center;
  gap: 6px;
}

#legend.collapsed #legendItems {
  display: none;
}

#legend.collapsed {
  padding: 6px 4px;
  border-radius: 8px 0 0 8px;
}

#legendToggle {
  font-size: 12px;
  opacity: 0.8;
  flex-shrink: 0;
  padding: 6px 2px;
}

#legendItems {
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow: hidden;
  white-space: nowrap;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.swatch {
  width: 14px;
  height: 14px;
  border-radius: 3px;
  flex-shrink: 0;
}

.swatch.pre-alert { background: rgba(255, 215, 0, 0.5); border: 1px solid #ffd700; }
.swatch.alert { background: rgba(255, 0, 0, 0.6); border: 1px solid #f44336; }
.swatch.shelter { background: rgba(255, 152, 0, 0.5); border: 1px solid #f57c00; }
.swatch.all-clear { background: rgba(0, 200, 0, 0.4); border: 1px solid #4caf50; }

/* Search overlay — positioned dynamically by JS next to search button */
#searchOverlay {
  position: fixed;
  top: 48px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1200;
  width: 320px;
  max-width: calc(100vw - 24px);
}

#searchOverlay.hidden { display: none; }

#searchBox {
  display: flex;
  gap: 0;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.15);
}

#searchInput {
  flex: 1;
  background: transparent;
  border: none;
  color: #fff;
  font-size: 16px;
  padding: 8px 12px;
  outline: none;
  min-width: 0;
}

#searchInput::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

#searchResults {
  margin-top: 4px;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(8px);
  border-radius: 8px;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid rgba(255, 255, 255, 0.1);
  display: none;
}

#searchResults:not(:empty) {
  display: block;
}

.search-result {
  padding: 8px 12px;
  color: #fff;
  font-size: 13px;
  cursor: pointer;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.search-result:hover {
  background: rgba(255, 255, 255, 0.1);
}

.search-result-name { font-weight: 600; }
.search-result-en { font-size: 11px; opacity: 0.5; }

/* Search toggle button */
.search-toggle-btn { font-size: 16px !important; }

/* Ad slot — mobile: centered 320x50 banner below status bar */
#adSlot {
  position: fixed;
  top: 40px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 999;
  width: 320px;
  height: 50px;
  overflow: hidden;
}

/* Settings panel — gear button + sliding drawer */
.settings-container {
  position: relative;
}

.settings-gear-btn {
  width: 34px;
  height: 34px;
  border-radius: 4px;
  border: 2px solid rgba(0,0,0,0.2);
  background: #fff;
  cursor: pointer;
  line-height: 30px;
  text-align: center;
  box-shadow: 0 1px 5px rgba(0,0,0,0.3);
  color: #333;
  font-size: 18px;
  z-index: 2;
  transition: transform 0.3s ease;
}
.settings-gear-btn.open {
  transform: rotate(90deg);
}
.settings-gear-btn:hover { background: #f4f4f4; }

.settings-panel {
  position: absolute;
  right: 0;
  top: 40px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.3s ease, opacity 0.25s ease;
}
.settings-panel.open {
  max-height: 400px;
  opacity: 1;
}

/* Buttons inside settings panel */
.settings-btn {
  width: 34px;
  height: 34px;
  border-radius: 4px;
  border: 2px solid rgba(0,0,0,0.2);
  background: #fff;
  cursor: pointer;
  line-height: 30px;
  text-align: center;
  box-shadow: 0 1px 5px rgba(0,0,0,0.3);
  color: #333;
  flex-shrink: 0;
}

.settings-btn.theme-toggle-btn { font-size: 18px; }
.settings-btn.lang-toggle-btn { font-size: 18px; }
.settings-btn.loc-toggle-btn { font-size: 16px; transition: opacity 0.2s; }
.settings-btn.search-toggle-btn { font-size: 16px; }
.settings-btn.history-toggle-btn { font-size: 16px; transition: opacity 0.2s; }

.settings-btn:hover { background: #f4f4f4; }

/* User location marker */
.user-location-icon {
  background: none !important;
  border: none !important;
  position: relative;
}

.user-dot {
  width: 14px;
  height: 14px;
  background: #4285f4;
  border: 2.5px solid #fff;
  border-radius: 50%;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  box-shadow: 0 0 6px rgba(66, 133, 244, 0.6);
  z-index: 2;
}

.user-compass-cone {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  width: 60px;
  height: 60px;
  transform: translate(-50%, -50%) rotate(0deg);
  transform-origin: center center;
  z-index: 1;
  pointer-events: none;
  background: conic-gradient(
    from -30deg at 50% 50%,
    transparent 0deg,
    rgba(66, 133, 244, 0.25) 15deg,
    rgba(66, 133, 244, 0.35) 30deg,
    rgba(66, 133, 244, 0.25) 45deg,
    transparent 60deg
  );
  clip-path: polygon(50% 50%, 20% 0%, 80% 0%);
  border-radius: 50%;
}

/* Laser beam easter egg */
.laser-beam {
  filter: drop-shadow(0 0 3px rgba(255, 0, 0, 0.6));
}

.user-dot-pulse {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: rgba(66, 133, 244, 0.2);
  animation: user-pulse 2s ease-out infinite;
}

@keyframes user-pulse {
  0% { transform: translate(-50%, -50%) scale(0.5); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1.5); opacity: 0; }
}

/* Dark popup for area info */
.dark-popup .leaflet-popup-content-wrapper {
  background: rgba(20, 20, 20, 0.92);
  color: #fff;
  border-radius: 10px;
  backdrop-filter: blur(8px);
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.dark-popup .leaflet-popup-tip {
  background: rgba(20, 20, 20, 0.92);
}

.dark-popup .leaflet-popup-close-button {
  color: rgba(255,255,255,0.6) !important;
}

.dark-popup .leaflet-popup-close-button:hover {
  color: #fff !important;
}

.area-popup {
  min-width: 180px;
}

.popup-title {
  font-size: 16px;
  font-weight: 700;
  direction: rtl;
}

[dir="ltr"] .popup-title {
  direction: ltr;
}

.popup-subtitle {
  font-size: 12px;
  opacity: 0.6;
  margin-bottom: 6px;
}

.popup-status {
  padding: 4px 0;
  font-size: 13px;
  font-weight: 600;
}

.popup-alert { color: #f44336; }
.popup-pre_alert { color: #ffd700; }
.popup-all_clear { color: #4caf50; }

.popup-history-title {
  font-size: 12px;
  font-weight: 600;
  margin-top: 8px;
  padding-bottom: 4px;
  opacity: 0.7;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.popup-history {
  max-height: 150px;
  overflow-y: auto;
}

.popup-event {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 0;
  font-size: 12px;
}

.popup-event-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.popup-event-dot.alert { background: #f44336; }
.popup-event-dot.pre_alert { background: #ffd700; }
.popup-event-dot.all_clear { background: #4caf50; }

.popup-event-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.popup-event-time {
  opacity: 0.5;
  font-size: 11px;
  white-space: nowrap;
  margin-inline-start: auto;
}

.popup-no-history {
  font-size: 12px;
  opacity: 0.5;
  padding: 4px 0;
}

/* Disclaimer modal */
#disclaimerOverlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}

#disclaimerOverlay.hidden {
  display: none;
}

#disclaimerModal {
  background: rgba(20, 20, 20, 0.95);
  border-radius: 16px;
  padding: 28px 24px 24px;
  max-width: 340px;
  width: 90%;
  text-align: center;
  color: #fff;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.5);
}

#disclaimerTitle {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 14px;
}

#disclaimerText {
  font-size: 14px;
  line-height: 1.6;
  opacity: 0.85;
  margin-bottom: 20px;
}

#disclaimerTextEn {
  font-size: 12px;
  line-height: 1.5;
  opacity: 0.55;
  margin-bottom: 20px;
  margin-top: 8px;
}

#disclaimerAccept {
  background: #d32f2f;
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 12px 32px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
  transition: background 0.2s;
}

#disclaimerAccept:hover {
  background: #b71c1c;
}

/* History toggle button */
.history-toggle-btn {
  font-size: 16px;
  transition: opacity 0.2s;
}

.history-toggle-btn.active {
  background: #d32f2f !important;
  color: #fff !important;
  border-color: #d32f2f !important;
}

/* Timeline slider bar */
#timelineBar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.9);
  backdrop-filter: blur(10px);
  z-index: 1003;
  padding: 10px 16px;
  border-radius: 16px 16px 0 0;
}

#timelineBar.hidden {
  display: none;
}

#timelineControls {
  display: flex;
  align-items: center;
  gap: 8px;
  direction: ltr;
  flex-wrap: wrap;
}

@media (max-width: 500px) {
  #timelineControls {
    gap: 6px;
  }
  #timelineLabel {
    min-width: auto;
    font-size: 11px;
  }
  #timelineRangeButtons {
    gap: 2px;
  }
  .range-btn {
    padding: 2px 6px;
    font-size: 10px;
  }
  #timelineLive {
    padding: 4px 10px;
    font-size: 11px;
  }
}

#timelinePlay {
  background: none;
  border: none;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  flex-shrink: 0;
}

#timelinePlay:hover {
  background: rgba(255, 255, 255, 0.1);
}

#timelineSlider {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

#timelineSlider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #d32f2f;
  cursor: pointer;
  box-shadow: 0 0 6px rgba(211, 47, 47, 0.5);
  margin-top: -6px;
}

#timelineSlider::-webkit-slider-runnable-track {
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
}

#timelineSlider::-moz-range-track {
  height: 4px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 2px;
  border: none;
}

#timelineSlider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #d32f2f;
  cursor: pointer;
  border: none;
  box-shadow: 0 0 6px rgba(211, 47, 47, 0.5);
}

#timelineLabel {
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  min-width: 110px;
  text-align: center;
}

#timelineRangeButtons {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.range-btn {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: rgba(255, 255, 255, 0.6);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  cursor: pointer;
}

.range-btn.active {
  background: rgba(211, 47, 47, 0.3);
  border-color: #d32f2f;
  color: #fff;
}

#timelineLive {
  background: #4caf50;
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 6px 14px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  flex-shrink: 0;
  letter-spacing: 0.5px;
  animation: live-pulse 2s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(76, 175, 80, 0.4); }
  50% { box-shadow: 0 0 0 6px rgba(76, 175, 80, 0); }
}

#timelineLive:hover {
  background: #388e3c;
}

/* Desktop adjustments */
@media (min-width: 768px) {
  #alertPanel {
    right: auto;
    left: 0;
    width: 360px;
    max-height: 60vh;
    border-radius: 0 16px 0 0;
  }

  #alertPanel.collapsed {
    transform: translateY(calc(100% - 44px));
  }

  /* On desktop, move ad to bottom-right corner */
  #adSlot {
    top: auto;
    bottom: 100px;
    left: auto;
    right: 8px;
    transform: none;
    width: 320px;
    height: 50px;
    border-radius: 8px;
  }

  /* Leaflet controls below status bar + logo on desktop */
  .leaflet-top {
    top: 150px !important;
  }

  #mapLogo {
    top: 48px;
    left: 10px;
  }
}

/* Tiny screens — Galaxy Watch and similar wearables */
@media (max-width: 380px) and (max-height: 380px) {
  #legend { display: none; }
  #mapLogo { display: none; }
  #statusBar { font-size: 10px; padding: 2px 6px; }
  #alertPanel { display: none; }
  #adSlot { display: none; }

  .leaflet-top.leaflet-right {
    top: 28px !important;
  }

  .settings-gear-btn,
  .settings-btn {
    width: 26px;
    height: 26px;
    font-size: 13px !important;
    line-height: 22px;
  }
  .settings-panel { gap: 3px; }
  .settings-panel.open { padding-top: 3px; }

  .leaflet-control-zoom a {
    width: 26px !important;
    height: 26px !important;
    line-height: 26px !important;
    font-size: 14px !important;
  }

  #timelineBar {
    padding: 4px 6px;
  }
  #timelineControls {
    gap: 4px;
  }
  #timelinePlay {
    width: 24px;
    height: 24px;
    font-size: 12px;
  }
  #timelineLabel {
    font-size: 9px;
    min-width: auto;
  }
  .range-btn {
    padding: 1px 4px;
    font-size: 8px;
  }
  #timelineLive {
    padding: 2px 6px;
    font-size: 9px;
  }
}
