/* -------------------------------------------------------------------------
   The case builder: the dental chart, the teeth selected on it, and the lines
   they become. Loaded only by the two pages that build or edit a case.
   ------------------------------------------------------------------------- */

.dl-chart-shell { background: transparent; border: 0; padding: 0; }

.dl-chart-layout { display: block; }

.dl-chart-wrap {
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
}

.dl-chart {
  display: block;
  width: 100%;
  height: auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.dl-arch-rule {
  stroke: var(--dl-border);
  stroke-width: 1;
  stroke-dasharray: 2 6;
  stroke-linecap: round;
}

.dl-arch-label {
  font-family: inherit;
  font-size: 10px;
  font-weight: var(--dl-fw-semibold);
  letter-spacing: 1.4px;
  fill: var(--dl-muted2);
  text-transform: uppercase;
  user-select: none;
  transition: fill var(--dl-ease);
}

.dl-arch-btn { cursor: pointer; outline: none; }

.dl-arch-pill {
  fill: var(--dl-bg);
  stroke: var(--dl-border);
  stroke-width: 1;
  vector-effect: non-scaling-stroke;
  transition: fill var(--dl-ease), stroke var(--dl-ease);
}

.dl-tooth-g { cursor: pointer; outline: none; }

.dl-chart-plain .dl-tooth-g { cursor: default; }

.dl-tooth-shape {
  fill: var(--dl-bg);
  stroke: var(--dl-border-strong);
  stroke-width: 1.4;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  transition: fill var(--dl-ease), stroke var(--dl-ease);
}

.dl-tooth-detail {
  fill: none;
  stroke: var(--dl-border-strong);
  stroke-width: 1;
  stroke-linecap: round;
  stroke-linejoin: round;
  vector-effect: non-scaling-stroke;
  opacity: .6;
  transition: stroke var(--dl-ease);
}

.dl-tooth-num {
  font-family: inherit;
  font-weight: var(--dl-fw-semibold);
  fill: var(--dl-muted);
  user-select: none;
  pointer-events: none;
  transition: fill var(--dl-ease);
}

@media (hover: hover) {
  .dl-tooth-g:hover .dl-tooth-shape { fill: var(--dl-primary-light); stroke: var(--dl-primary); }
  .dl-tooth-g:hover .dl-tooth-num { fill: var(--dl-primary-dark); }
  .dl-arch-btn:hover .dl-arch-pill { fill: var(--dl-neutral-bg); stroke: var(--dl-border-strong); }
  .dl-arch-btn:hover .dl-arch-label { fill: var(--dl-ink); }
}

.dl-tooth-g:focus-visible .dl-tooth-shape { stroke: var(--dl-primary); stroke-width: 3; }

.dl-arch-btn:focus-visible .dl-arch-pill { stroke: var(--dl-primary); stroke-width: 2; }

.dl-arch-btn[data-selected="true"] .dl-arch-pill { fill: var(--dl-active-bg); stroke: var(--dl-primary); }
.dl-arch-btn[data-selected="true"] .dl-arch-label { fill: var(--dl-active-text); }

.dl-tooth-g[data-selected="true"] .dl-tooth-shape { fill: var(--dl-primary); stroke: var(--dl-primary-dark); }
.dl-tooth-g[data-selected="true"] .dl-tooth-detail { stroke: var(--dl-on-primary); opacity: .6; }
.dl-tooth-g[data-selected="true"] .dl-tooth-num { fill: var(--dl-on-primary); }

.dl-tooth-g[data-assigned="true"] .dl-tooth-shape { fill: var(--dl-success-text); stroke: var(--dl-success-strong); }
.dl-tooth-g[data-assigned="true"] .dl-tooth-detail { stroke: var(--dl-on-primary); opacity: .6; }
.dl-tooth-g[data-assigned="true"] .dl-tooth-num { fill: var(--dl-on-primary); }

.dl-chart-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: var(--dl-space-16);
  padding: var(--dl-space-8) 0 var(--dl-space-2);
}

.dl-legend-item {
  display: inline-flex;
  align-items: center;
  gap: var(--dl-space-8);
  font-size: var(--dl-fs-xs);
  font-weight: var(--dl-fw-semibold);
  color: var(--dl-muted2);
}

.dl-legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 3px;
  display: inline-block;
}

.dl-legend-pending { background: var(--dl-primary); border: 1px solid var(--dl-primary-dark); }
.dl-legend-added { background: var(--dl-success-text); border: 1px solid var(--dl-success-strong); }

.dl-teeth-panel {
  margin-top: var(--dl-space-20);
  display: flex;
  flex-direction: column;
  gap: var(--dl-space-16);
  min-width: 0;
}

.dl-builder {
  border: 1px solid var(--dl-border);
  border-radius: var(--dl-radius-md);
  background: var(--dl-surface);
  padding: var(--dl-space-12);
  display: flex;
  flex-direction: column;
  gap: var(--dl-space-12);
  min-width: 0;
}

.dl-builder-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--dl-space-12);
}

.dl-builder-title {
  font-size: var(--dl-fs-2xs);
  font-weight: var(--dl-fw-semibold);
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--dl-muted2);
}

.dl-chip-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--dl-space-8);
  min-height: 28px;
}

