/* ThermiGraph AI — styles.css (JavaScript version)
   Port of the Streamlit dashboard's design system (v6.3.13), rebuilt for a
   plain HTML page so JavaScript and CSS animation have full freedom.
   Two themes, switched by html[data-theme="light" | "dark"].
   Fonts: Plus Jakarta Sans (UI), JetBrains Mono (numbers), Noto Sans Arabic. */

/* ---------- Theme variables ---------- */
:root {
    --font-ui: 'Plus Jakarta Sans', 'Noto Sans Arabic', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --accent: #0284c7;
    --accent-2: #1d4ed8;
    --accent-soft: #38bdf8;
    --green: #10b981;
    --amber: #f59e0b;
    --orange: #f97316;
    --red: #f43f5e;
}
html[data-theme="light"] {
    --bg: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    --surface: rgba(255, 255, 255, 0.88);
    --card-bg: #ffffff;
    --border: rgba(15, 23, 42, 0.08);
    --border-hover: rgba(14, 165, 233, 0.45);
    --text: #0f172a;
    --text-2: #334155; /* v15: was #475569; darkened to #334155 for AA contrast on white */
    --text-3: #334155;
    --shadow: 0 10px 28px -8px rgba(0, 0, 0, 0.08);
    --hero-bg: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(241, 245, 249, 0.85) 100%);
    --hero-title: linear-gradient(95deg, #0f172a 0%, #0369a1 100%);
    --chip-bg: #f1f5f9;
    --pill-bg: rgba(2, 132, 199, 0.10);
    --pill-text: #0284c7;
    --pill-border: rgba(2, 132, 199, 0.25);
    --kicker: #0284c7;
    --track: rgba(15, 23, 42, 0.12);
    --topbar-bg: rgba(248, 250, 252, 0.92);
}
html[data-theme="dark"] {
    --bg: linear-gradient(180deg, #060911 0%, #0b1120 100%);
    --surface: rgba(15, 23, 42, 0.68);
    --card-bg: rgba(15, 23, 42, 0.75);
    --border: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(56, 189, 248, 0.45);
    --text: #f8fafc;
    --text-2: #94a3b8;
    --text-3: #e2e8f0;
    --shadow: 0 10px 28px -8px rgba(0, 0, 0, 0.45);
    --hero-bg: linear-gradient(135deg, rgba(15, 23, 42, 0.85) 0%, rgba(15, 23, 42, 0.50) 100%);
    --hero-title: linear-gradient(95deg, #ffffff 0%, #bae6fd 55%, #38bdf8 100%);
    --chip-bg: rgba(15, 23, 42, 0.75);
    --pill-bg: rgba(56, 189, 248, 0.13);
    --pill-text: #7dd3fc;
    --pill-border: rgba(56, 189, 248, 0.30);
    --kicker: #38bdf8;
    --track: rgba(255, 255, 255, 0.12);
    --topbar-bg: rgba(8, 13, 25, 0.88);
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { scroll-behavior: smooth; font-size: 18px; }
body {
    margin: 0;
    font-family: var(--font-ui);
    color: var(--text);
    background: var(--bg);
    background-attachment: fixed;
    line-height: 1.6;
}
h1, h2, h3 { color: var(--text); letter-spacing: -0.02em; font-weight: 700; }
h2 { font-size: 1.45rem; margin: 0.2rem 0 1rem 0; }
a { color: var(--accent); }

/* v15 accessibility: visible keyboard focus on every interactive element.
   (Inputs keep their own focus ring as well; this is the fallback.) */
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* v15 RTL: when the Arabic toggle sets html[dir="rtl"], table text reads
   right-aligned and the slider value sits on the left. Flex/grid
   direction flips automatically with dir="rtl". Leaflet and Plotly
   keep their own internal layout. */
html[dir="rtl"] .tg-table th, html[dir="rtl"] .tg-table td { text-align: right; }
html[dir="rtl"] .tg-slider-value { text-align: left; }

/* v19 RTL FIX: Arabic chrome stays RTL, but English-untranslated blocks
   must stay LTR, otherwise full stops jump to the start of the line,
   "21.7 °C" renders as "C° 21.7", "+0 °C" as "C° 0+", and flex/grid
   order reverses (Ruwais first, Very heavy first, table columns reversed).
   Nothing here rotates anything; it only pins direction on the English
   blocks. Apply .tg-keep-ltr in index.html / app.js to those blocks. */
.tg-keep-ltr { direction: ltr; unicode-bidi: isolate; text-align: left; }
.tg-keep-ltr th, .tg-keep-ltr td { text-align: left; }
html[dir="rtl"] .tg-keep-ltr { direction: ltr; unicode-bidi: isolate; text-align: left; }
html[dir="rtl"] .tg-keep-ltr th, html[dir="rtl"] .tg-keep-ltr td { text-align: left; }
/* Keep the order of cards / pills / table columns in these containers. */
html[dir="rtl"] .tg-metric-grid.tg-keep-ltr,
html[dir="rtl"] .tg-niosh-grid.tg-keep-ltr,
html[dir="rtl"] .tg-split.tg-keep-ltr,
html[dir="rtl"] .tg-gauge-scale.tg-keep-ltr { direction: ltr; }
/* Leaflet and Plotly keep their own internal layout; pin their boxes LTR too. */
#mapContainer.tg-keep-ltr, #compareMapContainer.tg-keep-ltr, #strainChart.tg-keep-ltr { direction: ltr; unicode-bidi: isolate; }

/* ---------- Top bar ---------- */
.tg-topbar {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--topbar-bg);
    backdrop-filter: blur(22px);
    border-bottom: 1px solid var(--border);
}
.tg-topbar-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.6rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}
.tg-brand { font-weight: 800; font-size: 1.05rem; letter-spacing: -0.02em; }
.tg-brand span { background: var(--hero-title); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.tg-topbar-controls { display: flex; gap: 0.5rem; flex-wrap: wrap; }

/* ---------- Page ---------- */
.tg-page { max-width: 1400px; margin: 0 auto; padding: 1.5rem 1.5rem 3.5rem 1.5rem; }
.tg-section { margin-bottom: 0.5rem; }
.tg-divider { border: none; border-top: 1px solid var(--border); margin: 2.2rem 0; }
.tg-body { color: var(--text-3); margin: 0 0 1rem 0; }
.tg-caption { font-size: 1.05rem; color: var(--text-2); margin: 0.5rem 0; }

/* ---------- Scroll-in animations (sections fade up as you scroll to them) ---------- */
@keyframes tgPulse {
    0% { transform: scale(0.95); opacity: 0.8; }
    50% { transform: scale(1.25); opacity: 1; }
    100% { transform: scale(0.95); opacity: 0.8; }
}
/* v14 FIX (live check 2026-11-16): Sections 6 and 8 rendered very pale /
   low-contrast on scroll, with a large pale blank area before later
   sections faded in. The old fade was 0.9 s plus a stacked delay of
   60 ms per section (up to ~0.66 s), so a fast scroll or a screenshot
   caught sections mid-fade. Now the fade is 0.35 s with no delay and
   only an 8 px rise, so text reaches full opacity promptly. */
.tg-anim {
    opacity: 0; transform: translateY(8px);
    transition: opacity 0.35s ease, transform 0.35s ease;
    transition-delay: 0s;
}
.tg-anim.tg-visible { opacity: 1; transform: translateY(0); }
@media (prefers-reduced-motion: reduce) {
    .tg-anim { opacity: 1; transform: none; transition: none; }
}
.tg-hero { --anim-order: 0; }
.tg-section { --anim-order: 1; }

/* ---------- Pulsing map ring (hotter zones pulse faster) ---------- */
@keyframes tgRingPulse {
    0% { opacity: 0.55; }
    50% { opacity: 0.08; }
    100% { opacity: 0.55; }
}
.tg-pulse-ring { animation: tgRingPulse 2.4s ease-in-out infinite; }

/* ---------- Guided demo tour ---------- */
.tg-tour-bar {
    position: fixed; right: 1.2rem; top: 4.5rem; bottom: auto; left: auto; transform: none;
    z-index: 1000; width: auto; max-width: calc(100vw - 2rem);
    background: var(--card-bg); border: 1px solid var(--border-hover);
    border-radius: 999px; box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
    padding: 0.45rem 0.7rem; backdrop-filter: blur(16px);
}
.tg-tour-bar[hidden] { display: none; }
.tg-tour-title { display: none; }
.tg-tour-text { display: none; }
/* v13: guided tour removed from the UI (user decision 2026-11-14).
   The tour bar took up too much screen and hid the figures in the
   video. The tour JS stays in app.js so it can be restored later,
   but the button and the bar are hidden. The demo is driven by
   scrolling to each section and using its own controls. */
#tourBar { display: none !important; }
.tg-tour-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.tg-tour-step { font-family: var(--font-mono); font-size: 1.05rem; color: var(--text-2); margin-left: auto; }
.tg-tour-highlight { outline: 3px solid var(--accent); outline-offset: 6px; border-radius: 12px; }

/* ---------- Day scrubber + before/after slider ---------- */
.tg-scrub-readout {
    font-family: var(--font-mono); font-size: 1.03rem; font-weight: 600;
    background: var(--card-bg); border: 1px solid var(--border);
    border-radius: 12px; padding: 0.6rem 0.9rem; margin: 0.8rem 0;
}
.tg-table tr.tg-row-active td { background: rgba(2, 132, 199, 0.14); font-weight: 600; }
.tg-ba-labels { display: flex; justify-content: space-between; font-size: 1.05rem; color: var(--text-2); margin-top: 0.2rem; }

/* ---------- Hero ---------- */
.tg-hero {
    position: relative;
    overflow: hidden;
    padding: 1.8rem 2.2rem;
    border-radius: 22px;
    background: var(--hero-bg);
    backdrop-filter: blur(20px);
    border: 1px solid var(--border);
    box-shadow: 0 20px 40px -12px rgba(0, 0, 0, 0.12);
    margin-bottom: 1.5rem;
}
.tg-badge-row { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: center; margin-bottom: 0.75rem; }
/* v25 polish: thermal accent strip across the top of the hero card. */
.tg-hero::before {
    content: "";
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 4px;
    background: linear-gradient(90deg, #10b981 0%, #0284c7 35%, #f59e0b 70%, #f43f5e 100%);
}
/* v23: LIVE badge (Section 1) + Observed/Forecast legend (Section 3). */
.tg-live-badge {
    display: inline-flex; flex-wrap: wrap; align-items: center; gap: 0.5rem;
    padding: 0.35rem 0.85rem; border-radius: 999px; margin: 0.2rem 0 0.8rem 0;
    font-size: 1rem; font-weight: 700;
    color: var(--green); background: rgba(16, 185, 129, 0.12);
    border: 1px solid rgba(16, 185, 129, 0.45);
}
.tg-live-source { font-weight: 600; color: var(--text-2); }
.tg-legend { display: flex; flex-wrap: wrap; gap: 0.55rem; align-items: center; margin: 0.2rem 0 0.5rem 0; }
.tg-legend-chip {
    display: inline-flex; align-items: center; gap: 0.45rem;
    padding: 0.28rem 0.78rem; border-radius: 999px;
    font-size: 1rem; font-weight: 600;
    background: var(--pill-bg); border: 1px solid var(--pill-border);
}
.tg-legend-dot { width: 10px; height: 10px; border-radius: 50%; }
.tg-legend-observed .tg-legend-dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.tg-legend-forecast .tg-legend-dot { background: var(--amber); box-shadow: 0 0 8px var(--amber); }
.tg-pill {
    display: inline-flex; align-items: center; gap: 0.45rem;
    padding: 0.28rem 0.78rem; border-radius: 999px;
    font-size: 1rem; font-weight: 600; text-transform: uppercase;
    background: var(--pill-bg); color: var(--pill-text);
    border: 1px solid var(--pill-border);
}
.tg-pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 10px var(--green); animation: tgPulse 2s infinite; }
.tg-hero-title {
    font-size: 2.35rem; font-weight: 800; letter-spacing: -0.03em; line-height: 1.15;
    margin: 0 0 0.4rem 0;
    background: var(--hero-title);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.tg-hero-tagline { font-size: 1.05rem; font-weight: 600; color: var(--text-3); margin: 0 0 0.35rem 0; }
.tg-hero-sub { font-size: 1rem; color: var(--text-2); margin: 0; line-height: 1.5; }

/* ---------- Kickers, cards, metrics ---------- */
.tg-kicker {
    font-size: 1rem; font-weight: 700; text-transform: uppercase;
    letter-spacing: 0.09em; color: var(--kicker); margin-bottom: 0.15rem;
}
.tg-glass-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.2rem 1.4rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
    transition: border-color 0.25s ease, transform 0.25s ease, box-shadow 0.25s ease;
}
.tg-glass-card:hover { border-color: var(--border-hover); transform: translateY(-2px); }
.tg-metric-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.tg-metric-grid-3 { grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.tg-metric-grid-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.tg-metric {
    background: var(--card-bg);
    backdrop-filter: blur(16px);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.15rem 1.3rem;
    box-shadow: var(--shadow);
    transition: border-color 0.25s ease, transform 0.25s ease;
}
.tg-metric:hover { border-color: var(--border-hover); transform: translateY(-2px); }
.tg-metric-label { font-size: 1.03rem; font-weight: 600; text-transform: uppercase; color: var(--text-2); }
.tg-metric-value { font-family: var(--font-mono); font-size: 1.85rem; font-weight: 700; color: var(--text); margin: 0.2rem 0; font-variant-numeric: tabular-nums; letter-spacing: -0.03em; line-height: 1.15; }
.tg-gauge-number, .tg-slider-value, .tg-phone-wbgt, table.tg-table td { font-variant-numeric: tabular-nums; }
/* v25 polish: Arabic glyphs need breathing room for diacritics/descenders. */
html[dir="rtl"] body { line-height: 1.78; }
.tg-metric-delta { font-size: 1.05rem; color: var(--text-2); }

/* ---------- Buttons, inputs, sliders ---------- */
.tg-btn {
    background: linear-gradient(135deg, #0284c7 0%, #1d4ed8 100%);
    color: #ffffff; font-weight: 600; font-family: var(--font-ui);
    border: none; border-radius: 12px; padding: 0.6rem 1.3rem;
    cursor: pointer; font-size: 1.03rem;
    transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.2s ease;
}
.tg-btn:hover { filter: brightness(1.12); box-shadow: 0 8px 20px rgba(2, 132, 199, 0.35); transform: translateY(-1px); }
.tg-btn:active { transform: translateY(0); }
.tg-btn-ghost {
    background: transparent; color: var(--text);
    border: 1px solid var(--border);
}
.tg-btn-ghost:hover { box-shadow: none; border-color: var(--border-hover); }
.tg-btn-large { padding: 0.75rem 1.6rem; font-size: 1rem; }
.tg-btn-row { display: flex; gap: 0.7rem; flex-wrap: wrap; margin-bottom: 1rem; }
.tg-field-label { display: block; font-weight: 600; font-size: 1.02rem; color: var(--text); margin: 1rem 0 0.4rem 0; }
.tg-select, .tg-input, .tg-textarea {
    width: 100%; font-family: var(--font-ui); font-size: 1.05rem;
    color: var(--text); background: var(--card-bg);
    border: 1px solid var(--border); border-radius: 12px;
    padding: 0.65rem 0.9rem; outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.tg-select:focus, .tg-input:focus, .tg-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(2, 132, 199, 0.18); }
.tg-textarea { resize: vertical; min-height: 110px; line-height: 1.5; }
.tg-gps-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.tg-form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.tg-slider-row { display: flex; align-items: center; gap: 1rem; margin: 0.4rem 0 1rem 0; }
/* v25 polish: thermal gradient track + glowing round thumb. Direction
   stays pinned LTR by the rule at the bottom of this file. */
.tg-slider {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 8px;
    border-radius: 999px;
    background: linear-gradient(90deg, #0284c7 0%, #f59e0b 60%, #f43f5e 100%);
    outline: none;
    cursor: pointer;
}
.tg-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid var(--accent);
    box-shadow: 0 2px 10px rgba(2, 132, 199, 0.4);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.tg-slider::-webkit-slider-thumb:hover {
    transform: scale(1.16);
    box-shadow: 0 0 0 6px rgba(2, 132, 199, 0.18);
}
.tg-slider::-moz-range-thumb {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #ffffff;
    border: 3px solid var(--accent);
    box-shadow: 0 2px 10px rgba(2, 132, 199, 0.4);
    cursor: pointer;
}
.tg-slider-value { font-family: var(--font-mono); font-weight: 700; font-size: 1.05rem; min-width: 64px; text-align: right; }
.tg-split { display: grid; grid-template-columns: 1fr 2fr; gap: 1rem; align-items: start; }
@media (max-width: 800px) { .tg-split { grid-template-columns: 1fr; } .tg-gps-row { grid-template-columns: 1fr; } }

/* ---------- NIOSH chips ---------- */
.tg-niosh-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 0.6rem; margin-top: 0.6rem; }
.tg-niosh-chip {
    padding: 0.62rem 0.85rem; border-radius: 12px;
    font-family: var(--font-mono); font-size: 1.05rem;
    border: 1px solid var(--border); background: var(--chip-bg);
}
.tg-chip-ok { border-left: 3px solid var(--green); color: var(--green); }
.tg-chip-over { border-left: 3px solid var(--red); color: var(--red); background: rgba(244, 63, 94, 0.10); }
html[data-theme="light"] .tg-chip-ok { color: #047857; }
html[data-theme="light"] .tg-chip-over { color: #be123c; background: #ffe4e6; }

/* ---------- Map ---------- */
.tg-map-wrap { position: relative; border-radius: 16px; overflow: hidden; border: 1px solid var(--border); margin: 1rem 0; box-shadow: var(--shadow); }
/* v14: map height 460 -> 420 px, so more of the Abu Dhabi map fits in the
   first viewport and Ruwais is not left below the fold. The fitBounds
   padding in app.js (70 px) does the rest. */
#mapContainer { height: 420px; width: 100%; background: var(--card-bg); }
#compareMapContainer { height: 420px; width: 100%; background: var(--card-bg); margin-bottom: 1rem; }
.tg-map-fallback { padding: 1.2rem; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 0.8rem; }
.tg-map-fallback .tg-zone-card { border: 1px solid var(--border); border-radius: 12px; padding: 0.9rem 1rem; background: var(--card-bg); }
.tg-map-fallback .tg-zone-name { font-weight: 700; }
.tg-map-fallback .tg-zone-wbgt { font-family: var(--font-mono); font-size: 1.4rem; font-weight: 700; }

/* ---------- Leaflet map labels ---------- */
/* Leaflet draws its own tooltip boxes; make them match the dashboard. */
.tg-map-label {
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.18);
    font-family: var(--font-ui);
    font-size: 1.05rem;
    font-weight: 700;
    padding: 3px 8px;
}
.tg-map-label::before { display: none; } /* hide Leaflet's little arrow */

/* ---------- Tables ---------- */
.tg-table-wrap { overflow-x: auto; margin: 0.8rem 0 1rem 0; border: 1px solid var(--border); border-radius: 14px; background: var(--card-bg); }
table.tg-table { width: 100%; border-collapse: collapse; font-size: 1.02rem; }
table.tg-table th, table.tg-table td { padding: 0.6rem 0.9rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
table.tg-table th { font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-2); background: var(--surface); }
table.tg-table tr:last-child td { border-bottom: none; }
table.tg-table tr { transition: background 0.15s ease; }
table.tg-table tbody tr:hover { background: var(--surface); }
.tg-badge { display: inline-block; padding: 0.1rem 0.55rem; border-radius: 999px; font-size: 1.03rem; font-weight: 700; }
.tg-badge-red { background: rgba(244, 63, 94, 0.14); color: var(--red); }
.tg-badge-amber { background: rgba(245, 158, 11, 0.16); color: var(--amber); }
.tg-badge-green { background: rgba(16, 185, 129, 0.14); color: var(--green); }
.tg-badge-blue { background: rgba(2, 132, 199, 0.12); color: var(--accent); }
/* v15: badge text was the raw bright hues (#f59e0b amber, #10b981 green),
   which fail AA contrast on their pale backgrounds in light mode.
   Badges already carry words (Critical / High / Moderate / OK), so
   colour is never the only signal; this only fixes the contrast. */
html[data-theme="light"] .tg-badge-amber { color: #92400e; }
html[data-theme="light"] .tg-badge-green { color: #047857; }
html[data-theme="light"] .tg-badge-blue { color: #0369a1; }
html[data-theme="light"] .tg-badge-red { color: #be123c; }

/* ---------- Chart ---------- */
/* v14: chart container 340 -> 440 px min-height, padding 0.5 -> 0.75 rem,
   overflow visible, so the Plotly chart (420 px tall, margins t:55 b:60
   l:60 r:30 in app.js) is never clipped by its own box. */
.tg-chart { min-height: 440px; height: 440px; border: 1px solid var(--border); border-radius: 16px; background: var(--card-bg); padding: 0.75rem; margin-bottom: 1rem; box-shadow: var(--shadow); overflow: visible; }
.tg-chart-note { padding: 2rem; text-align: center; color: var(--text-2); }

/* ---------- Alerts ---------- */
.tg-alert { border-radius: 12px; padding: 0.9rem 1.1rem; margin: 0.8rem 0; font-weight: 600; border: 1px solid; }
.tg-alert-error { background: rgba(244, 63, 94, 0.10); border-color: rgba(244, 63, 94, 0.4); color: var(--red); }
.tg-alert-warn { background: rgba(245, 158, 11, 0.10); border-color: rgba(245, 158, 11, 0.4); color: #b45309; }
html[data-theme="dark"] .tg-alert-warn { color: #fbbf24; }
.tg-alert-info { background: rgba(2, 132, 199, 0.10); border-color: rgba(2, 132, 199, 0.4); color: var(--accent); }
.tg-status { border-radius: 12px; padding: 0.9rem 1.1rem; margin-bottom: 1rem; font-weight: 600; background: rgba(245, 158, 11, 0.10); border: 1px solid rgba(245, 158, 11, 0.4); color: #b45309; }
html[data-theme="dark"] .tg-status { color: #fbbf24; }

/* ---------- Strain gauge ---------- */
.tg-gauge { margin: 0.8rem 0 0.4rem 0; }
.tg-gauge-top { display: flex; justify-content: space-between; align-items: baseline; }
.tg-gauge-label { font-size: 0.98rem; font-weight: 600; color: var(--text-2); text-transform: uppercase; }
.tg-gauge-number { font-family: var(--font-mono); font-size: 1.4rem; font-weight: 700; transition: color 0.6s ease; }
.tg-gauge-track { position: relative; height: 14px; border-radius: 999px; background: var(--track); margin-top: 4px; }
.tg-gauge-fill { height: 100%; border-radius: 999px; width: 0%; transition: width 0.8s cubic-bezier(0.22, 1, 0.36, 1), background-color 0.6s ease; }
.tg-gauge-tick { position: absolute; left: 50%; top: -4px; width: 3px; height: 22px; background: var(--red); border-radius: 2px; }
.tg-gauge-scale { display: flex; justify-content: space-between; font-family: var(--font-mono); font-size: 1.02rem; color: var(--text-2); margin-top: 4px; }
.tg-gauge-redline { color: var(--red); font-weight: 600; }

/* ---------- Phone (worker view) ---------- */
.tg-phone-shell {
    max-width: 440px; margin: 0.5rem auto 1rem auto;
    border-radius: 32px; padding: 1.5rem 1.4rem;
    background: var(--card-bg);
    border: 2px solid var(--border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.35);
    transition: border-color 0.6s ease;
}
.tg-phone-notch { width: 96px; height: 6px; border-radius: 999px; background: var(--track); margin: 0 auto 1.2rem auto; }
.tg-phone-eyebrow { font-size: 1.02rem; text-transform: uppercase; color: var(--text-2); margin-bottom: 4px; }
.tg-phone-status { font-size: 1.55rem; font-weight: 800; transition: color 0.6s ease; }
.tg-phone-wbgt { font-family: var(--font-mono); font-size: 2rem; font-weight: 700; margin: 10px 0; }
.tg-phone-action, .tg-phone-promise { font-size: 1.05rem; padding: 10px; border-radius: 12px; margin-bottom: 8px; }
.tg-phone-action { background: rgba(2, 132, 199, 0.10); }
.tg-phone-promise { background: rgba(16, 185, 129, 0.10); }

/* ---------- Footer ---------- */
.tg-footer { font-size: 1.05rem; color: var(--text-2); padding: 1rem 0 0.5rem 0; }

/* ---------- Small screens ---------- */
@media (max-width: 640px) {
    .tg-hero { padding: 1.3rem 1.2rem; }
    .tg-hero-title { font-size: 1.8rem; }
    .tg-page { padding: 1rem 1rem 3rem 1rem; }
}

/* ---------- Mobile: 375px iPhone SE and up (v15) ---------- */
/* The 640px block above only shrank the hero. At 375px the grids still
   used auto-fit minmax(200-240px) columns, the maps were a fixed 420px,
   and wide tables could push the page wider than the viewport.
   NOTE: the chart keeps its 440px container (v14 unclipping fix) — the
   Plotly figure is drawn 420px tall in app.js, so shrinking the box
   on mobile would re-clip it. The chart is tall on a phone, not clipped. */
@media (max-width: 768px) {
    /* Grids stack to one column. */
    .tg-metric-grid, .tg-metric-grid-3, .tg-metric-grid-4,
    .tg-niosh-grid, .tg-form-grid { grid-template-columns: 1fr; }
    /* Maps scale with the viewport instead of a fixed height. */
    #mapContainer, #compareMapContainer { height: 60vh; min-height: 300px; }
    /* Tables scroll inside their own wrapper instead of widening the page. */
    .tg-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    table.tg-table { min-width: 540px; }
    /* No horizontal page scroll. overflow-x: clip (with hidden fallback)
       keeps position: sticky on the top bar working. */
    body { overflow-x: hidden; }
    @supports (overflow: clip) { body { overflow-x: clip; } }
    .tg-topbar-inner { padding: 0.5rem 0.75rem; }
    .tg-btn-large { width: 100%; }
    .tg-slider-row { flex-wrap: wrap; }
    .tg-slider-value { min-width: 56px; }
    .tg-phone-shell { max-width: 100%; }
}

/* ---------- Section 11 — Clinical Evidence & Validation (v14) ---------- */
.tg-evidence h3 { font-size: 1.05rem; margin: 1.2rem 0 0.4rem 0; }
.tg-evidence p, .tg-evidence li { color: var(--text-3); }
.tg-evidence ul { margin: 0.4rem 0 0.8rem 1.2rem; padding: 0; }
.tg-evidence li { margin-bottom: 0.35rem; }
.tg-evidence-ref { font-size: 1rem; line-height: 1.55; }
.tg-evidence-ref li { margin-bottom: 0.6rem; }
.tg-evidence-note {
    background: rgba(2, 132, 199, 0.08);
    border: 1px solid rgba(2, 132, 199, 0.35);
    border-radius: 12px; padding: 0.9rem 1.1rem; margin: 0.8rem 0;
    font-weight: 600; color: var(--text);
}

/* v17 PWA install button */
#installBtn[hidden] { display: none; }
#installBtn { border: 1px solid var(--accent, #0284c7); }
.tg-pwa-status { font-size: 1.02rem; color: var(--text-2); margin-left: 0.5rem; }

/* v20: metric values are numbers first (with a $/~/unit prefix at
   most), so they stay LTR in both languages. Arabic labels around them
   are RTL in Arabic mode because their containers are not pinned. */
.tg-metric-value, .tg-gauge-number { direction: ltr; unicode-bidi: isolate; }
html[dir="rtl"] .tg-map-label { direction: rtl; }

/* v19: the Install app button is always visible; only appinstalled hides it. */
#installBtn { border: 1px solid var(--accent, #0284c7); }

/* v21: sliders always run left-to-right, in English AND Arabic.
   In Arabic RTL mode the browser flips range inputs, so +0 starts on the
   right and +10 is on the left. The user asked for +0 / minimum always on
   the left, maximum on the right, thumb moving right as the value rises.
   Only the slider track/thumb direction is pinned LTR; labels, value text
   and surrounding layout stay in Arabic RTL as before. */
input[type="range"], .tg-slider {
    direction: ltr;
    unicode-bidi: isolate;
}
html[dir="rtl"] input[type="range"], html[dir="rtl"] .tg-slider {
    direction: ltr;
    unicode-bidi: isolate;
}

/* v23 fix: Section 4 explainable column must show the full sentence, not
   truncate mid-sentence; Section 3 dates must not wrap over two lines. */
table.tg-table td:last-child { min-width: 320px; white-space: normal; line-height: 1.55; }
table.tg-table td:first-child { white-space: nowrap; }

/* ========== v24 UX/UI Judge Polish (font size unchanged: html stays 18px) ========== */

/* Sticky section jump-nav bar */
.tg-subnav {
    border-top: 1px solid var(--border);
    background: var(--surface);
    overflow-x: auto;
    scrollbar-width: none;
}
.tg-subnav::-webkit-scrollbar { display: none; }
.tg-subnav-inner {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0.4rem 1.5rem;
    display: flex;
    gap: 0.45rem;
    white-space: nowrap;
}
.tg-nav-pill {
    text-decoration: none;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-2);
    padding: 0.28rem 0.72rem;
    border-radius: 999px;
    border: 1px solid transparent;
    transition: all 0.18s ease;
}
.tg-nav-pill:hover, .tg-nav-pill.active {
    color: var(--accent);
    background: var(--pill-bg);
    border-color: var(--pill-border);
}

/* Section 1: risk-colored clickable zone cards */
.tg-metric.tg-zone-interactive {
    cursor: pointer;
    border-top: 4px solid var(--green);
    position: relative;
}
.tg-metric.tg-zone-interactive.risk-amber { border-top-color: var(--amber); }
.tg-metric.tg-zone-interactive.risk-orange { border-top-color: var(--orange); }
.tg-metric.tg-zone-interactive.risk-red { border-top-color: var(--red); }
.tg-zone-header { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.tg-zone-hint {
    margin-top: 0.45rem;
    font-size: 0.76rem;
    font-weight: 600;
    color: var(--accent);
    opacity: 0.85;
}

/* Section 2: compact 2x2 control deck + effective-limit banner */
.tg-control-deck {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.1rem 1.25rem;
    margin: 0.9rem 0 1rem 0;
    box-shadow: var(--shadow);
}
/* v25 fix 1: exactly 2 columns on desktop (auto-fit made 4-across at
   1206 px), 1 column on narrow phones. */
.tg-control-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem 1rem;
}
@media (max-width: 640px) {
    .tg-control-grid { grid-template-columns: 1fr; }
}
.tg-eff-banner {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    margin-top: 0.8rem;
    padding: 0.65rem 0.9rem;
    border-radius: 12px;
    background: var(--pill-bg);
    border: 1px solid var(--pill-border);
    font-size: 0.86rem;
    font-weight: 600;
}

/* Section 4: shift table row highlights + trigger tags */
tr.tg-shift-stop td { background: rgba(244, 63, 94, 0.07); }
tr.tg-shift-half td { background: rgba(245, 158, 11, 0.07); }
tr.tg-shift-shade td { background: rgba(2, 132, 199, 0.07); }
.tg-trigger-tag {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 0.74rem;
    font-weight: 700;
    padding: 0.08rem 0.45rem;
    border-radius: 6px;
    margin-right: 0.25rem;
}
.tg-trig-red { background: rgba(244, 63, 94, 0.14); color: #be123c; }
.tg-trig-amber { background: rgba(245, 158, 11, 0.16); color: #92400e; }
.tg-trig-blue { background: rgba(2, 132, 199, 0.14); color: #0369a1; }
.tg-trig-green { background: rgba(16, 185, 129, 0.14); color: #047857; }
html[data-theme="dark"] .tg-trig-red { color: #fda4af; }
html[data-theme="dark"] .tg-trig-amber { color: #fcd34d; }
html[data-theme="dark"] .tg-trig-blue { color: #7dd3fc; }
html[data-theme="dark"] .tg-trig-green { color: #6ee7b7; }

/* ========== v25 Colour, Typography & Motion Polish ========== */

/* Dark-mode OpenStreetMap tiles: kill the white glare. Only applies
   while the Street base layer is active; Satellite stays full colour
   (toggled by the baselayerchange hook in app.js). */
html[data-theme="dark"] .tg-map-dark-tiles .leaflet-tile-pane {
    filter: invert(100%) hue-rotate(180deg) brightness(92%) contrast(92%) saturate(75%);
}
html[data-theme="dark"] .leaflet-control-attribution,
html[data-theme="dark"] .leaflet-control-layers {
    background: rgba(15, 23, 42, 0.88) !important;
    color: #cbd5e1 !important;
    border-color: rgba(255, 255, 255, 0.12) !important;
}

/* Red-line danger glow on the strain gauge + banner.
   v26 fix: the old keyframes dropped to exactly zero shadow at 0%/100%,
   so with ease-in-out the glow spent much of each 1.8 s cycle near
   invisible and stills caught a crisp-edged bar. The pulse now runs
   between a visible baseline glow and a stronger peak, never zero.
   The fill also keeps a static glow as a fallback, and the track is
   explicitly overflow-visible so nothing clips the halo. */
@keyframes tgDangerGlow {
    0%, 100% { box-shadow: 0 0 12px 3px rgba(244, 63, 94, 0.50); }
    50% { box-shadow: 0 0 24px 7px rgba(244, 63, 94, 0.65); }
}
.tg-gauge-track { overflow: visible; }
.tg-gauge-fill.is-critical {
    box-shadow: 0 0 14px 4px rgba(244, 63, 94, 0.55);
    animation: tgDangerGlow 1.8s ease-in-out infinite;
}
#strainBanner.is-critical {
    animation: tgDangerGlow 1.8s ease-in-out infinite;
}

/* Telemetry heartbeat flash (60 s Open-Meteo poll). */
@keyframes tgHeartbeatTick {
    0% { color: var(--green); transform: scale(1.02); }
    100% { color: var(--text-2); transform: scale(1); }
}
.tg-heartbeat-tick {
    display: inline-block;
    animation: tgHeartbeatTick 0.7s ease-out;
}

/* Triage loading skeleton shimmer. */
@keyframes tgShimmer {
    0% { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}
.tg-skeleton {
    height: 18px;
    border-radius: 8px;
    margin: 0.65rem 0;
    background: linear-gradient(90deg, var(--track) 25%, rgba(56, 189, 248, 0.16) 50%, var(--track) 75%);
    background-size: 800px 100%;
    animation: tgShimmer 1.3s linear infinite;
}

@media (prefers-reduced-motion: reduce) {
    .tg-gauge-fill.is-critical, #strainBanner.is-critical, .tg-heartbeat-tick, .tg-skeleton { animation: none; }
    /* v26 fix: with the pulse disabled the critical state must still be
       visible, so keep a static red halo instead of no glow at all. */
    .tg-gauge-fill.is-critical, #strainBanner.is-critical { box-shadow: 0 0 14px 4px rgba(244, 63, 94, 0.55); }
}
