/*──────────────────────────────────────────────────────────────
  Community AQHI Dashboard – unified stylesheet  (v2025-06-27b)
  Mobile-first design
──────────────────────────────────────────────────────────────*/

/* 0️⃣  Theme variables */
:root{
  --brand:    #004b8d;
  --text:     #ffffff;
  --bg:       #f5f7fa;
  --card-bg:  #e6f1ff;
  --radius:   6px;
  --header-pad-y: clamp(.9rem, 1.2vw + .7rem, 1.3rem);
  --header-pad-x: clamp(1rem, 2vw, 1.6rem);
  --header-offset: clamp(60px, 7vh, 88px);
}

/* 1️⃣  Resets & global layout */
*,*::before,*::after{box-sizing:border-box;}
html{scroll-behavior:smooth;max-width:100%;}
body{
  margin:0;
  font-family:system-ui,-apple-system,Segoe UI,Roboto,sans-serif;
  background:var(--bg);
  display:flex;flex-direction:column;min-height:100vh;max-width:100%;
}
main{flex:1;padding:1rem;box-sizing:border-box;max-width:100%;}
img{max-width:100%;height:auto;display:block;}

/* 2️⃣  Accessibility helpers */
.visually-hidden{position:absolute!important;width:1px;height:1px;margin:-1px;padding:0;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0;}
.skip-link{position:absolute;left:-999px;top:auto;background:var(--brand);color:var(--text);padding:.5rem 1rem;z-index:100;}
.skip-link:focus{left:0;}

/* Respect reduced-motion preferences */
@media (prefers-reduced-motion: reduce){
  html { scroll-behavior: auto; }                 /* disable smooth scroll */
  .nav-button, .hamburger, .card { transition: none; }
  .nav-button:hover,
  .nav-button:focus,
  .nav-button:focus-visible,
  .card:hover,
  .card:focus { transform: none; }                /* no lift on focus/hover */
}

/* 3️⃣ Header & navigation (HOME-PAGE STYLE, shared) */
.site-header{
  display:flex; align-items:center; gap:1rem; flex-wrap:wrap;
  padding-block: var(--header-pad-y, 1.1rem);
  padding-inline: calc(var(--header-pad-x, 1.6rem) + env(safe-area-inset-left))
                  calc(var(--header-pad-x, 1.6rem) + env(safe-area-inset-right));
  background: var(--brand); color: var(--text);
  position: sticky; top: 0; z-index: 50; width: 100%;
  min-height: clamp(60px, 7vh, 88px);
}

.logo{
  margin:0; flex:1;
  font-size: clamp(1.35rem, 1rem + 1.2vw, 2rem);
  font-weight:700; color:var(--text); text-decoration:none;
}

.hamburger{
  background: rgba(0,0,0,0.1);
  border: 1px solid rgba(255,255,255,0.25); /* lighter border for contrast */
  font-size: clamp(1.6rem, 1.1rem + 1.2vw, 2rem);
  color: var(--text);
  cursor: pointer;
  line-height: 1;
  display: none;
  padding: .25rem .5rem;             /* improved hit target */
  min-width: 44px; min-height: 44px; /* a11y touch size */
  border-radius: var(--radius);
}

.nav{
  display:flex; gap:.6rem; margin-left:auto; flex-wrap:wrap; width:auto;
}

.nav-button{
  display:inline-block;
  padding:.5rem 1rem;                        /* home-page padding */
  font-size: clamp(1rem, .9rem + .45vw, 1.2rem);
  color:var(--text);
  background-color: rgba(255,255,255,.15);   /* filled pill by default */
  text-decoration:none; border-radius: var(--radius);
  transition: background-color .15s, transform .15s;
}

/* Hover + ANY focus (allow native UA focus ring) */
.nav-button:hover,
.nav-button:focus{
  background-color: rgba(255,255,255,.30);
  transform: translateY(-2px);
}

/* Active page highlight */
.nav-button[aria-current="page"]{
  background-color: rgba(255,255,255,.30);
}

