:root {
  --logo-opacity: 0.18;
  --teal: #0d9488;
  --ink: #0f172a;
  --muted: #64748b;
  /* More transparent so logo text stays readable */
  --card-bg: linear-gradient(145deg, rgba(255,255,255,0.28), rgba(255,255,255,0.10));
}

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

html, body {
  background: #f8fafc;
  font-family: "Plus Jakarta Sans", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
  overflow-x: hidden; /* prevent horizontal scroll on mobile */
}

/* ----- Watermark: always centered ----- */
#watermark {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(70vw, 420px);
  height: auto;
  max-height: 70vh;
  object-fit: contain;
  opacity: var(--logo-opacity);
  z-index: 0;
  pointer-events: none;
}

/* ----- Watery background ----- */
#water {
  position: fixed; inset: 0; z-index: 0;
  overflow: hidden; pointer-events: none; background: #f8fafc;
}
#water i {
  position: absolute; border-radius: 50%;
  filter: blur(70px); opacity: 0.48;
  animation: drift 18s ease-in-out infinite alternate;
}
#water i:nth-child(1) { width: 55vmax; height: 55vmax; left: -15vmax; top: -18vmax; background: #bfe6f5; }
#water i:nth-child(2) { width: 50vmax; height: 50vmax; right: -16vmax; top: 10vh; background: #c9f0e4; animation-duration: 22s; }
#water i:nth-child(3) { width: 60vmax; height: 40vmax; left: 15vw; bottom: -20vmax; background: #cfe3fb; animation-duration: 26s; }
@keyframes drift {
  from { transform: translate(0,0) scale(1); }
  to   { transform: translate(4vmax,3vmax) scale(1.12); }
}

/* ----- Page ----- */
.page {
  position: relative; z-index: 1;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: 22px 16px 16px;
  min-height: 100vh;
  min-height: 100dvh; /* avoids extra scroll under mobile URL bar */
  display: flex; flex-direction: column;
}

header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; margin-bottom: 6px;
  flex-wrap: wrap;
}
header h1 {
  font-size: clamp(1.2rem, 3vw, 1.75rem);
  font-weight: 700;
  letter-spacing: -0.025em;
  color: #0f172a;
}
.live-pill {
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.04em;
  border: 1px solid rgba(13,148,136,0.25);
  background: rgba(255,255,255,0.45);
  border-radius: 999px; padding: 6px 12px;
  color: #0f766e; display: flex; align-items: center; gap: 7px;
  white-space: nowrap;
}
.live-pill .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 0 3px rgba(16,185,129,0.25);
  animation: liveBreathe 2s ease-in-out infinite;
}
@keyframes liveBreathe {
  0%, 100% {
    opacity: 1;
    transform: scale(1);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.32), 0 0 8px rgba(16, 185, 129, 0.55);
  }
  50% {
    opacity: 0.38;
    transform: scale(0.85);
    box-shadow: 0 0 0 7px rgba(16, 185, 129, 0.04), 0 0 2px rgba(16, 185, 129, 0.15);
  }
}

/* ----- City pills ----- */
.locations {
  display: flex; justify-content: center; gap: 8px;
  margin: 14px 0 18px; flex-wrap: wrap;
}
.locations button {
  padding: 5px 18px;
  border: 1.5px solid #35519a;
  background: rgba(255,255,255,0.4);
  color: #35519a;
  border-radius: 999px;
  font-family: inherit; /* buttons don't inherit the font by default */
  font-size: 0.8rem; font-weight: 600;
  cursor: pointer;
  transition: background .15s, color .15s, box-shadow .15s;
}
.locations button:hover { background: rgba(53, 81, 154, 0.12); }
.locations button.active {
  background: #35519a; color: #fff; border-color: #35519a;
  box-shadow: 0 2px 10px rgba(53, 81, 154, 0.3);
}

