/* ═══════════════════════════════════════════════════════════
   RCG — Fully Responsive Mobile CSS  v2
   Breakpoints:
     xs  : 0–479px   (small phones)
     sm  : 480–767px (large phones / small tablet portrait)
     md  : 768–1023px (tablet portrait / landscape phone)
     lg  : 1024–1279px (tablet landscape / small laptop)
   ═══════════════════════════════════════════════════════════ */

/* ══ 0. GLOBAL RESETS (all < 1280) ════════════════════════ */
html { min-width: 0 !important; }
body {
  min-width: 0 !important;
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}
#app-shell { min-width: 0 !important; }

/* Prevent horizontal overflow everywhere */
*, *::before, *::after { max-width: 100%; }
img, video, canvas { max-width: 100%; }

/* Better tap targets */
button, a, [onclick] {
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

/* ══ 1. CSS CUSTOM PROPERTIES — mobile overrides ══════════ */
:root {
  --hh: 52px;
  --bot-nav-h: 62px;
}

/* ══ 2. HEADER ══════════════════════════════════════════════ */
.header {
  height: var(--hh);
  padding: 0 14px;
  gap: 8px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
}

.header-brand { gap: 8px; }
.logo-circle { width: 32px; height: 32px; flex-shrink: 0; }
.wordmark { font-size: 13px; }
.view-crumb { display: none; }

.header-center { gap: 6px; }
#clockTime { font-size: 13px; letter-spacing: .02em; }
#clockDate { display: none; }
.status-chip { font-size: 10px; }
.dot { width: 6px; height: 6px; }

.header-actions { gap: 4px; }
.tsw { padding: 2px; gap: 1px; }
.tb { padding: 3px 7px; font-size: 10px; }

/* ══ 3. INTRO / LANDING PAGE ════════════════════════════════ */
#introView { position: fixed; inset: 0; overflow: hidden; }

.intro-content {
  height: 100dvh;
  height: 100vh; /* fallback */
  padding: 56px 18px 90px;
  gap: 0;
  justify-content: flex-start;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
  align-items: center;
  text-align: center;
}

.intro-badge {
  font-size: 10px;
  padding: 4px 12px;
  margin-bottom: 14px;
  letter-spacing: .06em;
}

.intro-logo-wrap {
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 10px;
}

.intro-logo-circle {
  width: 56px;
  height: 56px;
  border-width: 2px;
}

.intro-wordmark {
  font-size: clamp(30px, 9vw, 52px) !important;
}

.intro-fullname {
  font-size: 10px;
  letter-spacing: .12em;
  margin-bottom: 10px;
}

.intro-headline {
  font-size: clamp(14px, 4vw, 20px) !important;
  line-height: 1.45;
  margin-bottom: 8px;
  max-width: 100%;
}

.intro-sub {
  font-size: 12.5px;
  line-height: 1.65;
  margin-bottom: 18px;
  max-width: 100%;
}

/* Pillars: responsive grid */
.intro-pillars {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin-bottom: 18px;
  width: 100%;
}

.pillar {
  padding: 9px 10px;
  font-size: 11px;
  border-radius: 8px;
  justify-content: flex-start;
  text-align: left;
}
.pillar-icon { font-size: 15px; flex-shrink: 0; }

/* CTAs — full width stacked */
.intro-cta-row {
  flex-direction: column;
  gap: 9px;
  width: 100%;
  align-items: stretch;
}

.intro-enter {
  width: 100%;
  font-size: 14px;
  padding: 14px 20px;
  border-radius: 12px;
  justify-content: center;
  letter-spacing: .02em;
}

.intro-secondary {
  width: 100%;
  font-size: 13px;
  padding: 12px 20px;
  border-radius: 12px;
  justify-content: center;
  text-align: center;
}

/* Mascot — hide on very small screens, small on medium */
#mascotGuide {
  bottom: 90px;
  right: 10px;
  gap: 6px;
  z-index: 2100;
}

.mascot-bubble {
  max-width: 200px;
  font-size: 11.5px;
  padding: 9px 11px;
  border-radius: 12px 12px 3px 12px;
}

.bubble-actions { gap: 5px; margin-top: 8px; }
.bubble-btn { font-size: 10px; padding: 3px 8px; }

.mascot-avatar {
  width: 50px;
  height: 50px;
  cursor: pointer;
}

/* Social footer */
.intro-social-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  gap: 8px;
  padding: 10px 16px 14px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
}