/* 📱 Mobile collapse — match home page */
@media (max-width:640px){
  .hamburger{ display:inline-block; }
  .nav{ display:none; flex-direction:column; gap:.4rem; width:100%; margin-left:0; }
  .nav.open{ display:flex; }
  .logo{ font-size:1rem; }                   /* home page’s smaller logo on mobile */
}

/* 4️⃣  Cards grid (home page) */
.cards{
  display:grid;
  gap:1rem;
  padding:2rem 1rem;
  grid-template-columns:repeat(auto-fit,minmax(220px,1fr));
}

/* Photo cards */
.card{
  position:relative;
  display:grid;
  place-items:end start;
  aspect-ratio:16/9;
  min-height:9rem;
  padding:1rem;
  border-radius:10px;
  overflow:hidden;
  text-decoration:none;
  font-weight:700;
  letter-spacing:.2px;
  box-shadow:0 2px 6px rgba(0,0,0,.1);
  transition:transform .18s;

  /* use the per-card var */
  background: #0d2238 center/cover no-repeat;  /* fallback color */
  background-image: var(--card-image, none);

  /* readable text over photos */
  color: var(--card-color, #fff);
}

/* overlay for contrast */
.card::before{
  content:"";
  position:absolute; inset:0;
  background: linear-gradient(180deg, rgba(0,0,0,.08) 10%, rgba(0,0,0,.55) 100%);
  pointer-events:none;
  transition:opacity .2s ease;
}

/* label chip */
.card > span{
  position:relative; z-index:1;
  background: rgba(0,0,0,.35);
  padding:.4rem .6rem;
  border-radius:.5rem;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

/* hover/focus */
.card:hover,.card:focus{ transform: translateY(-3px); }
.card:focus-visible{ outline:3px solid #fff; outline-offset:2px; }

.card--map    { --card-image: url('../assets/cards/map.png');    --card-color:#fff; }
.card--graphs { --card-image: url('../assets/cards/graphs.png'); --card-color:#fff; }
.card--list   { --card-image: url('../assets/cards/list.png');   --card-color:#fff; }
.card--info   { --card-image: url('../assets/cards/info.png');   --card-color:#fff; }



/* 5️⃣  Detail cell + pollutant mini-table */
.detail-cell{ background:#eef6ff; padding:.8rem 1rem; font-size:.95rem; }
.poll-table{ width:100%; border-collapse:collapse; margin-top:.6rem; }
.poll-table th,.poll-table td{
  border:1px solid #d4e4ff; padding:.35rem .5rem; font-size:.9rem; text-align:left;
}
.poll-table th{ background:#ddecff; font-weight:500; }

/* Fit-to-width scaler for wide, no-wrap tables */
.table-scale-wrap{
  position: relative;
  width: 100%;
  overflow: hidden;     /* hide overflow once scaled */
  overflow-x: clip;     /* avoid horizontal scroll on modern browsers */
}

/* the table itself becomes the scale target */
.table-scale-wrap .scale-target{
  transform-origin: top left;
  will-change: transform;
  display: inline-block; /* shrink to intrinsic width instead of 100% */
}

/* Fixed 33% shrink (i.e., scale = 0.67) */
.shrink-33{ transform: scale(0.67); }

@media print{
  .table-scale-wrap{ overflow: visible; height: auto !important; }
  .table-scale-wrap .scale-target{ transform: none !important; }
}


/* 6️⃣  Footer */
.site-footer{text-align:center;padding:1rem 0;font-size:.9rem;color:#666;}

/* 7️⃣  Small-screen (≤640 px) */
@media (max-width:640px){
  .nav-button{ width:100%; margin:0; text-align:center; padding:.75rem 1rem; }
}

/* 8️⃣  Tablet (≥641 px) */
@media (min-width:641px){
  main{padding:1.5rem 2rem;}
}

/* 9️⃣  Desktop (≥1024 px) */
@media (min-width:1024px){
  main{padding:2rem 3rem;}
}

main h1[id],
main h2[id],
main h3[id],
main section[id],
main details[id]{
  scroll-margin-top: calc(var(--header-offset) + 8px);
}

/* 🔟 Air Quality advisory banner */
.aq-alert-banner{
  --aq-bg: #fff4e5;
  --aq-fg: #5b3100;
  --aq-border: #ffb74d;
  background: var(--aq-bg);
  color: var(--aq-fg);
  border-block: 1px solid var(--aq-border);
  box-shadow: 0 1px 0 rgba(0,0,0,.05) inset;
}
.aq-alert-banner__inner{
  max-width: 1100px;
  margin: 0 auto;
  padding: .75rem 1rem;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: .75rem;
  align-items: center;
}
.aq-alert-banner__icon{ font-size: 1.25rem; line-height: 1; }
.aq-alert-banner__text{ font-size: .95rem; }
.aq-alert-banner__link{
  color: currentColor;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.aq-alert-banner__close{
  appearance: none;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: .25rem .45rem;
}
.aq-alert-banner__close:hover{ border-color: var(--aq-border); }

@media (max-width: 640px){
  .aq-alert-banner__inner{ grid-template-columns: 1fr auto; }
  .aq-alert-banner__icon{ display:none; }
}

/* Hide the banner in print */
@media print{
  .aq-alert-banner{ display:none !important; }
}

/* Mobile cards for sensor list */
.sensor-cards{ display:none; }

@media (max-width:640px){
  .table-scale-wrap{ display:none; }        /* hide table on mobile */
  .sensor-cards{
    display:grid;
    gap:.75rem;
  }

  .sensor-card{
    display:grid;
    grid-template-columns: 1fr auto;        /* left info, right AQHI square */
    align-items:center;
    padding:.75rem 1rem;
    border:1px solid #d0d7de;
    border-radius: var(--radius);
    background:#fff;
    box-shadow:0 1px 2px rgba(0,0,0,.03);
    cursor:pointer;
  }
  .sensor-card__title{
    margin:0 0 .25rem 0;
    font-weight:700;
    font-size:1.05rem;
    color:#0b1f33;
  }
  .sensor-card__meta{
    font-size:.9rem;
    color:#334;
    line-height:1.35;
  }
  .sensor-card__meta strong{ font-weight:600; }

  .sensor-card__aqhi{
    width:52px; height:52px;
    border-radius:8px;
    display:flex; align-items:center; justify-content:center;
    color:#fff; font-weight:700;
    font-variant-numeric: tabular-nums;
    margin-left:1rem;
  }

  /* collapsible detail inside card */
  .sensor-card__detail{
    display:none;
    grid-column:1 / -1;
    margin-top:.6rem;
    background:#eef6ff;
    padding:.6rem .75rem;
    border-radius: var(--radius);
  }
  .sensor-card[aria-expanded="true"] .sensor-card__detail{ display:block; }
}

/* AQHI SCALE TABLE IMAGE */
.aqhi-img { display:block; max-width:100%; height:auto; }

/* Prevent the opened dropdown from growing the page too tall */
@media (max-width: 1080px) {
  #what-is-the-scale-for-the-aqhi[open] .aqhi-img-wrap{
    max-height: 70vh;        /* cap height to viewport */
    overflow: auto;          /* scroll inside the panel if needed */
    margin: .5rem 0;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 6px 18px rgba(0,0,0,.08);
    -webkit-overflow-scrolling: touch;
  }
}


/* Offline / stale sensor warning (details page) */
.sensor-offline-warning {
  display: none;
  align-items:flex-start;
  gap:.5rem;
  margin:0 0 1rem 0;
  padding:.5rem .75rem;
  border-radius: var(--radius);
  background:#fff4e5;
  border:1px solid #f2a65a;
  font-size:.9rem;
  color:#5b3100;
}

/* visible only when the [hidden] attribute is NOT present */
.sensor-offline-warning:not([hidden]) {
  display: flex;
}

.sensor-offline-warning__icon{
  font-size:1.3rem;
  line-height:1;
}

.sensor-offline-warning__text a{
  font-weight:600;
  text-decoration:underline;
  text-underline-offset:2px;
}
