/* site-polish.css
 *
 * Global cohesive look + responsive polish for every WiSWR page.
 * Loaded AFTER each page's inline CSS, so it overrides safely.
 *
 * Goals:
 *   1) Unified typography (Apple system font / Segoe / PingFang) on all pages.
 *   2) Unified dark gradient background that does not break the Leaflet map.
 *   3) Unified sticky top nav with glassmorphism and orange active state.
 *   4) Touch-friendly tap targets, safe-area insets, no iOS zoom on focus.
 *   5) Horizontal-scroll nav on phones, no wrapping.
 *   6) Tables that don't overflow phone viewports.
 *
 * What we deliberately DO NOT touch:
 *   - The actual map canvas (#map, .leaflet-container) layout — only its z-index.
 *   - Chart canvases.
 *   - Existing widget colors except for the nav band.
 */

/* ───── Typography ───── */
:root {
  --polish-bg-grad-a: rgba(229,114,0,0.06);
  --polish-bg-grad-b: rgba(20,33,73,0.40);
  --polish-bg: #0c1429;
  --polish-ink: #e9edf5;
  --polish-ink-dim: #9aa7c0;
  --polish-line: rgba(255,255,255,0.08);
  --polish-orange: #E57200;
  --polish-orange-soft: #ffb060;
}

html, body {
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
               "Helvetica Neue", "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Inter", sans-serif !important;
  letter-spacing: -0.005em;
}
body {
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  /* Layered background that still lets dark themes show through */
  background-image:
    radial-gradient(60vw 60vw at -10% -10%, var(--polish-bg-grad-a), transparent 60%),
    radial-gradient(60vw 60vw at 110%  0%, var(--polish-bg-grad-b), transparent 60%);
  background-attachment: fixed;
}

/* Touch feedback */
a, button, [role="button"], input[type=button], input[type=submit] {
  -webkit-tap-highlight-color: rgba(229,114,0,0.18);
  touch-action: manipulation;
}

/* ───── Unified top nav band (applied to ALL viewports) ───── */
.top-nav {
  position: sticky; top: 0; z-index: 1100;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  background: rgba(11,18,38,0.62);
  border-bottom: 1px solid var(--polish-line);
  padding: 10px max(env(safe-area-inset-left), 14px);
  display: flex; align-items: center; gap: 10px; flex-wrap: nowrap;
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}
.top-nav::-webkit-scrollbar { display: none; }
.top-nav { scrollbar-width: none; -ms-overflow-style: none; }

.top-nav a, .top-nav .btn, .top-nav .nav-btn {
  display: inline-flex !important;
  align-items: center;
  white-space: nowrap;
  flex: 0 0 auto;
  text-decoration: none;
  color: var(--polish-ink-dim);
  background: transparent;
  padding: 8px 14px !important;
  border-radius: 10px !important;
  border: 1px solid transparent !important;
  font-weight: 500;
  font-size: 0.92rem;
  letter-spacing: 0;
  min-height: 36px;
  transition: background 0.18s ease, color 0.18s ease, border-color 0.18s ease;
}
.top-nav a:hover, .top-nav .btn:hover, .top-nav .nav-btn:hover {
  background: rgba(255,255,255,0.06);
  color: var(--polish-ink);
}
.top-nav a.active, .top-nav .btn.active, .top-nav .nav-btn.active {
  background: var(--polish-orange) !important;
  color: white !important;
  box-shadow: 0 2px 12px rgba(229,114,0,0.28);
  border-color: var(--polish-orange) !important;
}
.top-nav sup {
  color: var(--polish-orange);
  font-size: 0.62em;
  vertical-align: super;
  opacity: 0.92;
  font-weight: 700;
  margin-left: 2px;
}

/* ───── Forms ───── */
input, select, textarea, button {
  font-family: inherit;
}
input[type="text"], input[type="number"], input[type="search"], select, textarea {
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--polish-line);
  border-radius: 8px;
  color: var(--polish-ink);
  padding: 8px 10px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}
