:root {
  --navy: #1b1b6f;
  --blue: #5b8fe0;
  --mint: #5fd7b5;
  --ink: #21262d;
  --muted: #6b7280;
  --bg: #f2f5f9;
  --card: #ffffff;
  --line: #dde3ea;
  --danger: #c0392b;
  --radius: 12px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  font-size: 16px;
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 1px 6px rgba(0,0,0,.06);
}
.topbar-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px clamp(14px, 3vw, 32px) 6px;
  padding-left: max(clamp(14px, 3vw, 32px), env(safe-area-inset-left));
  padding-right: max(clamp(14px, 3vw, 32px), env(safe-area-inset-right));
  max-width: 1400px;
  margin: 0 auto;
}
.fs-btn {
  border: 1px solid var(--line);
  background: #f4f7fb;
  color: var(--navy);
  font-size: 1rem;
  border-radius: 10px;
  width: 38px;
  height: 38px;
  cursor: pointer;
  flex: none;
}
.fs-btn:active { background: #e6ecf5; }
.back-btn {
  border: 1px solid var(--line);
  background: #f4f7fb;
  color: var(--navy);
  font-size: 1.1rem;
  font-weight: 700;
  border-radius: 10px;
  width: 38px;
  height: 38px;
  cursor: pointer;
  flex: none;
}
.back-btn:active { background: #e6ecf5; }
.topbar-logo { height: 40px; width: auto; }
.topbar-title { display: flex; flex-direction: column; line-height: 1.2; }
.topbar-title strong { color: var(--navy); font-size: 1rem; }
.topbar-title span { color: var(--muted); font-size: .78rem; }
.topbar-status {
  margin-left: auto;
  font-size: .75rem;
  color: var(--muted);
  background: #eef7f2;
  border: 1px solid #cfe8dc;
  border-radius: 999px;
  padding: 3px 10px;
  white-space: nowrap;
}
.topbar-status.dirty { background: #fdf6e3; border-color: #f0e0b0; }

.tabs {
  display: flex;
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 clamp(8px, 2.5vw, 28px);
}
.tab {
  flex: 1;
  border: none;
  background: none;
  padding: 10px 6px;
  font-size: .95rem;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 3px solid transparent;
  cursor: pointer;
}
.tab.active { color: var(--navy); border-bottom-color: var(--mint); }

/* ---------- Views ---------- */
.view {
  display: none;
  max-width: 1400px;
  margin: 0 auto;
  padding: 14px clamp(12px, 3vw, 32px) 90px;
  padding-left: max(clamp(12px, 3vw, 32px), env(safe-area-inset-left));
  padding-right: max(clamp(12px, 3vw, 32px), env(safe-area-inset-right));
  padding-bottom: calc(90px + env(safe-area-inset-bottom));
}
.view:not(.active) { display: none !important; }
.view.active { display: block; }

/* ---------- Home view: history + picker ---------- */
.home-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 6px 2px 16px;
}
.home-head h2 { margin: 0; color: var(--navy); font-size: 1.15rem; }

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 12px;
}
.history-empty {
  grid-column: 1 / -1;
  border: 2px dashed var(--line);
  border-radius: var(--radius);
  padding: 44px 16px;
  text-align: center;
  color: var(--muted);
  font-size: .95rem;
  line-height: 1.7;
  background: #fbfcfe;
}
.report-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 5px;
  text-align: left;
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent, var(--navy));
  border-radius: var(--radius);
  padding: 14px 34px 12px 14px;
  cursor: pointer;
  font: inherit;
  box-shadow: 0 1px 4px rgba(0,0,0,.05);
  transition: box-shadow .15s, transform .15s;
}
.report-tile:hover { box-shadow: 0 4px 14px rgba(0,0,0,.10); transform: translateY(-1px); }
.tile-kind {
  font-size: .72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--accent, var(--navy));
}
.tile-site { font-weight: 700; color: var(--ink); font-size: .98rem; }
.tile-site i { color: var(--muted); font-weight: 400; }
.tile-report { font-size: .8rem; color: var(--muted); word-break: break-all; }
.tile-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: .75rem;
  color: var(--muted);
  border-top: 1px solid var(--line);
  padding-top: 7px;
  margin-top: 3px;
}
.tile-del {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 26px;
  height: 26px;
  line-height: 24px;
  text-align: center;
  border-radius: 50%;
  color: var(--muted);
  font-size: .8rem;
}
.tile-del:hover { background: #fdeeec; color: var(--danger); }

.picker-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .45);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px;
}
@media (min-width: 640px) { .picker-overlay { align-items: center; } }
.picker-sheet {
  background: var(--card);
  border-radius: 16px;
  padding: 18px 16px;
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 88vh;
  overflow-y: auto;
}
.picker-sheet h3 { margin: 0; color: var(--navy); font-size: 1.05rem; }
.picker-sheet .hint { margin: 0 0 4px; }
.picker-list { display: flex; flex-direction: column; gap: 8px; }
.picker-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  text-align: left;
  font: inherit;
  background: #fbfcfe;
  border: 1px solid var(--line);
  border-left: 5px solid var(--accent, var(--navy));
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
}
.picker-card:hover { background: #f1f5fb; }
.picker-card b { color: var(--ink); font-size: .95rem; }
.picker-card span { color: var(--muted); font-size: .74rem; }

/* ---------- Edit toolbar & grammar checker ---------- */
.edit-toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.grammar-sheet { max-width: 640px; }
.grammar-list { display: flex; flex-direction: column; gap: 10px; overflow-y: auto; }
.grammar-row {
  border: 1px solid var(--line);
  border-left: 4px solid #e3a008;
  border-radius: 10px;
  padding: 10px 12px;
  background: #fbfcfe;
}
.grammar-row.g-done { border-left-color: #2f9e6e; opacity: .75; }
.grammar-row.g-stale { border-left-color: var(--danger); }
.g-where { font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin-bottom: 3px; }
.g-msg { font-size: .88rem; font-weight: 600; color: var(--ink); }
.g-ctx { font-size: .82rem; color: var(--muted); margin: 4px 0 8px; }
.g-ctx mark { background: #fdeeec; color: var(--danger); font-weight: 700; padding: 0 2px; border-radius: 3px; }
.g-sugg { display: flex; gap: 6px; flex-wrap: wrap; }
.g-fix { padding: 6px 12px; font-size: .82rem; }
.g-applied { color: #2f9e6e; font-weight: 700; font-size: .85rem; }

/* ---------- PDF capture (strip screen chrome while rendering pages) ---------- */
.pdf-capture .a4 { border: none !important; box-shadow: none !important; margin: 0 auto !important; }

/* ---------- Edit view: sections ---------- */
.doc-cover {
  background: linear-gradient(150deg, var(--navy), #2c3f8f 55%, #3f6fc4);
  color: #fff;
  border-radius: var(--radius);
  padding: 22px 18px;
  margin-bottom: 14px;
  text-align: center;
}
.doc-cover img { height: 54px; background: #fff; border-radius: 8px; padding: 5px 10px; }
.doc-cover h1 { margin: 12px 0 4px; font-size: 1.25rem; letter-spacing: .06em; }
.doc-cover p { margin: 0; opacity: .85; font-size: .85rem; }

.section-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}
.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  border: none;
  text-align: left;
  background: linear-gradient(90deg, #eef2fb, #f6fbf9);
  padding: 12px 14px;
  cursor: pointer;
}
.section-head h2 {
  margin: 0;
  font-size: .98rem;
  color: var(--navy);
  flex: 1;
  letter-spacing: .01em;
}
.section-head .chev { color: var(--muted); transition: transform .18s; }
.section-card.collapsed .chev { transform: rotate(-90deg); }
.section-body { padding: 12px 14px 16px; }
.section-card.collapsed .section-body { display: none; }

.sub-title {
  font-weight: 700;
  color: var(--navy);
  font-size: .9rem;
  margin: 14px 0 6px;
}
.sub-title:first-child { margin-top: 0; }

/* Toggleable sub-section: title + the same switch the section headers use */
.sub-group { margin-top: 14px; }
.sub-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sub-head .sub-title { margin: 0; }
.sub-hidden { opacity: 0.55; }
.sub-hidden > :not(.sub-head) { display: none !important; }

.table-caption {
  color: var(--muted);
  font-size: .82rem;
  margin: -2px 0 10px;
}

.field-label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  margin: 10px 0 4px;
}

input[type="text"], input[type="email"], input[type="date"], input[type="time"], select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  font: inherit;
  font-size: 9pt;
  color: var(--ink);
  background: #fcfdfe;
}
textarea { resize: vertical; min-height: 42px; overflow: hidden; line-height: 1.45; text-align: justify; }
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--mint);
  outline-offset: 0;
  border-color: var(--mint);
  background: #fff;
}

/* Fluid: 1 column on phones, 2 on tablets, 3+ on wide PC screens */
.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(250px, 100%), 1fr)); gap: 0 16px; }

