/* ============================================================
   CoolMax SRX CAN Protocol — print-style multi-page layout
   Forked from outputs/external/srx/user-manual-48v/user-manual-48v.css.
   Adds .id-tag / .reg-tag / .bit-range utilities for ID + bit-layout
   tables, plus tighter spec/code-table variants for register maps.
   Tokens imported transitively via the HTML's link to tokens.css.
   ============================================================ */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font-sans);
  font-size: var(--fs-14);
  line-height: var(--lh-normal);
  color: var(--fg-1);
  background: var(--gray-200);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* ---------- A4 page sheet ---------- */
.sheet {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 24px;
  padding: 32px 16px 64px;
}

.page {
  width: 794px;            /* A4 paper @ 96dpi */
  height: 1123px;          /* hard-cap at A4; not min-height */
  overflow: hidden;        /* clip overflow so authors SEE pages that don't fit */
  background: var(--bg-surface);
  box-shadow: var(--shadow-lg);
  padding: 68px 60px 92px; /* reserves the .pf footer band — per DESIGN_NOTES.md */
  position: relative;
  display: flex;
  flex-direction: column;
}
/* Over-full pages must overflow, never shrink their children into overlap. */
.page > * { flex-shrink: 0; }

/* ---------- Page header ---------- */
.ph {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 2px solid var(--gray-900);
  margin-bottom: 22px;
}
.ph__brand { display: flex; align-items: center; gap: 14px; }
.ph__logo  { height: 28px; width: auto; display: block; }
.ph__rule  { width: 1px; height: 22px; background: var(--border-strong); }
.ph__product {
  font-size: var(--fs-14);
  font-weight: 600;
  color: var(--fg-1);
  letter-spacing: -0.01em;
}
.ph__meta {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-3);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
}
.ph__meta .dot {
  width: 3px; height: 3px;
  background: var(--gray-300);
  border-radius: 50%;
}

/* ---------- Cover ---------- */
.cover { flex: 1 1 auto; display: flex; flex-direction: column; min-height: 0; }
.cover__hero {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 28px;
  align-items: center;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 22px;
}
.cover__copy { min-width: 0; }
.eyebrow {
  font-size: 11px; font-weight: 600;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--fg-accent);
  margin-bottom: 10px;
}
.cover__title {
  font-size: 40px; line-height: 1.05;
  letter-spacing: -0.025em;
  font-weight: 800;
  margin: 0 0 4px;
  color: var(--fg-1);
}
.cover__subtitle {
  font-size: 17px; font-weight: 400;
  color: var(--fg-2);
  margin: 0 0 12px;
  letter-spacing: -0.01em;
  max-width: 44ch;
}
.cover__model {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 12px; font-weight: 600;
  letter-spacing: var(--tracking-wide);
  color: var(--fg-accent);
  background: var(--primary-50);
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  margin-bottom: 12px;
}
.cover__lede {
  font-size: 13px; line-height: 1.55;
  color: var(--fg-2);
  margin: 0 0 12px;
  max-width: 48ch;
  text-wrap: pretty;
}
.cover__shot {
  margin: 0;
  display: flex; flex-direction: column;
  align-items: center; gap: 10px;
}
.cover__shot img {
  width: 100%; height: auto;
  max-height: 220px;
  object-fit: contain;
  display: block;
}
.cover__shot figcaption {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--fg-3);
}

/* Document meta block */
.docmeta {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border-top: 1px solid var(--border-subtle);
  border-left: 1px solid var(--border-subtle);
  margin-bottom: 20px;
}
.docmeta__cell {
  padding: 9px 12px;
  border-right: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  display: flex; flex-direction: column; gap: 2px;
}
.docmeta__k {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--fg-3);
}
.docmeta__v {
  font-size: 12.5px; font-weight: 600;
  color: var(--fg-1);
}

/* ---------- Section title ---------- */
.sec-title {
  font-size: 11px; font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--fg-2);
  margin: 0 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; gap: 10px;
}
.sec-title::before {
  content: "";
  width: 12px; height: 2px;
  background: var(--primary-500);
}

