/* Rut Bot Weather — web app styles. Mobile-first, dark command-center. */
:root {
  --bg: #0a0e14;
  --panel: #11161f;
  --panel-2: #161d29;
  --border: #232c3d;
  --red: #e63946;
  --red-dark: #a52833;
  --orange: #f4842b;
  --green: #2ecc71;
  --yellow: #ffd166;
  --text: #e8ecf1;
  --muted: #9aa4b2;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
  position: relative;
  max-width: 760px;
  margin: 0 auto;
}

/* ---------- Header ---------- */
#brandbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  z-index: 30;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 34px; height: 34px; flex: 0 0 auto; }
.brand-text { min-width: 0; }
#site-title {
  margin: 0;
  font-size: 18px;
  letter-spacing: 1.5px;
  font-weight: 800;
  white-space: nowrap;
}
#tagline {
  margin: 2px 0 0;
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Storm watch mode: header flips when a tornado warning is active */
#brandbar.stormwatch { border-bottom: 2px solid var(--red); }
#brandbar.stormwatch #site-title {
  color: #fff;
  background: var(--red);
  padding: 2px 8px;
  border-radius: 4px;
  animation: pulse-red 1.6s ease-in-out infinite;
}
@keyframes pulse-red {
  0%, 100% { background: var(--red); }
  50% { background: var(--red-dark); }
}

#live-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--muted);
  flex: 0 0 auto;
}
#live-badge .dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: #555;
}
#live-badge.live-on { color: var(--text); }
#live-badge.live-on .dot {
  background: var(--red);
  animation: blink 1.6s ease-in-out infinite;
}
@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* ---------- Views & tab bar ---------- */
#views {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
.view {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: none;
  padding: 12px 12px 20px;
}
.view.active { display: block; }
#view-radar { padding: 0; overflow: hidden; }

#tabbar {
  flex: 0 0 auto;
  display: flex;
  background: var(--panel);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 30;
}
#tabbar button {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 8px 2px 6px;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
  cursor: pointer;
}
#tabbar button svg { width: 24px; height: 24px; }
#tabbar button.active { color: var(--red); }
#tabbar button:active { background: var(--panel-2); }

/* ---------- Shared bits ---------- */
.sec-title {
  font-size: 14px;
  letter-spacing: 1px;
  margin: 18px 2px 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.sec-ic { color: var(--red); }
.loading, .empty { color: var(--muted); font-size: 14px; text-align: center; padding: 14px; }
.err { color: var(--orange); font-size: 14px; text-align: center; padding: 14px; }
.src { font-size: 11px; color: var(--muted); text-align: center; margin: 14px 0 4px; }
.est { font-size: 11px; color: var(--muted); font-style: italic; margin: 6px 0 0; }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
.card-title { font-weight: 800; letter-spacing: 1px; font-size: 13px; margin-bottom: 8px; }
.card-text { font-size: 14px; margin: 0; line-height: 1.5; white-space: pre-line; }

/* ---------- Home ---------- */
.loc-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 4px 2px 10px;
  font-size: 15px;
}
#home-loc { font-weight: 700; flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#home-locate {
  font-size: 12px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
}
#home-locate:active { background: #1c2432; }

#home-search { position: relative; margin-bottom: 12px; }
#home-search-input {
  width: 100%;
  height: 44px;
  padding: 0 14px;
  font-size: 16px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
#home-search-input::placeholder { color: var(--muted); }
#home-search-input:focus { outline: 2px solid var(--red); border-color: var(--red); }
#home-search-results {
  position: absolute;
  top: 50px; left: 0; right: 0;
  margin: 0; padding: 0;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 21;
}
#home-search-results li button {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
#home-search-results li:last-child button { border-bottom: none; }

.now-card { text-align: center; padding: 10px 0 4px; }
.big-temp { font-size: 84px; font-weight: 800; line-height: 1; letter-spacing: -2px; }
.feels { font-size: 17px; color: var(--text); margin-top: 6px; }
.hilo { font-size: 15px; color: var(--muted); margin-top: 4px; }

