:root {
  --blue: #2ea9e5;
  --frame-blue: #1272b6;
  --green: #2e7d32;
  --red: #e02020;
  --ink: #202124;
  --dim: #9a9a9a;
  --tooth-line: #b8bec6;
  --root-line: #e0e3e8;
}

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

body {
  background: var(--frame-blue);
  font-family: Roboto, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
}

.frame {
  background: #fff;
  margin: 14px;
  padding: 42px 60px 70px;
  min-height: calc(100vh - 28px);
}

/* ---- page mode buttons ---- */
.page-mode {
  display: flex;
  justify-content: flex-end;
  gap: 18px;
  margin-bottom: 34px;
}
.mode-btn {
  min-width: 200px;
  padding: 9px 26px;
  border-radius: 6px;
  border: 1px solid #b5b5b5;
  background: #fff;
  color: #333;
  font: 600 14px Roboto, "Segoe UI", Arial, sans-serif;
  cursor: pointer;
}
.mode-btn:hover { border-color: #888; }
.mode-btn.active {
  background: #43a047;
  border-color: #43a047;
  color: #fff;
}

/* ---- case number input ---- */
.case-search { text-align: center; margin-bottom: 46px; }
.case-search input {
  width: 400px;
  max-width: 90%;
  height: 36px;
  padding: 0 14px;
  font: 15px Roboto, "Segoe UI", Arial, sans-serif;
  color: #555;
  border: 1px solid #9aa0a6;
  border-radius: 6px;
  outline: none;
}
.case-search input:focus { border-color: var(--blue); }

/* ---- patient header ---- */
.patient-header { margin: 0 auto; }
.patient-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  font-size: 19px;
  margin-bottom: 10px;
}
.patient-name b { margin-left: 6px; }
.meta { text-align: left; font-size: 19px; line-height: 1.5; }
.meta b { margin-left: 8px; }

.rule { border: none; border-top: 1px solid #4a4a4a; }

.page-title {
  text-align: center;
  font-size: 23px;
  font-weight: 400;
  padding: 12px 0;
}

/* ---- tooth chart ---- */
.tooth-chart { margin: 6px 0 10px; position: relative; }
.tooth-chart svg { width: 100%; height: auto; display: block; }

.tooth { cursor: pointer; }
.tooth:hover .crown { stroke: var(--blue); }

.gap rect { cursor: pointer; }
.gap:hover rect { fill: rgba(46, 169, 229, 0.10); }

.rootline rect { cursor: pointer; }
.rootline:hover rect { fill: rgba(46, 169, 229, 0.12); }

/* ---- tooth symbol popover ---- */
.tooth-popover {
  position: absolute;
  z-index: 20;
  width: 200px;
  background: #fff;
  border: 1px solid #e2e2e2;
  border-radius: 8px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.14);
  padding: 30px 16px 10px;
}
.pop-close {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  background: transparent;
  color: #8a8a8a;
  cursor: pointer;
}
.pop-close:hover { color: #444; }
.pop-close svg { width: 100%; height: 100%; display: block; }

.pop-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  font-size: 13.5px;
  color: #333;
  cursor: pointer;
  user-select: none;
}
.pop-row input {
  width: 16px;
  height: 16px;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--blue);
  cursor: pointer;
}

/* ---- totals + boxes ---- */
.info-flex {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 40px;
}

.totals { margin-top: 150px; font-size: 20px; }
.totals-row {
  display: flex;
  align-items: center;
  gap: 22px;
  margin-bottom: 26px;
}
.totals-label { min-width: 210px; }
.totals-values div { margin: 3px 0; }
.totals-values b { font-size: 21px; }
.wear-note { margin-top: 34px; font-size: 19px; }
.wear-note b { font-size: 21px; }