/* ----- Metrics ----- */
.metrics {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.metric {
  background: var(--card-bg);
  -webkit-backdrop-filter: blur(10px) saturate(145%);
  backdrop-filter: blur(10px) saturate(145%);
  border: 1px solid rgba(255,255,255,0.55);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 4px 18px rgba(14,116,144,0.06);
}
.metric span { display: block; font-size: 0.72rem; font-weight: 500; color: var(--muted); }
.metric strong { display: block; font-size: 1.55rem; font-weight: 700; margin: 6px 0 2px; letter-spacing: -0.03em; }
.metric small { font-size: 0.7rem; color: var(--muted); }

/* ----- Cards ----- */
.card {
  background: var(--card-bg);
  -webkit-backdrop-filter: blur(10px) saturate(145%);
  backdrop-filter: blur(10px) saturate(145%);
  border: 1px solid rgba(255,255,255,0.55);
  border-radius: 14px;
  padding: 14px 16px;
  box-shadow: 0 4px 20px rgba(14,116,144,0.06);
}
.card-head { margin-bottom: 10px; }
.card-head h2 { font-size: 0.9rem; font-weight: 600; color: #334155; }
.card-head p, .card-head small { display: block; font-size: 0.72rem; color: var(--muted); margin-top: 2px; }
.card-head.row { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }

/* ----- Main grid ----- */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 16px;
  margin-bottom: 16px;
}

/* Square map */
.map-card #map {
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  background: #e8eef3;
  overflow: hidden;
}
.map-card {
  display: flex;
  flex-direction: column;
}
.legend {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  flex: 1;
  gap: 8px;
  margin-top: 12px;
  font-size: 0.75rem;
  color: var(--muted);
}
.legend span {
  display: flex;
  align-items: center;
  gap: 8px;
}
.legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Table */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 0.82rem; }
th {
  text-align: left; font-size: 0.68rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); padding: 7px 8px;
  border-bottom: 1.5px solid rgba(15,118,110,0.2);
}
td {
  padding: 8px; border-bottom: 1px solid rgba(15,118,110,0.08);
  white-space: nowrap;
}
tbody tr { cursor: pointer; transition: background .12s; }
tbody tr:hover { background: rgba(13,148,136,0.06); }
tr.sel { background: rgba(13,148,136,0.1); }
.badge {
  display: inline-block;
  font-weight: 700;
  font-size: 0.85rem;
}
.off { color: #94a3b8; font-size: 0.7rem; margin-left: 5px; }
.muted { color: var(--muted); font-size: 0.8rem; }

.history-card { margin-bottom: 12px; }
.chart-wrap { position: relative; height: 240px; } /* relative: required by Chart.js responsive sizing */
select {
  border: 1px solid rgba(15,118,110,0.25);
  border-radius: 8px; padding: 6px 10px;
  background: rgba(255,255,255,0.55); color: var(--ink);
  font-family: inherit; font-size: 0.8rem;
}

.message {
  font-size: 0.8rem; color: #92400e;
  background: rgba(254,243,199,0.75);
  border: 1px solid #fde68a;
  padding: 10px 14px; border-radius: 10px;
  margin-bottom: 14px;
}

/* ----- Footer Tiles ----- */
footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: auto;
  padding-top: 8px;
}

.footer-tile {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  border-radius: 10px;
  text-decoration: none;
  font-size: 0.72rem;
  letter-spacing: 0.02em;
  color: var(--muted);
  box-shadow: 0 3px 12px rgba(14,116,144,0.05);
  transition: transform .15s ease, border-color .15s ease, box-shadow .15s ease, background .15s ease;
}

.footer-tile span {
  font-weight: 500;
}

.footer-tile strong {
  font-weight: 700;
  color: #35519a;
}

.footer-tile:hover {
  transform: translateY(-1px);
  border-color: rgba(53, 81, 154, 0.45);
  box-shadow: 0 5px 16px rgba(53, 81, 154, 0.12);
}

/* ========== MOBILE ========== */
@media (max-width: 860px) {
  .page,
  .main-grid,
  .card,
  .map-card,
  .table-card,
  .history-card {
    min-width: 0;
    max-width: 100%;
  }

  .main-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .map-card #map {
    width: 100%;
    aspect-ratio: 16 / 9;
    height: auto;
    max-height: 280px;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* Keep the complete location table inside its card.
     Users can swipe left/right inside this area to view every column. */
  .table-wrap {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
    overscroll-behavior-x: contain;
    scrollbar-width: thin;
  }

  .table-wrap table {
    width: max-content;
    min-width: 100%;
    border-collapse: collapse;
  }
}

