/* T-PIE · the CSS half of the Basic / Advanced view mode (uimode.js).
 *
 * uimode.js stamps <html data-ui-mode="basic|advanced"> from <head>, before first paint, and adds
 * data-ui-gated while an Advanced-only page is open in Basic. Everything here keys off those two.
 *
 * Loaded on every page after the page's own stylesheets and before theme.css, which must stay last.
 * What one page shows in Basic lives with that page — the Overview's in style.css, the Forecast
 * page's in forecast.css; this file holds only what every page shares.
 */

/* ============ WHAT BASIC LEAVES OUT ============ */
/* Anything marked data-adv is Advanced-only. !important for the same reason as `#app [hidden]`:
   a panel grid or flex row declared by id would otherwise outrank the attribute. */
:root[data-ui-mode="basic"] [data-adv] { display: none !important; }
/* …and the other way round: data-basic marks something only Basic shows (a plain-language card
   standing in for an analyst one). Written as "not basic" so a page whose uimode.js never ran
   falls back to the full Advanced view, not to a mix of both. */
:root:not([data-ui-mode="basic"]) [data-basic] { display: none !important; }

/* The tabs of Advanced-only pages. The tab of the page you are on stays, so the bar still says
   where you are while the notice below covers that page. */
:root[data-ui-mode="basic"] #nav .tab[data-ui-tier="advanced"]:not(.active) { display: none; }

/* ============ THE SWITCH (top right of every page) ============ */
/* Neutral surface + the accent for the pressed state, like the other segmented controls — never
   violet (the what-if mode's colour) and never a PM2.5 band colour. Fixed px, not the page
   density var: the header looks the same on every page. */
.ui-mode-wrap { position: relative; flex: 0 0 auto; }
.ui-mode {
  display: inline-flex; align-items: center; gap: 2px; padding: 2px;
  background: var(--bg-2); border: 1px solid var(--border-2); border-radius: 8px;
}
.ui-mode-btn {
  font-family: inherit; font-size: 11px; font-weight: 700; line-height: 1.2; letter-spacing: .01em;
  color: var(--muted); background: transparent; border: 0; border-radius: 6px;
  padding: 5px 10px; cursor: pointer; white-space: nowrap;
}
.ui-mode-btn:hover { color: var(--text); }
.ui-mode-btn[aria-pressed="true"] {
  color: var(--accent); cursor: default;
  background: color-mix(in srgb, var(--accent) 16%, transparent);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--accent) 45%, transparent);
}
.ui-mode-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* The first-visit note hangs from the switch, so it needs no measuring (and §09's UI zoom cannot
   misplace it). z 70: over the map chrome and the province popovers, as a first-paint note should
   be; nothing else is open on a first load. */
.ui-hint {
  position: absolute; top: calc(100% + 12px); right: 0; z-index: 70;
  width: 300px; max-width: calc(100vw - 24px);
  background: var(--panel-2); color: var(--text);
  border: 1px solid color-mix(in srgb, var(--accent) 55%, var(--border-2)); border-radius: 10px;
  padding: 12px 14px; font-size: 12px; line-height: 1.55; text-align: left;
  box-shadow: 0 18px 40px -16px rgba(0, 0, 0, .85);
}
.ui-hint::before {
  content: ""; position: absolute; top: -6px; right: 30px; width: 10px; height: 10px;
  background: var(--panel-2); transform: rotate(45deg);
  border-left: 1px solid color-mix(in srgb, var(--accent) 55%, var(--border-2));
  border-top: 1px solid color-mix(in srgb, var(--accent) 55%, var(--border-2));
}
.ui-hint-title { font-weight: 700; color: var(--accent); margin-bottom: 4px; }
.ui-hint p { margin: 0 0 10px; color: var(--muted); }
.ui-hint-foot {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  font-size: 11px; color: var(--muted);
}
.ui-hint-ok {
  flex: 0 0 auto; font-family: inherit; font-size: 12px; font-weight: 700; cursor: pointer;
  color: var(--accent); background: transparent;
  border: 1px solid color-mix(in srgb, var(--accent) 55%, transparent); border-radius: 6px; padding: 4px 12px;
}
.ui-hint-ok:hover { background: color-mix(in srgb, var(--accent) 14%, transparent); }
.ui-hint-ok:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ============ AN ADVANCED-ONLY PAGE OPENED IN BASIC ============ */
/* Before first paint only the attribute exists, so the page under the bar is hidden until
   uimode.js lays the notice over it. visibility, not display: the layout stays real, so a map or
   chart that does start measures its true size, and hidden content leaves the tab order and the
   accessibility tree. */
:root[data-ui-gated] #app > :not(#topbar) { visibility: hidden !important; }
:root[data-ui-gated] body { overflow: hidden; }