input[type="text"]:focus, input[type="number"]:focus, select:focus, textarea:focus {
  border-color: rgba(229,114,0,0.7);
  background: rgba(255,255,255,0.06);
}

/* ───── Modal / dropdown polish ───── */
.modal-overlay > div, .modal-content {
  border-radius: 14px !important;
  border: 1px solid var(--polish-line);
  box-shadow: 0 16px 48px rgba(0,0,0,0.4);
}

/* ───── Mobile: under 720 px ───── */
@media (max-width: 720px) {
  body { font-size: 15px; }
  h1, .page-title { font-size: 1.4rem !important; line-height: 1.2; }
  h2 { font-size: 1.15rem !important; }
  h3 { font-size: 1.0rem !important; }

  .top-nav a, .top-nav .btn {
    padding: 6px 12px !important;
    font-size: 0.88rem !important;
    min-height: 36px;
  }

  /* Tables: horizontal-scroll wrapper */
  table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    max-width: 100%;
  }
  td, th { padding: 6px 8px !important; font-size: 0.84rem; }

  /* Multi-column grids stack on phones */
  .dashboard, .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr !important;
  }

  /* Side panels (forecast, SWR) stay inside the viewport */
  #practice-panel, #model-panel, .side-panel, .panel {
    max-width: calc(100vw - 24px) !important;
    left: 12px !important;
    right: 12px !important;
    font-size: 0.85rem !important;
  }

  /* Leaflet map needs minimum height to be usable */
  #map, .leaflet-container, .map-container {
    min-height: 60vh !important;
  }

  /* Avoid iOS auto-zoom on focus */
  input, select, textarea, button {
    font-size: 16px !important;
    min-height: 38px;
  }

  /* Wendy chat button - pull off bottom safe-area */
  #wendy-fab, .chat-fab, .wendy-button, .floating-chat-btn {
    bottom: max(env(safe-area-inset-bottom), 16px) !important;
    right: max(env(safe-area-inset-right), 16px) !important;
  }

  /* Modal: fit screen */
  .modal-overlay > div, .modal-content {
    max-width: calc(100vw - 24px) !important;
    max-height: calc(100dvh - 60px) !important;
    overflow-y: auto;
  }
}

/* ───── Narrow phones: under 420 px ───── */
@media (max-width: 420px) {
  body { font-size: 14px; }
  h1, .page-title { font-size: 1.25rem !important; }
  .top-nav a, .top-nav .btn { padding: 6px 10px !important; font-size: 0.82rem !important; }
  #practice-panel { font-size: 0.78rem !important; }
}

/* ───── High-DPI polish ───── */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
  hr, .divider { transform: scaleY(0.5); transform-origin: top; }
}

/* ───── Desktop only: extra width breathing room ───── */
@media (min-width: 1280px) {
  body { font-size: 15px; }
  .top-nav { padding-left: 22px; padding-right: 22px; }
}

/* ─── Hide the SWR-map model selector on phones ─────────────────────────
 * The model panel sits at right:12px;top:60px and visually blocks the map
 * on narrow viewports. The default (stiffness-based) model is correct for
 * 99% of users, so we hide the chooser on phones; desktop is unchanged.
 */
@media (max-width: 720px) {
  #model-panel { display: none !important; }
}

/* ─── SWR map right sidebar: bullet-proof hide on mobile ─────────────────
 * The map page has #sidebar { width:420px; right:0; transform:translateX(100%) }.
 * On narrow viewports the transform sometimes fails to fully hide it. Force
 * display:none unless the .open class is present.
 */
@media (max-width: 720px) {
  #sidebar:not(.open) { display: none !important; }
  /* When open, fit the screen instead of cropping a 420 px panel */
  #sidebar.open {
    width: 100% !important;
    max-width: 100vw !important;
  }
}