.intro-social-label {
  font-size: 9.5px;
  width: 100%;
  text-align: center;
  letter-spacing: .08em;
}

.intro-social-link { font-size: 12px; gap: 5px; }
.social-icon { width: 13px; height: 13px; }

/* ══ 4. PUBLIC MAP VIEW ══════════════════════════════════════ */
#publicView {
  padding-top: var(--hh);
  min-height: 100dvh;
  min-height: 100vh;
}

.map-shell {
  margin: 8px;
  border-radius: 12px;
  height: calc(100dvh - var(--hh) - 16px) !important;
  height: calc(100vh - var(--hh) - 16px) !important;
}

#map { border-radius: 12px; }

/* Map controls — thumb-friendly positions */
.tile-bar {
  position: absolute;
  top: 12px;
  right: 12px;
  bottom: auto;
  left: auto;
  flex-direction: row;
  gap: 2px;
  border-radius: 8px;
}

.tile-btn {
  font-size: 10px;
  padding: 6px 10px;
  border-radius: 6px;
}

.map-leg {
  position: absolute;
  bottom: 14px;
  left: 12px;
  padding: 8px 11px;
  border-radius: 9px;
}

.leg-hd { font-size: 9px; margin-bottom: 5px; }
.leg-row { font-size: 10px; margin-bottom: 2px; }
.leg-pip { width: 7px; height: 7px; }

/* Alert button + countdown */
#alertBtn {
  position: fixed !important;
  bottom: 14px !important;
  right: 14px !important;
  padding: 9px 14px;
  font-size: 12px;
  border-radius: 10px;
  z-index: 850;
}

#countdown {
  position: fixed;
  bottom: 58px;
  right: 14px;
  font-size: 10px;
  z-index: 800;
}

#dbBar {
  position: fixed;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 10px;
  z-index: 800;
  white-space: nowrap;
}

/* ══ 5. WEATHER WIDGET ══════════════════════════════════════ */
#weatherWidget {
  position: absolute !important;
  top: auto !important;
  right: 10px !important;
  bottom: 58px !important;
  left: 10px !important;
  width: auto !important;
  border-radius: 14px !important;
  transform: none !important;
  cursor: default;
  transition: all .25s ease !important;
}

/* Collapsed: only show header row */
#weatherWidget.wx-collapsed .wx-body { display: none; }
#weatherWidget.wx-collapsed .wx-divider { display: none; }

.wx-header { padding: 11px 13px 9px; cursor: pointer; user-select: none; }
.wx-temp { font-size: 34px; }
.wx-body { padding: 8px 13px 13px; }
.wx-stats { gap: 7px; }
.wx-chip { padding: 6px 8px; border-radius: 9px; }
.wx-stat-lbl { font-size: 8.5px; }
.wx-stat-val { font-size: 12px; }

/* Collapse indicator */
.wx-header::after {
  content: '▲';
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 9px;
  opacity: .4;
  transition: transform .2s;
}
#weatherWidget.wx-collapsed .wx-header::after {
  transform: rotate(180deg);
}

/* ══ 6. ALERT PANEL ═════════════════════════════════════════ */
#alertPanel {
  position: fixed !important;
  top: var(--hh) !important;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100% !important;
  border-left: none !important;
  border-top: 1px solid var(--b);
  z-index: 900;
}

.panel-head { padding: 12px 14px; }
.panel-title { font-size: 13px; }
.panel-body { padding: 8px; gap: 6px; }

.alert-item { padding: 9px 11px; border-radius: 9px; }
.alert-time { font-size: 10px; }
.alert-title { font-size: 12px; }
.alert-body { font-size: 11px; }

/* ══ 7. ADMIN LAYOUT — bottom-tab navigation ═══════════════ */
#adminView { position: relative; }

