/* niwcheck.com: one stylesheet for / (English) and /fa/ (Persian, right to left).
   Look: a printed bulletin sheet. Paper and ink, hairline rules instead of cards, a serif
   wordmark, and the dates set in a monospaced face like the bulletin's own tables.
   Every text color meets WCAG AA (4.5:1) on the paper in light and dark mode
   (tests/test_html_template.py). script.js reads the --chart-* tokens to color the chart. */

/* Self-hosted (SIL OFL, see fonts/Vazirmatn-OFL.txt): Google Fonts is unreliable for some visitors */
@font-face {
  font-family: "Vazirmatn";
  src: url("/assets/fonts/Vazirmatn-Variable.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --paper: #f6f3ec;
  --paper-2: #ede8dc;
  --ink: #1c1a17;
  --muted: #5f5a51;
  --rule: #d9d2c3;
  --final: #0e5a6b;
  --filing: #a64a12;
  --up: #23703a;
  --down: #b0261c;
  --flat: #5f5a51;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Segoe UI Mono", Menlo, Consolas, "Liberation Mono", monospace;

  --chart-surface: #f6f3ec;
  --chart-text: #3b3832;
  --chart-grid: #e6e0d3;
  --chart-axis: #8a8274;
  --chart-legend-bg: rgba(246, 243, 236, 0.92);
  --chart-final: #0e5a6b;
  --chart-filing: #a64a12;
  --chart-pd: #8f2d63;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151412;
    --paper-2: #211f1b;
    --ink: #ede8de;
    --muted: #b1aa9d;
    --rule: #3a3630;
    --final: #67b9ca;
    --filing: #e49b61;
    --up: #77c98c;
    --down: #f2897d;
    --flat: #b1aa9d;

    --chart-surface: #151412;
    --chart-text: #d6d0c4;
    --chart-grid: #2c2925;
    --chart-axis: #8d8678;
    --chart-legend-bg: rgba(21, 20, 18, 0.92);
    --chart-final: #67b9ca;
    --chart-filing: #e49b61;
    --chart-pd: #e58fbd;
  }
}

html[lang="fa"] {
  --font: "Vazirmatn", Tahoma, sans-serif;
  --serif: "Vazirmatn", Tahoma, sans-serif;
  --mono: "Vazirmatn", Tahoma, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

/* Plotly parks a measuring element far to the left; on the right-to-left page that would make the
   whole page scroll sideways (and phones zoom out). Clip horizontal overflow at the page level. */
html, body { overflow-x: hidden; }
@supports (overflow: clip) { html, body { overflow-x: clip; } }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 16px/1.55 var(--font);
  font-variant-numeric: tabular-nums;
}

a { color: inherit; text-underline-offset: 3px; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 2px solid var(--final); outline-offset: 2px; }

.wrap { max-width: 860px; margin: 0 auto; padding: 0 20px; }

/* Hidden until focused, without off-screen offsets (those scroll sideways on the right-to-left page) */
.skip-link:not(:focus) {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.skip-link:focus { position: absolute; inset-inline-start: 12px; top: 12px; z-index: 10; padding: 8px 12px; background: var(--ink); color: var(--paper); }

/* ---------- masthead: wordmark, language switch, double rule ---------- */
.masthead { border-bottom: 3px double var(--ink); }

.masthead-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-top: 22px;
}

.wordmark {
  font: 700 32px/1 var(--serif);
  letter-spacing: 0.01em;
  color: var(--ink);
  text-decoration: none;
}

.wordmark span {
  margin-left: 8px;
  font: 400 13px/1 ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--muted);
}

.lang { display: flex; gap: 4px; }

.lang a {
  font: 500 13px/1 var(--mono);
  padding: 5px 8px;
  border: 1px solid transparent;
  color: var(--muted);
  text-decoration: none;
}

.lang a[aria-current="page"] { color: var(--ink); border-color: var(--ink); }
.lang a[lang="fa"] { font-family: "Vazirmatn", Tahoma, sans-serif; }

.tagline {
  margin: 6px 0 12px;
  font: 400 14px/1.4 var(--font);
  color: var(--muted);
}

/* ---------- this month ---------- */
.dateline {
  margin: 22px 0 10px;
  font: 400 13px/1.5 var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.dateline strong { color: var(--ink); font-weight: 700; }

.figures {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--rule);
}

.figure { padding: 18px 0 20px; min-width: 0; }
.figure + .figure { border-inline-start: 1px solid var(--rule); padding-inline-start: 24px; }

.figure h2 {
  margin: 0 0 10px;
  font: 500 12px/1.3 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

/* A square in the line's color ties each date to its line in the chart */
.figure h2::before {
  content: "";
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-inline-end: 8px;
  background: var(--final);
}

.figure--filing h2::before { background: var(--filing); }

.figure-date {
  margin: 0;
  font: 600 clamp(26px, 5vw, 42px)/1.1 var(--mono);
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.figure-alt { margin: 4px 0 0; font-size: 14px; color: var(--muted); }

.figure-change { margin: 10px 0 0; font: 600 15px/1.3 var(--mono); }

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--flat); }