@media (max-width: 480px) {
  .page {
    width: 100%;
    padding: 12px 10px;
    overflow-x: clip;
  }

  /* Center the title and LIVE indicator as a single mobile header. */
  header {
    width: 100%;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 8px;
    margin-bottom: 8px;
  }

  header h1 {
    width: 100%;
    text-align: center;
    font-size: clamp(1.15rem, 5vw, 1.45rem);
    line-height: 1.25;
  }

  .live-pill {
    align-self: center;
    justify-content: center;
  }

  .locations {
    margin: 12px 0 16px;
  }

  .metrics {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .metric {
    min-width: 0;
    padding: 11px 10px;
    overflow-wrap: anywhere;
  }

  .metric strong {
    font-size: 1.25rem;
  }

  .metric small {
    overflow-wrap: anywhere;
  }

  .card {
    width: 100%;
    min-width: 0;
    padding: 12px;
    overflow: hidden;
  }

  .card-head {
    min-width: 0;
  }

  .card-head h2,
  .card-head p {
    overflow-wrap: anywhere;
  }

  /* Compact map tile: never wider than the screen/card. */
  .map-card #map {
    display: block;
    width: 100%;
    max-width: 100%;
    height: clamp(165px, 52vw, 220px);
    min-height: 0;
    aspect-ratio: auto;
    border-radius: 9px;
  }

  .legend {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-start;
    flex: initial;
    gap: 7px 10px;
    font-size: 0.65rem;
  }
  .legend span {
    gap: 5px;
  }

  /* The location data remains one complete table and is swipe-scrollable. */
  .table-wrap {
    width: 100%;
    max-width: 100%;
    margin: 0;
    padding-bottom: 3px;
  }

  .table-wrap table {
    min-width: 590px;
    font-size: 0.72rem;
  }

  th,
  td {
    padding: 6px 7px;
  }

  .card-head.row {
    align-items: flex-start;
  }

  .chart-wrap {
    width: 100%;
    max-width: 100%;
    height: 200px;
  }

  footer {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .footer-tile {
    justify-content: center;
    text-align: center;
  }
}


/* ============================================================
   LOGO VISIBILITY + GLASS TILES
   Desktop: square logo matches viewport height without cropping.
   Mobile: square logo matches viewport width without cropping.
   ============================================================ */
:root {
  --logo-opacity: 0.24;
  --card-bg: linear-gradient(
    145deg,
    rgba(255, 255, 255, 0.24),
    rgba(255, 255, 255, 0.11)
  );
}

/* Keep the complete square logo large behind the dashboard. */
#watermark {
  width: auto;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  object-fit: contain;
}

/* A light glass effect separates tiles while allowing the logo to show through. */
.metric,
.card,
.footer-tile {
  background: var(--card-bg);
  -webkit-backdrop-filter: blur(5px) saturate(125%);
  backdrop-filter: blur(5px) saturate(125%);
  border: 1px solid rgba(255, 255, 255, 0.42);
}

.live-pill {
  background: rgba(255, 255, 255, 0.30);
  -webkit-backdrop-filter: blur(5px);
  backdrop-filter: blur(5px);
}

@media (max-width: 600px) {
  /* On phones, use the full available screen width; height follows naturally. */
  #watermark {
    width: 100vw;
    height: auto;
    max-width: 100vw;
    max-height: 100vh;
    object-fit: contain;
  }

  /* Switch map legend to compact horizontal wrap at the same 600px mobile breakpoint */
  .legend {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: flex-start;
    flex: initial;
    gap: 7px 10px;
    font-size: 0.65rem;
  }
  .legend span {
    gap: 5px;
  }

  /* Keep chart legend aligned to the right on mobile so it never overlaps the left note */
  .hist-footer {
    justify-content: space-between !important;
    flex-wrap: nowrap !important;
    gap: 8px !important;
  }
  .hist-footer .chart-legend {
    position: static !important;
    transform: none !important;
    margin-left: auto !important;
    gap: 12px !important;
    flex-shrink: 0 !important;
  }

  /* History header: dropdown on the right, vertically centered
     between the "History" title and the line under it */
  .card-head.row {
    align-items: center;
    flex-wrap: nowrap;
  }
  .card-head.row > div {
    min-width: 0;
  }

  /* History dropdown: same text size as the "History" title, compact tile */
  select {
    font-size: 0.9rem;
    padding: 5px 10px;
    flex-shrink: 0;
  }

  /* iPhone/iPad only: 16px stops Safari zooming in when the dropdown is tapped
     (this will look larger than "History" on iOS only) */
  @supports (-webkit-touch-callout: none) {
    select { font-size: 16px; }
  }

  /* Bigger tap targets for city pills */
  .locations button { padding: 9px 18px; }

  /* Static blurred blobs: saves battery and avoids janky scrolling on cheap phones */
  #water i { animation: none; }
}

/* Respect users who ask for less motion */
@media (prefers-reduced-motion: reduce) {
  #water i,
  .live-pill .dot { animation: none; }
}