.sidebar {
  position: fixed !important;
  width: 100% !important;
  top: auto !important;
  bottom: 0 !important;
  left: 0;
  right: 0;
  min-height: 0 !important;
  height: var(--bot-nav-h) !important;
  border-right: none !important;
  border-top: 1px solid var(--b);
  flex-direction: row;
  z-index: 500;
  background: var(--s);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.sidebar-nav {
  flex-direction: row !important;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 4px 6px;
  gap: 2px;
  align-items: stretch;
  justify-content: space-around;
  width: 100%;
  height: 100%;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.sidebar-nav::-webkit-scrollbar { display: none; }

.nav-label { display: none !important; }

.nav-item {
  flex-direction: column !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 3px;
  padding: 5px 8px;
  min-width: 54px;
  font-size: 9.5px;
  border-radius: 10px;
  white-space: nowrap;
  flex: 1;
  text-align: center;
  border: none;
}

.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }

.nav-item.active {
  background: var(--acc-d);
  color: var(--acc);
}

.bc {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 9px;
  padding: 1px 4px;
  min-width: 14px;
}

/* Admin content area */
.content {
  margin-left: 0 !important;
  padding: 12px 12px calc(var(--bot-nav-h) + 12px);
  min-height: 100dvh;
  min-height: 100vh;
  padding-top: calc(var(--hh) + 12px);
}

/* ══ 8. STATS GRID ══════════════════════════════════════════ */
.stats-grid {
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 12px;
}

/* 5th card: span full if needed */
.stats-grid .stat-card:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

.stat-card {
  padding: 13px 14px;
  border-radius: 10px;
}

.stat-val { font-size: 26px; }
.stat-lbl { font-size: 10px; }

/* ══ 9. CARDS ═══════════════════════════════════════════════ */
.card {
  border-radius: 10px;
  margin-bottom: 12px;
  overflow: visible;
}

.card-head {
  padding: 11px 13px;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-start;
}

.card-head > div {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  flex: 1;
  min-width: 0;
}

.card-title { font-size: 12.5px; }
.card-body { padding: 10px; }

/* ══ 10. TABLES ═════════════════════════════════════════════ */
.tbl-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  /* Show subtle scroll hint */
  background: linear-gradient(to right, transparent 90%, rgba(201,162,39,.08)) local,
              linear-gradient(to left, transparent 90%, rgba(201,162,39,.08)) local;
}

table { font-size: 12px; min-width: 500px; }
th { padding: 8px 10px; font-size: 10px; }
td { padding: 8px 10px; font-size: 12px; }

/* ══ 11. ADMIN MAP ══════════════════════════════════════════ */
.map-admin {
  height: 220px !important;
  border-radius: 8px;
}

#pane-map .map-admin { height: 340px !important; }
#overviewMap, #adminMap { border-radius: 8px; }

/* ══ 12. BUTTONS ════════════════════════════════════════════ */
.btn-sm { padding: 7px 11px; font-size: 11px; }

/* Make card-head buttons wrap nicely */
.card-head .btn-sm { flex-shrink: 0; }

/* ══ 13. MODALS ═════════════════════════════════════════════ */
.modal {
  padding: 0;
  align-items: flex-end; /* sheet slides up from bottom */
}

.modal-box {
  width: 100% !important;
  max-height: 92dvh !important;
  max-height: 92vh !important;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  border-radius: 20px 20px 0 0 !important;
  /* Sheet drag handle */
  padding-top: 4px;
}

/* Drag handle visual */
.modal-box::before {
  content: '';
  display: block;
  width: 36px;
  height: 4px;
  background: var(--b2);
  border-radius: 2px;
  margin: 8px auto 0;
}

.modal-head {
  padding: 12px 16px;
  border-bottom: 1px solid var(--b);
}
.modal-head h2 { font-size: 15px; }

.field { padding: 6px 16px; }
.field label { font-size: 10.5px; }
.field input { font-size: 14px; padding: 10px 12px; }

.modal-actions {
  padding: 12px 16px;
  gap: 8px;
  flex-wrap: wrap;
}
.modal-actions button {
  flex: 1;
  min-width: 90px;
  justify-content: center;
  padding: 11px 16px;
  font-size: 13px;
}

.ibox, .wbox, .sbox { margin: 6px 16px; font-size: 12px; }

/* Why RCG modal guide steps */
.guide-step { padding: 10px 16px; gap: 10px; }
.guide-step h4 { font-size: 12.5px; margin-bottom: 3px; }
.guide-step p { font-size: 11.5px; line-height: 1.55; }

/* Channel badges in modal */
.channel-row { gap: 6px; flex-wrap: wrap; }
.ch-badge { font-size: 11px; padding: 5px 10px; }

/* ══ 14. ALERT BANNER ═══════════════════════════════════════ */
#alertBanner {
  top: var(--hh);
  font-size: 12px;
  padding: 7px 16px;
  width: calc(100% - 32px);
  left: 50%;
}

/* ══ 15. RCG STICKER ════════════════════════════════════════ */
#rcgSticker {
  width: 68px !important;
  bottom: calc(var(--bot-nav-h) + 8px) !important;
  left: 10px !important;
}