/* ═══════════════════════════════════════════════════════════════════════
   TOP NAV v2 — unified glass / pill style across every page
   ----------------------------------------------------------------------
   Handles every current markup variant:
     A. <nav class="top-nav"><a class="nav-brand"><span>Wi</span>SWR</a>
        <div class="nav-links">…</div></nav>                (forecast/fieldwork/history/current after rewrite)
     B. <nav class="top-nav"><a class="nav-brand">WiSWR<span>.</span></a>
        <div class="nav-links">…</div></nav>                (vibnet/monitoring)
     C. <div class="top-nav"><a class="btn …">…</a>…</div>  (dashboard)

   Loaded after each page's inline <style>, so it overrides via cascade
   order; uses !important only where inline-style attributes would
   otherwise win (e.g. legacy <span style="color:#2a72ff;">WiSWR</span>).
   ═══════════════════════════════════════════════════════════════════════ */
.top-nav {
  position: fixed !important;
  top: 0; left: 0; right: 0;
  z-index: 2000 !important;
  height: 56px !important;
  padding: 0 max(env(safe-area-inset-right), 18px) 0 max(env(safe-area-inset-left), 18px) !important;
  display: flex !important;
  align-items: center !important;
  gap: 4px;
  background:
    linear-gradient(180deg, rgba(11,18,38,0.94), rgba(11,18,38,0.86)) !important;
  -webkit-backdrop-filter: blur(16px) saturate(160%);
          backdrop-filter: blur(16px) saturate(160%);
  border-bottom: 1px solid rgba(255,255,255,0.08) !important;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.05),
    0 6px 24px rgba(0,0,0,0.34);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text",
               "Segoe UI", "Helvetica Neue", "PingFang SC",
               "Microsoft YaHei", Arial, sans-serif !important;
  color: #fff !important;
}

/* ─── Brand mark ────────────────────────────────────────────────────────
   Targets <a class="nav-brand"> in all variants and the legacy
   <span style="…">WiSWR</span> first-child in history/current.html.    */
.top-nav .nav-brand,
.top-nav > span:first-of-type {
  display: inline-flex !important;
  align-items: center !important;
  height: 36px;
  padding: 0 14px !important;
  margin-right: 10px;
  font-size: 17px !important;
  font-weight: 800 !important;
  letter-spacing: 0.3px !important;
  color: #fff !important;
  text-decoration: none !important;
  background: transparent !important;
  border: none !important;
  position: relative;
  white-space: nowrap;
}
/* Coloured letters inside the brand */
.top-nav .nav-brand span { color: #E57200 !important; }
/* Legacy span-only brand: tint the whole word orange */
.top-nav > span:first-of-type { color: #E57200 !important; }
/* Right-side hairline divider after the brand */
.top-nav .nav-brand::after,
.top-nav > span:first-of-type::after {
  content: "";
  position: absolute;
  right: -4px; top: 9px; bottom: 9px;
  width: 1px;
  background: rgba(255,255,255,0.10);
}

/* ─── Link group ──────────────────────────────────────────────────────── */
.top-nav .nav-links {
  display: flex !important;
  align-items: center !important;
  gap: 4px;
  flex: 1 1 auto;
  min-width: 0;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.top-nav .nav-links::-webkit-scrollbar { display: none; }

/* ─── Pill-shaped links / buttons (covers .nav-btn, .btn, plain <a>) ── */
.top-nav .nav-links a,
.top-nav .nav-links .nav-btn,
.top-nav > a:not(.nav-brand),
.top-nav .btn,
.top-nav .nav-btn {
  display: inline-flex !important;
  align-items: center !important;
  height: 34px !important;
  padding: 0 13px !important;
  font-size: 13px !important;
  font-weight: 500 !important;
  letter-spacing: 0.1px;
  white-space: nowrap;
  flex: 0 0 auto;
  color: rgba(255,255,255,0.78) !important;
  background: transparent !important;
  border: 1px solid transparent !important;
  border-radius: 9px !important;
  text-decoration: none !important;
  transition:
    background 160ms ease,
    color 160ms ease,
    border-color 160ms ease,
    transform 100ms ease;
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}
.top-nav .nav-links a:hover,
.top-nav .nav-links .nav-btn:hover,
.top-nav > a:not(.nav-brand):hover,
.top-nav .btn:hover,
.top-nav .nav-btn:hover {
  background: rgba(255,255,255,0.07) !important;
  color: #fff !important;
  border-color: rgba(255,255,255,0.10) !important;
}
.top-nav .nav-links a:active,
.top-nav > a:not(.nav-brand):active,
.top-nav .btn:active,
.top-nav .nav-btn:active { transform: scale(0.98); }

/* Active state — orange pill */
.top-nav .nav-links a.active,
.top-nav .nav-links .nav-btn.active,
.top-nav > a.active,
.top-nav .btn.active,
.top-nav .nav-btn.active {
  background: #E57200 !important;
  color: #fff !important;
  border-color: #E57200 !important;
  box-shadow: 0 2px 12px rgba(229,114,0,0.30);
}

/* ─── Right-side cluster (clock + search + Go) ────────────────────────── */
.top-nav .nav-cluster {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  padding-left: 12px;
  flex: 0 0 auto;
}
.top-nav .nav-clock,
.top-nav #nav-clock {
  font-size: 12.5px !important;
  color: rgba(255,255,255,0.62) !important;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  letter-spacing: 0.2px;
}
.top-nav .nav-search,
.top-nav #nl-query-input {
  width: 280px !important;
  height: 34px !important;
  padding: 0 12px !important;
  border: 1px solid rgba(255,255,255,0.12) !important;
  border-radius: 8px !important;
  background: rgba(255,255,255,0.06) !important;
  color: #fff !important;
  font-size: 13px !important;
  outline: none !important;
  transition: border-color 160ms ease, background 160ms ease;
}
.top-nav .nav-search::placeholder,
.top-nav #nl-query-input::placeholder {
  color: rgba(255,255,255,0.42);
}
.top-nav .nav-search:focus,
.top-nav #nl-query-input:focus {
  border-color: rgba(229,114,0,0.55) !important;
  background: rgba(255,255,255,0.10) !important;
}
.top-nav .nav-go,
.top-nav #nl-query-go {
  height: 34px !important;
  padding: 0 16px !important;
  border-radius: 8px !important;
  background: #2a72ff !important;
  color: #fff !important;
  font-size: 13px !important;
  font-weight: 600 !important;
  border: none !important;
  cursor: pointer;
  transition: background 160ms ease, transform 100ms ease;
}
.top-nav .nav-go:hover,
.top-nav #nl-query-go:hover { background: #1f5fe0 !important; }
.top-nav .nav-go:active,
.top-nav #nl-query-go:active { transform: scale(0.98); }