.guidance {
  font-size: .78rem;
  color: #8a6d1c;
  background: #fdf6e3;
  border: 1px dashed #ecd9a0;
  border-radius: 8px;
  padding: 7px 10px;
  margin: 6px 0;
}

/* ---------- Checklist tables ---------- */
.check-table { width: 100%; border-collapse: collapse; margin-top: 6px; }
.check-table th {
  text-align: left;
  font-size: .75rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  padding: 6px 6px;
  border-bottom: 2px solid var(--line);
}
.check-table td { padding: 6px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.check-table td.item-cell { font-size: .86rem; font-weight: 600; color: var(--ink); width: 42%; padding-top: 14px; }
.check-table select { width: 86px; padding: 7px 6px; }
@media (max-width: 640px) {
  .check-table, .check-table tbody, .check-table tr { display: block; }
  .check-table thead { display: none; }
  .check-table tr { border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-bottom: 8px; }
  .check-table td { display: block; border: none; padding: 4px 2px; }
  .check-table td.item-cell { width: auto; padding-top: 2px; }
  .check-table td[data-col]::before {
    content: attr(data-col);
    display: block;
    font-size: .7rem;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 2px;
  }
}

/* ---------- Photos ---------- */
.photo-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr)); gap: 12px; }
.photo-card {
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background: #fafbfc;
  display: flex;
  flex-direction: column;
}
.photo-card img { width: 100%; height: 170px; object-fit: cover; display: block; background: #e8ecf1; }
.photo-card .photo-meta { padding: 8px 10px 10px; display: flex; flex-direction: column; gap: 6px; }
.photo-card .photo-num { font-weight: 700; font-size: .82rem; color: var(--navy); display: flex; justify-content: space-between; align-items: center; }
.photo-card .del-photo {
  border: none; background: none; color: var(--danger);
  font-size: .78rem; cursor: pointer; padding: 2px 4px;
}
/* ---- Appendix attachments ---- */
.attach-section-wrap { margin-top: 16px; }
.attach-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: #fff;
  border: 1px solid var(--navy);
  color: var(--navy);
  font-weight: 600;
}
.attach-btn-logo { height: 20px; width: auto; display: block; }
.attach-list { display: flex; flex-direction: column; gap: 10px; }
.attach-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 10px 12px;
}
.attach-icon {
  flex: none;
  width: 54px;
  height: 54px;
  border-radius: 8px;
  background: #eef2f7;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  overflow: hidden;
}
.attach-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }
.attach-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.attach-head { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.attach-name {
  font-weight: 700;
  font-size: .85rem;
  color: var(--navy);
  overflow-wrap: anywhere;
}
.attach-size { flex: none; font-size: .75rem; color: var(--muted); }
.attach-tools { display: flex; gap: 12px; align-items: center; }
.attach-open { font-size: .78rem; font-weight: 600; color: var(--navy); }

.photo-empty {
  border: 2px dashed var(--line);
  border-radius: 10px;
  padding: 26px 14px;
  text-align: center;
  color: var(--muted);
  font-size: .88rem;
}

/* ---------- Buttons ---------- */
.btn {
  border: none;
  border-radius: 10px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
}
.btn.primary { background: var(--navy); color: #fff; }
.btn.primary:active { background: #2c2c8f; }
.btn.secondary { background: #e9eef7; color: var(--navy); }
.btn.danger.ghost { background: none; color: var(--danger); border: 1px solid #eccfcb; }
.btn:disabled { opacity: .55; cursor: wait; }

/* ---------- Client directory (Supabase) ---------- */
.client-save-bar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}
.client-save-bar .btn { padding: 9px 14px; }
.client-save-status { font-size: .8rem; color: var(--muted); }

.client-ac {
  position: absolute;
  z-index: 1000;
  max-height: 280px;
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(27, 27, 111, .16);
  padding: 4px;
}
.client-ac-item {
  padding: 8px 10px;
  border-radius: 7px;
  cursor: pointer;
}
.client-ac-item:hover { background: #eef3fc; }
.client-ac-title { font-weight: 700; color: var(--navy); font-size: .9rem; }
.client-ac-sub { font-size: .76rem; color: var(--muted); margin-top: 2px; }

.appfooter { max-width: 1400px; margin: 0 auto; padding: 0 12px calc(30px + env(safe-area-inset-bottom)); text-align: center; }

/* ---------- Review ---------- */
.review-toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.review-doc {
  font-family: Arial, "Segoe UI", sans-serif;
  line-height: 1.5;
  font-size: 9pt;
}

/* ---- A4 sheets ---- */
.a4 {
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: 0 2px 10px rgba(0,0,0,.07);
  width: 210mm;
  margin: 0 auto 18px;
  padding: 10mm 13mm 8mm;
  display: flex;
  flex-direction: column;
}
#pagesWrap { width: 210mm; margin: 0 auto; }
.a4.cover-page { min-height: 296mm; }
.a4.body-page { height: 297mm; }

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid var(--mint);
  padding-bottom: 6px;
  margin-bottom: 14px;
}
.page-head img { height: 36px; }
.review-doc[data-tpl="classA"] .page-head img { height: 28px; width: auto; flex: none; object-fit: contain; aspect-ratio: 270 / 175; }
.head-report { font-size: 8pt; font-weight: 700; color: var(--navy); }

.page-foot {
  display: flex;
  justify-content: space-between;
  border-top: 1px solid var(--line);
  padding-top: 6px;
  margin-top: auto;
  font-size: 8pt;
  color: var(--muted);
}
.body-page .page-foot { margin-top: 22px; }
.body-content { flex: 1; overflow: hidden; }

.cover-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  text-align: center;
  padding-bottom: 10mm;
}
.cover-logo { width: min(240px, 60%); height: auto; margin-bottom: 26px; }
.cover-center h1 {
  color: var(--navy);
  letter-spacing: .06em;
  font-size: 46px;
  line-height: 1.15;
  margin: 0 0 30px;
}
.cover-meta { font-size: 11pt; line-height: 2; }
.cover-meta b { color: var(--navy); }

/* ---- Class A photo cover ---- */
.a4.cover-photo { height: 296mm; padding: 0; overflow: hidden; }
.cover-photo-img {
  flex: 0 0 62%;
  background-size: cover;
  background-position: center top;
  background-repeat: no-repeat;
}
.cover-photo-banner {
  flex: 1;
  background: #88b6e0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 22px 13mm 8mm;
  position: relative;
}
.cover-photo-text { padding-left: 16px; }
.cover-photo-text h1 {
  color: #fff;
  font-size: 46px;
  letter-spacing: .02em;
  line-height: 1.15;
  margin: 0 0 10px;
}
.cover-photo-address { color: #fff; font-size: .95rem; opacity: .95; padding-left: 16px; }
.cover-photo-meta { color: #fff; font-size: .8rem; opacity: .95; padding-left: 16px; margin-top: 5px; }
.cover-photo .page-foot { border-top-color: rgba(255,255,255,.4); color: rgba(255,255,255,.85); }

/* ---- Cover footer: assessor / report number / date of issue ---- */
.cover-footwrap { margin-top: auto; }
/* Assessor name sits above the rule; the contact email takes its old slot below. */
.cover-foot-name {
  font-size: 9pt;
  font-weight: 700;
  padding-bottom: 7px;
  color: var(--navy);
}
.cover-photo .cover-foot-name { color: #fff; padding-left: 0; }
.cover-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 9pt;
  color: #fff;
}
.cover-foot .cf-left  { flex: 1; text-align: left; }
.cover-foot .cf-mid   { flex: 1; text-align: center; }
.cover-foot .cf-right { flex: 1; text-align: right; }
.cover-foot .r-empty { color: rgba(255,255,255,.75); }
/* The photo cover already sits on the blue banner, so white reads directly.
   The plain covers are white paper, so the band supplies the contrast. */
.cover-page:not(.cover-photo) .cover-foot {
  background: var(--accent, var(--navy));
  margin: 0 -13mm -8mm;
  padding: 7mm 13mm;
}
.cover-photo .cover-foot { padding-top: 6px; border-top: 1px solid rgba(255,255,255,.4); }
.review-doc h2 { color: var(--navy); font-size: 11pt; border-bottom: 2px solid var(--mint); padding-bottom: 4px; margin: 36px 0 18px; font-family: inherit; }
.review-doc h3 { color: var(--navy); font-size: 9.5pt; margin: 28px 0 14px; }
.review-doc p { margin: 1.5em 0; white-space: pre-wrap; }
.review-doc .r-table-caption { color: #6b7686; font-size: 8.5pt; margin: -8px 0 14px; white-space: normal; }
.review-doc .r-field { margin: 12px 0; }
.review-doc .r-field b { color: var(--navy); }
.review-doc .r-empty { color: #b3bac4; font-style: italic; }
.review-doc table { width: 100%; border-collapse: collapse; margin: 16px 0 24px; font-size: 9pt; }
.review-doc table th, .review-doc table td { border: 1px solid #c9d2dc; padding: 6px 8px; text-align: left; vertical-align: top; }
.review-doc table th { background: #eef2fb; color: var(--navy); }
/* 4.3 ACMs Remaining: filled title bar over a bordered body, like a one-cell table */
.review-doc h3.r-boxhead { background: #eef2fb; color: var(--navy); margin: 16px 0 0; padding: 6px 8px; border: 1px solid #c9d2dc; }
.review-doc .r-boxed { border: 1px solid #c9d2dc; border-top: 0; padding: 1px 10px; margin: 0 0 24px; }
.review-doc .r-boxed p { margin: .9em 0; }
/* Whole sections in the same box: h2 is the title bar, following blocks get side borders */
.review-doc h2.r-boxhead { background: #eef2fb; color: var(--navy); margin: 16px 0 0; padding: 6px 8px; border: 1px solid #c9d2dc; font-size: 10.5pt; }
.review-doc .r-in { display: flow-root; margin-top: 0; margin-bottom: 0; padding-left: 10px; padding-right: 10px; border-left: 1px solid #c9d2dc; border-right: 1px solid #c9d2dc; }
.review-doc h3.r-in { margin: 0; padding-top: 16px; padding-bottom: 2px; }
.review-doc .r-in.r-field { padding-top: 6px; padding-bottom: 6px; }
.review-doc .r-in.r-sigrow { margin: 0; padding-top: 10px; padding-bottom: 10px; }
.review-doc .r-in.r-in-last { border-bottom: 1px solid #c9d2dc; margin-bottom: 24px; }
.review-doc .r-fitgroup h2 { font-size: calc(11pt * var(--fit)); margin: calc(20px * var(--fit)) 0 calc(10px * var(--fit)); }
.review-doc .r-fitgroup h3.r-boxhead { margin: calc(14px * var(--fit)) 0 0; padding: calc(6px * var(--fit)) calc(8px * var(--fit)); }
.review-doc .r-fitgroup .r-boxed { margin-bottom: calc(14px * var(--fit)); }
/* 4.2.1-4.2.4 share one page; --fit (set by the pager) scales everything down to fit */
.review-doc .r-fitgroup { --fit: 1; }
.review-doc .r-fitgroup h3 { font-size: calc(9.5pt * var(--fit)); margin: calc(22px * var(--fit)) 0 calc(10px * var(--fit)); }
.review-doc .r-fitgroup table { font-size: calc(9pt * var(--fit)); margin: calc(12px * var(--fit)) 0 calc(18px * var(--fit)); }
.review-doc .r-fitgroup table th, .review-doc .r-fitgroup table td { padding: calc(6px * var(--fit)) calc(8px * var(--fit)); }
.review-doc .r-fitgroup .r-table-caption, .review-doc .r-fitgroup .r-field { font-size: calc(9pt * var(--fit)); margin: calc(8px * var(--fit)) 0; }
.review-doc .r-fitgroup p { font-size: calc(9pt * var(--fit)); margin: calc(1.2em * var(--fit)) 0; }
/* Assessor block: text left, signature right */
.sig-edit-row { display: flex; align-items: center; gap: 16px; }
.sig-edit-row .ta-field { flex: 1; }

/* ---------- Per-textarea undo/redo ---------- */
.ta-field { display: flex; flex-direction: column; }
.ta-hist-bar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 6px;
}
.ta-hist-btn {
  border: 1px solid var(--line);
  background: #f4f7fb;
  color: var(--navy);
  font-size: .82rem;
  font-weight: 600;
  border-radius: 8px;
  padding: 8px 14px;
  min-height: 36px;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
.ta-hist-btn:active:not(:disabled) { background: #e6ecf5; }
.ta-hist-btn:disabled { opacity: .4; cursor: default; }
.sig-edit-img {
  width: 150px;
  max-width: 34%;
  height: auto;
  flex: none;
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 6px 10px;
  background: #fff;
}
.review-doc .r-sigrow { display: flex; align-items: center; justify-content: space-between; gap: 20px; margin: 18px 0 24px; }
.review-doc .r-sigtext { flex: 1; }
.review-doc .r-signature { width: 160px; height: auto; flex: none; }

.review-doc .r-photo-entry {
  display: flex;
  align-items: flex-start;
  gap: 20px;
  margin: 18px 0;
  break-inside: avoid;
}
.body-content.justified-photos {
  display: flex;
  flex-direction: column;
}
.body-content.justified-photos .r-photo-entry {
  flex: 1;
  display: flex;
  align-items: center;
  margin: 0;
  padding: 8px 0;
}
/* Appendix photos inside the section box: keep side borders unbroken */
.review-doc .r-photo-entry.r-in { margin: 0; padding: 9px 10px; }
.body-content.justified-photos .r-photo-entry.r-in { padding: 8px 10px; }
.review-doc p.r-in { padding-top: 12px; padding-bottom: 12px; }
.review-doc .r-attach-entry.r-in { padding-top: 6px; padding-bottom: 6px; }
.review-doc .r-photo-img-wrap {
  flex: 0 0 45%;
  max-width: 45%;
}
.review-doc .r-photo-img-wrap img {
  width: 100%;
  max-height: 190px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
}
.review-doc .r-photo-comment {
  flex: 1;
  font-size: .85rem;
  line-height: 1.5;
  color: var(--ink);
  padding-top: 4px;
  text-align: justify;
}
.review-doc .r-photo-comment b {
  color: var(--navy);
}

/* ---------- Send ---------- */
.send-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px clamp(16px, 3vw, 28px);
  max-width: 720px;
  margin: 0 auto;
}
.send-card h2 { margin: 0 0 4px; color: var(--navy); font-size: 1.1rem; }
.hint { color: var(--muted); font-size: .82rem; }
.send-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.send-status {
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: .86rem;
  background: #eef7f2;
  border: 1px solid #cfe8dc;
  color: #1e6b4f;
}
.send-status.error { background: #fdeeec; border-color: #eccfcb; color: var(--danger); }

/* ---------- Print (Save as PDF from Review) ---------- */
/* The Review pages are already laid out as A4 sheets, so print them as they are: no page
   margin, one sheet per page, backgrounds kept. This gives a PDF with real, selectable text. */
@page { size: A4; margin: 0; }
@media print {
  html, body { background: #fff; margin: 0; height: auto; }
  .topbar, .appfooter, .no-print, .review-toolbar { display: none !important; }
  .view { display: none; padding: 0; max-width: none; }
  #reviewView { display: block !important; }
  #reviewDoc { height: auto !important; }
  #pagesWrap { transform: none !important; height: auto !important; margin: 0; }
  #reviewDoc .a4.a4 { border: none; box-shadow: none; max-width: none; margin: 0 !important; height: 297mm !important; min-height: 0; overflow: hidden; break-after: page; break-inside: avoid; }
  #reviewDoc .a4.a4:last-child { break-after: auto; }
  #reviewDoc * { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
}

/* ---------- Tri-state cycle button ---------- */
.cycle-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 76px;
  height: 40px;
  min-height: 40px;
  border-radius: 6px;
  border: 1px solid #cbd5e1;
  background: transparent;
  color: #94a3b8;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  /* Stop mobile browsers from swallowing rapid taps into a double-tap-zoom
     gesture — without this, single/double/triple taps can misfire or feel
     unresponsive on phones and tablets. */
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: all 0.2s ease;
}

.cycle-box.cycle-box-sm {
  width: 38px;
  height: 20px;
  min-height: 20px;
  border-radius: 3px;
  font-size: 0.6rem;
}

.cycle-box.state-yes {
  border-color: #22c55e;
  background: #dcfce7;
  color: #166534;
}

.cycle-box.state-no {
  border-color: #ef4444;
  background: #fee2e2;
  color: #991b1b;
}

.cycle-box.state-na {
  border-color: #94a3b8;
  background: #f1f5f9;
  color: #475569;
}

/* ---------- Section show/hide toggles ---------- */
.section-head-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.section-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  cursor: pointer;
  user-select: none;
}

.section-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.section-slider {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #fee2e2;
  border: 2px solid #ef4444;
  border-radius: 24px;
  transition: .2s;
}

.section-slider:before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: #ef4444;
  border-radius: 50%;
  transition: .2s;
}

.section-switch input:checked + .section-slider {
  background-color: #dcfce7;
  border-color: #22c55e;
}

.section-switch input:checked + .section-slider:before {
  transform: translateX(20px);
  background-color: #22c55e;
}

.section-hidden {
  opacity: 0.55;
  border: 1px dashed #94a3b8;
}

.section-hidden .section-body {
  display: none !important;
}

/* ==========================================================================
   Class A: Review laid out like the Word report, so both show the same pages.
   Sizes are the Word values (1pt = 1.333px, 15 twips = 1px): 1300-twip side
   margins, text from 100px to 93px above the bottom, 9pt body, one paragraph
   per line, light-blue title bars over 1/8pt grey borders.
   ========================================================================== */
.review-doc[data-tpl="classA"] { line-height: 1.15; }
.review-doc[data-tpl="classA"] .a4.body-page { padding: 47px 87px 47px; }
.review-doc[data-tpl="classA"] .page-head { padding-bottom: 5px; border-bottom-width: 1px; margin-bottom: 19px; }
.review-doc[data-tpl="classA"] .head-report { font-weight: 400; font-size: 8pt; }
.review-doc[data-tpl="classA"] .body-page .page-foot { margin-top: 27px; }

.review-doc[data-tpl="classA"] h2:not(.r-boxhead) { font-size: 17.33px; border: 0; padding: 0; margin: 30.67px 0 20px; line-height: 1.15; }
.review-doc[data-tpl="classA"] h3:not(.r-boxhead) { font-size: 15.33px; margin: 25.33px 0 16px; line-height: 1.15; }
.review-doc[data-tpl="classA"] .r-field { margin: 0 0 16px; }
.review-doc[data-tpl="classA"] p { margin: 0 0 16.67px; }
.review-doc[data-tpl="classA"] p.r-blank { margin: 0 0 10px; height: 13.8px; }
.review-doc[data-tpl="classA"] .r-empty { visibility: hidden; }
.review-doc[data-tpl="classA"] .r-sigtext p, .review-doc[data-tpl="classA"] .r-sigtext p.r-blank { margin: 0 0 10px; }
.review-doc[data-tpl="classA"] .r-sigrow { margin: 0 0 29.8px; }

.review-doc[data-tpl="classA"] h3.r-boxhead { font-size: 12px; margin: 0; padding: 4px 6.67px; border: 1px solid #9aa7b5; line-height: 1.15; }
.review-doc[data-tpl="classA"] .r-boxed { border: 1px solid #9aa7b5; border-top: 0; padding: 9.33px; margin: 0 0 29.8px; }
.review-doc[data-tpl="classA"] h2.r-boxhead { font-size: 16px; margin: 0; padding: 5.33px 9.33px; border: 1px solid #9aa7b5; line-height: 1.15; }
.review-doc[data-tpl="classA"] .r-in { padding-left: 11.33px; padding-right: 11.33px; border-left-color: #9aa7b5; border-right-color: #9aa7b5; }
.review-doc[data-tpl="classA"] h3.r-in { margin: 0; padding-top: 25.33px; padding-bottom: 16px; }
.review-doc[data-tpl="classA"] .r-boxhead + h3.r-in { padding-top: 40px; }
.review-doc[data-tpl="classA"] .r-boxhead + .r-in:not(h3) { padding-top: 14.67px; }
.review-doc[data-tpl="classA"] .r-in.r-in-last { border-bottom: 1px solid #9aa7b5; padding-bottom: 14.67px; margin-bottom: 0; }

.review-doc[data-tpl="classA"] .r-tw table { table-layout: fixed; margin: 0 0 29.8px; }
.review-doc[data-tpl="classA"] .r-tw th, .review-doc[data-tpl="classA"] .r-tw td { border: 1px solid #9aa7b5; padding: 4px 6.67px; line-height: 1.15; }
.review-doc[data-tpl="classA"] .r-tw th:nth-child(1) { width: 44.87%; }
.review-doc[data-tpl="classA"] .r-tw th:nth-child(2) { width: 14.96%; }
.review-doc[data-tpl="classA"] .r-table-caption { color: inherit; margin: 0 0 20px; font-size: 12px; }

/* 2.0+3.0 and 4.2.x are compact in Word too (smaller type, tighter spacing); --fit shrinks further only if needed */
.review-doc[data-tpl="classA"] .r-fitgroup { --fit: 1; font-size: calc(10.67px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup h2:not(.r-boxhead) { font-size: calc(14.67px * var(--fit)); margin: calc(13.33px * var(--fit)) 0 calc(8px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup h3:not(.r-boxhead) { font-size: calc(13.33px * var(--fit)); margin: calc(10.67px * var(--fit)) 0 calc(5.33px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup .r-field, .review-doc[data-tpl="classA"] .r-fitgroup p { font-size: calc(10.67px * var(--fit)); margin: 0 0 calc(5.33px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup p.r-blank { margin: 0 0 calc(2.67px * var(--fit)); height: calc(12.3px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup .r-table-caption { font-size: calc(10.67px * var(--fit)); margin: 0 0 calc(8px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup .r-tw table { font-size: calc(10.67px * var(--fit)); margin: 0 0 calc(16px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup .r-tw th, .review-doc[data-tpl="classA"] .r-fitgroup .r-tw td { padding: calc(2.67px * var(--fit)) calc(5px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup h3.r-boxhead { font-size: calc(10.67px * var(--fit)); padding: calc(2.67px * var(--fit)) calc(5px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup .r-boxed { padding: calc(6px * var(--fit)); margin: 0 0 calc(16px * var(--fit)); }

/* Cover: photo 653px on top, blue band running to the bottom edge, as in the Word cover */
.review-doc[data-tpl="classA"] .a4.cover-photo { height: 1123px; }
.review-doc[data-tpl="classA"] .cover-photo-img { flex: 0 0 653px; }
.review-doc[data-tpl="classA"] .cover-photo-banner { flex: 1; padding: 34.7px 49px 30px; }
.review-doc[data-tpl="classA"] .cover-photo-text h1 { letter-spacing: 0; }
.review-doc[data-tpl="classA"] .cover-photo-meta { font-size: 13.33px; }

/* Appendix photos: one under another, centred, 400px wide, caption below (as Word) */
.review-doc[data-tpl="classA"] .r-photo-entry { display: block; text-align: center; margin: 0; }
.review-doc[data-tpl="classA"] .r-photo-entry.r-in { padding: 0 11.33px; }
.review-doc[data-tpl="classA"] .r-photo-img-wrap { flex: none; max-width: none; padding: 21.3px 0 12px; }
.review-doc[data-tpl="classA"] .r-photo-img-wrap img { width: auto; max-width: 400px; height: auto; max-height: none; border: 0; border-radius: 0; object-fit: fill; }
.review-doc[data-tpl="classA"] .r-photo-comment { padding-bottom: 24px; text-align: center; }

/* Class B cover: the supplied page-sized image (photo on top, blue band below) is the whole
   page background; the dynamic fields sit over the band, the footer line at the bottom. */
/* ==========================================================================
   Class A type scale, from the original Word template (1pt = 1.333px): Calibri, 11pt body,
   12pt section headings, 11pt sub-headings, 20pt appendix headings, 1.15 line spacing,
   6pt after paragraphs, 3pt between bullets, 12pt before / 6pt after headings, 3pt cell padding.
   ========================================================================== */
.review-doc[data-tpl="classA"] { font-family: Calibri, Carlito, Arial, sans-serif; font-size: 14.67px; line-height: 1.15; }
.review-doc[data-tpl="classA"] .head-report { font-size: 9pt; }
.review-doc[data-tpl="classA"] .page-foot { font-size: 11pt; }
.review-doc[data-tpl="classA"] .page-foot span:first-child { font-size: 12pt; }

.review-doc[data-tpl="classA"] h2:not(.r-boxhead) { font-size: 16px; margin: 16px 0 8px; }
.review-doc[data-tpl="classA"] h3:not(.r-boxhead) { font-size: 14.67px; margin: 16px 0 8px; }
.review-doc[data-tpl="classA"] h3.r-boxhead { font-size: 14.67px; }
.review-doc[data-tpl="classA"] h2.r-boxhead { font-size: 16px; }
.review-doc[data-tpl="classA"] h2.r-boxhead.r-app { font-size: 26.67px; }
.review-doc[data-tpl="classA"] .r-app .app-sub { display: block; font-weight: 400; }
.review-doc[data-tpl="classA"] .r-field, .review-doc[data-tpl="classA"] p { font-size: 14.67px; margin: 0 0 8px; }
.review-doc[data-tpl="classA"] p.r-bullet { margin-bottom: 4px; }
.review-doc[data-tpl="classA"] h3.r-in { padding-top: 16px; padding-bottom: 8px; }
.review-doc[data-tpl="classA"] .r-boxhead + h3.r-in { padding-top: 30.67px; }
.review-doc[data-tpl="classA"] .r-table-caption { font-size: 14.67px; margin: 0 0 8px; }
.review-doc[data-tpl="classA"] .r-tw table { font-size: 14.67px; }

/* Cover: 46pt title, 16pt address, 11pt report / work order lines and footer */
.review-doc[data-tpl="classA"] .cover-photo-text h1 { font-size: 61.33px; }
.review-doc[data-tpl="classA"] .cover-photo-address { font-size: 21.33px; }
.review-doc[data-tpl="classA"] .cover-photo-meta, .review-doc[data-tpl="classA"] .cover-foot-name, .review-doc[data-tpl="classA"] .cover-foot { font-size: 14.67px; }

/* The one-page groups start at the same sizes; --fit only shrinks them if they would not fit */
.review-doc[data-tpl="classA"] .r-fitgroup { font-size: calc(14.67px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup h2:not(.r-boxhead) { font-size: calc(16px * var(--fit)); margin: calc(16px * var(--fit)) 0 calc(8px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup h3:not(.r-boxhead) { font-size: calc(14.67px * var(--fit)); margin: calc(16px * var(--fit)) 0 calc(8px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup .r-field, .review-doc[data-tpl="classA"] .r-fitgroup p { font-size: calc(14.67px * var(--fit)); margin: 0 0 calc(8px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup p.r-bullet { margin-bottom: calc(4px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup .r-table-caption { font-size: calc(14.67px * var(--fit)); margin: 0 0 calc(8px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup .r-tw table { font-size: calc(14.67px * var(--fit)); margin: 0 0 calc(16px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup .r-tw th, .review-doc[data-tpl="classA"] .r-fitgroup .r-tw td { padding: calc(4px * var(--fit)) calc(6.67px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup h3.r-boxhead { font-size: calc(14.67px * var(--fit)); padding: calc(4px * var(--fit)) calc(6.67px * var(--fit)); }
.review-doc[data-tpl="classA"] .r-fitgroup .r-boxed { padding: calc(9.33px * var(--fit)); margin: 0 0 calc(16px * var(--fit)); }

.a4.cover-bg { height: 1123px; padding: 0 49px 30px; overflow: hidden; background: #88b6e0 url("cover-bg.jpg") center top / 100% 100% no-repeat; }
.cover-bg .cover-bg-text { margin-top: 688px; padding-left: 16px; }
.cover-bg h1 { color: #fff; font-size: 46px; line-height: 1.15; letter-spacing: 0; margin: 0 0 10px; }
.cover-bg .cover-photo-meta { font-size: 13.33px; padding-left: 0; }
.cover-bg .cover-photo-meta b { font-weight: 700; }
.cover-bg .r-empty { color: rgba(255,255,255,.75); }
.a4.cover-bg .cover-foot-name { color: #fff; padding-bottom: 7px; }
.a4.cover-bg .cover-foot { background: none; margin: 0; padding: 6px 0 0; border-top: 1px solid rgba(255,255,255,.4); }

/* ===== Class A: cover colours only (baby blue #88B6E0, white, black) =====
   Heading bar #88B6E0 / white; sub-item bars and table headers #CFE2F3 / black; box edge
   #88B6E0; thin row lines #C9DDF2. Number column 1.4cm (52.9px); rows never split. */
.review-doc[data-tpl="classA"] { --c1: 52.9px; --c2: 286.7px; --s2: 233.3px; --s3: 93.3px; color: #000; }
.review-doc[data-tpl="classA"] .page-head { border-bottom-color: #88b6e0; }
.review-doc[data-tpl="classA"] .page-head img { height: 40px; width: auto; }
.review-doc[data-tpl="classA"] .head-report { color: #000; }
.review-doc[data-tpl="classA"] .body-page .page-foot { color: #000; border-top-color: #88b6e0; }
.review-doc[data-tpl="classA"] .ca-bar { background: #88b6e0; color: #fff; font-weight: 700; font-size: 16px; padding: 5.33px 6.67px; line-height: 1.15; }
.review-doc[data-tpl="classA"] .ca-gap { height: 8px; }
.review-doc[data-tpl="classA"] .ca-gap2 { height: 16px; }
.review-doc[data-tpl="classA"] .ca-row { box-sizing: border-box; border-left: 1px solid #88b6e0; border-right: 1px solid #88b6e0; color: #000; }
.review-doc[data-tpl="classA"] .ca-row.g-n { display: grid; grid-template-columns: var(--c1) var(--c2) 1fr; }
.review-doc[data-tpl="classA"] .ca-row.g-s { display: grid; grid-template-columns: var(--c1) var(--s2) var(--s3) 1fr; }
.review-doc[data-tpl="classA"] .ca-row.g-n > *, .review-doc[data-tpl="classA"] .ca-row.g-s > * { padding: 4px 6.67px; min-width: 0; }
.review-doc[data-tpl="classA"] .ca-row.ca-p { padding: 4px 6.67px; }
.review-doc[data-tpl="classA"] .ca-nr, .review-doc[data-tpl="classA"] .ca-tr, .review-doc[data-tpl="classA"] .ca-th { border-top: 1px solid #c9ddf2; }
.review-doc[data-tpl="classA"] .ca-date .c-ld { grid-column: 1 / 3; }
.review-doc[data-tpl="classA"] .ca-date .c-rv { grid-column: 3; }
.review-doc[data-tpl="classA"] .ca-sb, .review-doc[data-tpl="classA"] .ca-th { background: #cfe2f3; font-weight: 700; }
.review-doc[data-tpl="classA"] .ca-sb .c-tit { grid-column: 2 / -1; }
.review-doc[data-tpl="classA"] .ca-th .c-item, .review-doc[data-tpl="classA"] .ca-tr .c-item { grid-column: 1 / 3; }
.review-doc[data-tpl="classA"] .ca-th > :nth-child(n+2), .review-doc[data-tpl="classA"] .ca-tr > :nth-child(n+2) { border-left: 1px solid #c9ddf2; }
.review-doc[data-tpl="classA"] .ca-yes { background: #e2f0d9; }
.review-doc[data-tpl="classA"] .ca-nr .c-val p, .review-doc[data-tpl="classA"] .ca-nr .c-val { margin: 0; }
.review-doc[data-tpl="classA"] .ca-row.ca-top { border-top: 1px solid #88b6e0; }
.review-doc[data-tpl="classA"] .ca-row.ca-bottom { border-bottom: 1px solid #88b6e0; }
.review-doc[data-tpl="classA"] .ca-sigh { color: #000; font-size: 14.67px; margin: 16px 0 8px; }
.review-doc[data-tpl="classA"] .r-photo-comment b, .review-doc[data-tpl="classA"] .r-attach-entry b { color: #000; }
.review-doc[data-tpl="classA"] .ca-app { color: #000; font-size: 26.67px; font-weight: 700; line-height: 1.15; margin: 0 0 16px; }
.review-doc[data-tpl="classA"] .ca-app b { display: block; font-weight: 700; }


