:root {
  --accent: #7b52c9;
  --accent-line: #8a63c9;
  --accent-soft: #ede7f8;
  --tooth-fill: #ded4f2;
  --tooth-line: #b6a3e2;
  --ink: #1d1d1f;
  --red: #e02020;
}

:root[data-theme="red"] {
  --accent: #ee3b43;
  --accent-line: #f08087;
  --accent-soft: #fde9ea;
  --tooth-fill: #fadbdd;
  --tooth-line: #f2a5aa;
}

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

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

.sheet {
  max-width: 1000px;
  margin: 0 auto;
  padding: 36px 48px 60px;
}

/* ---- theme toggle (preview chrome, not part of the sheet) ---- */
.theme-toggle {
  position: fixed;
  top: 12px;
  right: 14px;
  z-index: 40;
  display: flex;
  gap: 8px;
}
.theme-btn {
  padding: 6px 16px;
  border-radius: 20px;
  border: 1px solid #ccc;
  background: #fff;
  font: 600 12px "Segoe UI", Arial, sans-serif;
  cursor: pointer;
  color: #555;
}
.theme-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ---- brand header ---- */
.brand-row {
  display: flex;
  align-items: center;
  gap: 22px;
  margin-bottom: 44px;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-pyoor { display: none; }
:root[data-theme="red"] .brand-arc { display: none; }
:root[data-theme="red"] .brand-pyoor { display: flex; }

.arc-mark { width: 44px; height: 44px; color: var(--accent); }
.arc-text { display: flex; flex-direction: column; line-height: 1.05; }
.arc-name { font-size: 27px; font-weight: 800; letter-spacing: 1px; }
.arc-sub { font-size: 9.5px; letter-spacing: 1.6px; color: #555; }

.pyoor-box {
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  border-radius: 6px;
  padding: 12px 10px;
}

.brand-bar {
  flex: 1;
  height: 12px;
  border-radius: 6px;
  background: var(--accent);
  align-self: flex-start;
  margin-top: 8px;
}

/* ---- counts / meta / legend ---- */
.top-grid {
  display: flex;
  justify-content: space-between;
  gap: 40px;
  margin-bottom: 40px;
}

.count-row {
  display: flex;
  align-items: center;
  gap: 26px;
  margin-bottom: 20px;
  font-size: 14.5px;
  font-weight: 700;
}
.count-input {
  width: 92px;
  height: 26px;
  background: #ececec;
  border: 1px solid #cfcfcf;
  border-radius: 4px;
  text-align: center;
  font: 600 13px "Segoe UI", Arial, sans-serif;
  color: #333;
  outline: none;
}
.count-input:focus { border-color: var(--accent); }
.count-input::-webkit-outer-spin-button,
.count-input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

.case-meta { font-size: 14px; line-height: 1.75; min-width: 330px; }
.case-meta b { font-weight: 700; }
.edit-field {
  display: inline-block;
  min-width: 60px;
  font-style: italic;
  color: #8a8a8a;
  outline: none;
  border-bottom: 1px dashed transparent;
  padding: 0 2px;
}
.edit-field:hover { border-bottom-color: #c5c5c5; }
.edit-field:focus { border-bottom: 1px solid var(--accent); color: #555; }

.legend-panel {
  margin-top: 12px;
  background: #ececec;
  border-radius: 8px;
  padding: 12px 18px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 34px;
  row-gap: 10px;
  font-size: 12.5px;
  font-weight: 600;
}
.lg-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.sw { width: 13px; height: 13px; border-radius: 3px; display: inline-block; }
.sw-att { background: #f5a623; }
.sw-btn { background: #7b52c9; border-radius: 50%; }
.sw-ramp { background: #4a7bd4; }
.sw-svg { width: 15px; height: 15px; }

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

.crown {
  fill: var(--tooth-fill);
  stroke: var(--tooth-line);
  stroke-width: 1.5;
  stroke-linejoin: round;
}
.marker { fill: var(--accent); }
.chart-line { stroke: var(--accent-line); stroke-width: 1.6; }
.num { fill: #333; font-weight: 600; }

.tooth { cursor: pointer; }
.tooth:hover .crown { stroke-width: 2.4; }
.gap rect { cursor: pointer; }
.gap:hover rect { fill: rgba(0, 0, 0, 0.05); }

/* ---- tooth popover ---- */
.tooth-popover {
  position: absolute;
  z-index: 20;
  width: 176px;
  background: #fff;
  border: 1px solid #e2e2e2;
  border-radius: 10px;
  box-shadow: 0 5px 20px rgba(0, 0, 0, 0.14);
  padding: 26px 16px 8px;
}
.pop-close {
  position: absolute;
  top: 6px;
  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: 8px 0;
  font-size: 13px;
  font-weight: 600;
  color: #333;
  cursor: pointer;
  user-select: none;
}
.pop-row input {
  width: 15px;
  height: 15px;
  margin: 0;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

/* ---- IPR modal ---- */
.ipr-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(255, 255, 255, 0.55);
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding-top: 120px;
}
.ipr-modal {
  position: relative;
  width: 440px;
  max-width: calc(100vw - 40px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.25);
  padding: 20px 24px 24px;
}
.ipr-modal h3 { text-align: center; font-size: 16px; font-weight: 700; margin-bottom: 6px; }
.ipr-close {
  position: absolute;
  top: 14px;
  right: 16px;
  width: 22px;
  height: 22px;
  padding: 0;
  border: none;
  background: transparent;
  color: #333;
  cursor: pointer;
}
.ipr-close svg { width: 100%; height: 100%; display: block; }
.ipr-label { display: block; font-size: 12.5px; font-weight: 600; color: #9a9a9a; margin: 12px 0 5px; }
.ipr-modal input {
  width: 100%;
  height: 36px;
  border: 1px solid #c9c9c9;
  border-radius: 8px;
  padding: 0 12px;
  font-size: 13.5px;
  outline: none;
}
.ipr-modal input:focus { border-color: var(--accent); }
.ipr-modal input::-webkit-outer-spin-button,
.ipr-modal input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.ipr-actions { display: flex; justify-content: space-between; margin-top: 22px; }
.ipr-clear {
  background: #fff;
  border: 1px solid #e2e2e2;
  border-radius: 8px;
  padding: 9px 22px;
  font: 700 12.5px "Segoe UI", Arial, sans-serif;
  cursor: pointer;
}
.ipr-submit {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 9px 26px;
  font: 700 13px "Segoe UI", Arial, sans-serif;
  cursor: pointer;
}

/* ---- info sections ---- */
.info-cols {
  display: flex;
  gap: 70px;
  margin-bottom: 40px;
}
.info-col { flex: 1; }

.info-item {
  display: flex;
  gap: 18px;
  margin-bottom: 30px;
}
.info-icon {
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 13px;
  background: var(--accent-soft);
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.info-icon svg { width: 27px; height: 27px; }
.info-text h4 { font-size: 13.5px; font-weight: 700; margin-bottom: 6px; }
.info-text p { font-size: 11.8px; line-height: 1.55; color: #222; }

.inline-num {
  border: none;
  background: transparent;
  font: 700 12px "Segoe UI", Arial, sans-serif;
  color: var(--ink);
  width: 2.8ch;
  padding: 0 1px;
  border-bottom: 1px dashed transparent;
  outline: none;
}
.inline-num:hover { border-bottom-color: #c5c5c5; }
.inline-num:focus { border-bottom: 1px solid var(--accent); }
.inline-num::-webkit-outer-spin-button,
.inline-num::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* ---- treatment notes ---- */
.notes {
  background: var(--accent-soft);
  border-radius: 10px;
  padding: 14px 22px 18px;
}
.notes h4 { font-size: 13.5px; font-weight: 700; margin-bottom: 10px; }
.notes-line {
  min-height: 22px;
  border-bottom: 1px solid #555;
  font-size: 13px;
  outline: none;
  padding: 2px 4px;
}

/* ---- generate pdf ---- */
.pdf-row { text-align: center; margin-top: 40px; }
.generate-pdf {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  padding: 9px 26px;
  font: 600 13px "Segoe UI", Arial, sans-serif;
  cursor: pointer;
}
.generate-pdf:hover { filter: brightness(1.08); }

/* ---- pdf export state ----
 * Tightened spacing so the whole sheet fits a single A4 page. */
.exporting .theme-toggle,
.exporting .pdf-row { display: none !important; }

.exporting .sheet { width: 1000px; max-width: none; margin: 0; padding: 20px 48px 30px; }
.exporting .brand-row { margin-bottom: 24px; }
.exporting .count-row { margin-bottom: 12px; }
.exporting .top-grid { margin-bottom: 20px; }
.exporting .tooth-chart { margin: 0 0 24px; }
.exporting .info-cols { gap: 50px; margin-bottom: 20px; }
.exporting .info-item { margin-bottom: 16px; }

@media print {
  .theme-toggle, .pdf-row { display: none; }
}
