/* ==========================================================================
   Track 40 — design v2 module (opyeb static sites)
   1) input/select/textarea border contrast (#64748b, 4.76:1 on white)
   2) 390px overflow fixes (tabs / quick rows / header row)
   3) comparison table, related-tool cards, print summary sheet
   Written against the sites' own design tokens (var(--line2) …) with
   neutral fallbacks so it also works on pages that define fewer tokens.
   No @import, no url(), no network access.
   ========================================================================== */

/* ---------- 1. form control border contrast ------------------------------- */
/* One colour for both themes: #64748b.
     on #ffffff  4.76:1   (WCAG 1.4.11 asks for 3:1 on non-text UI)
     on #f4f6fb  4.52:1
     on #0b0b0d  4.00:1
   That keeps the border legal on light, off-white and near-black surfaces, and
   avoids picking the wrong tone on pages whose data-theme attribute and colour
   palette disagree (crossclock does exactly that). :focus is untouched so each
   site keeps its own focus ring colour. */
/* !important is needed: several sites pin their hairline border with
   `html[data-theme="light"] input { border-color: … !important }`
   (localstash does). Focus and explicit error states are left to the site. */
html body input:not([type="checkbox"]):not([type="radio"]):not([type="range"]):not([type="color"]):not([type="file"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not(:focus):not(.invalid):not(.is-invalid):not([aria-invalid="true"]),
html body select:not(:focus):not(.invalid):not([aria-invalid="true"]),
html body textarea:not(:focus):not(.invalid):not([aria-invalid="true"]) {
  border-color: #64748b !important;
}

/* ---------- 2. 390px overflow fixes -------------------------------------- */
/* dsr #calc-4 / dividend #calc-4: quick-value and tab rows could not shrink
   below their min-content width and pushed the card ~66px / ~4px off screen. */
.tabs { flex-wrap: wrap; }
.quick { flex-wrap: wrap; }
/* .card-head is a no-wrap flex row of <h2> + <span class="hint">; on 390px the
   hint's min-content width decided the whole card width (dsr +66px,
   dividend +4px). Let it wrap and shrink. */
.card-head { flex-wrap: wrap; }
.card-head > *, .hint { min-width: 0; }
/* dsr #calc-4: two 200px .split-box cards sat in a no-wrap row (410px). */
.split-2, .split-3, .split, .grid-2, .grid-3 { flex-wrap: wrap; }
.split-2 > *, .split-3 > *, .split > * { min-width: 0; flex: 1 1 150px; }
.quick > *, .tabs > * { min-width: 0; }
.card, .pan, .result-card, .col-main, .col-side,
.layout > *, .calc-grid > *, .fields > *, main > * { min-width: 0; }
/* finance pages put #calc straight into a column flex row with align-items:
   start, so the card's max-content width (one long card-head line) decided the
   page width. Stretching the card to the column is what lets the rules above
   take effect: 440px → 358px at a 390px viewport. */
.wrap.layout { align-items: stretch; }
.wrap.layout > *, .col-main > *, .layout > * { min-width: 0; flex-shrink: 1; }
.wrap.layout > .card, .col-main > .card { width: 100%; max-width: 100%; }
.tablewrap { max-width: 100%; -webkit-overflow-scrolling: touch; }

@media (max-width: 430px) {
  /* crossclock: brand + nav + theme button ran 10px past the right edge. */
  .site-head .wrap, .head-inner { min-width: 0; }
  .site-head .site-nav { min-width: 0; overflow-x: auto; }
}

/* ---------- 3. comparison table ----------------------------------------- */
.t40-block {
  margin: 38px 0;
  font-family: inherit;
  /* secondary text colour for the block; t40.js re-derives it from the real
     background behind the block (site palettes range from white to near-black,
     and some pages set data-theme that disagrees with their palette) */
  --t40-mut: #4b5563;
}
[data-theme="dark"] .t40-block, html.dark .t40-block { --t40-mut: #c3cbd6; }
@media (prefers-color-scheme: dark) {
  html:not([data-theme="light"]) .t40-block { --t40-mut: #c3cbd6; }
}
.t40-wrap {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
  box-sizing: border-box;
}
.t40-block h2 {
  margin: 0 0 6px;
  font-size: clamp(17px, 2.2vw, 22px);
  line-height: 1.35;
  color: inherit;
}
.t40-block p { color: var(--t40-mut); line-height: 1.6; }
.t40-kicker {
  display: inline-block;
  margin: 0 0 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--t40-mut);
}
.t40-lead { margin: 0 0 14px; font-size: 13.5px; max-width: 68ch; color: var(--t40-mut); }
.t40-tablewrap {
  width: 100%;
  overflow-x: auto;
  border: 1px solid var(--line, rgba(128, 128, 128, .28));
  border-radius: var(--radius, 14px);
  background: var(--panel, transparent);
}
table.t40-table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  font-size: 13.5px;
  line-height: 1.55;
}
table.t40-table caption {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
table.t40-table th, table.t40-table td {
  padding: 11px 14px;
  word-break: keep-all;
  overflow-wrap: anywhere;
  border-bottom: 1px solid var(--line, rgba(128, 128, 128, .22));
  text-align: left;
  vertical-align: top;
}
table.t40-table thead th {
  font-size: 12.5px;
  font-weight: 700;
  background: var(--panel2, rgba(128, 128, 128, .1));
  color: inherit;
}
table.t40-table thead th.t40-now { color: inherit; font-weight: 800; }
table.t40-table tbody th {
  width: 19%;
  font-weight: 700;
  color: inherit;
  white-space: nowrap;
}
table.t40-table tbody td { color: inherit; }
table.t40-table td.t40-now { background: var(--accent-dim, rgba(128, 128, 128, .08)); }
table.t40-table tbody tr:last-child th,
table.t40-table tbody tr:last-child td { border-bottom: 0; }
table.t40-table a { color: inherit; text-decoration: underline; text-underline-offset: 2px; }
table.t40-table .t40-dash { color: inherit; font-weight: 400; }
.t40-src { margin: 8px 0 0; font-size: 12px; }

@media (max-width: 700px) {
  table.t40-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.t40-table, table.t40-table tbody, table.t40-table tr, table.t40-table th, table.t40-table td { display: block; width: auto; }
  table.t40-table { border: 0; }
  table.t40-table tbody tr {
    border: 1px solid var(--line, rgba(128, 128, 128, .28));
    border-radius: var(--radius-sm, 10px);
    margin: 0 0 10px;
    padding: 4px 0;
    background: var(--panel, transparent);
  }
  table.t40-table tbody tr:last-child { margin-bottom: 0; }
  table.t40-table tbody th,
  table.t40-table tbody td { border: 0; padding: 6px 12px; white-space: normal; width: auto; }
  table.t40-table tbody th { font-size: 11.5px; letter-spacing: .04em; color: var(--t40-mut); }
  table.t40-table tbody td { padding-top: 0; }
  table.t40-table tbody td[data-col]::before {
    content: attr(data-col) ": ";
    display: block;
    font-size: 11px;
    font-weight: 700;
    color: var(--t40-mut);
    margin-bottom: 2px;
  }
  table.t40-table td.t40-now { background: transparent; }
}

/* ---------- 4. related tool cards --------------------------------------- */
.t40-rel {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
  margin-top: 4px;
}
.t40-rel a {
  display: block;
  padding: 13px 15px;
  border: 1px solid var(--line, rgba(128, 128, 128, .3));
  border-radius: var(--radius-sm, 12px);
  background: var(--panel, transparent);
  color: inherit;
  text-decoration: none;
  transition: border-color .15s ease, background .15s ease;
}
.t40-rel a:hover, .t40-rel a:focus-visible {
  border-color: var(--accent, var(--line2, #64748b));
  background: var(--panel2, rgba(128, 128, 128, .08));
}
.t40-rel b { display: block; font-size: 14px; line-height: 1.35; }
.t40-rel span { display: block; margin-top: 3px; font-size: 12px; line-height: 1.5; color: var(--t40-mut); }

/* ---------- 5. print summary sheet -------------------------------------- */
.t40-print-card {
  border: 1px solid var(--line, rgba(128, 128, 128, .28));
  border-radius: var(--radius, 14px);
  padding: 16px 18px;
  background: var(--panel, transparent);
}
.t40-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 10px; }
.t40-printbtn {
  /* fixed CTA colours: 6.9:1 on any page palette (site accents range from
     #ffb84d to near-black, so they cannot be trusted for white text) */
  appearance: none;
  border: 1px solid #1d4ed8;
  background: #1d4ed8;
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: var(--radius-sm, 10px);
  cursor: pointer;
  min-height: 40px;
}
.t40-printbtn:hover { filter: brightness(1.06); }
.t40-printbtn:focus-visible { outline: 2px solid #1d4ed8; outline-offset: 3px; }
.t40-printnote { margin: 0; font-size: 12px; color: var(--t40-mut); }

#t40-printroot { display: none; }

@media print {
  @page { margin: 14mm; }
  html { color-scheme: light !important; background: #fff !important; }
  body { background: #fff !important; margin: 0 !important; padding: 0 !important; }
  body::before, body::after, body.t40-print-ready::before, body.t40-print-ready::after { display: none !important; }
  body.t40-print-ready > *:not(#t40-printroot) { display: none !important; }
  body.t40-print-ready #t40-printroot {
    display: block !important;
    color: #000;
    background: #fff;
    font-family: system-ui, -apple-system, "Malgun Gothic", "Apple SD Gothic Neo", "Segoe UI", sans-serif;
    font-size: 10.5pt;
    line-height: 1.45;
  }
  #t40-printroot { margin: 0 !important; padding: 0 !important; position: static !important; transform: none !important; }
  #t40-printroot .t40-sheet { max-width: 172mm; margin: 0 !important; }
  #t40-printroot .t40-sheet-kicker { font-size: 9pt; letter-spacing: .12em; color: #444; margin: 0 0 4mm; }
  #t40-printroot h1 { font-size: 17pt; margin: 0 0 2mm; line-height: 1.25; }
  #t40-printroot .t40-sheet-sub { font-size: 11pt; color: #222; margin: 0 0 4mm; }
  #t40-printroot .t40-sheet-url { font-size: 7.5pt; color: #555; word-break: break-all; margin: 0 0 5mm; }
  #t40-printroot h2 { font-size: 11pt; margin: 5mm 0 2mm; }
  #t40-printroot table { width: 100%; border-collapse: collapse; margin: 0 0 3mm; }
  #t40-printroot th, #t40-printroot td { border: 1px solid #999; padding: 1.6mm 2.4mm; text-align: left; vertical-align: top; font-size: 10pt; }
  #t40-printroot th { width: 34%; background: #f2f2f2; font-weight: 700; }
  #t40-printroot .t40-sheet-note { font-size: 8pt; color: #444; margin: 4mm 0 0; line-height: 1.5; }
  #t40-printroot .t40-sheet-empty { font-size: 9.5pt; color: #333; }
}