/* ══ 16. POPUPS (Leaflet) ═══════════════════════════════════ */
.leaflet-popup-content {
  min-width: 180px !important;
  padding: 12px !important;
}
.popup-name { font-size: 13px; }
.popup-id { font-size: 10px; }
.popup-grid { gap: 5px; }
.popup-chip { padding: 6px 7px; border-radius: 6px; }
.popup-chip-label { font-size: 9px; }
.popup-chip-val { font-size: 11px; }

/* ══ 17. SAFE-AREA (notched phones, iOS home bar) ════════════ */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .sidebar {
    height: calc(var(--bot-nav-h) + env(safe-area-inset-bottom)) !important;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .content {
    padding-bottom: calc(var(--bot-nav-h) + env(safe-area-inset-bottom) + 12px);
  }
  #rcgSticker {
    bottom: calc(var(--bot-nav-h) + env(safe-area-inset-bottom) + 8px) !important;
  }
  #alertBtn {
    bottom: calc(var(--bot-nav-h) + env(safe-area-inset-bottom) + 8px) !important;
  }
  .modal-box { padding-bottom: env(safe-area-inset-bottom); }
  .intro-content {
    padding-bottom: calc(90px + env(safe-area-inset-bottom));
  }
}

/* ══ 18. LANDSCAPE PHONE ════════════════════════════════════ */
@media (max-height: 500px) and (orientation: landscape) {
  .intro-content {
    padding-top: 12px;
    padding-bottom: 60px;
    justify-content: center;
  }

  .intro-logo-circle { width: 40px; height: 40px; }
  .intro-wordmark { font-size: clamp(22px, 5vh, 36px) !important; }
  .intro-headline { font-size: clamp(12px, 2.5vh, 16px) !important; }
  .intro-sub { font-size: 11px; margin-bottom: 10px; }

  .intro-pillars {
    grid-template-columns: repeat(3, 1fr);
    margin-bottom: 12px;
  }

  .intro-cta-row { flex-direction: row; }
  .intro-enter, .intro-secondary { width: auto; flex: 1; }

  #mascotGuide { display: none; }

  .map-shell { height: calc(100dvh - var(--hh) - 16px) !important; }
}

/* ══ 19. SMALL PHONES (≤ 375px) ════════════════════════════ */
@media (max-width: 375px) {
  .intro-wordmark { font-size: clamp(24px, 8vw, 36px) !important; }
  .intro-headline { font-size: 13px !important; }
  .intro-sub { font-size: 12px; }

  .intro-pillars { grid-template-columns: 1fr 1fr; gap: 6px; }
  .pillar { font-size: 10px; padding: 7px 8px; }

  .stats-grid { grid-template-columns: 1fr 1fr; gap: 6px; }
  .stat-val { font-size: 22px; }

  .mascot-bubble { max-width: 180px; font-size: 11px; }
  .mascot-avatar { width: 44px; height: 44px; }

  table { min-width: 440px; }
}

/* ══ 20. TABLET PORTRAIT (768–1023px) ══════════════════════ */
@media (min-width: 768px) and (max-width: 1023px) {
  :root {
    --hh: 56px;
    --bot-nav-h: 66px;
  }

  .intro-content { padding: 70px 40px 100px; }
  .intro-wordmark { font-size: clamp(40px, 7vw, 64px) !important; }
  .intro-logo-circle { width: 68px; height: 68px; }
  .intro-headline { font-size: clamp(18px, 3vw, 24px) !important; }
  .intro-sub { font-size: 14px; max-width: 540px; }

  .intro-pillars { grid-template-columns: repeat(3, 1fr); gap: 9px; }
  .pillar { font-size: 12px; padding: 10px 12px; }

  .intro-cta-row { flex-direction: row; justify-content: center; width: auto; }
  .intro-enter { width: auto; min-width: 180px; font-size: 15px; }
  .intro-secondary { width: auto; min-width: 140px; }

  #mascotGuide { bottom: 100px; right: 20px; }
  .mascot-bubble { max-width: 260px; font-size: 13px; }
  .mascot-avatar { width: 62px; height: 62px; }

  /* Header — show breadcrumb on tablet */
  .view-crumb { display: inline-flex; }
  .wordmark { font-size: 14px; }
  .logo-circle { width: 34px; height: 34px; }

  /* Bottom nav — slightly taller */
  .nav-item { min-width: 60px; font-size: 10px; }
  .nav-item svg { width: 22px; height: 22px; }

  /* Stats: 3-col on tablet */
  .stats-grid { grid-template-columns: repeat(3, 1fr); }

  /* Map */
  .map-shell { margin: 12px; }
  .map-admin { height: 280px !important; }
  #pane-map .map-admin { height: 420px !important; }

  /* Tables native width on tablet */
  table { min-width: 0; }
}

