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

html,
body {
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  font-family:
    -apple-system,
    BlinkMacSystemFont,
    'Segoe UI',
    'Inter',
    system-ui,
    sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  -webkit-font-smoothing: antialiased;
}

#map {
  position: absolute;
  inset: 0;
  z-index: 0;
}

.weather-panel {
  position: absolute;
  top: max(1rem, env(safe-area-inset-top));
  left: max(1rem, env(safe-area-inset-left));
  right: max(1rem, env(safe-area-inset-right));
  max-width: 22rem;
  background: rgba(15, 23, 42, 0.92);
  padding: 1rem 1.25rem;
  border-radius: 14px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  z-index: 10;
  border: 1px solid rgba(148, 163, 184, 0.15);
}

.weather-panel header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.weather-panel h2 {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.65;
}

.weather-panel time {
  font-size: 0.75rem;
  opacity: 0.5;
  font-variant-numeric: tabular-nums;
}

.weather-panel .temp {
  font-size: 3rem;
  font-weight: 200;
  line-height: 1;
  letter-spacing: -0.02em;
}

.weather-panel .meta {
  display: flex;
  gap: 1.25rem;
  margin-top: 0.75rem;
  font-size: 0.875rem;
  opacity: 0.75;
  font-variant-numeric: tabular-nums;
}

.weather-panel .meta strong {
  font-weight: 500;
}

.weather-panel .placeholder,
.weather-panel .error {
  font-size: 0.875rem;
  opacity: 0.6;
  padding: 0.5rem 0;
}

.weather-panel .error {
  color: #fca5a5;
  opacity: 1;
}

.alerts-panel {
  position: absolute;
  top: calc(max(1rem, env(safe-area-inset-top)) + 9.5rem);
  left: max(1rem, env(safe-area-inset-left));
  max-width: 22rem;
  background: rgba(15, 23, 42, 0.92);
  padding: 0.875rem 1.25rem;
  border-radius: 14px;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
  z-index: 10;
  border: 1px solid rgba(148, 163, 184, 0.15);
}

.alerts-panel header {
  margin-bottom: 0.5rem;
}

.alerts-panel h2 {
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  opacity: 0.65;
  margin: 0;
}

/* Toggle nappi varoitusotsikossa. Mobiilissa tämä avaa/sulkee listan,
   desktopilla nappi piilotetaan ja lista näytetään aina. */
.alerts-panel .alerts-toggle {
  appearance: none;
  background: transparent;
  border: 0;
  color: inherit;
  padding: 0;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  cursor: pointer;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
}

.alerts-panel .alerts-toggle-indicator {
  font-size: 0.75rem;
  opacity: 0.6;
  transition: transform 150ms ease;
}

.alerts-panel .alerts-toggle[aria-expanded="true"] .alerts-toggle-indicator {
  transform: rotate(180deg);
}

.alerts-panel .alerts-count {
  font-size: 0.875rem;
  opacity: 0.7;
  margin-bottom: 0.5rem;
}

.alerts-panel .alerts-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  font-size: 0.8125rem;
  line-height: 1.35;
  max-height: 12rem;
  overflow-y: auto;
}

.alerts-panel .alerts-list li {
  padding: 0.5rem 0.625rem;
  border-left: 5px solid #94a3b8;
  background: rgba(148, 163, 184, 0.06);
  border-radius: 0 4px 4px 0;
  cursor: pointer;
  transition: background 120ms ease;
  -webkit-tap-highlight-color: transparent;
}

.alerts-panel .alerts-list li:hover,
.alerts-panel .alerts-list li:focus-visible {
  background: rgba(148, 163, 184, 0.14);
  outline: none;
}

.alerts-panel .alerts-list li:active {
  background: rgba(148, 163, 184, 0.22);
}

/* Severity tint mirrors the map line + marker colours. Minor stays
   neutral so the panel doesn't look noisy when most rows are routine
   peto-media incidents; moderate / severe / extreme get progressively
   more saturated background washes plus a thicker matching border.

   The selectors target `li.alert-*` rather than `.alert-*` because the
   base `.alerts-panel .alerts-list li` rule (specificity 0,2,1) would
   otherwise win the border-left-color cascade and paint every row
   gray. `li.alert-moderate` lands at (0,3,1) so the severity wash
   takes precedence. */