.i485 { margin: 14px 0 0; font-size: 15px; color: var(--muted); }
.i485 strong { color: var(--ink); font-weight: 600; }

/* ---------- sections ---------- */
.section-title {
  margin: 40px 0 14px;
  padding-top: 10px;
  border-top: 1px solid var(--ink);
  font: 700 21px/1.3 var(--serif);
}

.note { margin: 8px 0 0; font-size: 13px; color: var(--muted); }

/* ---------- priority-date check ---------- */
.check-form { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 12px; }

.check-form label {
  font: 500 12px/1.3 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.check-form input {
  min-width: 11.5em;
  padding: 9px 10px;
  font: 16px/1.2 var(--mono);
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 0;
}

.check-form input[aria-invalid="true"] { border-color: var(--down); }

.check-form button {
  padding: 10px 20px;
  font: 700 13px/1.2 var(--mono);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--paper);
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: 0;
  cursor: pointer;
}

.check-form button:hover { color: var(--ink); background: transparent; }

.check-result:empty { display: none; }
.check-result { margin-top: 16px; }

.result-table { width: 100%; border-collapse: collapse; }

.result-table th,
.result-table td {
  padding: 10px 0;
  border-top: 1px solid var(--rule);
  text-align: start;
  vertical-align: top;
}

.result-table th { width: 34%; padding-inline-end: 16px; font: 500 14px/1.4 var(--mono); }
.result-table td { font-size: 15px; }
.result-row--yes td::before { content: "✓ "; color: var(--up); font-weight: 700; }
.result-row--no td::before { content: "○ "; color: var(--muted); }
.result-est { display: inline-block; margin-top: 2px; color: var(--muted); }
.result-est strong { color: var(--ink); }

.result-i485 { margin: 10px 0 0; padding-top: 10px; border-top: 1px solid var(--rule); font-size: 15px; }
.result-note { margin: 6px 0 0; font-size: 13px; color: var(--muted); }
.tool-error { margin: 0; color: var(--down); }

/* ---------- chart ---------- */
.chart { width: 100%; min-height: 470px; }
.chart-caption:empty { display: none; }
.chart-fallback { padding: 24px 0; color: var(--muted); }

/* ---------- history ---------- */
.history { margin-top: 36px; }

.history summary {
  padding: 12px 0;
  border-top: 1px solid var(--ink);
  border-bottom: 1px solid var(--rule);
  font: 600 14px/1.4 var(--mono);
  letter-spacing: 0.04em;
  cursor: pointer;
  list-style: none;
}

.history summary::-webkit-details-marker { display: none; }
.history summary::before { content: "+ "; color: var(--muted); }
.history details[open] summary::before { content: "− "; }

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.history-table { width: 100%; min-width: 560px; border-collapse: collapse; font: 14px/1.4 var(--mono); }

.history-table th,
.history-table td {
  padding: 7px 10px 7px 0;
  border-bottom: 1px solid var(--rule);
  text-align: start;
  white-space: nowrap;
}

html[dir="rtl"] .history-table th,
html[dir="rtl"] .history-table td { padding: 7px 0 7px 10px; }

.history-table thead th { font-weight: 500; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); }
.history-table tbody th { font-weight: 600; }
.history-table .num { text-align: end; }
.history-table tbody tr:nth-child(even) { background: var(--paper-2); }

/* ---------- footer ---------- */
.colophon { margin-top: 48px; border-top: 3px double var(--ink); padding: 16px 0 40px; }

.telegram { margin: 0 0 12px; font: 600 14px/1.4 var(--mono); }
.telegram a { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; }
.telegram a:hover span { text-decoration: underline; }

.disclaimer { margin: 0; max-width: 64ch; font-size: 13px; color: var(--muted); }
.meta { margin: 8px 0 0; font: 12px/1.4 var(--mono); color: var(--muted); }
.meta:empty { display: none; }

/* ---------- phones ---------- */
@media (max-width: 640px) {
  .wrap { padding: 0 16px; }
  .masthead-row { padding-top: 16px; }
  .wordmark { font-size: 27px; }
  .figures { grid-template-columns: 1fr; }
  .figure + .figure { border-inline-start: 0; padding-inline-start: 0; border-top: 1px solid var(--rule); }
  .figure-date { font-size: 32px; }
  .section-title { margin-top: 32px; font-size: 19px; }
  .check-form input { flex: 1 1 12em; }
  .check-form button { flex: 0 0 auto; }
  .result-table th { width: auto; display: block; padding-bottom: 0; border-top: 1px solid var(--rule); }
  .result-table td { display: block; border-top: 0; padding-top: 4px; }
  .result-table tr { display: block; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; animation: none !important; }
}

@media print {
  .check, .chart-section, .lang { display: none; }
  .history details > *:not(summary) { display: block; }
}