/* Big chapter heading (used at the top of body sections) */
.chapter {
  font-size: 26px; font-weight: 800;
  letter-spacing: -0.02em;
  margin: 0 0 4px;
  color: var(--fg-1);
}
.chapter__num {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--fg-accent);
  margin-bottom: 2px;
}
.chapter__rule {
  height: 2px; width: 48px;
  background: var(--primary-500);
  margin: 10px 0 14px;
}

/* H3 / H4 inside chapters */
.h3 {
  font-size: 15px; font-weight: 700;
  margin: 14px 0 4px;
  color: var(--fg-1);
  letter-spacing: -0.01em;
}
.h4 {
  font-size: 12px; font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--fg-2);
  margin: 10px 0 4px;
}

p { margin: 0 0 8px; font-size: 12.5px; line-height: 1.55; color: var(--fg-2); }
p strong { color: var(--fg-1); font-weight: 600; }

ul, ol { margin: 0 0 10px; padding-left: 20px; }
li { font-size: 12.5px; line-height: 1.5; color: var(--fg-2); }
li + li { margin-top: 2px; }

/* ---------- TOC ---------- */
.toc {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 24px;
  border-top: 1px solid var(--border-subtle);
}
.toc__entry {
  display: grid;
  grid-template-columns: 28px 1fr 36px;
  gap: 8px;
  align-items: baseline;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 12.5px;
}
.toc__num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-accent);
  font-weight: 600;
}
.toc__name { color: var(--fg-1); font-weight: 500; }
.toc__name small {
  display: block;
  font-size: 11px; font-weight: 400;
  color: var(--fg-3);
  margin-top: 2px;
}
.toc__page {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-3);
  text-align: right;
}

/* ---------- Callouts ---------- */
.callout {
  border-left: 4px solid var(--primary-500);
  background: var(--primary-50);
  padding: 10px 14px;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin: 10px 0;
  display: flex; gap: 10px;
  align-items: flex-start;
}
.callout__icon {
  width: 20px; height: 20px;
  flex: 0 0 20px;
  display: flex; align-items: center; justify-content: center;
  margin-top: 1px;
}
.callout__body { min-width: 0; }
.callout__label {
  display: block;
  font-size: 10.5px; font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  margin-bottom: 2px;
}
.callout__body p {
  margin: 0 0 4px;
  font-size: 11.5px; line-height: 1.45;
  color: var(--fg-1);
}
.callout__body p:last-child { margin-bottom: 0; }
.callout--important {
  border-left-color: var(--status-info);
  background: var(--status-info-bg);
}
.callout--important .callout__label { color: var(--status-info); }
.callout--note {
  border-left-color: var(--gray-700);
  background: var(--gray-50);
}
.callout--note .callout__label { color: var(--fg-2); }

/* ---------- Spec tables ---------- */
table.spec-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  margin: 6px 0 10px;
}
table.spec-table th,
table.spec-table td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}
table.spec-table th {
  background: var(--gray-900);
  color: var(--white);
  font-weight: 600;
  font-size: 10.5px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  padding: 7px 10px;
}
table.spec-table tbody tr:nth-child(even) td {
  background: var(--gray-50);
}
table.spec-table td:first-child {
  font-weight: 500;
  color: var(--fg-1);
}
table.spec-table td.value,
table.spec-table td:not(:first-child) {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-1);
}

/* For tables where every column should read as code (bit ranges, IDs) */
table.spec-table.mono td:first-child {
  font-family: var(--font-mono);
  font-size: 11px;
}

.spec-block + .spec-block { margin-top: 8px; }
.spec-block__head {
  font-size: 11px; font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--fg-accent);
  margin: 10px 0 4px;
  padding-bottom: 4px;
  border-bottom: 2px solid var(--primary-500);
  display: inline-block;
}

/* ---------- Two-column grid for spec pages ---------- */
.col2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 18px;
}