.alerts-panel .alerts-list li.alert-moderate {
  border-left-color: #fbbf24;
  background: rgba(251, 191, 36, 0.10);
}
.alerts-panel .alerts-list li.alert-moderate:hover,
.alerts-panel .alerts-list li.alert-moderate:focus-visible {
  background: rgba(251, 191, 36, 0.20);
}
.alerts-panel .alerts-list li.alert-severe {
  border-left-color: #fb923c;
  background: rgba(251, 146, 60, 0.14);
}
.alerts-panel .alerts-list li.alert-severe:hover,
.alerts-panel .alerts-list li.alert-severe:focus-visible {
  background: rgba(251, 146, 60, 0.24);
}
.alerts-panel .alerts-list li.alert-extreme {
  border-left-color: #ef4444;
  background: rgba(239, 68, 68, 0.16);
}
.alerts-panel .alerts-list li.alert-extreme:hover,
.alerts-panel .alerts-list li.alert-extreme:focus-visible {
  background: rgba(239, 68, 68, 0.28);
}

.alerts-panel .alert-icon {
  display: inline-block;
  margin-right: 0.4rem;
  font-size: 0.95rem;
  line-height: 1;
  vertical-align: middle;
}

.alerts-panel .distance {
  display: inline-block;
  opacity: 0.55;
  font-variant-numeric: tabular-nums;
  font-size: 0.75rem;
  margin-right: 0.25rem;
}

.alerts-panel .alert-group {
  padding: 0;
  cursor: default;
  overflow: hidden;
}

.alerts-panel .alert-group > details > summary {
  display: flex;
  gap: 0.45rem;
  align-items: center;
  padding: 0.5rem 0.625rem;
  cursor: pointer;
  list-style: none;
  -webkit-tap-highlight-color: transparent;
}

.alerts-panel .alert-group > details > summary::-webkit-details-marker {
  display: none;
}

.alerts-panel .alert-group-icons {
  display: inline-flex;
  align-items: center;
  margin-right: 0.1rem;
}

.alerts-panel .alert-group-icon {
  width: 1.35rem;
  height: 1.35rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.55);
  border: 1px solid rgba(226, 232, 240, 0.2);
  font-size: 0.8rem;
}

.alerts-panel .alert-group-icon + .alert-group-icon {
  margin-left: -0.35rem;
}

.alerts-panel .alert-group-title {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: 600;
}

.alerts-panel .alert-group-action {
  font-size: 0.7rem;
  opacity: 0.65;
}

.alerts-panel .alert-group > details[open] .alert-group-action {
  opacity: 0;
}

.alerts-panel .alert-group-items {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  padding: 0 0.375rem 0.375rem 0.625rem;
  margin: 0;
}

.alerts-panel .alert-group-items .alert-row {
  font-size: 0.78rem;
  padding: 0.45rem 0.5rem;
  background: rgba(15, 23, 42, 0.28);
}

/* ── Alert detail modal ─────────────────────────────────────────────────
   Mobile-first: full-width bottom sheet that slides up; on larger
   viewports, center as a card with a comfortable max width. */
.alert-modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  animation: backdrop-in 140ms ease-out;
}

@keyframes backdrop-in {
  from { background: rgba(0, 0, 0, 0); }
  to   { background: rgba(0, 0, 0, 0.55); }
}

.alert-modal {
  width: 100%;
  max-height: 88dvh;
  background: #0f172a;
  color: #e2e8f0;
  border-radius: 18px 18px 0 0;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-bottom: 0;
  box-shadow: 0 -16px 48px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
  padding: 1rem 1.25rem max(1.25rem, env(safe-area-inset-bottom));
  animation: sheet-in 200ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

@keyframes sheet-in {
  from { transform: translateY(20%); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}

.alert-modal header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.625rem;
}

.alert-modal .badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
}

.alert-modal .badge {
  display: inline-block;
  padding: 0.25rem 0.625rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  background: rgba(148, 163, 184, 0.18);
  color: #cbd5e1;
}

