.admin-page .tooth-chart {
  display: grid;
  gap: 16px;
  padding: clamp(12px, 3vw, 24px);
  border: 1px solid var(--admin-rule);
  border-radius: 16px;
  background: linear-gradient(150deg, #f5fbfd, #fcfefe 68%);
  color: var(--admin-navy);
  container: tooth-chart / inline-size;
}

.admin-page .tooth-chart [hidden] { display: none !important; }

.admin-page .tooth-chart-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 5px 12px;
}

.admin-page .tooth-chart h3,
.admin-page .tooth-chart h4,
.admin-page .tooth-chart p { margin: 0; }

.admin-page .tooth-chart-header h3 { font-size: 1.3rem; line-height: 1.2; }
.admin-page .tooth-chart-caption { grid-row: 2; }

.admin-page .tooth-chart-caption,
.admin-page .tooth-chart-empty,
.admin-page .tooth-chart-legend {
  color: var(--admin-copy);
  font-size: .82rem;
  line-height: 1.5;
}

.admin-page .tooth-chart-types {
  display: inline-flex;
  grid-column: 2;
  grid-row: 1 / 3;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--admin-rule);
  border-radius: 10px;
  background: #ecf5f8;
  justify-self: end;
}

.admin-page .tooth-chart-type {
  min-height: 36px;
  padding: 4px 9px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--admin-navy);
  cursor: pointer;
  font: inherit;
  font-size: .78rem;
  font-weight: 700;
}

.admin-page .tooth-chart-type[aria-pressed="true"] {
  background: var(--admin-blue);
  color: #fff;
}

.admin-page .tooth-chart-legend {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 5px;
}

.admin-page .tooth-chart-legend::before,
.admin-page .tooth-chart-tooth[data-recorded="true"]::after {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  color: var(--admin-blue);
  content: "";
}

.admin-page .tooth-chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  --tooth-columns: 8;
}

.admin-page .tooth-chart-grid[data-dentition="primary"] { --tooth-columns: 5; }

.admin-page .tooth-chart-quadrant {
  display: grid;
  gap: 8px;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--admin-rule);
  border-radius: 11px;
  background: #fff;
}

.admin-page .tooth-chart-region {
  color: var(--admin-copy);
  font-size: .78rem;
  font-weight: 700;
}

.admin-page .tooth-chart-teeth {
  display: grid;
  grid-template-columns: repeat(var(--tooth-columns), minmax(0, 1fr));
  gap: clamp(2px, .7cqi, 5px);
}

.admin-page .tooth-chart-tooth {
  position: relative;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 4px;
  min-width: 0;
  min-height: 55px;
  padding: 5px 0;
  border: 1px solid #e2edf1;
  border-radius: 7px;
  background: #f4f9fb;
  color: var(--admin-navy);
  cursor: pointer;
  font: inherit;
  font-size: .75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.admin-page .tooth-chart-tooth:hover { border-color: var(--admin-blue); }

.admin-page .tooth-chart-tooth[aria-pressed="true"] {
  border-color: var(--admin-blue);
  background: var(--admin-blue);
  color: #fff;
}

.admin-page .tooth-chart-tooth[data-recorded="true"]::after {
  position: absolute;
  inset: 3px 3px auto auto;
  width: 4px;
  height: 4px;
}

.admin-page .tooth-chart-tooth[data-recorded="true"][aria-pressed="true"]::after { color: #fff; }

.admin-page .tooth-chart-shape {
  display: block;
  position: relative;
  width: min(64%, 15px);
  height: 20px;
  transform: rotate(180deg);
  --tooth-shape: polygon(18% 5%, 76% 5%, 92% 15%, 94% 36%, 80% 57%, 67% 90%, 55% 97%, 42% 88%, 23% 51%, 5% 31%, 6% 16%);
}

.admin-page .tooth-chart-shape[data-shape="posterior"] {
  width: min(78%, 20px);
  --tooth-shape: polygon(12% 8%, 34% 3%, 52% 10%, 69% 3%, 86% 8%, 96% 22%, 92% 45%, 85% 57%, 80% 89%, 69% 96%, 60% 86%, 53% 64%, 46% 64%, 36% 87%, 25% 95%, 15% 85%, 12% 57%, 4% 37%, 3% 22%);
}

.admin-page .tooth-chart-quadrant:nth-child(n+3) .tooth-chart-shape { transform: none; }

.admin-page .tooth-chart-shape::before,
.admin-page .tooth-chart-shape::after {
  position: absolute;
  inset: 0;
  clip-path: var(--tooth-shape);
  background: currentColor;
  content: "";
}

.admin-page .tooth-chart-shape::after {
  inset: 2px;
  background: #f4f9fb;
}

.admin-page .tooth-chart-tooth[aria-pressed="true"] .tooth-chart-shape::after { background: var(--admin-blue); }

.admin-page .tooth-chart-type:focus-visible,
.admin-page .tooth-chart-tooth:focus-visible {
  outline: 2px solid var(--admin-blue);
  outline-offset: 2px;
  z-index: 1;
}

.admin-page .tooth-chart-empty { padding-block: 5px; }

.admin-page .tooth-chart-editor {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding-top: 13px;
  border-top: 1px solid var(--admin-rule);
}

.admin-page .tooth-chart-editor h4 { font-size: 1rem; }

.admin-page .tooth-chart-editor label {
  display: grid;
  gap: 5px;
  color: var(--admin-copy);
  font-size: .85rem;
  font-weight: 700;
}

.admin-page .tooth-chart-editor textarea {
  display: block;
  min-width: 0;
  width: 100%;
  max-width: 100%;
  resize: vertical;
}

.admin-page .tooth-chart-readonly { white-space: pre-wrap; overflow-wrap: anywhere; }
.admin-page .tooth-chart-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.admin-page .tooth-chart-actions .button { min-height: 38px; padding: 6px 12px; }
.admin-page .tooth-chart-message { font-size: .85rem; }
.admin-page .tooth-chart-message:empty { display: none; }
.admin-page .tooth-chart-message[data-state="error"] { color: #9a3434; }
.admin-page .tooth-chart-message[data-state="success"] { color: #17634f; }

@container tooth-chart (max-width: 560px) {
  .admin-page .tooth-chart-grid { grid-template-columns: minmax(0, 1fr); }
}

@container tooth-chart (max-width: 350px) {
  .admin-page .tooth-chart-header { grid-template-columns: minmax(0, 1fr); }
  .admin-page .tooth-chart-types { grid-column: 1; grid-row: 3; justify-self: start; }
  .admin-page .tooth-chart-quadrant { padding: 6px; }
}
