/* Reading layer for Japanese, Chinese and English, on PC and phone (operator request 2026-11-23:
   "all japanese chinese and english are not well presented").

   Loaded after Pico and after the shell's own <style>, so it decides typography for every page:
   - each language gets a font stack in its own script first, with the other scripts behind it,
     because guest names, property names and messages arrive in any language on any page;
   - Pico's headings, buttons and inputs read --pico-font-family (system-ui first). On a Japanese
     Windows PC that is Yu Gothic UI, so Chinese headings came out in a Japanese font with simplified
     characters patched in from another one. Pico's variable now points at the same stacks;
   - <html> carries data-theme="light": the portal's cards are white, and Pico's automatic dark
     theme turned the text light grey on phones set to dark mode;
   - Japanese and Chinese get CJK line spacing and strict line breaking; English stops breaking in
     the middle of words (overflow-wrap:anywhere is kept only for addresses, ids and URLs). */

:root {
  --font-latin: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial;
  /* BIZ UDPGothic (Windows 10+) and Hiragino (Apple) before Meiryo: both are drawn for reading at
     small sizes; Yu Gothic is left out because Windows renders its regular weight too thin. */
  --font-ja: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "BIZ UDPGothic", Meiryo, "Noto Sans JP", "Noto Sans CJK JP";
  --font-zh: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei UI", "Microsoft YaHei", "Noto Sans SC", "Noto Sans CJK SC", "Source Han Sans SC";
  --font-ne: "Noto Sans Devanagari", "Nirmala UI", "Kohinoor Devanagari", "Devanagari Sangam MN", Mangal;
  --font-emoji: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji";
  --font-ui: var(--font-latin), var(--font-ja), var(--font-zh), var(--font-ne), sans-serif, var(--font-emoji);
  --reading-line: 1.6;
  --heading-line: 1.3;
  --label-tracking: .04em;
}
html:lang(ja) {
  --font-ui: var(--font-latin), var(--font-ja), var(--font-zh), var(--font-ne), sans-serif, var(--font-emoji);
  --reading-line: 1.75;
  --heading-line: 1.4;
  --label-tracking: .02em;
}
html:lang(zh) {
  --font-ui: var(--font-latin), var(--font-zh), var(--font-ja), var(--font-ne), sans-serif, var(--font-emoji);
  --reading-line: 1.75;
  --heading-line: 1.4;
  --label-tracking: .02em;
}
html:lang(en) {
  --reading-line: 1.55;
  --heading-line: 1.25;
}
/* Nepali UI (2026-11-23). Devanagari hangs from its headline and stacks vowel signs above and below,
   so it needs more line height than Latin; letter-spacing would break the headline between letters. */
