/* ============================================================
   CoolPro — Modbus RTU Communications Protocol — multi-page layout
   Forked from srx/rs485-protocol.css (same shell, same A4 contract);
   adds byte-frame / wire-table utilities and a figure box.
   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; /* 18mm / 16mm / reserved .pf band — matches DESIGN_NOTES */
  position: relative;
  display: flex;
  flex-direction: column;
}

/* ---------- 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; display: flex; flex-direction: column; }
.cover__hero {
  display: grid;
  grid-template-columns: 1.1fr 1fr;
  gap: 28px;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-subtle);
  margin-bottom: 16px;
}
.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" — drop-in for the product image on a protocol cover */
.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: 10px;
  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;
}

/* 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: 16px;
}
.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: 8px 0 12px;
}

/* H3 / H4 inside chapters */
.h3 {
  font-size: 14.5px; font-weight: 700;
  margin: 12px 0 5px;
  color: var(--fg-1);
  letter-spacing: -0.01em;
}
.h4 {
  font-size: 11.5px; font-weight: 700;
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  color: var(--fg-2);
  margin: 8px 0 4px;
}
/* function-code sub-heading: mono code chip + name on one line */
.fn-head {
  display: flex; align-items: baseline; gap: 10px;
  margin: 8px 0 4px;
}
.fn-head__code {
  font-family: var(--font-mono);
  font-size: 12px; font-weight: 700;
  color: var(--fg-accent);
  background: var(--primary-50);
  padding: 2px 8px;
  border-radius: var(--radius-sm);
}
.fn-head__name {
  font-size: 13.5px; font-weight: 700;
  color: var(--fg-1);
  letter-spacing: -0.01em;
}

p { margin: 0 0 7px; font-size: 12px; line-height: 1.5; color: var(--fg-2); }
p strong { color: var(--fg-1); font-weight: 600; }
.lead { font-size: 12.5px; color: var(--fg-2); }

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

.mono { font-family: var(--font-mono); font-size: 11px; color: var(--fg-1); }

/* ---------- 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: 6px 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: 10.5px; 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;
}
.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 (general) ---------- */
table.spec-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11.5px;
  margin: 5px 0 6px;
}
table.spec-table th,
table.spec-table td {
  text-align: left;
  padding: 5px 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.mono,
table.spec-table td.num {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--fg-1);
}

/* ---------- Two-column grid ---------- */
.col2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 22px;
  align-items: start;
}
.col2--wide-left { grid-template-columns: 1.25fr 1fr; }

/* ---------- Pinout / settings small key-value cards ---------- */
.kv-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-top: 1px solid var(--border-subtle);
  border-left: 1px solid var(--border-subtle);
  margin: 6px 0 12px;
}
.kv-card__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;
}
.kv-card__k {
  font-family: var(--font-mono);
  font-size: 10px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--fg-3);
}
.kv-card__v {
  font-size: 12.5px; font-weight: 600;
  color: var(--fg-1);
  font-family: var(--font-mono);
}
.kv-card__cell--accent { background: var(--primary-50); }
.kv-card__cell--accent .kv-card__v { color: var(--fg-accent); }

/* ---------- Figure box (images) ---------- */
.figbox {
  margin: 6px 0 10px;
  padding: 10px;
  background: var(--gray-50);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  text-align: center;
}
.figbox img { max-width: 100%; height: auto; display: block; margin: 0 auto; }
.figbox figcaption {
  margin-top: 6px;
  font-size: 10px;
  color: var(--fg-3);
  line-height: 1.4;
  text-align: center;
}
.figbox--rj45 img { max-height: 132px; }
.figbox--topology img { max-height: 470px; }

/* ---------- Frame / field-format box ---------- */
.fmt {
  font-family: var(--font-mono);
  font-size: 9.5px;
  line-height: 1.5;
  color: var(--fg-1);
  background: var(--gray-50);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--primary-500);
  padding: 7px 12px;
  border-radius: var(--radius-md);
  margin: 3px 0 6px;
  overflow-wrap: anywhere;
}
.fmt__k {
  display: block;
  font-size: 9px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  color: var(--fg-accent);
  margin-bottom: 2px;
}
.fmt__k + .fmt__line { margin-bottom: 5px; display: block; }
.fmt__line:last-child { margin-bottom: 0; }

/* ---------- Wire / byte-sequence table ---------- */
table.wire-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin: 4px 0 10px;
  table-layout: fixed;
}
table.wire-table th,
table.wire-table td {
  text-align: left;
  padding: 3px 7px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
table.wire-table thead th {
  background: var(--gray-900);
  color: var(--white);
  font-weight: 600;
  font-size: 9px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}
table.wire-table .col-dir   { width: 78px; }
table.wire-table .col-bytes { width: 200px; }
table.wire-table .col-note  { width: auto; }
table.wire-table td.dir {
  font-family: var(--font-mono);
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--fg-accent);
}
table.wire-table td.dir.dir--rsp { color: var(--fg-2); }
table.wire-table td.bytes {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--fg-1);
  letter-spacing: 0.02em;
}
table.wire-table td.note {
  font-size: 10.5px;
  color: var(--fg-2);
}
table.wire-table tbody tr:nth-child(even) td { background: var(--gray-50); }