/* ---------- Figure ---------- */
.figure {
  margin: 8px 0 12px;
  background: var(--gray-50);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 10px;
  display: flex; flex-direction: column;
  gap: 6px;
}
.figure img {
  width: 100%; height: auto;
  display: block;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
}
.figure figcaption {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--fg-3);
  text-align: center;
}
.figure--tight img { max-height: 200px; object-fit: contain; }
.figure--xtight img { max-height: 130px; object-fit: contain; }

/* ---------- Side-by-side text + figure layout ---------- */
.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  align-items: start;
  margin: 8px 0 12px;
}
.split .figure { margin: 0; }

/* ---------- Pinout small tables (CAN / RS485) ---------- */
.pinout-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 8px 0 10px;
}
.pinout-pair table.spec-table { margin: 4px 0 0; }

/* ============================================================
   CAN-protocol-specific utilities
   ============================================================ */

/* Inline ID tag — used in section headings to surface "Master + 22" style */
.id-tag {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: var(--tracking-wide);
  color: var(--fg-accent);
  background: var(--primary-50);
  border: 1px solid var(--primary-200);
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  margin-left: 6px;
  vertical-align: 2px;
  white-space: nowrap;
}
.id-tag--master { color: var(--status-info); background: var(--status-info-bg); border-color: rgba(37,99,235,0.2); }
.id-tag--len    { color: var(--fg-2); background: var(--gray-50); border-color: var(--border-subtle); }

/* Reg-tag — for register/offset hex callouts inline */
.reg-tag {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--fg-accent);
  background: var(--primary-50);
  padding: 1px 6px;
  border-radius: var(--radius-sm);
}

/* Bit range column — fixed-width mono for "63...32" style cells */
.bit-range {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--fg-1);
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* Section card — wraps each broadcast/command message block with a uniform
   border + meta line, so the dense run of message tables reads as a list of
   blocks rather than a wall of text. */
.msg {
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  padding: 10px 12px 8px;
  margin: 8px 0 10px;
}
.msg + .msg { margin-top: 10px; }
.msg__head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 12px;
  margin-bottom: 4px;
  padding-bottom: 6px;
  border-bottom: 1px dashed var(--border-subtle);
}
.msg__title {
  font-size: 12.5px; font-weight: 700;
  color: var(--fg-1);
  letter-spacing: -0.01em;
  margin: 0;
}
.msg__num {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-3);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}
.msg__meta {
  margin-left: auto;
  display: flex; gap: 6px; align-items: baseline;
}
.msg p { margin: 4px 0 6px; font-size: 11.5px; line-height: 1.45; color: var(--fg-2); }
.msg table.spec-table { margin: 4px 0 4px; font-size: 11px; }
.msg table.spec-table th { padding: 5px 8px; font-size: 9.5px; }
.msg table.spec-table td { padding: 4px 8px; }

/* Tight inline note row below a message (for §1.2.10 GF Status Note) */
.msg__note {
  font-size: 10.5px;
  line-height: 1.5;
  color: var(--fg-2);
  background: var(--gray-50);
  border-left: 3px solid var(--gray-700);
  padding: 6px 10px;
  margin: 4px 0 0;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.msg__note strong { color: var(--fg-1); }

/* Fault-flag table needs to be very tight to fit 32 rows on one page. */
table.flag-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
  margin: 4px 0 6px;
  table-layout: fixed;
}
table.flag-table th,
table.flag-table td {
  text-align: left;
  padding: 3px 6px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
  word-wrap: break-word;
}
table.flag-table thead th {
  background: var(--gray-900);
  color: var(--white);
  font-weight: 600;
  font-size: 9.5px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  padding: 5px 6px;
}
table.flag-table tbody tr:nth-child(even) td {
  background: var(--gray-50);
}
table.flag-table .col-bit  { width: 38px; }
table.flag-table .col-name { width: 140px; }
table.flag-table thead th { white-space: nowrap; }
table.flag-table td.bit {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  color: var(--fg-accent);
  text-align: right;
  padding-right: 8px;
}
table.flag-table td.name {
  font-weight: 600;
  color: var(--fg-1);
  font-size: 10px;
}
table.flag-table td.desc {
  color: var(--fg-2);
  font-size: 9.5px;
  line-height: 1.35;
}