.stat-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 16px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 4px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.stat-ic { font-size: 20px; }
.stat-label { font-size: 10px; color: var(--muted); }
.stat-val { font-size: 14px; font-weight: 700; }
.stat-sub { font-size: 10px; color: var(--green); }

.hstrip {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
}
.hcell {
  flex: 0 0 64px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 4px;
  text-align: center;
  font-size: 13px;
}
.hcell .hh { color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.hcell .ht { font-weight: 800; font-size: 16px; margin: 4px 0; }
.hcell .hp { color: var(--muted); font-size: 11px; }
.hcell.now { border-color: var(--red); }
.hcell.now .hh { color: var(--red); font-weight: 700; }

.dlist { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.drow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.drow:last-child { border-bottom: none; }
.drow .dd { flex: 0 0 52px; font-weight: 600; }
.drow .di { flex: 0 0 30px; text-align: center; font-size: 18px; }
.drow .ds { flex: 1 1 auto; color: var(--muted); font-size: 12px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.drow .dt { font-weight: 700; white-space: nowrap; }
.drow .dt .lo { color: var(--muted); font-weight: 400; }

.says {
  margin-top: 16px;
  background: var(--panel);
  border: 1px solid var(--red-dark);
  border-top: 3px solid var(--red);
  border-radius: var(--radius);
  padding: 14px;
}
.says-head { color: var(--red); font-weight: 800; letter-spacing: 1px; font-size: 13px; margin-bottom: 6px; display: flex; align-items: center; gap: 8px; }
.bot-face { font-size: 20px; }
.says p { margin: 0; font-size: 15px; line-height: 1.5; }

/* ---------- Radar tab ---------- */
#radar-banner {
  display: block;
  width: calc(100% - 24px);
  margin: 10px 12px 0;
  padding: 12px 14px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.5px;
  cursor: pointer;
  text-align: left;
  z-index: 26;
  position: relative;
}
#radar-banner .rb-sub { display: block; font-size: 11px; font-weight: 400; opacity: 0.9; margin-top: 2px; }

#map-wrap {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
}
#view-radar.has-banner #map-wrap { top: 64px; }
#map { position: absolute; inset: 0; }

#searchbar {
  position: absolute;
  top: 10px; left: 12px; right: 12px;
  display: flex;
  gap: 8px;
  z-index: 20;
}
#search-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  font-size: 16px;
  color: var(--text);
  background: rgba(17, 22, 31, 0.94);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
#search-input::placeholder { color: var(--muted); }
#search-input:focus { outline: 2px solid var(--red); border-color: var(--red); }

#locate-btn {
  flex: 0 0 44px;
  height: 44px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: rgba(17, 22, 31, 0.94);
  color: var(--text);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
#locate-btn:active { background: var(--panel-2); }

#search-results {
  position: absolute;
  top: 50px; left: 0; right: 52px;
  margin: 0; padding: 0;
  list-style: none;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  z-index: 21;
}
#search-results li button {
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text);
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
#search-results li:last-child button { border-bottom: none; }
#search-results li button:active { background: var(--panel-2); }

#map-controls {
  position: absolute;
  right: 12px;
  bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 20;
}
#map-controls button {
  width: 46px; height: 46px;
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
  background: rgba(17, 22, 31, 0.94);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  line-height: 1;
}
#map-controls button:active { background: var(--panel-2); }
#play-pause.paused { color: var(--orange); border-color: var(--orange); }
#basemap-toggle { font-size: 13px; letter-spacing: 1px; }
#basemap-toggle.sat-on { color: var(--green); border-color: var(--green); }

#radar-legend {
  position: absolute;
  left: 12px;
  bottom: 14px;
  z-index: 20;
  background: rgba(17, 22, 31, 0.85);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 11px;
  color: var(--muted);
}
#radar-legend .legend-title { font-weight: 800; color: var(--text); letter-spacing: 1px; margin-right: 6px; }
.legend-loop { color: var(--green); margin-left: 6px; font-weight: 700; }

