/* ============================================================
   CoolMax SRX: CAN Integration Guide: multi-page layout
   Same A4 card shell as the SRX RS485 protocol; adds the per-flag
   response table, class pills and the controller checklist. Tokens
   imported transitively via the HTML's link to tokens.css.

   Print contract (see DESIGN_NOTES.md and the @media print block at the
   end): the screen card IS the printed page. doc.css flattens
   article.page to auto height / zero padding under print, so this file
   re-asserts the fixed A4 card with matching specificity, later in the
   cascade. Every .page child is flex-shrink: 0 so an over-full page
   overflows honestly (and trips overflow-check.js) instead of squashing
   its children into each other.
   ============================================================ */

* { 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; /* 18mm / 16mm / reserved .pf band, matches DESIGN_NOTES */
  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.1fr 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: 18px; font-weight: 400;
  color: var(--fg-2);
  margin: 0 0 12px;
  letter-spacing: -0.01em;
}
.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 16px;
  max-width: 44ch;
  text-wrap: pretty;
}

/* Cover "spec marquee": key numbers in place of a product image */
.cover__marquee {
  margin: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
  padding: 18px 20px;
  background: linear-gradient(180deg, var(--gray-50) 0%, var(--white) 100%);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
}
.cover__marquee__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
  border-bottom: 1px dashed var(--border-subtle);
}
.cover__marquee__row:last-child { border-bottom: 0; }
.cover__marquee__k {
  font-family: var(--font-mono);
  font-size: 10.5px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--fg-3);
}
.cover__marquee__v {
  font-family: var(--font-mono);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--fg-1);
  text-align: right;
}
.cover__marquee__v--danger { color: var(--status-danger); }

/* Document meta block */
.docmeta {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  border-top: 1px solid var(--border-subtle);
  border-left: 1px solid var(--border-subtle);
  margin-bottom: 22px;
}
.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: 10.5px;
  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;
  line-height: 1.15;
  margin: 0 0 4px;
  padding: 0;
  border: 0;
  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: 8px 0 12px;
}

.h3 {
  font-size: 14.5px; font-weight: 700;
  line-height: 1.3;
  margin: 16px 0 6px;
  color: var(--fg-1);
  letter-spacing: -0.01em;
}

p { margin: 0 0 7px; font-size: 13px; line-height: 1.5; color: var(--fg-2); }
p strong { color: var(--fg-1); font-weight: 600; }
p.small { font-size: 11.5px; color: var(--fg-3); }

ul, ol { margin: 0 0 9px; padding-left: 20px; }
li { font-size: 13px; line-height: 1.5; color: var(--fg-2); }
li + li { margin-top: 2px; }
li strong { color: var(--fg-1); font-weight: 600; }

/* ---------- 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: 12px;
}
.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: 9px 13px;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin: 8px 0;
  box-shadow: none;
}
.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: 13px; 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--danger {
  border-left-color: var(--status-danger);
  background: var(--status-danger-bg);
}
.callout--danger .callout__label { color: var(--status-danger); }

/* ---------- Generic tables ---------- */
table.spec-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
  margin: 6px 0 10px;
  background: transparent;
}
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 thead th {
  background: var(--gray-900);
  color: var(--white);
  font-weight: 600;
  font-size: 11px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  padding: 7px 10px;
  border-bottom: 0;
}
table.spec-table tbody tr:nth-child(even) td { background: var(--gray-50); }
table.spec-table td:first-child { font-weight: 600; color: var(--fg-1); }
table.spec-table td { color: var(--fg-2); }
table.spec-table td.num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-accent);
}

/* ---------- Numbered general rules ---------- */
ol.rules {
  list-style: none;
  counter-reset: rule;
  padding: 0;
  margin: 2px 0 8px;
  border-top: 1px solid var(--border-subtle);
}
ol.rules > li {
  counter-increment: rule;
  display: grid;
  grid-template-columns: 26px 1fr;
  gap: 8px;
  padding: 5px 0;
  margin: 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 12.5px;
  line-height: 1.5;
}
ol.rules > li::before {
  content: counter(rule, decimal-leading-zero);
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-accent);
  padding-top: 1px;
}
/* Highlighted rule: tinted like a callout, ruled on the left */
ol.rules > li.rule--key {
  background: var(--primary-50);
  box-shadow: inset 4px 0 0 var(--primary-500);
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  border-bottom-color: transparent;
  padding: 8px 12px 8px 14px;
  margin: 4px 0;
  color: var(--fg-1);
}