.alert-modal .badge.severity.minor    { background: rgba(148, 163, 184, 0.22); color: #cbd5e1; }
.alert-modal .badge.severity.moderate { background: rgba(251, 191, 36, 0.22);  color: #fde68a; }
.alert-modal .badge.severity.severe   { background: rgba(251, 146, 60, 0.22);  color: #fed7aa; }
.alert-modal .badge.severity.extreme  { background: rgba(239, 68, 68, 0.22);   color: #fecaca; }

.alert-modal .close {
  flex-shrink: 0;
  appearance: none;
  border: 0;
  background: rgba(148, 163, 184, 0.12);
  color: #e2e8f0;
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 999px;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

.alert-modal .close:hover {
  background: rgba(148, 163, 184, 0.22);
}

.alert-modal h3 {
  font-size: 1.0625rem;
  line-height: 1.3;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.alert-modal .meta {
  font-size: 0.8125rem;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
  margin-bottom: 0.875rem;
}

.alert-modal .description {
  flex: 1 1 auto;
  overflow-y: auto;
  font-size: 0.9rem;
  line-height: 1.5;
  -webkit-overflow-scrolling: touch;
  padding-right: 0.25rem;
}

.alert-modal .description p {
  margin-bottom: 0.625rem;
}

.alert-modal .description p:last-child {
  margin-bottom: 0;
}

.alert-modal .description .empty {
  opacity: 0.55;
  font-style: italic;
}

/* Tablet / desktop: switch to a centred card with rounded corners on every
   side and a dialog-like max width. */
@media (min-width: 640px) {
  .alert-modal-backdrop {
    align-items: center;
  }
  .alert-modal {
    max-width: 32rem;
    max-height: 80dvh;
    border-radius: 18px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    margin: 0 1rem;
  }
}

/* ── Weather-camera markers ─────────────────────────────────────────────
   Small button-shaped markers; large enough for fingers (44 px hit area
   on mobile per the iOS HIG). */
.camera-marker {
  width: 1.875rem;
  height: 1.875rem;
  padding: 0;
  border: 2px solid rgba(15, 23, 42, 0.85);
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.92);
  color: #0f172a;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  -webkit-tap-highlight-color: transparent;
  transition: transform 120ms ease, background 120ms ease;
}

.camera-marker:hover,
.camera-marker:focus-visible {
  background: rgba(125, 211, 252, 0.95);
  transform: scale(1.1);
  outline: none;
}

.camera-marker:active {
  transform: scale(0.95);
}

/* Camera modal preset grid: stacked single column on mobile, two-up on
   wider viewports. */
.camera-modal .camera-presets {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.625rem;
  padding-right: 0.25rem;
}

.camera-modal .camera-preset {
  margin: 0;
}

.camera-modal .camera-preset img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 8px;
  background: rgba(148, 163, 184, 0.08);
  aspect-ratio: 16 / 9;
  object-fit: cover;
}

.camera-modal .camera-preset figcaption {
  font-size: 0.7rem;
  opacity: 0.55;
  margin-top: 0.25rem;
  font-variant-numeric: tabular-nums;
}

@media (min-width: 640px) {
  .camera-modal .camera-presets {
    grid-template-columns: repeat(2, 1fr);
  }
}

.alerts-panel .placeholder,
.alerts-panel .error {
  font-size: 0.8125rem;
  opacity: 0.6;
}

.alerts-panel .error {
  color: #fca5a5;
  opacity: 1;
}

.locate-btn {
  position: absolute;
  bottom: max(1.5rem, env(safe-area-inset-bottom));
  right: max(1.5rem, env(safe-area-inset-right));
  background: #fb923c;
  color: #0f172a;
  border: 0;
  padding: 0.875rem 1.5rem;
  border-radius: 999px;
  font-weight: 600;
  font-size: 0.9375rem;
  cursor: pointer;
  box-shadow: 0 6px 20px rgba(251, 146, 60, 0.4);
  z-index: 10;
  transition:
    background 120ms ease,
    transform 120ms ease;
}

.locate-btn:hover {
  background: #fdba74;
}

.locate-btn:active {
  transform: scale(0.97);
}

.locate-btn[disabled] {
  background: #475569;
  color: #cbd5e1;
  cursor: not-allowed;
  box-shadow: none;
}

.attribution {
  position: absolute;
  bottom: 0.5rem;
  left: 0.75rem;
  font-size: 0.6875rem;
  opacity: 0.55;
  z-index: 5;
  pointer-events: none;
}

/* Sprint 6: AI-linked news + police bulletins inside the alert modal. */
.alert-links {
  margin-top: 1rem;
  border-top: 1px solid rgba(148, 163, 184, 0.25);
  padding-top: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.alert-links-section > summary {
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: #cbd5e1;
  list-style: none;
}

.alert-links-section > summary::-webkit-details-marker {
  display: none;
}

.alert-links-section[open] > summary {
  margin-bottom: 0.5rem;
}

.alert-links-section ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.alert-link a {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 0.5rem;
  row-gap: 0.125rem;
  text-decoration: none;
  color: inherit;
  padding: 0.5rem 0.625rem;
  border-radius: 0.5rem;
  background: rgba(30, 41, 59, 0.55);
  border: 1px solid rgba(148, 163, 184, 0.2);
  transition: background 120ms ease;
}

.alert-link a:hover,
.alert-link a:focus-visible {
  background: rgba(51, 65, 85, 0.75);
  outline: none;
}

.alert-link-source {
  grid-row: 1 / 3;
  align-self: center;
  font-size: 0.6875rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  white-space: nowrap;
}

.alert-link-title {
  font-size: 0.9375rem;
  font-weight: 500;
  color: #e2e8f0;
  line-height: 1.3;
}

.alert-link-meta {
  font-size: 0.75rem;
  color: #94a3b8;
}

/* Sprint 6: Point-alert markers (peto-media et al). Same hit-area envelope
   as the camera markers; emoji icon picked per category in map-init.js. */
.alert-marker {
  width: 1.875rem;
  height: 1.875rem;
  padding: 0;
  border: 2px solid rgba(15, 23, 42, 0.85);
  border-radius: 999px;
  background: rgba(148, 163, 184, 0.92);
  color: #0f172a;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  -webkit-tap-highlight-color: transparent;
  transition: transform 120ms ease, filter 120ms ease;
}

.alert-marker:hover,
.alert-marker:focus-visible {
  transform: scale(1.15);
  filter: brightness(1.1);
  outline: none;
}

.alert-marker:active {
  transform: scale(0.95);
}

.alert-marker-cluster {
  position: relative;
  width: 2.45rem;
  height: 2.05rem;
  border-radius: 0.75rem;
  gap: 0.15rem;
  font-weight: 700;
}

.alert-marker-cluster::before,
.alert-marker-cluster::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  border: 2px solid rgba(15, 23, 42, 0.75);
  background: inherit;
  z-index: -1;
}

.alert-marker-cluster::before {
  transform: translate(4px, 4px);
  opacity: 0.65;
}

.alert-marker-cluster::after {
  transform: translate(8px, 8px);
  opacity: 0.35;
}

.alert-marker-cluster-icons {
  display: inline-flex;
  align-items: center;
  font-size: 0.75rem;
  letter-spacing: -0.25rem;
  transform: translateX(-0.1rem);
}

.alert-marker-count {
  min-width: 1rem;
  height: 1rem;
  padding: 0 0.25rem;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.86);
  color: #f8fafc;
  font-size: 0.65rem;
  line-height: 1rem;
  font-variant-numeric: tabular-nums;
}

.alert-cluster-popup {
  color: #e2e8f0;
  font-family: inherit;
}

.alert-cluster-popup-shell .maplibregl-popup-content {
  background: rgba(15, 23, 42, 0.96);
  border: 1px solid rgba(148, 163, 184, 0.25);
  border-radius: 0.85rem;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.45);
  padding: 0.75rem;
}
.alert-cluster-popup-shell .maplibregl-popup-close-button {
  color: #cbd5e1;
  font-size: 1rem;
  padding: 0.25rem 0.45rem;
}

.alert-cluster-popup-heading {
  font-size: 0.78rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.alert-cluster-popup-list {
  max-height: 14rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.alert-cluster-popup-item {
  width: 100%;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.45rem;
  align-items: start;
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-left: 4px solid #94a3b8;
  border-radius: 0.45rem;
  background: rgba(30, 41, 59, 0.75);
  color: inherit;
  padding: 0.45rem 0.5rem;
  text-align: left;
  cursor: pointer;
}

.alert-cluster-popup-item:hover,
.alert-cluster-popup-item:focus-visible {
  background: rgba(51, 65, 85, 0.9);
  outline: none;
}

.alert-cluster-popup-item.alert-marker-sev-moderate {
  border-left-color: #fbbf24;
}

.alert-cluster-popup-item.alert-marker-sev-severe {
  border-left-color: #fb923c;
}

.alert-cluster-popup-item.alert-marker-sev-extreme {
  border-left-color: #ef4444;
}

.alert-cluster-popup-icon {
  line-height: 1;
}

.alert-cluster-popup-title {
  font-size: 0.76rem;
  line-height: 1.25;
}

.alert-cluster-popup-more {
  font-size: 0.72rem;
  color: #94a3b8;
  padding: 0.25rem 0.2rem 0;
}

/* The map-init.js sets background-color inline per category; the
   per-class hooks below let us tune the emoji size or border independently
   if a particular icon needs more contrast. */
.alert-marker-fire,
.alert-marker-traffic_accident {
  border-color: rgba(255, 255, 255, 0.95);
}

/* ── Mobile compaction ────────────────────────────────────────────────
   Mobiilissa sääpaneeli kutistuu yhden rivin yläpalkiksi ja varoituslista
   on oletuksena suljettu. Desktop (>= 640px) ei näe näitä muutoksia. */
@media (max-width: 639px) {
  .weather-panel {
    padding: 0.5rem 0.75rem;
    border-radius: 12px;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    flex-wrap: nowrap;
    max-width: none;
  }

  .weather-panel header {
    margin: 0;
    flex: 0 0 auto;
    align-items: center;
    gap: 0.4rem;
  }

  .weather-panel h2 {
    font-size: 0.65rem;
  }

  .weather-panel time {
    display: none;
  }

  .weather-panel .temp {
    font-size: 1.25rem;
    font-weight: 500;
    line-height: 1;
    flex: 0 0 auto;
  }

  .weather-panel .meta {
    margin: 0;
    gap: 0.6rem;
    font-size: 0.7rem;
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .weather-panel .meta strong {
    font-weight: 500;
    opacity: 0.6;
  }

  .weather-panel .placeholder,
  .weather-panel .error {
    padding: 0;
    font-size: 0.75rem;
    flex: 1 1 auto;
  }

  /* Sijaintivirhe omalle riville, ei riko yhden rivin layoutia. */
  .weather-panel > .error {
    flex-basis: 100%;
    margin-top: 0.25rem;
  }

  /* Varoituspaneeli näytetään lähelle sääpalkkia, koska se on nyt matalampi. */
  .alerts-panel {
    top: calc(max(1rem, env(safe-area-inset-top)) + 3.25rem);
    right: max(1rem, env(safe-area-inset-right));
    max-width: none;
    padding: 0.5rem 0.75rem;
  }

  .alerts-panel.is-collapsed .alerts-body {
    display: none;
  }

  .alerts-panel:not(.is-collapsed) .alerts-body {
    margin-top: 0.5rem;
  }

  /* Avattuna lista on rajatun pituinen ja vierittyy. */
  .alerts-panel:not(.is-collapsed) .alerts-list {
    max-height: min(45dvh, 22rem);
  }
}

/* Desktop ja sitä isommat: piilota toggle-indikaattori ja varmista, että
   varoituslista on aina näkyvissä collapsed-tilasta riippumatta. */
@media (min-width: 640px) {
  .alerts-panel .alerts-toggle {
    cursor: default;
  }

  .alerts-panel .alerts-toggle-indicator {
    display: none;
  }

  .alerts-panel.is-collapsed .alerts-body {
    display: block;
  }
}