/* ---------- Storms ---------- */
.meter-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 8px; }
.meter-title { font-weight: 800; letter-spacing: 1px; font-size: 13px; }
.meter-num { font-size: 30px; font-weight: 800; color: var(--red); }
.meter-bar {
  height: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--green), var(--yellow) 40%, var(--orange) 70%, var(--red));
  transition: width 0.6s ease;
}
.meter-label { font-size: 15px; font-weight: 700; margin-top: 8px; }
.meter-line { font-size: 14px; color: var(--muted); margin: 6px 0 0; line-height: 1.5; }
.meter-sub { font-size: 12px; color: var(--muted); margin: 8px 0 0; }

.storm-list { margin: 0; padding: 0; list-style: none; }
.storm-list li { margin-bottom: 10px; }
.storm-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 14px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-left: 5px solid var(--muted);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
}
.storm-item:active { background: var(--panel-2); }
.storm-item .evt { font-weight: 800; display: block; font-size: 15px; }
.storm-item .area { color: var(--muted); display: block; font-size: 13px; margin-top: 3px; }
.storm-item .timing { color: var(--muted); display: block; font-size: 12px; margin-top: 3px; }
.storm-item.sev-tornado { border-left-color: var(--red); }
.storm-item.sev-thunder { border-left-color: var(--orange); }
.storm-item.sev-flood { border-left-color: var(--green); }
.storm-item.sev-watch { border-left-color: var(--yellow); }

/* ---------- Chat ---------- */
#view-rutbot { display: none; flex-direction: column; }
#view-rutbot.active { display: flex; }
#chat-log {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 2px 10px;
  min-height: 0;
}
.msg {
  max-width: 85%;
  padding: 10px 13px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.45;
  white-space: pre-line;
}
.msg.bot {
  align-self: flex-start;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg.user {
  align-self: flex-end;
  background: var(--red-dark);
  border-bottom-right-radius: 4px;
}
#chat-chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 6px 2px 10px;
  flex: 0 0 auto;
}
#chat-chips button {
  flex: 0 0 auto;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 18px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
}
#chat-chips button:active { border-color: var(--red); }
#chat-form {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
  padding-bottom: 4px;
}
#chat-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 44px;
  padding: 0 14px;
  font-size: 16px;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
}
#chat-input:focus { outline: 2px solid var(--red); border-color: var(--red); }
#chat-form button {
  flex: 0 0 auto;
  height: 44px;
  padding: 0 20px;
  border-radius: 22px;
  border: none;
  background: var(--red);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
#chat-form button:active { background: var(--red-dark); }

/* ---------- Alert detail card ---------- */
#alert-detail {
  position: absolute;
  left: 12px; right: 12px;
  bottom: 76px;
  z-index: 40;
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 4px solid var(--red);
  border-radius: var(--radius);
  padding: 16px;
  max-height: 60dvh;
  overflow-y: auto;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.6);
}
#detail-close {
  position: absolute;
  top: 6px; right: 10px;
  font-size: 28px;
  background: none; border: none;
  color: var(--muted);
  cursor: pointer;
  padding: 6px;
}
#alert-detail h2 { margin: 0 34px 6px 0; font-size: 17px; }
#detail-headline { color: var(--muted); font-size: 13px; margin: 0 0 10px; }
#alert-detail dl { margin: 0; font-size: 14px; }
#alert-detail dl > div { margin-bottom: 8px; }
#alert-detail dt { font-weight: 700; color: var(--orange); font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }
#alert-detail dd { margin: 2px 0 0; white-space: pre-line; }
.detail-src { font-size: 11px; color: var(--muted); margin: 10px 0 0; }

/* ---------- Toast ---------- */
#toast {
  position: absolute;
  top: 70px; left: 50%;
  transform: translateX(-50%);
  z-index: 50;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  max-width: 90%;
  text-align: center;
}

/* ---------- Footer ---------- */
#attrib {
  flex: 0 0 auto;
  font-size: 10px;
  color: var(--muted);
  text-align: center;
  padding: 5px 8px;
  background: var(--bg);
  border-top: 1px solid var(--border);
  z-index: 30;
}

/* MapLibre tweaks */
.maplibregl-ctrl-attrib { font-size: 10px; }
.maplibregl-ctrl-attrib a { color: var(--muted); }
.locate-marker { pointer-events: none; }
