/*
  Chart PDF page (chart/chart_pdf.html) and the document that html2pdf captures from it.

  Layout rules that matter for the PDF:
  - html2pdf lays the document out at the paper width (11in = 1056px) and cuts it into pages every 816px (8.5in).
    Page 1 is therefore EXACTLY 816px tall, so page 2 (notes) always starts on a fresh sheet. Do not let page 1 grow.
  - Sizes are px on purpose (the old page relied on a % font-size chain that html2canvas rendered inconsistently).
  - Avoid CSS columns and color-mix(): html2canvas does not paint them reliably. Grid and flex are fine.
  Everything is prefixed pdf-.
*/

body.pdf-body {
  margin: 0;
  background: #E9ECF1;
}

/* ---------- on-screen toolbar (not part of the PDF) ---------- */
.pdf-toolbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  background: #FFFFFF;
  border-bottom: 1px solid #D9DDE3;
  font-family: "Noto Sans", sans-serif;
}
.pdf-tb-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  color: #1D1E1F;
}
.pdf-tb-sub {
  margin: 2px 0 0 0;
  font-size: 13px;
  color: #6B7280;
}
.pdf-tb-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.pdf-status {
  font-size: 13px;
  color: #6B7280;
}
.pdf-btn {
  padding: 9px 18px;
  border: 1px solid #2F81F8;
  border-radius: 3px;
  background: #2F81F8;
  color: #FFFFFF;
  font-family: "Noto Sans", sans-serif;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.pdf-btn:hover:not(:disabled) {
  background: #FFFFFF;
  color: #2F81F8;
}
.pdf-btn:disabled {
  opacity: 0.55;
  cursor: default;
}
.pdf-btn-ghost {
  background: #FFFFFF;
  color: #1D1E1F;
  border-color: #B9C0CA;
}
.pdf-btn-ghost:hover:not(:disabled) {
  background: #FFFFFF;
  color: #2F81F8;
  border-color: #2F81F8;
}

.pdf-stage {
  display: flex;
  justify-content: center;
  padding: 24px;
  overflow-x: auto;
}

/* ---------- the document ---------- */
.pdf-doc {
  --pdf-cols: 22px 26px 20px 34px 26px 22px 30px 20px 28px 38px 38px 36px;
  flex: 0 0 auto;
  width: 1056px;
  background: #FFFFFF;
  box-shadow: 0 2px 6px rgba(16, 24, 40, 0.12), 0 8px 24px rgba(16, 24, 40, 0.10);
  color: #1D1E1F;
  font-family: "Noto Sans", sans-serif;
  font-size: 9px;
  line-height: 1.25;
  text-align: left;
}
.pdf-doc *,
.pdf-doc *::before,
.pdf-doc *::after {
  box-sizing: border-box;
  font-family: "Noto Sans", sans-serif;
}
.pdf-doc p {
  margin: 0;
}

.pdf-page {
  display: flex;
  flex-direction: column;
  width: 1056px;
  height: 816px;
  padding: 24px 30px 14px 30px;
  overflow: hidden;
  background: #FFFFFF;
}
/* faint line on screen (and a hairline at the very bottom edge of the sheet) marking where page 1 ends */
.pdf-has-next {
  border-bottom: 1px dashed #CBD2DA;
}
.pdf-page-2 {
  height: auto;
  min-height: 816px;
  overflow: visible;
}

/* ---------- header ---------- */
.pdf-head {
  display: grid;
  grid-template-columns: 1.2fr 1fr 0.9fr;
  align-items: center;
  gap: 18px;
  padding-bottom: 9px;
  border-bottom: 2px solid #2F81F8;
}
.pdf-clinic {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.pdf-logo {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
}
.pdf-logo img {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  border-radius: 3px;
}
.pdf-clinic-name {
  font-size: 13px;
  font-weight: 700;
  color: #1D1E1F;
}
.pdf-clinic-line {
  font-size: 9px;
  color: #4B5563;
}
.pdf-patient-name {
  font-size: 22px;
  font-weight: 700;
  line-height: 1.1;
  color: #2F81F8;
}
.pdf-line {
  font-size: 10px;
  color: #374151;
}
.pdf-k {
  display: inline-block;
  min-width: 58px;
  margin-right: 6px;
  font-size: 8px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #6B7280;
}
.pdf-meta .pdf-line {
  margin-bottom: 2px;
}
.pdf-compact-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 18px;
  padding-bottom: 9px;
  border-bottom: 2px solid #2F81F8;
}
.pdf-compact-head .pdf-patient-name {
  font-size: 18px;
}

/* ---------- tooth tables + diagram ---------- */
.pdf-main {
  display: grid;
  grid-template-columns: 340px 1fr 340px;
  gap: 10px;
  margin-top: 10px;
}
.pdf-table-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 3px;
  font-size: 7.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6B7280;
}
.pdf-thead {
  display: grid;
  grid-template-columns: var(--pdf-cols);
  border-radius: 2px;
  background: #2F81F8;
}
.pdf-th {
  padding: 4px 0;
  text-align: center;
  font-size: 6.5px;
  font-weight: 700;
  color: #FFFFFF;
}
.pdf-group {
  border: 1px solid #E5E7EB;
  border-radius: 2px;
}
.pdf-group + .pdf-group {
  margin-top: 5px;
}
.pdf-row {
  display: grid;
  grid-template-columns: var(--pdf-cols);
  min-height: 15.5px;
  border-bottom: 1px solid #EEF0F3;
}
.pdf-row:last-child {
  border-bottom: none;
}
.pdf-row:nth-child(even) {
  background: #F7F8FA;
}
.pdf-cell {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 1px;
  border-left: 1px solid #EEF0F3;
  text-align: center;
}
.pdf-cell:first-child {
  justify-content: flex-start;
  padding-left: 5px;
  border-left: none;
  font-size: 9px;
  font-weight: 700;
}
.pdf-tag {
  display: inline-block;
  padding: 1px 2px;
  border: 1px solid var(--c);
  border-radius: 2px;
  background: var(--bg);
  font-size: 8px;
  font-weight: 600;
  line-height: 1.1;
  white-space: nowrap;
}
.pdf-tag-sm {
  font-size: 6.5px;
}
.pdf-c-dsc,
.pdf-c-mal {
  padding: 1px 1.5px;
  font-size: 7.5px;
}
.pdf-c-perio { --c: #2FF895; --bg: rgba(47, 248, 149, 0.16); }
.pdf-c-mob   { --c: #D476FA; --bg: rgba(212, 118, 250, 0.14); }
.pdf-c-fx    { --c: #F983C0; --bg: rgba(249, 131, 192, 0.16); }
.pdf-c-wear  { --c: #21AB1F; --bg: rgba(33, 171, 31, 0.12); }
.pdf-c-dsc   { --c: #F5EE17; --bg: rgba(245, 238, 23, 0.25); }
.pdf-c-mal   { --c: #281BF5; --bg: rgba(40, 27, 245, 0.10); }
.pdf-c-tp    { --c: #A4211D; --bg: rgba(164, 33, 29, 0.10); }

/* the 3D chart. The wrapper is forced to the box size so the snapshot taken for the PDF has the same aspect ratio */
.pdf-diagram {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 392px;
  overflow: hidden;
  border: 1px solid #E5E7EB;
  border-radius: 3px;
  background: #F2F2F2;
}
.pdf-diagram #chart-3d-wrapper,
.pdf-diagram #chart-cat-3d-wrapper {
  width: 100% !important;
  height: 100% !important;
}

/* ---------- bottom: overview, color key, glossary ---------- */
.pdf-bottom {
  display: grid;
  grid-template-columns: 262px 1fr;
  gap: 14px;
  flex: 1 1 auto;
  min-height: 0;
  margin-top: 10px;
}
.pdf-box-title {
  margin-bottom: 4px;
  padding-bottom: 2px;
  border-bottom: 1px solid #D9DDE3;
  font-size: 7.5px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #6B7280;
}
.pdf-overview-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 1.5px 0;
  font-size: 9px;
}
.pdf-overview-row span:first-child {
  color: #6B7280;
}
.pdf-overview-row span:last-child {
  font-weight: 600;
  text-align: right;
}
.pdf-key {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 8px;
  margin-top: 0;
}
.pdf-key-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 7.5px;
}
.pdf-sw {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border: 1.5px solid var(--c);
  border-radius: 2px;
  background: transparent;
}
.pdf-sw-fill {
  background: var(--c);
}

.pdf-gloss {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.pdf-gcol {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.pdf-g {
  padding-top: 3px;
  border-top: 2px solid var(--c);
}
.pdf-g-head {
  display: flex;
  align-items: baseline;
  gap: 5px;
  margin-bottom: 1px;
}
.pdf-g-code {
  font-size: 10px;
  font-weight: 700;
}
.pdf-g-name {
  font-size: 7.5px;
  color: #6B7280;
}
.pdf-g-item {
  font-size: 7.5px;
  line-height: 1.3;
  color: #374151;
}
.pdf-g-item b {
  font-weight: 700;
  color: #1D1E1F;
}
.pdf-foot-note {
  margin-top: 6px;
  font-size: 7px;
  color: #6B7280;
}

/* ---------- page footer ---------- */
.pdf-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  padding-top: 6px;
  border-top: 1px solid #E5E7EB;
  font-size: 8px;
  color: #6B7280;
}
.pdf-powered {
  display: flex;
  align-items: center;
  gap: 6px;
}
.pdf-powered img {
  display: block;
  width: auto;
  height: 34px;
}

/* ---------- page 2: notes ---------- */
.pdf-notes-body {
  flex: 1 1 auto;
  padding-top: 14px;
}
.pdf-notes-heading {
  margin: 0 0 6px 0;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #2F81F8;
}
.pdf-notes-block + .pdf-notes-block {
  margin-top: 18px;
}
.pdf-general {
  padding: 10px 12px;
  border: 1px solid #D9DDE3;
  border-left: 3px solid #2F81F8;
  border-radius: 3px;
  background: #F7F8FA;
}
.pdf-note-text {
  font-size: 11px;
  line-height: 1.5;
  color: #1D1E1F;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.pdf-note-row {
  display: grid;
  grid-template-columns: 46px 1fr;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid #E5E7EB;
  break-inside: avoid;
  page-break-inside: avoid;
}
.pdf-note-badge {
  align-self: start;
  padding: 3px 0;
  border-radius: 3px;
  background: #2F81F8;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: #FFFFFF;
}
