/* Weather225 Live Regional Alerts - V3 (matches the SPC risk maps) */

:root {
  /* Brand */
  --navy: #102252;
  --navy-2: #1A2F6B;
  --paper: #F4F6FA;
  /* Map console */
  --ink: #0C1015;
  --panel: #141A22;
  --panel-2: #1A212B;
  --border: #2B3542;
  --fg: #E9EDF2;
  --muted: #8D98A7;
  --focus: #7FA6FF;
  /* Type */
  --display: "Barlow Condensed", "Arial Narrow", system-ui, sans-serif;
  --body: "Barlow", system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, Menlo, Consolas, monospace;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ink);
  color: var(--fg);
  font-family: var(--body);
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

button:focus-visible, input:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Header (HTML version of the banner) ---------- */

.brand {
  flex: 0 0 auto;
  border-bottom: 1px solid var(--navy-2);
}

.brand .bar {
  background: var(--navy);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  padding: 8px max(16px, env(safe-area-inset-right, 0px)) 8px max(16px, env(safe-area-inset-left, 0px));
  min-height: 56px;
}

.brand h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(26px, 4.2vw, 48px);
  line-height: 1;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: #fff;
  text-wrap: balance;
  text-align: center;
}

.live {
  position: absolute;
  right: max(16px, env(safe-area-inset-right, 0px));
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: #B9C6E6;
}

