/* Markers, gaps, and treatment overlays */

:root {
  /* Clearance between the row of IPR values and the FDI number row. */
  --dc-ipr-row-clearance: 4px;
  /* Step from the per-tooth value row up to the between-teeth value row: one
     stacked "Step N / 0.25 mm" tag plus clearance. */
  --dc-ipr-row-step: 28px;
  /* Extra lift so the between-teeth Step / mm label sits above the per-tooth ones. */
  --dc-ipr-gap-label-lift: 26px;
  /* How far an IPR line runs past the tooth, toward the values. */
  --dc-ipr-line-overhang: 12px;
}

.tooth__markers {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
  overflow: visible;
}

.marker-item {
  position: absolute;
  pointer-events: none;
  overflow: visible;
}

.marker-item--attachment,
.marker-item--pressure_point,
.marker-item--bite_ramp,
.marker-item--missing_tooth,
.marker-item--extract {
  left: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: auto;
  transform: translate(-50%, -50%);
}

/* Crown face toward the occlusal/incisal end (not mid-crown / cervix).
   Upper: roots up / crown down → push markers lower. Lower: crown up → raise them. */
.tooth--upper .marker-item--attachment,
.tooth--upper .marker-item--pressure_point,
.tooth--upper .marker-item--bite_ramp,
.tooth--upper .marker-item--missing_tooth,
.tooth--upper .marker-item--extract {
  top: 86%;
}

.tooth--lower .marker-item--attachment,
.tooth--lower .marker-item--pressure_point,
.tooth--lower .marker-item--bite_ramp,
.tooth--lower .marker-item--missing_tooth,
.tooth--lower .marker-item--extract {
  top: 13%;
}

/* Keep the same crown-center anchor; nudge the two X markers apart so both
   colors read as separate crosses when Missing + Extract are applied. */
.tooth--stacked-crosses .marker-item--missing_tooth {
  transform: translate(calc(-50% - 5px), calc(-50% - 4px));
  z-index: 1;
}

.tooth--stacked-crosses .marker-item--extract {
  transform: translate(calc(-50% + 5px), calc(-50% + 4px));
  z-index: 2;
}

.tooth--stacked-crosses .marker-item--missing_tooth .marker-x svg,
.tooth--stacked-crosses .marker-item--extract .marker-x svg {
  filter: drop-shadow(0 0 1px rgba(255, 255, 255, 0.9));
}

/* Attachment + Pressure Point share the crown center; offset slightly when both. */
.tooth--stacked-attachments .marker-item--attachment {
  transform: translate(calc(-50% - 7px), -50%);
  z-index: 1;
}

.tooth--stacked-attachments .marker-item--pressure_point {
  transform: translate(calc(-50% + 8px), -50%);
  z-index: 2;
}

.tooth--stacked-attachments .marker-item--bite_ramp {
  transform: translate(-50%, calc(-50% + 11px));
  z-index: 3;
}

.marker-item--button_cut_out,
.marker-item--lingual_button {
  left: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: auto;
}

/* Keep the original cervix placement. Upper teeth show a normal U; lower teeth
   show the mirrored shape so the opening faces the crown end. */
.tooth--lower .marker-item--button_cut_out,
.tooth--lower .marker-item--lingual_button {
  top: 30%;
  transform: translate(-50%, -50%) scaleY(-1);
}

.tooth--upper .marker-item--button_cut_out,
.tooth--upper .marker-item--lingual_button {
  top: 70%;
  transform: translate(-50%, -50%);
}

/* Same cervix anchor; nudge cut-outs apart when both are applied. */
.tooth--stacked-cutouts.tooth--lower .marker-item--button_cut_out {
  transform: translate(calc(-50% - 10px), -50%) scaleY(-1);
}

.tooth--stacked-cutouts.tooth--lower .marker-item--lingual_button {
  transform: translate(calc(-50% + 10px), -50%) scaleY(-1);
}

.tooth--stacked-cutouts.tooth--upper .marker-item--button_cut_out {
  transform: translate(calc(-50% - 10px), -50%);
}

.tooth--stacked-cutouts.tooth--upper .marker-item--lingual_button {
  transform: translate(calc(-50% + 10px), -50%);
}

