/* Dental Carmen · expediente clínico y odontograma.
   Layout: buscador fijo a la izquierda (tablet/escritorio), expediente a la derecha; en celular todo en una columna. */
:root {
  --dc-bg: #F8FAFC;
  --dc-surface: #FFFFFF;
  --dc-ink: #0F172A;
  --dc-ink-2: #475569;
  --dc-ink-3: #94A3B8;
  --dc-line: #E2E8F0;
  --dc-line-2: #CBD5E1;
  --dc-accent: #0284C7;
  --dc-accent-soft: #E0F2FE;
  --dc-ok: #10B981;
  --dc-on-accent: #FFFFFF;
  --dc-danger: #DC2626;
  --dc-tooth: #FFFFFF;
  --dc-tooth-line: #94A3B8;
  --dc-root: #F1F5F9;
  /* Estados clínicos: rojo = pendiente de tratar, azul = tratamiento hecho (convención de odontograma). */
  --dc-sano: #10B981;
  --dc-caries: #EF4444;
  --dc-resina: #0284C7;
  --dc-corona: #F59E0B;
  --dc-endodoncia: #8B5CF6;
  --dc-extraccion: #B91C1C;
  --dc-font: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --dc-font-display: 'Plus Jakarta Sans', 'Inter', system-ui, sans-serif;
  --dc-radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --dc-bg: #0B1220; --dc-surface: #111A2B; --dc-ink: #E2E8F0; --dc-ink-2: #A3B1C6; --dc-ink-3: #64748B;
    --dc-line: #1E293B; --dc-line-2: #334155; --dc-accent: #38BDF8; --dc-accent-soft: #0C2A3F; --dc-on-accent: #04121F;
    --dc-tooth: #1A2538; --dc-tooth-line: #64748B; --dc-root: #152033;
    --dc-resina: #38BDF8; --dc-caries: #F87171; --dc-extraccion: #EF4444; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --dc-bg: #0B1220; --dc-surface: #111A2B; --dc-ink: #E2E8F0; --dc-ink-2: #A3B1C6; --dc-ink-3: #64748B;
  --dc-line: #1E293B; --dc-line-2: #334155; --dc-accent: #38BDF8; --dc-accent-soft: #0C2A3F; --dc-on-accent: #04121F;
  --dc-tooth: #1A2538; --dc-tooth-line: #64748B; --dc-root: #152033;
  --dc-resina: #38BDF8; --dc-caries: #F87171; --dc-extraccion: #EF4444; color-scheme: dark;
}

.dc-exp {
  display: grid; grid-template-columns: minmax(240px, 300px) minmax(0, 1fr); gap: 20px; align-items: start;
  font-family: var(--dc-font); color: var(--dc-ink); font-size: 14px; line-height: 1.5;
}
.dc-exp *, .dc-exp *::before, .dc-exp *::after { box-sizing: border-box; }
.dc-exp [hidden] { display: none !important; }
.dc-exp h2, .dc-exp h3 { font-family: var(--dc-font-display); margin: 0; text-wrap: balance; }
.dc-exp kbd {
  font: 500 11px/1 var(--dc-font); color: var(--dc-ink-3); border: 1px solid var(--dc-line-2);
  border-radius: 5px; padding: 2px 5px; background: var(--dc-surface);
}
.dc-label { display: block; font-size: 12px; font-weight: 600; color: var(--dc-ink-2); letter-spacing: .02em; margin-bottom: 6px; }
.dc-meta, .dc-muted { color: var(--dc-ink-3); font-size: 12px; }
.dc-sub { color: var(--dc-ink-2); margin: 2px 0 0; }
.dc-empty { color: var(--dc-ink-3); margin: 0; }