/* editable inline values — look like bold text until focused */
.inline-num {
  border: none;
  background: transparent;
  padding: 0 2px;
  font: 700 21px Roboto, "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  width: 3.4ch;
  border-bottom: 1.5px dashed transparent;
  border-radius: 0;
  outline: none;
}
.inline-num.days { width: 4.4ch; }
.inline-num:hover { border-bottom-color: #c5c5c5; }
.inline-num:focus { border-bottom: 1.5px solid var(--blue); }
.inline-num::-webkit-outer-spin-button,
.inline-num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.inline-num[type="number"] { -moz-appearance: textfield; appearance: textfield; }

/* editable inline text (header, elastic box) — synced across both pages */
.edit-field {
  display: inline-block;
  min-width: 30px;
  padding: 0 2px;
  border-bottom: 1.5px dashed transparent;
  outline: none;
}
.edit-field:hover { border-bottom-color: #c5c5c5; }
.edit-field:focus { border-bottom: 1.5px solid var(--blue); }

.side-boxes { width: 340px; flex-shrink: 0; }

.elastic-box {
  border: 1.6px solid var(--green);
  padding: 12px 16px;
  font-size: 16px;
  line-height: 1.7;
  margin-bottom: 22px;
}
.elastic-box .dim { color: var(--dim); margin-right: 8px; }

.legend-box {
  border: 1.6px solid var(--green);
  padding: 16px 18px 18px;
  font-size: 14.5px;
}
.lg-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 9px;
}
.lg-row.snug { margin-bottom: 4px; }
.lg-row.tall { margin-bottom: 6px; }
.lg-row.indent { padding-left: 14px; }
.lg-icon { width: 44px; flex-shrink: 0; display: inline-flex; }
.lg-icon svg { width: 44px; height: 26px; }
.lg-row.tall .lg-icon svg { height: 34px; }
.ipr-row { margin: 10px 0 12px; }
.ipr { color: var(--red); font-weight: 700; font-size: 15px; padding-left: 6px; }

/* ---- IPR modal ---- */
.ipr-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.5);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 130px;
}