.dl-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--dl-space-2);
  padding-block: 3px;
  padding-inline: 9px var(--dl-space-4);
  border-radius: 7px;
  font-size: var(--dl-fs-sm);
  font-weight: var(--dl-fw-semibold);
  background: var(--dl-primary-light);
  color: var(--dl-primary-dark);
  border: 1px solid var(--dl-accent-line);
  unicode-bidi: isolate;
}

.dl-chip-assigned {
  background: var(--dl-success-bg);
  color: var(--dl-success-text);
  border-color: var(--dl-success-border);
}

.dl-chip-remove {
  font-family: inherit;
  font-size: var(--dl-fs-sm);
  line-height: 1;
  width: var(--dl-space-20);
  height: var(--dl-space-20);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: none;
  border-radius: 5px;
  background: transparent;
  color: inherit;
  opacity: .6;
  cursor: pointer;
}

.dl-chip-remove svg { display: block; width: 9px; height: 9px; }
.dl-chip-remove:hover { opacity: 1; background: var(--dl-neutral-bg); }

.dl-chip-hint { font-size: var(--dl-fs-xs); color: var(--dl-muted2); }

.dl-builder-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px auto;
  gap: var(--dl-space-8);
  align-items: center;
}

.dl-builder-fields .dl-btn,
.dl-qty-add-row .dl-btn {
  height: var(--dl-field-h);
  padding: 0 var(--dl-space-16);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.dl-group-list,
.dl-qty-list {
  display: flex;
  flex-direction: column;
  gap: var(--dl-space-12);
  min-width: 0;
}

.dl-group-list:empty,
.dl-qty-list:empty { display: none; }

.dl-group {
  border: 1px solid var(--dl-border);
  border-radius: var(--dl-radius-sm);
  background: var(--dl-bg);
  padding: var(--dl-space-12) var(--dl-space-12);
  display: flex;
  flex-direction: column;
  gap: 9px;
  min-width: 0;
}

.dl-group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--dl-space-12);
}

.dl-group-count {
  font-size: var(--dl-fs-2xs);
  font-weight: var(--dl-fw-semibold);
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--dl-muted2);
}

.dl-group-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  gap: var(--dl-space-8);
  align-items: center;
}

.dl-remove-tooth {
  width: 38px;
  height: 38px;
  border-radius: var(--dl-radius-sm);
  border: 1px solid var(--dl-border);
  background: var(--dl-bg);
  cursor: pointer;
  color: var(--dl-muted2);
  font-size: var(--dl-fs-lg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
  transition: background var(--dl-ease), color var(--dl-ease), border-color var(--dl-ease);
}

.dl-remove-tooth:hover {
  background: var(--dl-danger-bg);
  color: var(--dl-danger);
  border-color: var(--dl-danger-border);
}

.dl-remove-tooth svg { display: block; width: 12px; height: 12px; }
.dl-remove-tooth-sm { width: 30px; height: 30px; }

.dl-qty-builder {
  border: 1px solid var(--dl-border);
  border-radius: var(--dl-radius-md);
  background: var(--dl-surface);
  padding: var(--dl-space-12);
  margin-bottom: var(--dl-space-16);
  min-width: 0;
}

.dl-qty-add-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px auto;
  gap: var(--dl-space-12);
  align-items: end;
}

.dl-qty-field { min-width: 0; }
.dl-qty-add-row .dl-btn { white-space: nowrap; }

.dl-qty-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px var(--dl-field-h);
  gap: var(--dl-space-8);
  align-items: center;
  border: 1px solid var(--dl-border);
  border-radius: var(--dl-radius-sm);
  background: var(--dl-bg);
  padding: var(--dl-space-8) var(--dl-space-12);
  width: 100%;
}

.dl-qty-row .dl-remove-tooth { width: var(--dl-field-h); height: var(--dl-field-h); }

.dl-qty-name {
  font-weight: var(--dl-fw-semibold);
  font-size: var(--dl-fs-md);
  color: var(--dl-ink);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (min-width: 769px) {
  .dl-chart-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .dl-chart-col { padding-inline-end: var(--dl-space-20); }
  .dl-chart-sticky { position: sticky; top: var(--dl-space-12); }
  .dl-teeth-col {
    padding-inline-start: var(--dl-space-20);
    border-inline-start: 1px solid var(--dl-border);
    min-width: 0;
  }
  .dl-chart-wrap { max-width: 310px; }
  .dl-teeth-col .dl-teeth-panel { margin-top: 0; }
}

@media (max-width: 600px) {
  .dl-builder-fields { grid-template-columns: minmax(0, 1fr) auto; }
  .dl-builder-fields .dl-select { grid-column: 1 / 3; }
  .dl-group-fields { grid-template-columns: minmax(0, 1fr); }
  .dl-authwidget .dl-remove-tooth-sm { width: 34px; height: 34px; min-height: 34px; }
}

@media (max-width: 430px) {
  .dl-qty-builder { padding: var(--dl-space-12); }
  .dl-qty-add-row {
    grid-template-columns: minmax(0, 1fr) 72px auto;
    gap: var(--dl-space-8);
  }
  .dl-qty-row {
    grid-template-columns: minmax(0, 1fr) 72px var(--dl-field-h);
    gap: var(--dl-space-8);
    padding: var(--dl-space-8);
  }
  .dl-builder-fields .dl-btn,
  .dl-qty-add-row .dl-btn { padding: 0 11px; }
}

@media (prefers-reduced-motion: reduce) {
  .dl-tooth-shape,
  .dl-tooth-detail,
  .dl-tooth-num { transition: none; }
}
