/*
 * site_nav.css - Shared header/nav/drawer styles for every page.
 *
 * Paired with site_nav.js, which injects the header into the
 * <div id="site-header" ...> placeholder. All selectors are scoped under
 * #site-header so they reliably win over any leftover inline rules, and they
 * use the same CSS custom properties (--surface/--border/--text/...) every
 * page already defines in :root. Include this <link> AFTER the page's inline
 * <style> so equal-specificity rules cascade in our favour.
 *
 * Breakpoint: 768px (matches every existing media query in the codebase).
 * At/below it the nav collapses behind a hamburger button into an overlay
 * drawer (position:fixed, so it overlays full-screen pages like map.html
 * instead of pushing layout).
 */

#site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 1100;
  transition: transform 0.3s ease;
}
#site-header.sn-static { position: relative; }
#site-header.header-hidden { transform: translateY(-100%); }

#site-header .header-left { display: flex; align-items: center; gap: 12px; }
#site-header .header-logo { height: 36px; width: auto; }
#site-header .header-left h1 { font-size: 18px; font-weight: 600; color: var(--text); letter-spacing: -0.3px; }
#site-header .header-left p { font-size: 12px; color: var(--muted); margin-top: 2px; }

#site-header .sn-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* Nav occupies its own full-width row beneath the bar on desktop. */
#site-header .nav-links { display: flex; gap: 6px; width: 100%; justify-content: center; padding-top: 10px; align-items: flex-start; order: 3; }
#site-header .nav-links > a { color: var(--muted); text-decoration: none; font-size: 13px; transition: color 0.2s; padding-top: 14px; }
#site-header .nav-links a:hover, #site-header .nav-links a.active { color: var(--accent); }
#site-header .nav-group { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 0 10px; border-left: 1px solid var(--border); }
#site-header .nav-group:last-of-type { border-right: 1px solid var(--border); }
#site-header .nav-group-label { font-size: 9px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--text); font-weight: 600; }
#site-header .nav-group-links { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
#site-header .nav-group-links a { color: var(--muted); text-decoration: none; font-size: 13px; transition: color 0.2s; white-space: nowrap; }
#site-header .nav-group-links a:hover, #site-header .nav-group-links a.active { color: var(--accent); }

#site-header .theme-toggle { background: none; border: 1px solid var(--border); color: var(--muted); cursor: pointer; padding: 6px; border-radius: 6px; display: flex; align-items: center; justify-content: center; }
#site-header .theme-toggle:hover { color: var(--text); border-color: var(--text); }
#site-header .theme-toggle svg { width: 16px; height: 16px; }
#site-header .theme-toggle .icon-moon { display: none; }
[data-theme="light"] #site-header .theme-toggle .icon-sun { display: none; }
[data-theme="light"] #site-header .theme-toggle .icon-moon { display: block; }

/* Hamburger - hidden on desktop, shown in the drawer breakpoint. */
#site-header .nav-toggle { display: none; background: none; border: 1px solid var(--border); color: var(--text); cursor: pointer; padding: 7px; border-radius: 6px; align-items: center; justify-content: center; }
#site-header .nav-toggle svg { width: 18px; height: 18px; display: block; }

/* Small pill links/actions (Login, Admin, Back to Dashboard, ...). */
#site-header .sn-pill { color: var(--muted); font-size: 12px; text-decoration: none; border: 1px solid var(--border); padding: 4px 10px; border-radius: 6px; white-space: nowrap; }
#site-header .sn-pill:hover { color: var(--text); }

/* Account/login section lives inside the drawer. Hidden on desktop (the
 * top-bar pills handle it there); shown only inside the mobile drawer. */
#site-header .nav-account { display: none; }

/* Optional connection status badge (map.html). Only layout is defined here -
 * the dot's COLOUR/animation is owned by the page's own .status-dot rules
 * (green/pulse + .error/.info states), which must not be clobbered, so we
 * deliberately set no background here. */
#site-header .status-badge { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
#site-header .status-dot { width: 8px; height: 8px; border-radius: 50%; }

@media (max-width: 768px) {
  #site-header { gap: 8px 16px; padding: 12px 16px; }
  #site-header .header-left h1 { font-size: 15px; }
  #site-header .nav-toggle { display: flex; }

  #site-header .nav-links {
    order: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 8px 16px 16px;
    position: fixed;
    left: 0; right: 0;
    top: var(--sn-h, 56px);
    max-height: calc(100dvh - var(--sn-h, 56px));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    transform: translateY(-8px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.18s ease, transform 0.18s ease, visibility 0.18s;
    z-index: 1090;
  }
  #site-header.nav-open .nav-links { transform: translateY(0); opacity: 1; visibility: visible; }
  #site-header .nav-links > a { padding: 12px 4px; border-bottom: 1px solid var(--border); }
  #site-header .nav-group { flex-direction: column; align-items: stretch; gap: 2px; padding: 10px 0; border-left: none; border-right: none; border-bottom: 1px solid var(--border); }
  #site-header .nav-group:last-of-type { border-right: none; border-bottom: none; }
  #site-header .nav-group-label { padding: 2px 4px; }
  #site-header .nav-group-links { flex-direction: column; align-items: stretch; gap: 0; }
  #site-header .nav-group-links a { padding: 10px 8px; font-size: 14px; }

  /* Keep a VISIBLE "Log in" button in the top bar on mobile for logged-out
   * users (no hamburger needed to log in). Only the signed-in controls are
   * decluttered into the drawer. */
  #site-header.has-nav .sn-right #adminLink,
  #site-header.has-nav .sn-right #userMenu { display: none !important; }
  /* Make the top-bar Log in obvious on phones. */
  #site-header .sn-right #loginLink { color: var(--accent); border-color: var(--accent); font-weight: 600; }
  #site-header .nav-account { display: block; margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border); }
  #site-header .nav-account-name { font-size: 12px; color: var(--muted); padding: 8px 8px 4px; }
  #site-header .nav-account-link { display: block; padding: 12px 8px; font-size: 14px; color: var(--accent); text-decoration: none; }
  #site-header .nav-account-link:hover { color: var(--text); }
}

/* ---------------------------------------------------------------------------
 * Shared mobile-hardening utilities.
 *
 * Note: the heavy data tables (dam_summary, constraints, shiftfactors matrix,
 * uplift heatmap) already wrap in overflow-x:auto, and the fixed-width side
 * panels (uplift tooltip pane, eia923 donut) already collapse to full width in
 * their own page CSS - so those need nothing here. The one cross-cutting gap is
 * Leaflet's small default controls on touch screens:
 * ------------------------------------------------------------------------- */

/* Enlarge Leaflet zoom/control touch targets on small screens and keep the
 * controls below the sticky header. Applies wherever Leaflet is loaded. */
@media (max-width: 768px) {
  .leaflet-touch .leaflet-bar a,
  .leaflet-touch .leaflet-control-zoom a {
    width: 36px; height: 36px; line-height: 36px;
  }
  .leaflet-control-container .leaflet-top { z-index: 800; }
}