/* ---- Buscador ---- */
.dc-search { position: sticky; top: 16px; display: flex; flex-direction: column; gap: 6px; max-height: calc(100vh - 32px); min-width: 0; }
.dc-search-box {
  display: flex; align-items: center; gap: 8px; background: var(--dc-surface); border: 1px solid var(--dc-line-2);
  border-radius: 12px; padding: 0 10px; transition: border-color .15s, box-shadow .15s;
}
.dc-search-box:focus-within { border-color: var(--dc-accent); box-shadow: 0 0 0 3px var(--dc-accent-soft); }
.dc-search-box svg { width: 18px; height: 18px; fill: none; stroke: var(--dc-ink-3); stroke-width: 2; stroke-linecap: round; flex: none; }
.dc-search-box input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; font: inherit; font-size: 15px; padding: 11px 0; color: var(--dc-ink); }
.dc-results { list-style: none; margin: 0; padding: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.dc-results li { padding: 9px 10px; border-radius: 10px; cursor: pointer; display: flex; flex-direction: column; min-width: 0; }
.dc-results li:hover { background: var(--dc-surface); }
.dc-results li[aria-selected="true"] { background: var(--dc-surface); box-shadow: inset 0 0 0 1px var(--dc-line-2); }
.dc-results li.is-open { background: var(--dc-accent-soft); box-shadow: none; }
.dc-r-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dc-r-meta { font-size: 12px; color: var(--dc-ink-2); font-variant-numeric: tabular-nums; }

/* ---- Expediente ---- */
.dc-record { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.dc-record > *, .dc-chart-card > *, .dc-columns > * { min-width: 0; max-width: 100%; }
.dc-card { background: var(--dc-surface); border: 1px solid var(--dc-line); border-radius: var(--dc-radius); padding: 16px; min-width: 0; }
.dc-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.dc-card-head h3 { font-size: 15px; }

.dc-patient { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; padding: 4px 0; }
.dc-avatar {
  width: 48px; height: 48px; border-radius: 50%; background: var(--dc-accent-soft); color: var(--dc-accent);
  display: grid; place-items: center; font: 700 16px var(--dc-font-display); flex: none;
}
.dc-patient-main { flex: 1; min-width: 200px; }
.dc-patient-main h2 { font-size: 22px; letter-spacing: -.01em; }
.dc-patient-chips { display: flex; gap: 6px; flex-wrap: wrap; }

.dc-pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; padding: 3px 10px;
  border-radius: 999px; background: var(--dc-bg); color: var(--dc-ink-2); border: 1px solid var(--dc-line); white-space: nowrap;
}
.dc-pill.st-sano { color: var(--dc-sano); }
#dc-pending-count { color: var(--dc-corona); border-color: currentColor; background: transparent; }

.dc-swatch { width: 10px; height: 10px; border-radius: 3px; flex: none; display: inline-block; background: var(--dc-line-2); }
.dc-swatch.st-sano { background: var(--dc-sano); }
.dc-swatch.st-caries { background: var(--dc-caries); }
.dc-swatch.st-resina { background: var(--dc-resina); }
.dc-swatch.st-corona { background: var(--dc-corona); }
.dc-swatch.st-endodoncia { background: var(--dc-endodoncia); }
.dc-swatch.st-extraccion { background: transparent; border: 2px solid var(--dc-extraccion); border-radius: 2px; position: relative; }

/* ---- Barra de herramientas ---- */
.dc-toolbar { display: flex; flex-wrap: wrap; gap: 10px; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.dc-tools { display: flex; flex-wrap: wrap; gap: 6px; }
.dc-toolbar-end { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.dc-tool {
  display: inline-flex; align-items: center; gap: 7px; min-height: 38px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--dc-line-2); background: var(--dc-surface); color: var(--dc-ink); font: 500 13px var(--dc-font); cursor: pointer;
}
.dc-tool kbd { margin-left: 2px; }
.dc-tool[aria-checked="true"] { border-color: var(--dc-accent); background: var(--dc-accent-soft); box-shadow: inset 0 0 0 1px var(--dc-accent); font-weight: 600; }
.dc-seg { display: inline-flex; border: 1px solid var(--dc-line-2); border-radius: 10px; padding: 2px; background: var(--dc-bg); }
.dc-seg button { border: 0; background: transparent; padding: 7px 12px; border-radius: 8px; font: 500 13px var(--dc-font); color: var(--dc-ink-2); cursor: pointer; }
.dc-seg button[aria-checked="true"] { background: var(--dc-surface); color: var(--dc-ink); box-shadow: 0 1px 2px rgb(15 23 42 / .12); font-weight: 600; }

.dc-btn {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 16px; border-radius: 10px;
  font: 600 14px var(--dc-font); cursor: pointer; border: 1px solid transparent;
}
.dc-btn:disabled { opacity: .45; cursor: default; }
.dc-btn-primary { background: var(--dc-accent); color: var(--dc-on-accent); }
.dc-btn-primary kbd { color: inherit; opacity: .8; border-color: currentColor; background: transparent; }
.dc-btn-ghost { background: transparent; color: var(--dc-ink-2); border-color: var(--dc-line-2); }
.dc-btn-danger { background: var(--dc-danger); color: #fff; }
.dc-exp button:focus-visible, .dc-exp textarea:focus-visible { outline: 2px solid var(--dc-accent); outline-offset: 2px; }

/* ---- Odontograma ---- */
.dc-chart-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 4px; }
.dc-odontogram { display: block; width: 100%; min-width: 640px; max-width: 980px; margin: 0 auto; height: auto; user-select: none; }
.dc-odontogram .midline { stroke: var(--dc-line-2); stroke-width: 1; stroke-dasharray: 3 4; }
.tooth { cursor: pointer; }
.tooth .hit { fill: transparent; }
.tooth .root { fill: var(--dc-root); stroke: var(--dc-tooth-line); stroke-width: 1; }
.tooth .crown { fill: var(--dc-tooth); stroke: var(--dc-tooth-line); stroke-width: 1.2; }
.tooth .silhouette:hover .crown, .tooth .silhouette:hover .root { stroke: var(--dc-accent); }
.tooth.has-corona .crown { fill: var(--dc-corona); stroke: var(--dc-corona); }
.tooth.has-endodoncia .root { fill: var(--dc-endodoncia); stroke: var(--dc-endodoncia); }
.tooth.has-extraccion .silhouette, .tooth.has-extraccion .faces { opacity: .35; }
.tooth .x-mark { stroke: var(--dc-extraccion); stroke-width: 3.5; stroke-linecap: round; fill: none; pointer-events: none; }
.tooth .face { fill: var(--dc-tooth); stroke: var(--dc-tooth-line); stroke-width: .8; transition: fill .12s; }
.tooth .face:hover { fill: var(--dc-accent-soft); }
.tooth .face.st-caries { fill: var(--dc-caries); }
.tooth .face.st-resina { fill: var(--dc-resina); }
.tooth .face.st-corona, .tooth .face.st-endodoncia, .tooth .face.st-extraccion { fill: var(--dc-tooth); }
.tooth .box-outline { fill: none; stroke: var(--dc-tooth-line); stroke-width: 1.2; pointer-events: none; }
.tooth.has-corona .box-outline { stroke: var(--dc-corona); stroke-width: 3; }
.tooth .num { font: 600 12px var(--dc-font); fill: var(--dc-ink-2); text-anchor: middle; font-variant-numeric: tabular-nums; }
.tooth .num:hover { fill: var(--dc-accent); text-decoration: underline; }
.tooth.is-selected .num { fill: var(--dc-accent); font-weight: 700; }
.tooth.is-selected .box-outline { stroke: var(--dc-accent); stroke-width: 2.5; }
.tooth.is-pending .num { fill: var(--dc-corona); }
.dc-hint { margin: 8px 0 0; font-size: 12px; color: var(--dc-ink-3); }

/* ---- Detalle de pieza y sesión ---- */
.dc-columns { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.2fr); gap: 16px; }
.dc-detail-body { display: flex; gap: 16px; align-items: center; margin: 10px 0 12px; flex-wrap: wrap; }
.dc-tooth-big { width: 132px; height: 132px; flex: none; }
.dc-tooth-big .face-letter { font: 700 5px var(--dc-font); fill: var(--dc-ink-3); text-anchor: middle; dominant-baseline: middle; pointer-events: none; }
.dc-tooth-big .face.st-caries + .face-letter, .dc-tooth-big .face.st-resina + .face-letter { fill: #fff; }
.dc-faces { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; flex: 1; min-width: 170px; }
.dc-faces li { display: grid; grid-template-columns: 22px 1fr auto; gap: 8px; align-items: center; font-size: 13px; }
.dc-face-code { font-weight: 700; color: var(--dc-ink-3); }
.dc-face-st { font-weight: 600; color: var(--dc-sano); font-size: 12px; }
.dc-face-st.st-caries { color: var(--dc-caries); }
.dc-face-st.st-resina { color: var(--dc-resina); }
.dc-whole { border-top: 1px solid var(--dc-line); padding-top: 12px; }

.dc-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.dc-chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 32px; padding: 0 11px; border-radius: 999px;
  border: 1px solid var(--dc-line-2); background: var(--dc-surface); color: var(--dc-ink); font: 500 12.5px var(--dc-font); cursor: pointer;
}
.dc-chip:hover { border-color: var(--dc-accent); }
.dc-chip[aria-pressed="true"] { background: var(--dc-accent-soft); border-color: var(--dc-accent); font-weight: 600; }
.dc-session .dc-chips { margin-bottom: 12px; }
.dc-session textarea {
  width: 100%; resize: vertical; min-height: 92px; border: 1px solid var(--dc-line-2); border-radius: 10px; padding: 10px 12px;
  font: inherit; color: var(--dc-ink); background: var(--dc-surface);
}
.dc-changes { list-style: none; margin: 10px 0 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.dc-changes li { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; background: var(--dc-bg); border-radius: 8px; padding: 4px 9px; font-variant-numeric: tabular-nums; }
.dc-changes .dc-muted { font-weight: 400; }
.dc-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.dc-error { color: var(--dc-danger); font-size: 13px; margin: 10px 0 0; }
.dc-banner {
  margin-top: 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 10px 12px;
  border-radius: 10px; background: var(--dc-bg); border: 1px solid var(--dc-corona); font-size: 13px;
}
.dc-banner span { flex: 1 1 200px; }

/* ---- Historial ---- */
.dc-timeline { list-style: none; margin: 4px 0 0; padding: 0; }
.dc-timeline > li { display: grid; grid-template-columns: 104px minmax(0, 1fr); gap: 14px; padding: 12px 0; border-top: 1px solid var(--dc-line); }
.dc-timeline > li:first-child { border-top: 0; }
.dc-timeline > li.dc-empty { display: block; }
.dc-timeline time { font-weight: 600; font-size: 13px; color: var(--dc-ink-2); font-variant-numeric: tabular-nums; }
.dc-tl-body p { margin: 0 0 6px; max-width: 70ch; }
.dc-tl-changes { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.dc-tl-changes li { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dc-ink-2); background: var(--dc-bg); padding: 2px 8px; border-radius: 6px; font-variant-numeric: tabular-nums; }
.dc-timeline > li.is-new { animation: dc-flash 1.6s ease-out; }
@keyframes dc-flash { from { background: var(--dc-accent-soft); } to { background: transparent; } }
.dc-more { margin-top: 8px; }

@media (prefers-reduced-motion: reduce) { .dc-timeline > li.is-new { animation: none; } .tooth .face { transition: none; } }

/* Tablet vertical y celular */
@media (max-width: 900px) {
  .dc-exp { grid-template-columns: minmax(0, 1fr); }
  .dc-search { position: static; max-height: none; }
  .dc-results { max-height: 260px; }
  .dc-columns { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 520px) {
  .dc-timeline > li { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .dc-tool kbd, .dc-btn kbd { display: none; }
}