.eg-title {
  font-size: 11px; font-weight: 700;
  color: var(--fg-1);
  margin: 10px 0 3px;
}

/* ---------- Modbus register table ---------- */
table.modbus-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10px;
  margin: 4px 0 10px;
  table-layout: fixed;
}
table.modbus-table th,
table.modbus-table td {
  text-align: left;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
table.modbus-table thead th {
  background: var(--gray-900);
  color: var(--white);
  font-weight: 600;
  font-size: 9px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  padding: 6px 6px;
}
table.modbus-table tbody tr:nth-child(even) td {
  background: var(--gray-50);
}
table.modbus-table .col-addr { width: 66px; }
table.modbus-table .col-off  { width: 58px; }
table.modbus-table thead th { white-space: nowrap; }
table.modbus-table .col-desc { width: auto; }
table.modbus-table .col-rng  { width: 70px; }
table.modbus-table .col-unit { width: 46px; }
table.modbus-table .col-conv { width: auto; }
table.modbus-table .col-type { width: 60px; }
table.modbus-table td.mono,
table.modbus-table td.addr,
table.modbus-table td.off,
table.modbus-table td.conv {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--fg-1);
}
table.modbus-table td.addr {
  font-weight: 600;
  color: var(--fg-accent);
}
table.modbus-table td.off  { color: var(--fg-3); }
table.modbus-table td.desc { color: var(--fg-1); }
table.modbus-table td.unit {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--fg-2);
}

/* ---------- Bit-field table ---------- */
table.bitfield-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10.5px;
  margin: 4px 0 10px;
  table-layout: fixed;
}
table.bitfield-table th,
table.bitfield-table td {
  text-align: left;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
  word-wrap: break-word;
}
table.bitfield-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;
}
table.bitfield-table tbody tr:nth-child(even) td { background: var(--gray-50); }
table.bitfield-table .col-bit  { width: 40px; }
table.bitfield-table .col-hex  { width: 64px; }
table.bitfield-table .col-name { width: 180px; }
table.bitfield-table .col-desc { width: auto; }
table.bitfield-table td.bit {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-accent);
  font-weight: 600;
}
table.bitfield-table td.hex {
  font-family: var(--font-mono);
  font-size: 9.5px;
  color: var(--fg-2);
}
table.bitfield-table td.name { font-weight: 600; color: var(--fg-1); }
table.bitfield-table td.desc { color: var(--fg-2); }

/* ---------- Exception-codes / function-codes table ---------- */
table.fc-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 11px;
  margin: 6px 0 10px;
}
table.fc-table th,
table.fc-table td {
  text-align: left;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: top;
}
table.fc-table thead th {
  background: var(--gray-900);
  color: var(--white);
  font-weight: 600;
  font-size: 10px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}
table.fc-table td.code {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--fg-accent);
  width: 96px;
}
table.fc-table td.name {
  font-weight: 600;
  color: var(--fg-1);
  width: 190px;
}
table.fc-table td.desc { color: var(--fg-2); }
table.fc-table tbody tr:nth-child(even) td { background: var(--gray-50); }

/* ---------- Revision history table ---------- */
table.revhist {
  width: 100%;
  border-collapse: collapse;
  font-size: 10.5px;
  margin: 6px 0 10px;
}
table.revhist th,
table.revhist td {
  text-align: left;
  padding: 5px 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: 9.5px;
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
}
table.revhist td.rev {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-accent);
  font-weight: 600;
  width: 56px;
}
table.revhist td.date {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--fg-2);
  width: 92px;
}
table.revhist td.officer {
  color: var(--fg-2);
  font-size: 10px;
  width: 130px;
}
table.revhist td.change { color: var(--fg-1); }
table.revhist tbody tr:nth-child(even) td { background: var(--gray-50); }

/* ---------- Page footer ----------
   Reserved band per DESIGN_NOTES.md: absolutely positioned within .page.
   --------------------------------------------------------------- */
.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 ----------
   Page size, margins, running header/footer, chrome hiding, and all
   break-protection rules live in doc.css (project-wide print contract).
   --------------------------------------------------------------- */
@media print {
  /* Per-page .ph header is redundant with the @page running header; keep it on
     the cover only so the string-set hooks resolve. The in-page .pf footer is
     absolutely positioned and, once .page is auto-height in print, would float
     up into short content (e.g. the cover TOC) — so drop it on every page and
     let the @page running footer own pagination. */
  .page:not(:first-of-type) .ph,
  .pf { display: none; }
  .no-print, #tweaks-root, tweaks-panel { display: none !important; }
}