.ipr-modal {
  position: relative;
  width: 520px;
  max-width: calc(100vw - 40px);
  background: #fff;
  border-radius: 24px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.25);
  padding: 24px 30px 30px;
}
.ipr-modal h3 {
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  margin: 2px 0 8px;
}
.ipr-close {
  position: absolute;
  top: 16px;
  right: 18px;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  color: #333;
  cursor: pointer;
}
.ipr-close:hover { color: #000; }
.ipr-close svg { width: 100%; height: 100%; display: block; }

.ipr-label {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: #9a9a9a;
  margin: 16px 0 8px;
}
.ipr-modal input {
  width: 100%;
  height: 46px;
  border: 1px solid #d5d5d5;
  border-radius: 10px;
  padding: 0 14px;
  font-size: 16px;
  outline: none;
}
.ipr-modal input:focus { border-color: var(--blue); }
.ipr-modal input::-webkit-outer-spin-button,
.ipr-modal input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ipr-modal input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

.ipr-actions {
  display: flex;
  justify-content: space-between;
  margin-top: 26px;
}
.ipr-clear {
  background: #fff;
  border: 1px solid #e2e2e2;
  border-radius: 12px;
  padding: 13px 30px;
  font: 700 15px Roboto, "Segoe UI", Arial, sans-serif;
  cursor: pointer;
}
.ipr-clear:hover { border-color: #b5b5b5; }
.ipr-submit {
  background: var(--blue);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 13px 36px;
  font: 700 15px Roboto, "Segoe UI", Arial, sans-serif;
  cursor: pointer;
}
.ipr-submit:hover { background: #1d9bd8; }

/* ---- page 2 ---- */
.page-two { margin-top: 220px; }

.smile-summary {
  text-align: center;
  font-size: 36px;
  font-weight: 800;
  letter-spacing: 0.5px;
  margin-top: 90px;
}

/* ---- smile summary image grid ---- */
.smile-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  column-gap: 60px;
  row-gap: 44px;
  width: 84%;
  margin: 60px auto 0;
}

.img-slot { display: flex; flex-direction: column; gap: 14px; }

.slot-box {
  position: relative;
  aspect-ratio: 1 / 1;
  border: 1.5px solid #b9b9b9;
  border-radius: 8px;
  background: #f4f4f4;
  cursor: pointer;
  overflow: hidden;
}
.slot-box:hover { border-color: #8f8f8f; }
.slot-box::after {
  content: "+";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 52px;
  font-weight: 300;
  color: #d2d2d2;
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
}
.slot-box:hover::after { opacity: 1; }
.slot-box.has-image::after { content: none; }

.slot-box img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.slot-clear {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: transparent;
  color: #8a8a8a;
  cursor: pointer;
}
.slot-clear:hover { color: #444; }
.slot-clear svg { width: 100%; height: 100%; display: block; }

.img-slot figcaption {
  text-align: center;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.3px;
}

/* ---- page 3 : movement chart + IPR summary ---- */
[hidden] { display: none !important; }

.page-three .page-break { margin-top: 220px; }

.section-title {
  text-align: center;
  font-size: 30px;
  font-weight: 800;
  letter-spacing: 0.5px;
  margin: 70px 0 40px;
}
.ipr-title { margin-top: 90px; }

.movement-wrap { margin-bottom: 28px; overflow-x: auto; }
.movement-table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
.movement-table th,
.movement-table td { border: 1px solid #e2e2e2; padding: 5px 3px; text-align: center; }
.movement-table .row-label {
  text-align: left;
  padding-left: 10px;
  width: 150px;
  font-weight: 500;
  white-space: nowrap;
}
.movement-table.upper thead th { background: #f6caca; font-weight: 700; }
.movement-table.upper .row-label { background: #fbe3e3; }
.movement-table.lower thead th { background: #bfe0f5; font-weight: 700; }
.movement-table.lower .row-label { background: #ddeffa; }
.movement-table td[contenteditable]:focus { outline: 2px solid var(--blue); outline-offset: -2px; }

.ipr-grid { width: 74%; column-gap: 80px; margin-top: 40px; }
.ipr-grid .slot-box { aspect-ratio: 1 / 1.15; }

.slot-box.paste-hint::before {
  content: "Paste your image here.";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  color: #9a9a9a;
  pointer-events: none;
}
.slot-box.paste-hint.has-image::before { content: none; }

.ipr-grid figcaption {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.stage-select {
  border: none;
  background: transparent;
  font: 700 13.5px Roboto, "Segoe UI", Arial, sans-serif;
  color: #333;
  cursor: pointer;
  outline: none;
}

/* ---- pdf export state ----
 * Compact layout so each section fits a single A4 page: the big screen-only
 * gaps collapse (page breaks separate the pages instead) and the image grids
 * shrink enough for three rows per page. */
body.exporting { background: #fff; }
.exporting .frame { margin: 0; width: 1650px; }
.exporting .page-mode,
.exporting .pdf-row,
.exporting .slot-clear { display: none !important; }

.exporting .case-search input {
  border-color: transparent;
  text-align: center;
  font-weight: 700;
  font-size: 17px;
  color: var(--ink);
}
.exporting .page-two { margin-top: 0; }
.exporting .page-three .page-break { margin-top: 0; }
.exporting .smile-summary { margin-top: 40px; }
.exporting .smile-grid { width: 72%; row-gap: 30px; margin-top: 40px; }
.exporting .section-title { margin: 40px 0 30px; }
.exporting .ipr-title { margin-top: 50px; }
.exporting .ipr-grid { width: 60%; column-gap: 60px; }

/* ---- generate pdf ---- */
.pdf-row { text-align: center; margin-top: 80px; }
.generate-pdf {
  background: #1b1bb0;
  color: #fff;
  border: none;
  border-radius: 4px;
  padding: 8px 24px;
  font: 600 13px Roboto, "Segoe UI", Arial, sans-serif;
  cursor: pointer;
}
.generate-pdf:hover { background: #2525cc; }

@media print {
  body { background: #fff; }
  .frame { margin: 0; padding: 20px 30px; }
  .page-two { break-before: page; margin-top: 40px; }
  .pdf-row, .slot-clear { display: none; }
  .slot-box { cursor: default; }
  .slot-box::after { content: none; }
}