html:lang(ne) {
  --font-ui: var(--font-latin), var(--font-ne), var(--font-ja), var(--font-zh), sans-serif, var(--font-emoji);
  --reading-line: 1.8;
  --heading-line: 1.45;
  --label-tracking: 0;
}
html:lang(ne) :is(h1, h2, h3, h4, h5, h6, .stat-label, .metric-tile span, .entity-eyebrow, .hero-eyebrow,
    .dashboard-table th, .eyebrow, .section-eyebrow, .ops-overview-eyebrow, .site-nav-link, .language-pill,
    button, [role="button"], .pill, .badge-soft, .mobile-nav-label, .brand-title) {
  letter-spacing: 0;
  text-transform: none;
}
html[lang] {
  --body-font: var(--font-ui);
  --display-font: var(--font-ui);
  --pico-font-family: var(--font-ui);
  --pico-font-family-sans-serif: var(--font-ui);
  --pico-line-height: var(--reading-line);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body {
  font-family: var(--font-ui);
  line-height: var(--reading-line);
}
button, input, select, textarea, optgroup { font-family: inherit; }

/* Text in another script inside a page: a Nepali translation line on an English page, a Chinese
   reply on a Japanese page. Elements marked with their own lang use that script's font first. */
[lang="ne"]:not(html) { font-family: var(--font-ne), var(--font-latin), sans-serif; line-height: 1.8; }
[lang|="ja"]:not(html) { font-family: var(--font-latin), var(--font-ja), var(--font-zh), sans-serif; }
[lang|="zh"]:not(html) { font-family: var(--font-latin), var(--font-zh), var(--font-ja), sans-serif; }
.mono, code, kbd, pre, samp { font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "BIZ UDGothic", monospace; }

/* ---- Line breaking ---- */
p, li, dd, dt, td, th, label, blockquote, figcaption, .entity-subtitle, .action-card-title,
.stack-item h3, .stack-item h4, .stack-item p, .table-stack td, .table-stack th {
  overflow-wrap: break-word;
  word-break: normal;
}
p, li, dd, blockquote, figcaption { text-wrap: pretty; }
/* Long unbroken tokens may still break anywhere: e-mail addresses, ids, URLs, tokens. */
.mono, code, .break-anywhere, a[href^="http"], a[href^="mailto:"] { overflow-wrap: anywhere; }
html:lang(ja), html:lang(zh) { line-break: strict; }
h1, h2, h3, h4, h5, h6 { line-height: var(--heading-line); text-wrap: balance; }
html:lang(ja) h1, html:lang(ja) h2, html:lang(ja) h3, html:lang(ja) h4 {
  /* Proportional kana in headings only (body text keeps full-width spacing for reading). */
  font-feature-settings: "palt" 1;
  letter-spacing: .02em;
}
/* Short labels wrap at phrase boundaries in Japanese (Chrome 119+) rather than mid-word, and never
   collapse into a column of single characters. */
html:lang(ja) :is(h1, h2, h3, h4, button, [role="button"], .site-nav-link, .pill, .badge-soft, th, label, .entity-title, .action-card-title, .mobile-nav-label, .stat-label, .metric-tile span, .ops-label) {
  word-break: auto-phrase;
}
:is(.language-pill, .mobile-nav-label) { white-space: nowrap; }
/* Pills and badges may wrap onto a second line ("Operations lead" pushed the English users page past a
   phone's width when it could not), but never inside a word. */
:is(.pill, .badge-soft) { max-width: 100%; overflow-wrap: break-word; }
:is(button, [role="button"], a[role="button"], input[type="submit"]) { line-height: 1.35; }

/* ---- Labels written as English small caps ----
   Uppercase and wide tracking are an English device. Japanese and Chinese have no capitals, and
   .12em of tracking pulled each word apart into separate characters. */
:is(.stat-label, .metric-tile span, .entity-eyebrow, .hero-eyebrow, .dashboard-table th, .eyebrow, .section-eyebrow) {
  letter-spacing: var(--label-tracking);
}
html:lang(ja) :is(.stat-label, .metric-tile span, .entity-eyebrow, .hero-eyebrow, .dashboard-table th, .eyebrow, .section-eyebrow),
html:lang(zh) :is(.stat-label, .metric-tile span, .entity-eyebrow, .hero-eyebrow, .dashboard-table th, .eyebrow, .section-eyebrow) {
  text-transform: none;
  font-size: max(.82rem, 13px);
  font-weight: 700;
}
html:lang(en) :is(.entity-eyebrow, .hero-eyebrow) { letter-spacing: .08em; }

/* ---- Numbers line up in tables, counters and dates ---- */
:is(table, .stat-value, .metric-tile strong, .hero-stat strong, time, .tabular) { font-variant-numeric: tabular-nums; }

/* ---- Contrast: grey metadata was #5f7386/#666 at 12-13px; darker so it reads on phones ---- */
.muted, .entity-subtitle, .action-card-copy, .stat-label, .metric-tile span, small { color: #4b6075; }
.muted { font-size: max(.9rem, 14px); }

/* ---- Prose width: long paragraphs stay readable on wide PC screens ---- */
.hero-copy, .empty-state p, .box > p, .surface-header p { max-width: 46em; }
html:lang(ja) :is(.hero-copy, .empty-state p, .box > p, .surface-header p),
html:lang(zh) :is(.hero-copy, .empty-state p, .box > p, .surface-header p) { max-width: 40em; }

/* ---- Phone ---- */
@media (max-width: 640px) {
  /* 16px is the floor for body text on phones; CJK below 13px loses strokes. */
  html { font-size: 16px; }
  .mobile-nav-item { font-size: 12px; }
  .mobile-nav-label { line-height: 1.15; }
  /* Pico's 2rem h1 fills a third of a phone line with CJK; class-sized headings keep their own. */
  h1 { --pico-font-size: 1.55rem; }
  h2 { --pico-font-size: 1.3rem; }
  h3 { --pico-font-size: 1.12rem; }
  .dashboard-table { font-size: .9rem; }
  /* Column titles wrap so a four-column table fits a phone instead of scrolling. */
  .dashboard-table th { white-space: normal; vertical-align: bottom; }
  .table-wrap .dashboard-table { min-width: 0; }
  .pill { font-size: .86rem; }
  input, select, textarea { font-size: 16px; } /* below 16px iOS zooms the page on focus */
}

/* ---- Layout guards found by the 2026-11-23 audit ----
   A grid column is as wide as its widest unbreakable content unless its items may shrink, so one
   nowrap table inside .grid-2 pushed the whole English dashboard to 518px on a 390px phone (the
   page then scrolled sideways). Items may shrink; wide tables scroll inside their own .table-wrap. */
:is(.dashboard-shell, .grid-2, .info-split-grid, .stats-grid, .hero-layout, .hero-stats, .entity-grid,
    .action-card-grid, .compact-form-grid, .mobile-card-grid, .ops-board) > * { min-width: 0; }
.table-wrap { max-width: 100%; }
/* The three menu bars of the phone header button were laid out in a row ("- - -"). */
.nav-toggle { flex-direction: column; }
/* Dashboard tiles: the label was .78rem at 75% opacity, too faint to read on a phone. */
.ops-label { font-size: max(.86rem, 13px); opacity: 1; color: #4b6075; line-height: 1.4; }

/* Hidden file inputs: Pico gives every input width:100% with higher specificity than a page's own
   .visually-hidden, so the three hidden pickers on the cleaning evidence page made it 1832px wide on PC. */
input.visually-hidden, .visually-hidden {
  position: absolute !important; width: 1px !important; height: 1px !important; min-height: 0 !important;
  padding: 0 !important; margin: -1px !important; overflow: hidden !important; clip: rect(0, 0, 0, 0) !important;
  border: 0 !important; white-space: nowrap !important;
}