/* ---------- Class pills ---------- */
.cls {
  display: inline-block;
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  line-height: 1;
  padding: 3px 6px;
  border-radius: var(--radius-pill);
  white-space: nowrap;
  border: 1px solid transparent;
}
.cls--info     { color: var(--fg-3);          background: var(--gray-100);         border-color: var(--gray-200); }
.cls--auto     { color: var(--status-ok);     background: var(--status-ok-bg);     border-color: #b7e4cc; }
.cls--config   { color: var(--status-info);   background: var(--status-info-bg);   border-color: #c7d7fb; }
.cls--service  { color: var(--fg-accent);   background: var(--primary-50);       border-color: var(--primary-200); }
.cls--critical { color: var(--white);         background: var(--status-danger);    border-color: var(--status-danger); }

/* Class key: one row per class */
table.spec-table td.cls-cell { width: 92px; }

/* ---------- Per-flag response table ---------- */
table.flag-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10.5px;
  line-height: 1.35;
  margin: 4px 0 10px;
  table-layout: fixed;
  background: transparent;
}
table.flag-table th,
table.flag-table td {
  text-align: left;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}
table.flag-table td { overflow-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;
  border-bottom: 0;
  vertical-align: bottom;
}
table.flag-table tbody tr:nth-child(even) td { background: var(--gray-50); }
table.flag-table .col-bit   { width: 30px; }
table.flag-table .col-flag  { width: 94px; }
table.flag-table .col-class { width: 66px; }
table.flag-table .col-halt  { width: 62px; }
table.flag-table .col-cause { width: auto; }
table.flag-table .col-do    { width: 186px; }
table.flag-table .col-ev    { width: 66px; }
table.flag-table th.c, table.flag-table td.c { text-align: center; }
table.flag-table td.bit {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--fg-accent);
}
table.flag-table td.flag { font-weight: 600; color: var(--fg-1); }
table.flag-table td.cause { color: var(--fg-2); }
table.flag-table td.do { color: var(--fg-1); }
table.flag-table td.do strong { font-weight: 700; }
table.flag-table td.ev {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--fg-3);
}
table.flag-table td.halt { font-family: var(--font-mono); font-size: 10px; color: var(--fg-3); }
table.flag-table td.halt--yes { color: var(--status-danger); font-weight: 700; }
/* Critical rows: tinted across the row, ruled on the left */
table.flag-table tbody tr.row-critical td,
table.flag-table tbody tr.row-critical:nth-child(even) td { background: var(--status-danger-bg); }
table.flag-table tbody tr.row-critical td:first-child { box-shadow: inset 3px 0 0 var(--status-danger); }

/* ---------- Controller checklist ---------- */
ul.checklist {
  list-style: none;
  padding: 0;
  margin: 4px 0 10px;
  border-top: 1px solid var(--border-subtle);
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: repeat(5, auto);
  grid-auto-flow: column;   /* read down the left column, then the right */
  column-gap: 24px;
}
ul.checklist > li + li { margin-top: 0; }
ul.checklist > li {
  display: grid;
  grid-template-columns: 20px 1fr;
  gap: 8px;
  align-items: start;
  padding: 6px 0;
  margin: 0;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 12.5px;
  line-height: 1.4;
  color: var(--fg-1);
}
ul.checklist > li::before {
  content: "";
  width: 13px; height: 13px;
  margin-top: 1px;
  border: 1.5px solid var(--gray-700);
  border-radius: 3px;
  background: var(--white);
}

/* ---------- Revision history table ---------- */
table.revhist {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  line-height: 1.35;
  margin: 6px 0 10px;
  background: transparent;
}
table.revhist th,
table.revhist td {
  text-align: left;
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}
table.revhist thead th {
  background: var(--gray-900);
  color: var(--white);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  border-bottom: 0;
}
table.revhist td.rev {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-accent);
  font-weight: 600;
  width: 52px;
}
table.revhist td.date {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-2);
  width: 74px;
}
table.revhist td.officer { color: var(--fg-2); font-size: 11px; width: 118px; }
table.revhist td.change { color: var(--fg-1); }

/* ---------- Page footer ----------
   Reserved band per DESIGN_NOTES.md: absolutely positioned within .page;
   do NOT use margin-top:auto.
   --------------------------------------------------------------- */
.pf {
  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 ----------
   The screen card is the printed page. doc.css flattens .page/article.page
   to auto height and zero padding (with !important), so this block wins
   by matching the article.page specificity later in the cascade. The
   in-page .ph/.pf carry the running header and footer, so the @page
   margin is zero and Chromium's own header/footer stays off
   (build script passes --no-pdf-header-footer).
   --------------------------------------------------------------- */
@media print {
  @page { size: A4; margin: 0; }

  html, body { background: #fff !important; }
  body { font-size: var(--fs-14); }

  .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, .cover__model, .cover__marquee, .chapter__rule,
  .sec-title::before, tbody tr td, .cls, .ph, .pf,
  ul.checklist > li::before, ol.rules > li::before, ol.rules > li.rule--key {
    -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; }
}