/* Two-column wrapper for the 32-bit fault flag table */
.flag-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0 14px;
}

/* Topology card — used on the network topology page */
.topo {
  border: 1px solid var(--border-subtle);
  background: var(--gray-50);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin: 8px 0 10px;
  font-size: 11.5px;
  color: var(--fg-2);
  line-height: 1.5;
}
.topo strong { color: var(--fg-1); }

/* Inline KV strip — used for "ID / Length" stats on cover and intro */
.kv-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin: 6px 0 10px;
}
.kv-strip__cell {
  font-family: var(--font-mono);
  font-size: 10.5px;
  background: var(--gray-50);
  border: 1px solid var(--border-subtle);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  color: var(--fg-2);
}
.kv-strip__cell b {
  color: var(--fg-accent);
  font-weight: 600;
}

/* Bit-rate / ID-range pill block */
.id-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  border-top: 1px solid var(--border-subtle);
  border-left: 1px solid var(--border-subtle);
  margin: 6px 0 10px;
}
.id-grid__cell {
  padding: 8px 12px;
  border-right: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  display: flex; flex-direction: column; gap: 2px;
}
.id-grid__cell--accent { background: var(--primary-50); }
.id-grid__k {
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--fg-3);
}
.id-grid__v {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 700;
  color: var(--fg-1);
}
.id-grid__cell--accent .id-grid__v { color: var(--fg-accent); }

/* Revision history table — keep compact for last page */
table.rev-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10.5px;
  margin: 4px 0 6px;
}
table.rev-table th,
table.rev-table td {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}
table.rev-table thead th {
  background: var(--gray-900);
  color: var(--white);
  font-size: 9.5px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}
table.rev-table tbody tr:nth-child(even) td { background: var(--gray-50); }
table.rev-table td:first-child,
table.rev-table td:nth-child(2) {
  font-family: var(--font-mono);
  font-size: 10px;
  white-space: nowrap;
}

/* ---------- Page footer ---------- */
.pf {
  /* Absolutely positioned per DESIGN_NOTES.md — reserved band in .page padding. */
  position: absolute;
  left: 60px;
  right: 60px;
  bottom: 24px;
  padding-top: 12px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--fg-3);
}
.pf__folio b { color: var(--fg-accent); font-weight: 700; }

/* ---------- Print ----------
   Page size, margins, running header/footer, chrome hiding, and all
   break-protection rules live in doc.css (the project-wide print
   contract). Because .page is already hard-capped to A4 on screen,
   what authors see is what prints — no per-doc tuning required.
   --------------------------------------------------------------- */
@media print {
  @page { size: A4; margin: 0; }

  html, body { background: #fff !important; }

  .sheet {
    display: block !important;
    padding: 0 !important; margin: 0 !important; gap: 0 !important;
    background: transparent !important;
  }

  article.page {
    width: 210mm !important;
    height: 297mm !important;
    padding: 68px 60px 92px !important;   /* mirrors the screen card */
    margin: 0 !important;
    background: #fff !important;
    overflow: hidden !important;
    box-shadow: none !important;
    border: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    break-after: page; page-break-after: always;
    break-inside: avoid; page-break-inside: avoid;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  article.page:last-child { break-after: auto; page-break-after: auto; }

  /* every tinted surface must keep its ink */
  thead th, .callout, .msg, .msg__note, .id-tag, .reg-tag, .id-grid__cell,
  .id-grid__cell--accent, .cover__model, .kv-strip__cell, .topo, .chapter__rule,
  .sec-title::before, .mono, tbody tr:nth-child(even) td, .ph, .pf, .figure,
  .flag-table thead th {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }

  /* Defensive: hide the dev tweaks panel + no-print anchors. */
  .no-print, #tweaks-root, tweaks-panel, .overflow-banner { display: none !important; }
}