.ui-gate {
  /* --ui-gate-top: the bottom of the top bar (placeGate in uimode.js) */
  position: fixed; left: 0; right: 0; bottom: 0; top: var(--ui-gate-top, 72px); z-index: 200;
  display: grid; place-items: center; overflow-y: auto; padding: 24px 16px;
  background: var(--bg);
}
.ui-gate-card {
  width: min(560px, 100%);
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--border-2); border-radius: 12px; padding: 22px 24px 18px;
  box-shadow: 0 24px 60px -30px rgba(0, 0, 0, .9);
}
.ui-gate-eyebrow { font-size: 11px; font-weight: 700; color: var(--accent); margin-bottom: 6px; }
.ui-gate-title { margin: 0 0 8px; font-size: 18px; line-height: 1.4; font-weight: 700; color: var(--text); }
.ui-gate-text { margin: 0 0 16px; font-size: 13px; line-height: 1.65; color: var(--muted); }
.ui-gate-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; }
.ui-gate-primary {
  font-family: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
  color: #04141c; background: var(--accent); border: 0; border-radius: 8px; padding: 9px 16px;
}
.ui-gate-primary:hover { filter: brightness(1.08); }
.ui-gate-primary:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.ui-gate-links { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 12px; color: var(--muted); }
.ui-gate-link {
  color: var(--text); text-decoration: none; font-weight: 600;
  border: 1px solid var(--border-2); border-radius: 6px; padding: 5px 10px;
}
.ui-gate-link:hover { border-color: var(--accent); color: var(--accent); }
.ui-gate-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
/* --muted, not --faint, for the small print here: --faint falls under AA contrast on these cards */
.ui-gate-note { margin: 16px 0 0; font-size: 12px; color: var(--muted); line-height: 1.6; }

/* ============ ROOM FOR THE SWITCH ============ */
/* The bar is one row of brand · menu · right block, and only the menu shrinks — its tabs never
   wrap, so a menu that runs out of room paints over the clock. Basic has two tabs and room to
   spare; these steps are for Advanced's eight, measured on the Overview (the widest right block:
   it also carries ทำไม?) so the last tab clears the switch at every desk width from 1280px up.
   scripts/check_layout_fit.py fails a run where it does not. */
#topbar { gap: 16px; }
.topbar-right { gap: 14px; }
/* 1441–1600px: the full-size menu (12px, icons) is widest here; below 1536 its icons go, as
   they already do from 1440 down */
@media (min-width: 1441px) and (max-width: 1600px) {
  #nav .tab { padding-left: 5px; padding-right: 5px; gap: 4px; }
}
@media (min-width: 1441px) and (max-width: 1535px) {
  #nav .tab { padding-left: 7px; padding-right: 7px; }
  #nav .tab-icon { display: none; }
}
@media (max-width: 1366px) {
  #topbar { gap: 12px; }
  .topbar-right { gap: 10px; }
  .clock-date { font-size: 14px; }
}
@media (max-width: 1280px) {
  .ui-mode-btn { padding: 5px 8px; }
  .why-btn { padding-left: 11px; padding-right: 11px; }
}
/* 1201–1279px, below the narrowest defended desk (1280): the Overview's ทำไม? keeps only its ✦
   (the label stays for screen readers, and the button's title names it) */
@media (max-width: 1279px) {
  #topbar { gap: 10px; }
  .topbar-right { gap: 8px; }
  .ui-mode-btn { padding: 5px 7px; }
  .clock-date { font-size: 13px; }
  .why-btn #why-btn-label {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
}
/* ≤1200px the page already stacks and scrolls, and eight Thai tabs no longer fit beside the clock
   at any spacing: the menu scrolls sideways instead of running under it (impact.css does the same
   for its pages at ≤1080px). The 2px keeps a focused tab's ring inside the scrolling box. */
@media (max-width: 1200px) {
  #nav { overflow-x: auto; overflow-y: hidden; padding: 2px 0; scrollbar-width: none; }
  #nav::-webkit-scrollbar { display: none; }
}

/* ============ PHONES ============ */
/* ≤720px the bar wraps instead of overflowing: --top-h only sizes grid rows (no calc() reads it),
   so `auto` lets the first row grow to the wrapped bar. */
@media (max-width: 720px) {
  :root { --top-h: auto; }
  #topbar { flex-wrap: wrap; row-gap: 8px; padding: 8px 12px; }
  .topbar-right { flex-wrap: wrap; justify-content: flex-end; gap: 8px 12px; }
  /* Basic has two pages, and on a phone this menu is the only way between them (the full
     eight-tab menu stays hidden here, as before) */
  :root[data-ui-mode="basic"] #nav { display: flex; order: 3; flex: 1 0 100%; }
}

/* ============ SHARED BITS ============ */
/* screen-reader-only text (the switch announces itself through #ui-mode-live) */
.ui-sr {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
@media print {
  .ui-hint, .ui-mode-wrap { display: none !important; }
}
