/* =========================================================
   وحدة الأسنان — خريطة الفم، اللوحة الجانبية، مكبّر الأشعة
   ========================================================= */

.dental-wrap {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px; margin-bottom: 16px;
}

.dental-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-bottom: 10px;
}

/* ---------- مخطط الأسنان التشريحي ---------- */
.dental-chart {
  display: block; width: 100%; height: auto;
  user-select: none; -webkit-tap-highlight-color: transparent;
  touch-action: manipulation; overflow: visible;
}

/* الأشكال الأساسية */
.dental-chart .crown,
.dental-chart .root { fill: #fdfdfb; stroke: none; }
.dental-chart .crown-outline {
  fill: none; stroke: #64748b; stroke-width: 1.3;
  stroke-linejoin: round; vector-effect: non-scaling-stroke;
}
.dental-chart .root { stroke: #94a3b8; stroke-width: 1.1; vector-effect: non-scaling-stroke; }
.dental-chart .tnum { fill: #64748b; font-weight: 700; font-variant-numeric: tabular-nums; }
.dental-chart .side-lbl { fill: #cbd5e1; font-weight: 700; }

/* مناطق الأسطح */
.dental-chart .surf { stroke: #cbd5e1; stroke-width: .5; vector-effect: non-scaling-stroke; }
.dental-chart .surf.on { stroke: rgba(255,255,255,.55); stroke-width: .6; }
.dental-chart.is-interactive .surf { cursor: pointer; }
.dental-chart.is-interactive .surf:hover { fill: rgba(13,128,116,.3) !important; }
.dental-chart.is-readonly .surf { pointer-events: none; }

/* تفاعل السن */
.dental-chart .tooth { cursor: default; }
.dental-chart.is-interactive .tooth { cursor: pointer; }
.dental-chart.is-interactive .tooth:hover .crown-outline,
.dental-chart.is-interactive .tooth:focus .crown-outline { stroke: #0d8074; stroke-width: 2.4; }
.dental-chart .tooth:focus { outline: none; }
.dental-chart .tooth.selected .crown-outline { stroke: #0f172a; stroke-width: 2.8; }
.dental-chart .tooth.selected .root { stroke: #0f172a; stroke-width: 1.8; }

/* حالات كامل السن */
.dental-chart .st-missing { opacity: .3; }
.dental-chart .st-missing .crown-outline,
.dental-chart .st-missing .root {
  stroke-dasharray: 3 2.5; stroke: #94a3b8;
}
.dental-chart .st-missing .crown, .dental-chart .st-missing .root { fill: none; }

.dental-chart .st-extracted { opacity: .5; }
.dental-chart .ex-mark {
  stroke: #dc2626; stroke-width: 2.4; stroke-linecap: round;
  fill: none; vector-effect: non-scaling-stroke;
}

.dental-chart .st-crown .crown { fill: #fff7e6; }
.dental-chart .st-crown .crown-outline { stroke: #b45309; stroke-width: 2.6; }
.dental-chart .st-crown .root { fill: #fffbf0; stroke: #d9a441; }

.dental-chart .canal {
  stroke: #7c3aed; stroke-width: 2.6; stroke-linecap: round; vector-effect: non-scaling-stroke;
}
.dental-chart .st-rct .crown-outline { stroke: #6d28d9; }

.dental-chart .implant-body { fill: #0d8074; stroke: #0f665e; stroke-width: 1; }
.dental-chart .implant-thread {
  stroke: #ffffff; stroke-width: 1.2; opacity: .85; vector-effect: non-scaling-stroke;
}
.dental-chart .st-implant .crown-outline { stroke: #0f665e; stroke-width: 2.2; }

.dental-chart .bridge-link {
  stroke: #0891b2; stroke-width: 7; stroke-linecap: round; opacity: .8;
}
.dental-chart .st-bridge .crown-outline { stroke: #0e7490; stroke-width: 2.2; }

.dental-chart .gum { fill: #ec4899; opacity: .5; }
.dental-chart .pain-tint { fill: #f97316; opacity: .22; }

/* المؤشرات */
.dental-chart .dot-pain { fill: #f97316; stroke: #fff; stroke-width: 1.1; }
.dental-chart .dot-plan { fill: #facc15; stroke: #fff; stroke-width: 1.1; }


/* وسيلة الإيضاح */
.dental-legend {
  display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 10px;
  padding-top: 10px; border-top: 1px dashed var(--border);
}
.dl-item { display: inline-flex; align-items: center; gap: 5px; font-size: .76rem; color: var(--ink-600); }
.dl-item i {
  width: 13px; height: 13px; border-radius: 4px; border: 1.5px solid; display: inline-block;
}

/* اللوحة الجانبية */
.tooth-panel {
  border: 1px solid var(--teal-200); background: var(--teal-50);
  border-radius: var(--radius); padding: 14px; margin-top: 14px;
}
.tooth-panel.hide { display: none; }
.tooth-panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-bottom: 10px; padding-bottom: 8px; border-bottom: 1px solid var(--teal-200);
}
.tooth-badge {
  width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center;
  background: var(--teal-600); color: #fff; font-weight: 800; font-size: 1.1rem;
}
.surface-row { display: flex; flex-wrap: wrap; gap: 8px; }
.surface-row label {
  display: inline-flex; align-items: center; gap: 5px; font-size: .82rem;
  background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 5px 9px;
  cursor: pointer; font-weight: 600;
}
.surface-row input:checked + span { color: var(--teal-700); }

.pain-row { display: flex; align-items: center; gap: 10px; }
.pain-row input[type="range"] { flex: 1; accent-color: var(--teal-600); }
.pain-value {
  min-width: 42px; text-align: center; font-weight: 800; font-variant-numeric: tabular-nums;
  background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 3px 6px;
}

.status-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 6px; }
.status-grid label {
  display: flex; align-items: center; gap: 6px; padding: 7px 9px; border-radius: 8px;
  border: 1.5px solid var(--border); background: #fff; cursor: pointer; font-size: .82rem; font-weight: 700;
}
.status-grid label i { width: 13px; height: 13px; border-radius: 4px; border: 1.5px solid; }
.status-grid input { position: absolute; opacity: 0; pointer-events: none; }
.status-grid input:checked + i + span { color: var(--teal-800); }
.status-grid label:has(input:checked) { border-color: var(--teal-500); background: var(--teal-50); }

/* سجل السن */
.tooth-history { margin-top: 10px; max-height: 220px; overflow-y: auto; }
.th-item {
  border-inline-start: 3px solid var(--teal-300); padding: 5px 10px; margin-bottom: 6px;
  background: #fff; border-radius: 0 8px 8px 0; font-size: .82rem;
}
.th-item .th-date { color: var(--ink-500); font-size: .72rem; }

/* خطة العلاج */
.plan-row {
  display: flex; align-items: center; gap: 10px; padding: 9px 0;
  border-bottom: 1px dashed var(--border); flex-wrap: wrap;
}
.plan-row:last-child { border-bottom: 0; }
.plan-tooth {
  width: 38px; height: 38px; border-radius: 10px; flex: none; display: grid; place-items: center;
  background: var(--ink-100); font-weight: 800; font-variant-numeric: tabular-nums;
}
.plan-done { opacity: .55; }
.plan-done .plan-what { text-decoration: line-through; }

/* الجلسات */
.session-bar { display: flex; gap: 3px; margin-top: 5px; }
.session-bar i {
  height: 6px; flex: 1; border-radius: 3px; background: var(--ink-200); display: block;
}
.session-bar i.on { background: var(--teal-500); }

/* مكبّر صور الأشعة */
.xray-overlay {
  position: fixed; inset: 0; z-index: 300; background: rgba(2, 6, 23, .93);
  display: none; align-items: center; justify-content: center; touch-action: none;
}
.xray-overlay.open { display: flex; }
.xray-overlay img {
  max-width: none; transform-origin: center center; cursor: grab;
  will-change: transform; user-select: none; -webkit-user-drag: none;
}
.xray-overlay img:active { cursor: grabbing; }
.xray-bar {
  position: fixed; inset-block-end: 18px; inset-inline: 0; display: flex;
  gap: 8px; justify-content: center; z-index: 310;
}
.xray-bar button {
  background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.28);
  border-radius: 10px; padding: 9px 16px; font-family: inherit; font-size: 1rem;
  font-weight: 700; cursor: pointer; min-width: 48px;
}
.xray-bar button:hover { background: rgba(255,255,255,.26); }
.xray-hint {
  position: fixed; inset-block-start: 16px; inset-inline: 0; text-align: center;
  color: #cbd5e1; font-size: .8rem; z-index: 310; pointer-events: none;
}
.xray-zoomable { cursor: zoom-in; }

@media (max-width: 620px) {
  .status-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  .dental-legend { gap: 4px 8px; }
  .dl-item { font-size: .7rem; }
}