.pulse {
  width: 9px; height: 9px; border-radius: 50%;
  background: #3FCB03;
  box-shadow: 0 0 0 0 rgba(63, 203, 3, .6);
}
.live.is-stale .pulse { background: #FFDE59; }
.live.is-error .pulse { background: #FF4D4D; }

@media (prefers-reduced-motion: no-preference) {
  .pulse { animation: pulse 2s infinite; }
  @keyframes pulse {
    0% { box-shadow: 0 0 0 0 rgba(63, 203, 3, .55); }
    70% { box-shadow: 0 0 0 8px rgba(63, 203, 3, 0); }
    100% { box-shadow: 0 0 0 0 rgba(63, 203, 3, 0); }
  }
}

.stripe {
  background: var(--paper);
  display: grid;
  grid-template-columns: minmax(16px, 1fr) auto minmax(16px, 1fr);
  align-items: center;
  gap: 12px;
  padding: 5px 12px;
}

.hatch {
  height: 14px;
  background: repeating-linear-gradient(-65deg, var(--navy) 0 5px, transparent 5px 14px);
}

.legend {
  display: flex;
  align-items: center;
  gap: 6px 14px;
  overflow-x: auto;
  scrollbar-width: none;
  min-width: 0;
}
.legend::-webkit-scrollbar { display: none; }

.lg-group { display: flex; align-items: center; gap: 5px; flex: 0 0 auto; }

.lg-title {
  font-family: var(--body);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #111;
  margin-right: 4px;
}

.chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 7px;
  border: 0;
  border-radius: 1px;
  font-family: var(--body);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: .02em;
  text-transform: uppercase;
  color: #111;
  white-space: nowrap;
  cursor: pointer;
}
.chip.light-text { color: #fff; }
.chip.is-watch { box-shadow: inset 0 0 0 2px rgba(16, 34, 82, .55); }
.chip[aria-pressed="false"] {
  background: #D5DAE3 !important;
  color: #7A8496;
  text-decoration: line-through;
  box-shadow: none;
}
.chip .n {
  min-width: 17px;
  padding: 0 4px;
  border-radius: 9px;
  background: var(--navy);
  color: #fff;
  font-size: 11px;
  line-height: 17px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ---------- Map ---------- */

.map-wrap { position: relative; flex: 1 1 auto; min-height: 0; }
#map { position: absolute; inset: 0; background: #11161D; }

.leaflet-container { font-family: var(--body); background: #11161D; }
.leaflet-control-zoom a { background: rgba(20, 26, 34, .92); color: var(--fg); border-color: var(--border) !important; }
.leaflet-control-zoom a:hover { background: var(--panel-2); color: #fff; }
.leaflet-control-attribution { background: rgba(12, 16, 21, .7) !important; color: var(--muted); font-size: 10px; }
.leaflet-control-attribution a { color: #B9C6E6; }

/* ---------- Town labels (navy chips, like the risk map) ---------- */

.town { background: transparent; border: 0; pointer-events: none; }
.town.is-hidden, .towns-off .town { visibility: hidden; }

.town .dot {
  position: absolute;
  width: 7px; height: 7px;
  margin: -3.5px 0 0 -3.5px;
  border-radius: 50%;
  background: #fff;
  border: 1.5px solid #0A0D12;
}

.town .name {
  position: absolute;
  bottom: 6px;
  left: 0;
  transform: translateX(-50%);
  padding: 2px 6px 1px;
  white-space: nowrap;
  background: var(--navy);
  border: 1px solid rgba(255, 255, 255, .28);
  border-radius: 2px;
  font-family: var(--body);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .5);
}

/* ---------- Floating panel ---------- */

.status-card {
  position: absolute;
  top: 12px;
  right: max(12px, env(safe-area-inset-right, 0px));
  z-index: 1000;
  width: 330px;
  max-height: calc(100% - 24px);
  overflow-y: auto;
  padding: 14px 16px 12px;
  background: rgba(20, 26, 34, .95);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, .5);
}

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.count-block { display: flex; align-items: center; gap: 12px; min-width: 0; }

.alert-count {
  min-width: 46px;
  font-family: var(--display);
  font-size: 48px;
  font-weight: 700;
  line-height: .9;
  font-variant-numeric: tabular-nums;
  color: #fff;
}
.alert-count.has-alerts { color: #FFDE59; }

.count-text { display: flex; flex-direction: column; min-width: 0; }
.count-label {
  font-family: var(--display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: .04em;
  text-transform: uppercase;
  line-height: 1.05;
}
.count-sub { font-size: 12.5px; color: var(--muted); }

.icon-btn {
  flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; padding: 0;
  border: 1px solid var(--border); border-radius: 6px;
  background: transparent; color: var(--fg); cursor: pointer;
}
.icon-btn:hover { background: var(--panel-2); }
.icon-btn svg { transition: transform .15s ease; }
.status-card.collapsed .icon-btn svg { transform: rotate(180deg); }

.card-body { margin-top: 12px; }
.status-card.collapsed .card-body { display: none; }

/* Alert list */
.alert-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.alert-list:empty { display: none; }

.alert-item {
  display: grid;
  grid-template-columns: 6px minmax(0, 1fr);
  gap: 10px;
  width: 100%;
  padding: 8px 10px 8px 0;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg);
  text-align: left;
  font: inherit;
  cursor: pointer;
  overflow: hidden;
}
.alert-item:hover { border-color: #46525F; background: #1F2733; }
.alert-item .bar { align-self: stretch; margin: -8px 0; }
.alert-item.is-watch .bar { background-image: repeating-linear-gradient(180deg, transparent 0 4px, rgba(12,16,21,.55) 4px 7px); }
.alert-item b {
  display: block;
  font-family: var(--display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: .03em;
  text-transform: uppercase;
  line-height: 1.1;
}
.alert-item .where { display: block; font-size: 13px; color: #C3CCD8; margin-top: 2px; }
.alert-item .until { display: block; font-family: var(--mono); font-size: 11.5px; color: var(--muted); margin-top: 3px; }

.status-msg { margin: 0; font-size: 13px; line-height: 1.4; color: var(--muted); }
.status-msg:empty { display: none; }
.status-msg.is-error { color: #FF9B8F; }
.status-msg.is-warn { color: #FFD37A; }
.status-msg.is-calm {
  padding: 10px 12px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  color: #C3CCD8;
}

.meta { margin: 12px 0 0; padding: 0; }
.meta-row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 5px 0; border-top: 1px solid var(--border); font-size: 13px;
}
.meta-row dt { color: var(--muted); }
.meta-row dd { margin: 0; text-align: right; font-family: var(--mono); font-size: 12px; font-variant-numeric: tabular-nums; }

.actions { display: flex; gap: 8px; margin-top: 12px; }
.btn {
  flex: 1 1 0;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--fg);
  font: inherit; font-size: 14px; font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--panel-2); }
.btn-primary { background: var(--fg); border-color: var(--fg); color: var(--ink); }
.btn-primary:hover { background: #fff; }
.btn[disabled] { opacity: .6; cursor: progress; }

.group { margin-top: 14px; }
.group h2 {
  margin: 0 0 6px;
  font-family: var(--display);
  font-weight: 600;
  font-size: 13px;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.segmented { display: flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.segmented button {
  flex: 1 1 0; padding: 8px 6px; border: 0;
  background: transparent; color: var(--muted);
  font-family: var(--display); font-weight: 600; font-size: 15px; letter-spacing: .05em; text-transform: uppercase;
  cursor: pointer;
}
.segmented button + button { border-left: 1px solid var(--border); }
.segmented button:hover { color: var(--fg); }
.segmented button[aria-pressed="true"] { background: var(--fg); color: var(--ink); }

.toggles { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: #B9C6E6; cursor: pointer; }

.foot {
  margin: 12px 0 0; padding-top: 8px;
  border-top: 1px solid var(--border);
  font-size: 12px; line-height: 1.4; color: var(--muted);
}

/* ---------- Popups ---------- */

.w225-popup .leaflet-popup-content-wrapper {
  padding: 0; overflow: hidden;
  border-radius: 8px;
  background: var(--panel);
  color: var(--fg);
  border: 1px solid var(--border);
}
.w225-popup .leaflet-popup-tip { background: var(--panel); }
.w225-popup .leaflet-popup-content { margin: 0; font-size: 13.5px; line-height: 1.45; }
.w225-popup a.leaflet-popup-close-button { color: #fff; }

.pop-head { padding: 10px 34px 9px 14px; border-left: 6px solid; background: var(--navy); color: #fff; }
.pop-event {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: .03em;
  text-transform: uppercase;
  line-height: 1.1;
}
.pop-tag {
  display: inline-block; margin-top: 4px; padding: 1px 7px;
  font-size: 11.5px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  color: #111;
}
.pop-body { padding: 10px 14px 12px; }
.pop-body p { margin: 0 0 8px; }
.pop-label {
  display: block;
  font-family: var(--display); font-weight: 600; font-size: 12.5px;
  letter-spacing: .08em; text-transform: uppercase; color: var(--muted);
}
.pop-desc {
  max-height: 150px; overflow-y: auto;
  padding: 8px 10px; border-radius: 6px;
  background: var(--panel-2);
  white-space: pre-line; font-size: 12.5px;
}
.pop-link { display: inline-block; margin-top: 4px; font-weight: 600; color: var(--focus); }

/* ---------- Mobile ---------- */

@media (max-width: 760px) {
  .brand .bar { flex-direction: column; gap: 4px; min-height: 0; padding-block: 8px 6px; }
  .live { position: static; transform: none; }
  .stripe { grid-template-columns: 10px minmax(0, 1fr) 10px; gap: 8px; padding-inline: 6px; }
}

@media (max-width: 640px) {
  .status-card {
    top: auto;
    right: calc(8px + env(safe-area-inset-right, 0px));
    left: calc(8px + env(safe-area-inset-left, 0px));
    bottom: calc(22px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-height: 62%;
    padding: 10px 12px;
  }
  .alert-count { font-size: 38px; min-width: 34px; }
  .foot { display: none; }
  .leaflet-control-zoom { display: none; }
  .town .name { font-size: 10.5px; padding: 1px 5px 0; }
}

@media (pointer: coarse) {
  .btn, .segmented button { min-height: 44px; }
  .icon-btn { width: 44px; height: 44px; }
  .chip { padding-block: 6px; }
}

@media (prefers-reduced-motion: reduce) {
  .icon-btn svg { transition: none; }
}