.marker-item--hook_slit {
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Outer crown corner: left half faces left, right half faces right.
   Upper points up (toward roots/numbers); lower points down. */
.tooth--upper .marker-hook-slit--up-left {
  top: 56%;
  left: 10%;
  transform: scaleX(-1);
}

.tooth--upper .marker-hook-slit--up-right {
  top: 56%;
  right: 10%;
  left: auto;
}

.tooth--lower .marker-hook-slit--down-left {
  top: 28%;
  left: 10%;
  transform: scale(-1);
}

.tooth--lower .marker-hook-slit--down-right {
  top: 28%;
  right: 10%;
  left: auto;
  transform: scaleY(-1);
}

.marker-item--power_arm { bottom: 8px; right: 4px; }

/* IPR side / whole-tooth lines: horizontal placement + width only. The box is
   wide enough for the line to bow toward the tooth being treated; the vertical
   extent (line length) is set per-arch below.

   The line sits on the edge of the tooth, not the edge of the icon box, which is
   wider than the art. --dc-tooth-art-inset (set per tooth in JS) is the gap
   between the two; the extra 2px lines the shaft itself up with the tooth edge,
   since the shaft is drawn 2px inside its box. */
.marker-item--ipr_tooth { left: 50%; transform: translateX(-50%); width: 12px; }
.marker-item--ipr_side { width: 12px; overflow: visible; z-index: 4; }
.marker-item--ipr_side.marker-ipr-side--distal { left: calc(var(--dc-tooth-art-inset, 0%) - 2px); }
.marker-item--ipr_side.marker-ipr-side--mesial { right: calc(var(--dc-tooth-art-inset, 0%) - 2px); }

/* Side/tooth IPR line length: the line runs past the crown toward the value row
   (up for upper teeth, down for lower) and stops short of the root tip. */
.tooth--upper .marker-item--ipr_side,
.tooth--upper .marker-item--ipr_tooth { top: calc(-1 * var(--dc-ipr-line-overhang)); bottom: 12%; }
.tooth--lower .marker-item--ipr_side,
.tooth--lower .marker-item--ipr_tooth { top: 12%; bottom: calc(-1 * var(--dc-ipr-line-overhang)); }

/* Stage on the first line, measurement with mm under it, centred on the IPR line. */
.ipr-marker__tag {
  position: absolute;
  left: 50%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1;
  white-space: nowrap;
  text-align: center;
  pointer-events: none;
  z-index: 3;
  /* Halo keeps the value readable where it passes a tooth number or the crown. */
  text-shadow: 0 0 3px #ffffff, 0 0 2px #ffffff;
}

/* Per-tooth IPR values sit just outside the FDI numbers (between-teeth values
   get the row above). --dc-ipr-label-shift is set per label in JS to spread
   values sideways when neighbouring contacts are too close. */
.tooth--upper .ipr-marker__tag {
  bottom: 100%;
  transform:
    translate(-50%, calc(var(--dc-ipr-line-overhang) - var(--dc-tooth-number-row) - var(--dc-ipr-row-clearance)))
    translateX(var(--dc-ipr-label-shift, 0px));
}

.tooth--lower .ipr-marker__tag {
  top: 100%;
  transform:
    translate(-50%, calc(var(--dc-tooth-number-row) + var(--dc-ipr-row-clearance) - var(--dc-ipr-line-overhang)))
    translateX(var(--dc-ipr-label-shift, 0px));
}

.ipr-marker__stage,
.gap-marker__label {
  font-size: 0.625rem;
  font-weight: 750;
  color: var(--dc-ipr-color, #8a4e4e);
  line-height: 1;
}

.ipr-marker__amount,
.gap-marker__amount {
  font-size: 0.625rem;
  font-weight: 700;
  color: var(--dc-ipr-color, #8a4e4e);
  line-height: 1;
  white-space: nowrap;
}

/* Marker popover */

.tooth__marker-menu {
  position: fixed;
  top: 0;
  left: 0;
  display: none;
  flex-direction: column;
  gap: 4px;
  padding: 6px;
  background: #ffffff;
  border: 1px solid #e2e9f2;
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(28, 55, 90, 0.2);
  z-index: 1100;
  pointer-events: auto;
  white-space: nowrap;
  cursor: default;
}

.tooth__marker-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: 8px;
}

.tooth__marker-chip:hover { background: rgba(0, 194, 168, 0.08); }

.tooth__marker-chip-icon {
  flex: 0 0 16px;
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.tooth__marker-chip-icon > div {
  position: static !important;
  inset: auto !important;
  width: 100% !important;
  height: 100% !important;
  display: flex;
  align-items: center;
  justify-content: center;
  transform: none !important;
}

.tooth__marker-chip-icon svg { width: 14px; height: 14px; display: block; }
.tooth__marker-chip-icon .marker-attachment__square { width: 12px; height: 8px; }
.tooth__marker-chip-icon .marker-pressure-point svg { width: 16px; height: 10px; }

.tooth__marker-chip-label {
  flex: 1 1 auto;
  font-size: 0.6875rem;
  font-weight: 650;
  color: var(--dc-text, #0f1b2d);
  text-transform: capitalize;
  padding-right: 8px;
}

.tooth__marker-chip-remove {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  margin-left: auto;
  border: none;
  border-radius: 50%;
  background: #f43f5e;
  cursor: pointer;
  flex: 0 0 16px;
}

.tooth__marker-chip-remove svg {
  width: 9px;
  height: 9px;
  stroke: #fff;
  stroke-width: 2;
  stroke-linecap: round;
}

.tooth__marker-chip-remove:hover { background: #e11d48; }

/* Marker states on teeth */

.tooth--has-marker .tooth__number {
  color: var(--dc-blue, #2f7cff);
  font-weight: 750;
}

.tooth--has-marker .tooth__enamel {
  fill: #dceaff;
  stroke: rgba(47, 124, 255, 0.4);
}

.tooth--attachment .tooth__enamel {
  fill: #c7f1e8;
  stroke: rgba(0, 194, 168, 0.45);
}

.tooth--attachment .tooth__number { color: var(--dc-mint-strong, #02a890); }

/* Marker shapes */

.marker-attachment {
  display: flex;
  align-items: center;
  justify-content: center;
}

.marker-attachment__square {
  width: 16px;
  height: 10px;
  border-radius: 2px;
  background: #0f766e;
  box-shadow: 0 0 6px rgba(15, 118, 110, 0.45);
}

.marker-attachment__bar {
  width: 30px;
  height: 6px;
  border-radius: 2px;
  background: #00c2a8;
  box-shadow: 0 0 6px rgba(0, 194, 168, 0.6);
}

.marker-bite-ramp {
  display: flex;
  align-items: center;
  justify-content: center;
}

.marker-bite-ramp__frame {
  display: flex;
  align-items: center;
  justify-content: center;
  width: auto;
  height: auto;
  padding: 0;
  box-sizing: border-box;
  border: 2.5px dotted #475569;
  border-radius: 2px;
  background: transparent;
  line-height: 0;
}

.marker-bite-ramp__block {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 0;
  background: #b9a0e0;
  box-shadow: none;
}

.tooth__marker-chip-icon .marker-bite-ramp__frame {
  padding: 0;
  border-width: 2px;
}

.tooth__marker-chip-icon .marker-bite-ramp__block {
  width: 12px;
  height: 12px;
}

.marker-pressure-point svg {
  width: 26px;
  height: 13px;
  display: block;
  filter: drop-shadow(0 1px 1px rgba(239, 68, 68, 0.28));
}
.marker-button-cutout svg,
.marker-lingual-button svg { width: 30px; height: 22px; display: block; }
.marker-x svg { width: 28px; height: 28px; }
.marker-power-arm svg { width: 32px; height: 32px; }
.marker-hook-slit svg { width: 20px; height: 20px; display: block; }

.marker-x--blue line {
  stroke: #2f7cff;
  stroke-width: 2.5;
  stroke-linecap: round;
}

.marker-x--red line {
  stroke: #f43f5e;
  stroke-width: 2.5;
  stroke-linecap: round;
}

.marker-ipr-tooth,
.marker-ipr-side { width: 100%; height: 100%; }

.marker-ipr-tooth svg,
.marker-ipr-side svg {
  width: 100%;
  height: 100%;
  display: block;
  overflow: visible;
}

.marker-ipr-tooth path,
.marker-ipr-side path {
  stroke: var(--dc-ipr-color, #8a4e4e);
}

/* The path is drawn bending right at its top end, which points at the tooth for
   an upper-arch marker on the tooth's left (distal) edge. Mirror it per side and
   per arch so the bend always faces the tooth and stays at the labelled end. */
.marker-ipr-side--mesial svg { transform: scaleX(-1); }

.tooth--lower .marker-ipr-tooth svg,
.tooth--lower .marker-ipr-side svg { transform: scaleY(-1); }

.tooth--lower .marker-ipr-side--mesial svg { transform: scale(-1, -1); }

/* Gaps */

.tooth-gap {
  flex: 0 0 var(--dc-ipr-contact-gap, 8px);
  min-width: var(--dc-ipr-contact-gap, 8px);
  max-width: var(--dc-ipr-contact-gap, 8px);
  align-self: stretch;
  position: relative;
  /* Below teeth so side IPR remains visible/clickable after a straight-line gap IPR. */
  z-index: 2;
  overflow: visible;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 3px;
  transition: flex 0.2s ease, min-width 0.2s ease, max-width 0.2s ease, background 0.12s;
}

/* Keep the hit target inside the gap slot — do not spill onto neighboring teeth. */
.tooth-gap::before,
.arch-midline-gap::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  width: auto;
  transform: none;
}

.tooth-gap--narrow {
  flex: 0 0 4px !important;
  min-width: 4px !important;
  max-width: 4px !important;
}

.tooth-gap--collapsed {
  flex: 0 0 0 !important;
  min-width: 0 !important;
  max-width: 0 !important;
  width: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  overflow: hidden;
  pointer-events: none;
}

.arch-midline-gap.tooth-gap--collapsed {
  width: 0 !important;
  min-width: 0 !important;
}

/* Match full tooth column height (icon + FDI numbers) so the IPR line
   reaches the numbering row (e.g. 13 / 14). */
.dental-arch--upper .tooth-gap,
.dental-arch--lower .tooth-gap {
  align-self: stretch;
  height: auto;
  min-height: 100%;
}

.tooth-gap:hover { background: rgba(245, 158, 11, 0.16); }

.tooth-gap--selected,
.arch-midline-gap.tooth-gap--selected {
  background: rgba(0, 194, 168, 0.2);
  outline: 2px solid var(--dc-mint, #00c2a8);
  box-shadow: 0 0 0 3px rgba(0, 194, 168, 0.14);
}

.tooth-gap--excluded,
.arch-midline-gap.tooth-gap--excluded {
  opacity: 0.2;
  pointer-events: none;
  cursor: not-allowed;
}

.tooth-gap--flash,
.arch-midline-gap--flash {
  background: rgba(245, 158, 11, 0.22);
  outline: 2px solid var(--dc-amber, #f59e0b);
  outline-offset: -1px;
}

/* Gap IPR marker */

.gap-marker {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  pointer-events: none;
  width: 100%;
  box-sizing: border-box;
}

/* The between-teeth line runs higher than the per-tooth lines (lower on the lower
   arch). Its Step / mm label sits on the tip of that line, inside the arch padding
   so it is not clipped by the chart. */
.dental-arch--upper .gap-marker {
  top: calc(-1 * (var(--dc-ipr-row-step) + var(--dc-ipr-gap-label-lift)));
}

.dental-arch--lower .gap-marker {
  bottom: calc(-1 * (var(--dc-ipr-row-step) + var(--dc-ipr-gap-label-lift)));
  flex-direction: column-reverse;
}

.gap-marker__meta {
  position: relative;
  left: auto;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  line-height: 1;
  white-space: nowrap;
  text-align: center;
  pointer-events: none;
  z-index: 3;
  text-shadow: 0 0 3px #ffffff, 0 0 2px #ffffff;
  transform: translateX(var(--dc-ipr-label-shift, 0px));
}

.dental-arch--upper .gap-marker__meta {
  margin-bottom: var(--dc-ipr-row-clearance);
}

.dental-arch--lower .gap-marker__meta {
  margin-top: var(--dc-ipr-row-clearance);
}

.gap-marker__line {
  width: 4px;
  flex: 1 1 auto;
  min-height: 48px;
  background: var(--dc-ipr-color, #8a4e4e);
  border-radius: 2px;
  box-shadow: 0 0 4px var(--dc-ipr-glow, rgba(138, 78, 78, 0.18));
}

.arch-midline-gap {
  width: var(--dc-ipr-contact-gap, 8px);
  min-width: var(--dc-ipr-contact-gap, 8px);
  max-width: var(--dc-ipr-contact-gap, 8px);
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  cursor: pointer;
  align-self: stretch;
  height: auto;
  min-height: 100%;
  border-radius: 3px;
  transition: background 0.12s;
}

.dental-arch--upper .arch-midline-gap,
.dental-arch--lower .arch-midline-gap {
  align-self: stretch;
  height: auto;
}

.arch-midline-gap:hover { background: rgba(245, 158, 11, 0.16); }
