/* Ficha del paciente, versión B (2026-10-26): columna lateral por grupos con íconos de colores, botón grande «Volver a pacientes»,
   cifras arriba, odontograma + (antecedentes, próximas citas, pendientes), planificación + últimos archivos, e historial compacto.
   Solo escritorio ancho. Mismos botones y funciones de siempre: solo cambia el orden y el aspecto. Para volver atrás: quitar el <link> y el <script> de ficha-b en index.html. */
@media (min-width: 835px) {
  #patientDetail.pd-has-rail.fb { display: grid !important; grid-template-columns: minmax(0, 7fr) minmax(0, 5fr); gap: 14px; align-items: stretch; padding: 18px 18px 18px 284px; background: #EFF1F6; }
  #patientDetail.fb > .pd-rail { width: 248px; left: 18px; }
  #patientDetail.fb > .pd-card, #patientDetail.fb > .pd-section { grid-column: 1 / -1; margin: 0 !important; width: auto !important; }
  #patientDetail.fb > .pd-section[data-sec="odonto"] { grid-column: 1; grid-row: span 3; order: 1; }
  #patientDetail.fb > .pd-card:has(> .pd-head) { order: 0; }
  #patientDetail.fb > .pd-section[data-sec="salud"] { order: 2; } #patientDetail.fb > .pd-section[data-sec="citas"] { order: 3; } #patientDetail.fb > .pd-section[data-sec="pend"] { order: 4; }
  #patientDetail.fb > .pd-section[data-sec="plan"] { order: 5; } #patientDetail.fb > .pd-section[data-sec="arch"] { order: 6; }
  #patientDetail.fb > .pd-section[data-sec="hist"] { order: 7; } #patientDetail.fb > .pd-section[data-sec="rec"] { order: 8; } #patientDetail.fb > .pd-section[data-sec="linea"], #patientDetail.fb > .pd-section[data-sec="otro"] { order: 9; }
  #patientDetail.fb > .pd-section .pd-empty-line { margin: 0; padding: 4px 14px 12px; }
  #patientDetail.fb > .pd-section[data-sec="salud"], #patientDetail.fb > .pd-section[data-sec="citas"], #patientDetail.fb > .pd-section[data-sec="pend"] { grid-column: 2; }
  #patientDetail.fb > .pd-section[data-sec="plan"] { grid-column: 1; }
  #patientDetail.fb > .pd-section[data-sec="arch"] { grid-column: 2; }
  #patientDetail.fb > .pd-section[data-sec="rx"], #patientDetail.fb > .pd-section[data-sec="fotos"], #patientDetail.fb > .pd-section[data-sec="esp"] { display: none; }
  /* si no hay planificación, los archivos ocupan la fila entera */
  #patientDetail.fb > .pd-section[data-sec="arch"]:first-of-type { grid-column: 2; }

  /* ---- encabezado: nombre grande y cifras en una franja ---- */
  #patientDetail.fb > .pd-card:has(> .pd-head) { background: transparent !important; box-shadow: none !important; padding: 0 !important; display: grid !important; gap: 14px; }
  #patientDetail.fb .pd-head { padding: 0 !important; background: transparent !important; border: 0 !important; }
  #patientDetail.fb .pd-title h3 { font-size: 1.9rem !important; font-weight: 800; letter-spacing: -.02em; color: #0F172A; }
  #patientDetail.fb > .pd-card:has(> .pd-head) > .pd-stats { display: grid !important; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 0; margin: 0; padding: 0; background: #fff; border-radius: 18px; box-shadow: 0 0 0 1px rgba(15, 23, 42, .06) !important; overflow: hidden; }
  #patientDetail.fb .pd-stat { display: flex; flex-direction: column-reverse; align-items: flex-start; justify-content: flex-end; gap: 2px; padding: 12px 16px; border: 0; border-right: 1px solid rgba(15, 23, 42, .08); border-radius: 0; background: transparent; box-shadow: none; min-width: 0; }
  #patientDetail.fb .pd-stat:last-child { border-right: 0; }
  #patientDetail.fb .pd-stat .pd-stat-ic { display: none; }
  #patientDetail.fb .pd-stat span { font-size: .8rem; font-weight: 600; color: var(--muted); }
  #patientDetail.fb .pd-stat b { font-size: 1.3rem; font-weight: 800; letter-spacing: -.01em; }
  #patientDetail.fb .pd-stat-saldo { order: -3; }
  #patientDetail.fb .pd-stat:nth-child(2) { order: -2; }
  #patientDetail.fb .pd-stat:nth-child(3) { order: -1; }

  /* ---- columna lateral ---- */
  #patientDetail.fb .pd-rail-in { gap: 12px; }
  #patientDetail.fb .pd-rail-back { align-self: stretch; width: 100%; margin: 0; min-height: 50px; padding: 0 14px; gap: 6px; font-size: 1rem; font-weight: 700; color: var(--ink); background: #fff; border: 1px solid rgba(15, 23, 42, .1); border-radius: 12px; }
  #patientDetail.fb .pd-rail-back svg { width: 22px; height: 22px; color: var(--blue, #0284C7); }
  #patientDetail.fb .pd-rail-cta { height: 50px !important; min-height: 50px; margin: 0; justify-content: center; border-radius: 12px; background: var(--blue, #0284C7); color: #fff; font-size: 1rem; font-weight: 700; box-shadow: 0 4px 12px rgba(2, 132, 199, .28); }
  #patientDetail.fb .pd-rail-cta:hover { background: #0275b3; }
  #patientDetail.fb .pd-rail-cta svg { width: 20px; height: 20px; }
  #patientDetail.fb .pd-rail-grp { margin: 2px 12px -8px; font-size: .72rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
  #patientDetail.fb .pd-rail-nav { background: #fff; border: 1px solid rgba(15, 23, 42, .08); border-radius: 18px; padding: 6px; gap: 0; }
  #patientDetail.fb .pd-rail-nav.pd-rail-danger { background: transparent; border: 0; }
  #patientDetail.fb .pd-rail-item { min-height: 46px; padding: 5px 8px; border-radius: 12px; font-size: .95rem; gap: 10px; }
  #patientDetail.fb .pd-rail-item > svg:first-child { width: 30px !important; height: 30px !important; padding: 6px; border-radius: 9px; background: color-mix(in srgb, var(--c, #64748B) 14%, transparent); color: var(--c, #64748B); }
  #patientDetail.fb .pd-rail-item span { font-weight: 600; overflow: visible; text-overflow: clip; font-size: .86rem; letter-spacing: -.01em; }
  #patientDetail.fb .pd-rail-item em { background: #E9EDF4; border-radius: 99px; padding: 1px 8px; font-weight: 700; font-size: .75rem; }
  #patientDetail.fb .pd-rail-item::after { content: ""; flex: none; width: 7px; height: 7px; margin: 0 4px 0 2px; border-right: 2px solid #B6BFCC; border-top: 2px solid #B6BFCC; transform: rotate(45deg); }
  #patientDetail.fb .pd-rail-danger .pd-rail-item { justify-content: center; color: #DC2626; font-weight: 700; }
  #patientDetail.fb .pd-rail-danger .pd-rail-item::after { display: none; }
  #patientDetail.fb .pd-rail-danger .pd-rail-item > svg:first-child { background: transparent; color: #DC2626; padding: 4px; width: 26px !important; height: 26px !important; }

  /* ---- historial: detalle y método de pago bajo cada fila (columnas ocultas) ---- */
  #patientDetail.fb .pd-table .fb-hide { display: none !important; }
  #patientDetail.fb .pd-table .fb-dt { display: block; margin-top: 2px; font-size: .78rem; font-weight: 500; color: var(--muted); white-space: normal; }
  #patientDetail.fb .pd-table th, #patientDetail.fb .pd-table td { white-space: nowrap; }
  #patientDetail.fb .pd-table td:nth-child(3) { white-space: normal; min-width: 170px; }
  #patientDetail.fb .pd-table td .small { white-space: nowrap; }

  /* ---- tarjeta «Últimos archivos» ---- */
  .fb-arch .fb-ths { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
  .fb-th { display: flex; flex-direction: column; gap: 3px; text-align: left; border: 0; background: transparent; padding: 0; color: var(--ink); min-width: 0; cursor: pointer; }
  .fb-th .im { position: relative; display: block; width: 100%; aspect-ratio: 1 / 1; border-radius: 14px; overflow: hidden; border: 1px solid rgba(15, 23, 42, .1); background: #F1F5F9; }
  .fb-th .im img { width: 100%; height: 100%; object-fit: cover; display: block; }
  .fb-th .im.doc { display: grid; place-items: center; color: #64748B; }
  .fb-th .im.doc svg { width: 30px; height: 30px; }
  .fb-th em { position: absolute; left: 6px; top: 6px; font-style: normal; font-size: .68rem; font-weight: 800; color: #fff; border-radius: 99px; padding: 1px 7px; }
  .fb-th small { display: block; max-width: 100%; font-size: .78rem; font-weight: 600; line-height: 1.25; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .fb-th small.f { color: var(--muted); font-weight: 500; }
  .fb-arch-foot { display: flex; gap: 8px; margin-top: 10px; }
  .fb-arch-foot button { flex: 1; min-height: 40px; justify-content: center; }
  .fb-arch .pd-empty-line { margin: 4px 0 10px; }
}

/* ---- tipografía y color como en la maqueta (tamaños en px: el resto de la app usa rem y se ve más grande) ---- */
@media (min-width: 835px) {
  #patientDetail.fb { color: #0F172A; --fb-mut: #5A6580; --fb-line: rgba(15, 23, 42, .08); }
  #patientDetail.fb > .pd-card, #patientDetail.fb > .pd-section { border-radius: 18px !important; box-shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 0 0 1px var(--fb-line) !important; }
  #patientDetail.fb > .pd-section { padding: 16px !important; }
  #patientDetail.fb > .pd-section .pd-sec-head { margin: 0 0 12px; padding: 0; gap: 10px; }
  #patientDetail.fb .pd-sec-head h4 { font-size: 17px; font-weight: 800; letter-spacing: -.01em; color: #0F172A; gap: 10px; }
  #patientDetail.fb .pd-sec-head .pd-ic { width: 34px; height: 34px; border-radius: 10px; }
  #patientDetail.fb .pd-sec-head .pd-ic svg { width: 19px; height: 19px; }
  #patientDetail.fb .pd-sec-head .pd-count { font-size: 15px; font-weight: 700; color: var(--fb-mut); background: none; }
  #patientDetail.fb .pd-sec-actions button, #patientDetail.fb .pd-sec-head > button, #patientDetail.fb .pd-odo-open { font-size: 14.5px; font-weight: 700; color: var(--blue, #0284C7); background: none !important; border: 0 !important; box-shadow: none !important; min-height: 36px; padding: 0 6px; }
  #patientDetail.fb .pd-sec-actions button svg { display: none; }
  #patientDetail.fb .pd-note, #patientDetail.fb .pd-empty-line, #patientDetail.fb .pd-dl dd, #patientDetail.fb .pd-dl dt { font-size: 14.5px; line-height: 1.35; }
  #patientDetail.fb .pd-dl dt { color: var(--fb-mut); font-weight: 600; }
  #patientDetail.fb .pd-empty-line, #patientDetail.fb .pd-note { color: var(--fb-mut); }
  #patientDetail.fb .pd-title h3 { font-size: 30px !important; font-weight: 800; line-height: 1.1; }
  #patientDetail.fb .pd-title .pd-sub { font-size: 14.5px; color: var(--fb-mut); }
  #patientDetail.fb .pd-contact span { font-size: 14.5px; color: var(--fb-mut); }
  #patientDetail.fb .pd-alerts *, #patientDetail.fb .pd-nameline > span, #patientDetail.fb .pd-nameline > div > * { font-size: 13.5px; font-weight: 700; text-transform: none; letter-spacing: 0; }
  #patientDetail.fb .pd-stat span { font-size: 13px; font-weight: 600; }
  #patientDetail.fb .pd-stat b { font-size: 21px; font-weight: 800; }
  /* iconos de color por tarjeta */
  #patientDetail.fb [data-sec="odonto"] .pd-ic, #patientDetail.fb [data-sec="hist"] .pd-ic { background: #0E9F9A1F; color: #0E9F9A; }
  #patientDetail.fb [data-sec="plan"] .pd-ic { background: #7C5CFC1F; color: #7C5CFC; }
  #patientDetail.fb [data-sec="salud"] .pd-ic { background: #FDECEC; color: #B42323; }
  #patientDetail.fb [data-sec="citas"] .pd-ic { background: #0284C71F; color: #0284C7; }
  #patientDetail.fb [data-sec="pend"] .pd-ic { background: #FFF4D6; color: #B45309; }
  #patientDetail.fb [data-sec="arch"] .pd-ic { background: #0891B21F; color: #0891B2; }
  /* tabla del historial */
  #patientDetail.fb .pd-table { font-size: 14.5px; }
  #patientDetail.fb .pd-table th { font-size: 12.5px; font-weight: 700; letter-spacing: .04em; color: var(--fb-mut); background: #F1F5F9; padding: 9px 10px; }
  #patientDetail.fb .pd-table td { font-size: 14.5px; padding: 10px; border-bottom: 1px solid var(--fb-line); color: #0F172A; }
  #patientDetail.fb .pd-table td b, #patientDetail.fb .pd-table td strong { font-weight: 700; }
  /* columna lateral */
  #patientDetail.fb .pd-rail-item span { font-size: 15px !important; letter-spacing: 0; }
  #patientDetail.fb .pd-rail-grp { font-size: 12px; color: var(--fb-mut); }
  #patientDetail.fb .pd-rail-back, #patientDetail.fb .pd-rail-cta { font-size: 16px; }
  #patientDetail.fb .pd-rail-item em { font-size: 12.5px; color: var(--fb-mut); }
  #patientDetail.fb .pd-rail-danger .pd-rail-item span { font-size: 14.5px !important; }
  /* últimos archivos */
  .fb-th small { font-size: 12.5px; }
  .fb-arch-foot button { font-size: 14.5px; font-weight: 700; }
}

/* ---- refuerzo: la ficha antigua fuerza algunos valores con !important ---- */
@media (min-width: 835px) {
  #patientDetail.fb > .pd-section > .pd-sec-head { padding: 0 !important; margin: 0 0 12px !important; min-height: 36px; background: transparent !important; }
  #patientDetail.fb > .pd-section > .pd-sec-head h4 { color: #0F172A !important; font-size: 17px !important; font-weight: 800 !important; }
  #patientDetail.fb > .pd-section .pd-sec-head .pd-ic { width: 34px !important; height: 34px !important; border-radius: 10px !important; }
  #patientDetail.fb > .pd-section .pd-sec-head .pd-ic svg, #patientDetail.fb > .pd-section .pd-sec-head .pd-ic .di { width: 19px !important; height: 19px !important; }
  #patientDetail.fb > [data-sec="odonto"] .pd-sec-head .pd-ic, #patientDetail.fb > [data-sec="hist"] .pd-sec-head .pd-ic { background: #0E9F9A1F !important; color: #0E9F9A !important; }
  #patientDetail.fb > [data-sec="plan"] .pd-sec-head .pd-ic { background: #7C5CFC1F !important; color: #7C5CFC !important; }
  #patientDetail.fb > [data-sec="salud"] .pd-sec-head .pd-ic { background: #FDECEC !important; color: #B42323 !important; }
  #patientDetail.fb > [data-sec="citas"] .pd-sec-head .pd-ic { background: #0284C71F !important; color: #0284C7 !important; }
  #patientDetail.fb > [data-sec="pend"] .pd-sec-head .pd-ic { background: #FFF4D6 !important; color: #B45309 !important; }
  #patientDetail.fb > [data-sec="arch"] .pd-sec-head .pd-ic { background: #0891B21F !important; color: #0891B2 !important; }
  #patientDetail.fb > .pd-section .pd-sec-head button { height: auto !important; min-height: 36px !important; padding: 0 6px !important; background: none !important; border: 0 !important; color: var(--blue, #0284C7) !important; font-size: 14.5px !important; font-weight: 700 !important; }
  #patientDetail.fb > .pd-section .pd-sec-head .pd-count { background: none !important; color: #5A6580 !important; border: 0 !important; font-size: 15px !important; font-weight: 700 !important; }
}
/* «Últimos archivos»: miniaturas de tamaño fijo y pequeño (antes ocupaban un tercio del ancho: enormes en iPad) */
.fb-arch .fb-ths { grid-template-columns: repeat(auto-fill, minmax(92px, 124px)); gap: 10px; justify-content: start; }
.fb-arch .fb-th .im { aspect-ratio: 4 / 3; border-radius: 10px; }
.fb-arch .fb-th small { font-size: 11.5px; }
/* iPad: el odontograma ocupa todo el ancho (en media columna los números de las piezas se encimaban) */
@media (min-width: 835px) and (max-width: 1199px) {
  #patientDetail.fb > .pd-card, #patientDetail.fb > .pd-section,
  #patientDetail.fb > .pd-section[data-sec="odonto"], #patientDetail.fb > .pd-section[data-sec="salud"], #patientDetail.fb > .pd-section[data-sec="citas"],
  #patientDetail.fb > .pd-section[data-sec="pend"], #patientDetail.fb > .pd-section[data-sec="plan"], #patientDetail.fb > .pd-section[data-sec="arch"],
  #patientDetail.fb > .pd-section[data-sec="arch"]:first-of-type { grid-column: 1 / -1; grid-row: auto; }
  #patientDetail.pd-has-rail.fb { grid-auto-flow: row dense; }
}

/* ---- riel completo a lo largo: ocupa todo el alto que requiere sin barra de desplazamiento interna ---- */
@media (min-width: 835px) {
  #patientDetail.fb > .pd-rail .pd-rail-in,
  #patientDetail.fb.pd-mod > .pd-rail .pd-rail-in { max-height: none !important; overflow: visible !important; }
  #patientDetail.fb:not(.pd-mod) { align-content: start; }
}
@media (min-width: 835px) and (max-height: 900px) {
  #patientDetail.fb .pd-rail-in { gap: 8px; }
  #patientDetail.fb .pd-rail-back, #patientDetail.fb .pd-rail-cta { height: 40px !important; min-height: 40px; }
  #patientDetail.fb .pd-rail-grp { margin: 0 12px -5px; }
  #patientDetail.fb .pd-rail-item { min-height: 38px; padding: 3px 8px; }
  #patientDetail.fb .pd-rail-item > svg:first-child { width: 26px !important; height: 26px !important; padding: 5px; }
}
@media (min-width: 835px) and (max-height: 740px) {
  #patientDetail.fb .pd-rail-in { gap: 5px; }
  #patientDetail.fb .pd-rail-back { height: 36px !important; min-height: 36px; }
  #patientDetail.fb .pd-rail-item { min-height: 34px; padding: 2px 8px; }
  #patientDetail.fb .pd-rail-item > svg:first-child { width: 24px !important; height: 24px !important; padding: 4px; }
  #patientDetail.fb .pd-rail-item span { font-size: 14px !important; }
}

/* ---- riel estable (2026-11-15): nada se encoge ni se corta, y la opción activa se ve ---- */
@media (min-width: 1280px) {
  #patientDetail.fb .pd-rail-in > * { flex: none; }
  #patientDetail.fb .pd-rail-nav { flex: none; overflow: visible; }
  #patientDetail.fb .pd-rail-item { flex: none; box-sizing: border-box; min-width: 0; height: auto; }
  #patientDetail.fb .pd-rail-item > svg:first-child { flex: none; }
  #patientDetail.fb .pd-rail-item > span { flex: 1 1 auto; min-width: 0; white-space: normal; line-height: 1.15; overflow-wrap: break-word; hyphens: manual; }
  #patientDetail.fb .pd-rail-item em { flex: none; }
  /* la flecha de la derecha sobra: quita ancho y evita que el texto se corte */
  #patientDetail.fb .pd-rail-item::after { display: none; }
  /* opción activa: fondo azul suave y barra interior (la barra anterior quedaba fuera del riel y se cortaba) */
  #patientDetail.fb .pd-rail-item.pd-on, #patientDetail.fb .pd-rail-item.on { background: rgba(2, 132, 199, .12) !important; color: var(--blue, #0284C7); box-shadow: inset 3px 0 0 var(--blue, #0284C7); }
  #patientDetail.fb .pd-rail-item.pd-on::before, #patientDetail.fb .pd-rail-item.on::before { display: none; }
  #patientDetail.fb .pd-rail-item.pd-on span, #patientDetail.fb .pd-rail-item.on span { font-weight: 800; }
  /* riel angosto (176 px): texto y ícono más chicos para que las palabras largas quepan enteras */
  #patientDetail.fb.pd-rail-a .pd-rail-item { gap: 8px; padding: 3px 6px !important; }
  #patientDetail.fb.pd-rail-a .pd-rail-item > svg:first-child { width: 24px !important; height: 24px !important; padding: 4px; }
  #patientDetail.fb.pd-rail-a .pd-rail-item span { font-size: 13.5px !important; }
}
/* modo solo íconos (835–1279 px): misma marca de opción activa; los nombres siguen saliendo como globo */
@media (min-width: 835px) and (max-width: 1279px) {
  #patientDetail.fb .pd-rail-item.pd-on, #patientDetail.fb .pd-rail-item.on { background: rgba(2, 132, 199, .16) !important; color: var(--blue, #0284C7); box-shadow: inset 0 0 0 2px var(--blue, #0284C7); }
  #patientDetail.fb .pd-rail-item.pd-on::before, #patientDetail.fb .pd-rail-item.on::before { display: none; }
  /* el nombre ahora lo muestra un globo fijo desde ficha-b.js (el de CSS se recortaba por el scroll interno de la barra) */
  #patientDetail.fb .pd-rail-item::after, #patientDetail.fb .pd-rail-back::after, #patientDetail.fb .pd-rail-danger .pd-rail-item::after { display: none; }
}

/* ---- barra reordenada (2026-11-15, maqueta aprobada): Examinar / Documentos / Archivos, especialidades plegadas en su grupo, «Editar datos» como lápiz en el encabezado ---- */
@media (min-width: 835px) {
  #patientDetail .pd-rail-sub { display: flex; flex-direction: column; max-height: 0; overflow: hidden; opacity: 0; visibility: hidden; transition: max-height .24s cubic-bezier(.23, 1, .32, 1), opacity .18s ease, visibility 0s linear .24s; }
  #patientDetail .pd-rail-nav.sub-open .pd-rail-sub { max-height: 220px; opacity: 1; visibility: visible; transition: max-height .24s cubic-bezier(.23, 1, .32, 1), opacity .2s ease .04s, visibility 0s; }
  @media (prefers-reduced-motion: reduce) { #patientDetail .pd-rail-sub, #patientDetail .pd-rail-nav.sub-open .pd-rail-sub { transition: none; } }
  #patientDetail.fb .pd-rail-moret { color: var(--blue, #0284C7); font-weight: 700; }
  #patientDetail.fb .pd-rail-moret > svg:first-child { background: #EFF1F6; color: var(--blue, #0284C7); transition: transform .18s ease; }
  #patientDetail.fb .pd-rail-nav.sub-open .pd-rail-moret > svg:first-child { transform: rotate(180deg); }
  #patientDetail.fb .pd-rail-moret span { font-weight: 700; }
  #patientDetail.fb .pd-rail-nav.pd-rail-danger { background: #fff; border: 1px solid rgba(220, 38, 38, .25); padding: 3px; }
  html body #patientDetail .pdb-btns { grid-template-columns: auto auto 40px; }
  html body #patientDetail .pdb-btn.pdb-ico { width: 40px; padding: 0; background: var(--card); color: var(--accent); }
  @container (max-width: 640px) {
    html body #patientDetail .pdb-btns { grid-template-columns: 1fr 1fr 40px; }
  }
}