/* Loading state hook used by history.html / current.html JS */
.top-nav .nav-btn.loading,
.top-nav .nav-links a.loading { opacity: 0.55; pointer-events: none; }

/* ─── Phones (≤720) ────────────────────────────────────────────────────
   Keep nav single-line, allow horizontal scroll, hide LLM search.     */
@media (max-width: 720px) {
  .top-nav {
    height: 52px !important;
    padding: 0 12px !important;
  }
  .top-nav .nav-brand,
  .top-nav > span:first-of-type {
    font-size: 15px !important;
    padding: 0 8px !important;
    margin-right: 4px;
  }
  .top-nav .nav-links a,
  .top-nav .nav-btn,
  .top-nav > a:not(.nav-brand),
  .top-nav .btn {
    height: 32px !important;
    padding: 0 10px !important;
    font-size: 12.5px !important;
  }
  .top-nav .nav-cluster { gap: 6px; padding-left: 6px; }
  .top-nav .nav-clock { display: none; }
  .top-nav .nav-search,
  .top-nav #nl-query-input,
  .top-nav .nav-go,
  .top-nav #nl-query-go { display: none !important; }
}

/* ─── Narrow phones (≤420) ─────────────────────────────────────────── */
@media (max-width: 420px) {
  .top-nav .nav-brand,
  .top-nav > span:first-of-type {
    font-size: 14px !important;
    padding: 0 6px !important;
  }
  .top-nav .nav-links a,
  .top-nav .nav-btn,
  .top-nav > a:not(.nav-brand),
  .top-nav .btn {
    height: 30px !important;
    padding: 0 8px !important;
    font-size: 11.5px !important;
  }
}