/* ══ 21. TABLET LANDSCAPE (1024–1279px) ════════════════════ */
@media (min-width: 1024px) and (max-width: 1279px) {
  :root {
    --hh: 58px;
    --bot-nav-h: 0px;
  }

  /* Restore sidebar on large tablets */
  .sidebar {
    position: absolute !important;
    width: 180px !important;
    top: var(--hh) !important;
    bottom: auto !important;
    left: 0;
    right: auto;
    height: auto !important;
    min-height: calc(100vh - var(--hh)) !important;
    border-right: 1px solid var(--b) !important;
    border-top: none !important;
    flex-direction: column !important;
  }

  .sidebar-nav {
    flex-direction: column !important;
    overflow-y: auto;
    overflow-x: hidden;
    justify-content: flex-start;
    padding: 10px;
    gap: 2px;
    height: auto !important;
  }

  .nav-label { display: block !important; }

  .nav-item {
    flex-direction: row !important;
    align-items: center !important;
    justify-content: flex-start !important;
    font-size: 12px;
    gap: 8px;
    min-width: 0;
    padding: 8px 10px;
    text-align: left;
    flex: 0;
  }

  .nav-item svg { width: 16px; height: 16px; }

  .content {
    margin-left: 180px !important;
    padding: 16px 16px 16px !important;
    padding-top: calc(var(--hh) + 16px) !important;
  }

  .stats-grid { grid-template-columns: repeat(3, 1fr); }

  /* Show crumb and date */
  .view-crumb { display: inline-flex; }
  #clockDate { display: block; }

  #rcgSticker { bottom: 24px !important; left: 20px !important; width: 80px !important; }
  #alertBtn { bottom: 20px !important; right: 20px !important; }
  #countdown { bottom: 64px; right: 20px; }
}


/* ══ 22. NAV TAB LABEL (injected by JS) ════════════════════ */
.nav-tab-label {
  font-size: 9.5px;
  line-height: 1;
  margin-top: 2px;
  display: block;
  color: inherit;
  font-family: var(--font);
}

/* Hide label on landscape phones (height < 500px) */
@media (max-height: 500px) and (orientation: landscape) {
  .nav-tab-label { display: none; }
  .nav-item { min-width: 44px; padding: 4px 6px; }
  :root { --bot-nav-h: 50px; }
}

/* ══ 23. INTRO VIEW — fixed to viewport ════════════════════ */
#introView {
  position: fixed;
  inset: 0;
  z-index: 2000;
}

/* ══ 24. ADMIN VIEW layout fix for fixed header + bottom nav */
#adminView {
  min-height: 100dvh;
  min-height: 100vh;
}

/* ══ 25. PUBLIC VIEW spacing — below fixed header ══════════ */
#publicView { padding-top: var(--hh); }

/* ══ 26. MISC MOBILE POLISH ═════════════════════════════════ */

/* Better focus rings for accessibility */
button:focus-visible {
  outline: 2px solid var(--acc);
  outline-offset: 2px;
}

/* Smoother scrollable areas */
.panel-body, .sidebar-nav, .modal-box, .intro-content {
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

/* Ensure modals appear above everything */
.modal { z-index: 3000; }

/* Fix for leaflet controls on mobile */
.leaflet-control-zoom {
  margin-right: 12px !important;
  margin-bottom: 160px !important; /* above alert button */
}

/* Wider touch targets for leaflet zoom buttons */
.leaflet-control-zoom a {
  width: 36px !important;
  height: 36px !important;
  line-height: 36px !important;
  font-size: 18px !important;
}

/* Status dot in header — slightly larger tap area */
.status-chip { padding: 4px 0; }

/* Better visibility for pills in tables on small screens */
.pill { font-size: 10px; padding: 2px 7px; }

/* Prevent text from overflowing in table cells */
td { word-break: break-word; max-width: 160px; }

/* Intro rain layer performance */
@media (prefers-reduced-motion: reduce) {
  .raindrop, .lightning-flash,
  .mascot-avatar, .wx-icon-wrap,
  .intro-badge::before { animation: none !important; }
}

