/* Cabecera de la ficha del paciente, versión B (maqueta aprobada 2026-11-13):
   nombre + contacto + Nueva atención | Agendar cita lado a lado, cifras en tarjetas y barra plegable con motivo y signos vitales.
   Solo escritorio (≥ 835 px); en celular se sigue usando la cabecera de siempre. */
#patientDetail .pdb { display: none; }

@media (min-width: 835px) {
  html body #patientDetail.patient-detail .pd-card:has(> .pdb):has(> .pd-head) > .pd-head,
  html body #patientDetail.patient-detail .pd-card:has(> .pdb):has(> .pd-head) > .pd-stats,
  #patientDetail .pd-card:has(> .pdb) > .pd-head,
  #patientDetail .pd-card:has(> .pdb) > .pd-stats { display: none !important; }
  #patientDetail.pd-has-rail .pd-card:has(> .pdb) { padding: 0 !important; overflow: hidden; }
  #patientDetail.pd-has-rail > .pd-rail .pd-rail-cta { display: none !important; } /* el botón pasó a la cabecera */

  #patientDetail .pdb { display: block !important; color: var(--ink); container-type: inline-size; }
  #patientDetail .pdb * { box-sizing: border-box; }
  #patientDetail .pdb-top { display: grid; grid-template-columns: auto minmax(0, 1fr) max-content; gap: 14px; align-items: start; padding: 13px 16px; }
  #patientDetail .pdb .pdb-av { width: 72px !important; height: 72px !important; min-width: 72px !important; min-height: 72px !important; max-width: 72px !important; max-height: 72px !important; aspect-ratio: 1 / 1 !important; padding: 0 !important; margin: 0 !important; border-radius: 50% !important; overflow: visible; position: relative; flex: none; display: block; grid-column: 1 !important; grid-row: 1 !important; align-self: start !important; justify-self: start !important; position: relative !important; top: auto !important; left: auto !important; transform: none !important; background-size: cover !important; background-position: center !important; background-repeat: no-repeat !important; }
  #patientDetail .pdb-id { min-width: 0; }
  #patientDetail .pdb-id { padding-top: 4px; }
  #patientDetail .pdb-name { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; min-width: 0; }
  #patientDetail .pdb-name h3 { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #patientDetail .pdb-name .pdb-chip { flex: none; }
  #patientDetail .pdb-btns { align-self: start; }
  /* Alertas clínicas: fila propia bajo nombre y contacto, compactas */
  #patientDetail .pdb-alerts { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 8px; }
  #patientDetail .pdb-alerts .pd-chip-warn { flex: none; min-height: 22px !important; padding: 2px 9px !important; font-size: .72rem !important; gap: 5px; }
  #patientDetail .pdb-alerts .pd-chip-warn .dot { width: 7px; height: 7px; border-radius: 50%; background: #D98A00; flex: none; }
  #patientDetail .pdb-alerts .pd-chip-warn b { margin-left: 0; font-weight: 700; }
  #patientDetail .pdb-alerts .clinical-banner { flex: 1 1 240px; min-width: 0; margin: 0 !important; padding: 5px 10px !important; gap: 8px !important; border-width: 1px !important; border-radius: 8px !important; font-size: .74rem; }
  #patientDetail .pdb-alerts .clinical-banner > div:first-child { min-width: 0 !important; flex: 1 1 auto !important; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; }
  #patientDetail .pdb-alerts .clinical-banner b { font-size: .74rem !important; }
  #patientDetail .pdb-alerts .clinical-banner > div:first-child > div { font-size: .74rem !important; margin: 0 !important; }
  #patientDetail .pdb-name h3 { margin: 0; font-size: 1.05rem; font-weight: 800; letter-spacing: -.01em; line-height: 1.15; }
  #patientDetail .pdb-chip { display: inline-flex; align-items: center; padding: 3px 8px; border-radius: 999px; background: rgba(148, 163, 184, .16); color: var(--muted); font-size: .7rem; font-weight: 600; white-space: nowrap; }
  #patientDetail .pdb-chip.pdb-code { font-family: "IBM Plex Mono", ui-monospace, monospace; background: rgba(2, 132, 199, .12); color: var(--accent); }
  #patientDetail .pdb-ct { display: flex; gap: 6px 12px; flex-wrap: wrap; margin-top: 6px; font-size: .72rem; color: var(--muted); }
  #patientDetail .pdb-ct span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
  #patientDetail .pdb-ct svg, #patientDetail .pdb-ct i { width: 13px; height: 13px; flex: none; }
  #patientDetail .pdb-btns { display: grid; grid-template-columns: auto auto; gap: 6px; }
  #patientDetail .pdb-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 40px; padding: 0 11px; border-radius: 11px; font-weight: 700; font-size: .8rem; cursor: pointer; white-space: nowrap; border: 1.5px solid var(--accent); margin: 0; width: auto; }
  #patientDetail .pdb-btn svg, #patientDetail .pdb-btn i { width: 16px; height: 16px; flex: none; }
  #patientDetail .pdb-btn.pdb-p { background: var(--accent); color: #fff; }
  #patientDetail .pdb-btn.pdb-s { background: var(--card); color: var(--accent); }

  /* Si la tarjeta es angosta (barra lateral abierta + riel), los botones bajan a su propia fila */
  @container (max-width: 640px) {
    #patientDetail .pdb-top { grid-template-columns: auto minmax(0, 1fr); }
    #patientDetail .pdb-btns { grid-column: 1 / -1; grid-template-columns: 1fr 1fr; }
    #patientDetail .pdb-name h3 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
  }

  #patientDetail .pdb-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(104px, 1fr)); gap: 8px; padding: 0 16px 12px; }
  #patientDetail .pdb-st { background: rgba(148, 163, 184, .09); border: 1px solid var(--line); border-radius: 10px; padding: 7px 11px; min-width: 0; }
  #patientDetail .pdb-st b { display: block; font-weight: 800; font-size: .98rem; line-height: 1.1; white-space: nowrap; }
  #patientDetail .pdb-st b.ok { color: #15803d; }
  #patientDetail .pdb-st b.debe, #patientDetail .pdb-st b.warn { color: #B45309; }
  #patientDetail .pdb-st span { display: block; margin-top: 2px; font-size: .58rem; font-weight: 700; letter-spacing: .05em; color: var(--muted); text-transform: uppercase; }

  #patientDetail .pdb-fold { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 9px 16px; border-top: 1px solid var(--line); font-size: .76rem; color: var(--muted); }
  #patientDetail .pdb-fold b { color: var(--ink); }
  #patientDetail .pdb-fold .pdb-sep { opacity: .4; }
  #patientDetail .pdb-tg { margin-left: auto; display: inline-flex; align-items: center; gap: 5px; height: auto; padding: 4px 11px; border-radius: 999px; border: 1px solid rgba(2, 132, 199, .35); background: rgba(2, 132, 199, .08); color: var(--accent); font-weight: 700; font-size: .76rem; cursor: pointer; width: auto; margin-top: 0; margin-bottom: 0; }
  #patientDetail .pdb-tg svg { width: 13px; height: 13px; transition: transform .15s; }
  #patientDetail .pdb-tg .pdb-o { display: none; }
  #patientDetail .pdb.open .pdb-tg .pdb-o { display: inline; }
  #patientDetail .pdb.open .pdb-tg .pdb-v { display: none; }
  #patientDetail .pdb.open .pdb-tg svg { transform: rotate(180deg); }
  #patientDetail .pdb-more { display: none; padding: 2px 16px 13px; }
  #patientDetail .pdb.open .pdb-more { display: block; }
  #patientDetail .pdb-vts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
  #patientDetail .pdb-vt { border: 1px solid var(--line); border-radius: 10px; padding: 7px 11px; background: var(--card); }
  #patientDetail .pdb-vt small, #patientDetail .pdb-inf small { display: block; font-size: .58rem; font-weight: 700; letter-spacing: .05em; color: var(--muted); text-transform: uppercase; }
  #patientDetail .pdb-vt b { font-weight: 800; font-size: .98rem; }
  #patientDetail .pdb-vt b i { font-style: normal; font-weight: 600; font-size: .64rem; color: var(--muted); margin-left: 3px; }
  #patientDetail .pdb-vt.alto b { color: #DC2626; }
  #patientDetail .pdb-infs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; margin-top: 10px; }
  #patientDetail .pdb-inf span { font-size: .8rem; line-height: 1.3; }
}

/* ===== Ventana «Agendar cita» desde la ficha (solo se elige fecha, hora y tratamiento) ===== */
.fcm { position: fixed; inset: 0; z-index: 99990; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(15, 23, 42, .45); }
.fcm[hidden] { display: none; }
.fcm-card { width: 470px; max-width: 100%; max-height: calc(100vh - 32px); display: flex; flex-direction: column; background: var(--card, #fff); color: var(--ink); border-radius: 18px; box-shadow: 0 30px 80px -20px rgba(15, 23, 42, .5); overflow: hidden; }
.fcm-h { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--line); }
.fcm-hi { width: 34px; height: 34px; border-radius: 10px; background: rgba(2, 132, 199, .12); color: var(--accent); display: grid; place-items: center; flex: none; }
.fcm-hi svg, .fcm-hi i { width: 18px; height: 18px; }
.fcm-t { font-weight: 700; font-size: 1.05rem; line-height: 1.2; }
.fcm-s { font-size: .74rem; color: var(--muted); }
.fcm-x { margin-left: auto; width: 34px; height: 34px; border-radius: 9px; border: 0; background: transparent; color: var(--muted); font-size: 1.3rem; cursor: pointer; padding: 0; }
.fcm-b { padding: 16px 18px; overflow-y: auto; }
.fcm-p { display: flex; align-items: center; gap: 10px; background: rgba(148, 163, 184, .1); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; margin-bottom: 14px; }
.fcm-av { width: 38px; height: 38px; border-radius: 50%; background: rgba(2, 132, 199, .14); color: var(--accent); display: grid; place-items: center; font-weight: 700; flex: none; }
.fcm-pn { font-weight: 700; font-size: .95rem; }
.fcm-lb { display: flex; justify-content: space-between; align-items: center; margin: 0 0 7px; font-size: .72rem; font-weight: 700; letter-spacing: .05em; color: var(--muted); text-transform: uppercase; }
.fcm-lb em { font-style: normal; letter-spacing: 0; text-transform: none; font-weight: 700; color: var(--accent); font-size: .8rem; }
.fcm-dc { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.fcm-dc button { height: auto; width: auto; margin: 0; padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: var(--card); color: var(--ink); font-weight: 600; font-size: .82rem; cursor: pointer; }
.fcm-dc button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.fcm-in { width: 100%; height: 40px; margin: 0 0 16px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: .9rem; background: var(--card); color: var(--ink); }
.fcm-g { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; font-size: .68rem; font-weight: 800; letter-spacing: .07em; color: var(--muted); opacity: .85; }
.fcm-g::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.fcm-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; margin-bottom: 12px; }
.fcm-chip { height: auto; width: auto; margin: 0; padding: 9px 0; text-align: center; border-radius: 10px; border: 1.5px solid var(--line); background: var(--card); color: var(--ink); font-weight: 600; font-size: .84rem; font-variant-numeric: tabular-nums; cursor: pointer; }
.fcm-chip.occ { background: rgba(148, 163, 184, .14); border-color: transparent; color: var(--muted); opacity: .6; text-decoration: line-through; }
.fcm-chip.sel { background: var(--accent); border-color: var(--accent); color: #fff; opacity: 1; text-decoration: none; box-shadow: 0 4px 12px -4px rgba(2, 132, 199, .6); }
.fcm-lg { display: flex; gap: 14px; font-size: .7rem; color: var(--muted); margin: -2px 0 12px; }
.fcm-lg i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.fcm-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 4px; }
.fcm-row label { display: block; font-size: .72rem; font-weight: 700; letter-spacing: .05em; color: var(--muted); text-transform: uppercase; }
.fcm-row select { display: block; width: 100%; height: 40px; margin: 5px 0 0; padding: 0 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); font-size: .86rem; font-weight: 600; text-transform: none; letter-spacing: 0; }
.fcm-end { margin: 8px 0 0; font-size: .8rem; color: var(--accent); font-weight: 600; min-height: 1.1em; }
.fcm-err { margin: 10px 0 0; padding: 9px 12px; border-radius: 10px; background: rgba(220, 38, 38, .1); color: #B91C1C; font-size: .8rem; font-weight: 600; }
.fcm-err:empty { display: none; }
.fcm-f { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--line); background: rgba(148, 163, 184, .08); }
.fcm-f button { height: 42px; width: auto; margin: 0; padding: 0 20px; border-radius: 10px; font-weight: 700; font-size: .86rem; cursor: pointer; border: 1px solid var(--line); background: var(--card); color: var(--ink); }
.fcm-f button.go { background: var(--accent); border-color: var(--accent); color: #fff; }
.fcm-f button.go:disabled { opacity: .45; cursor: not-allowed; }
@media (max-width: 520px) { .fcm-grid { grid-template-columns: repeat(4, 1fr); } .fcm-card { border-radius: 14px; } }

/* Riel compacto solo iconos (maqueta 17, 2026-11-13): con la ventana angosta (barra lateral abierta) el riel de 232 px pasa a 48 px;
   el nombre de cada opción sale al pasar el mouse. En pantalla ancha (≥ 1280 px) queda el riel completo. */
@media (min-width: 835px) and (max-width: 1279px) {
  html body #patientDetail.pd-has-rail { padding-left: 76px !important; }
  html body #patientDetail.pd-has-rail > .pd-rail { width: 48px !important; }
  #patientDetail .pd-rail-in { align-items: center; gap: 3px !important; }
  #patientDetail .pd-rail-nav { align-items: center; gap: 3px; width: 100%; }
  #patientDetail .pd-rail-grp { height: 1px; width: 22px; margin: 6px auto !important; padding: 0 !important; font-size: 0 !important; background: var(--line); overflow: hidden; }
  #patientDetail .pd-rail-back { width: 36px; height: 36px; margin: 0 0 2px !important; padding: 0 !important; justify-content: center; align-self: center; font-size: 0 !important; line-height: 0 !important; border-radius: 10px; background: rgba(148,163,184,.14) !important; }
  #patientDetail .pd-rail-back svg { width: 18px; height: 18px; }
  #patientDetail .pd-rail-item { position: relative; width: 36px !important; min-height: 36px !important; height: 36px; padding: 0 !important; justify-content: center; gap: 0; }
  #patientDetail .pd-rail-item > span:not(.ec-only), #patientDetail .pd-rail-item > em:not(.x) { display: none; }
  #patientDetail .pd-rail-item svg { width: 18px !important; height: 18px !important; }
  #patientDetail .pd-rail-item em { position: absolute; top: 2px; right: 1px; display: inline-flex !important; min-width: 14px; height: 14px; padding: 0 3px; border-radius: 99px; background: var(--accent); color: #fff; font-size: .58rem; font-weight: 700; align-items: center; justify-content: center; }
  #patientDetail .pd-rail-back::after, #patientDetail .pd-rail-item::after { font-size: .74rem; line-height: 1.2; content: attr(data-tip); position: absolute; left: calc(100% + 8px); top: 50%; transform: translateY(-50%); padding: 4px 9px; border-radius: 7px; background: #0f172a; color: #fff; font-size: .74rem; font-weight: 600; white-space: nowrap; opacity: 0; pointer-events: none; transition: opacity .12s; z-index: 30; }
  #patientDetail .pd-rail-back:hover::after, #patientDetail .pd-rail-item:hover::after, #patientDetail .pd-rail-back:focus-visible::after, #patientDetail .pd-rail-item:focus-visible::after { opacity: 1; }
  #patientDetail .pd-rail-back { position: relative; }
}

/* Riel ancho más angosto (maqueta 18-A, 2026-11-13; solo clínica demo-ecuador por ahora, clase pd-rail-a): 160 px, menos margen, y las opciones poco usadas dentro de «Más». */
.pd-rail-morebtn { display: none; }
@media (min-width: 1280px) {
  html body #patientDetail.pd-has-rail.pd-rail-a { padding: 12px 12px 12px 198px !important; }
  html body #patientDetail.pd-has-rail.pd-rail-a > .pd-rail { left: 12px !important; top: 12px !important; bottom: 12px !important; width: 176px !important; }
  #patientDetail.pd-rail-a .pd-rail-item { min-height: 30px !important; font-size: .8rem !important; gap: 8px !important; padding: 0 8px !important; }
  #patientDetail.pd-rail-a .pd-rail-item::after, #patientDetail.pd-rail-a .pd-rail-item::before { display: none !important; }
  #patientDetail.pd-rail-a .pd-rail-grp { margin: 10px 8px 2px !important; font-size: .66rem !important; }
  #patientDetail.pd-rail-a .pd-rail-back { font-size: .8rem !important; }
  #patientDetail.pd-rail-a .pd-rail-morebtn { display: flex; align-items: center; gap: 8px; width: 100%; min-height: 30px; margin-top: 8px; padding: 0 8px; border: 0; border-radius: 9px; background: none; font: inherit; font-size: .8rem; font-weight: 700; color: var(--accent); cursor: pointer; }
  #patientDetail.pd-rail-a .pd-rail-morebtn:hover { background: rgba(2, 132, 199, .09); }
  #patientDetail.pd-rail-a .pd-rail-morebtn svg { width: 16px; height: 16px; flex: none; }
  #patientDetail.pd-rail-a .pd-rail-morebtn em { margin-left: auto; font-style: normal; font-size: .7rem; color: var(--muted); }
  #patientDetail.pd-rail-a .pd-rail-more { display: none; }
  #patientDetail.pd-rail-a .pd-rail.more-open .pd-rail-more { display: block; }
  #patientDetail.pd-rail-a .pd-rail-more .pd-rail-danger { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--line); }
}

/* ===== Maqueta 19 (2026-11-14) — solo clínica demo por ahora (body.ui-compacto, ver index.html) ===== */
@media (min-width: 835px) {
  /* Menú lateral: pasó a todas las cuentas (sidebar-b.css) */
  /* Ficha: las tarjetas no se estiran (sin huecos) y las vacías se reducen a una línea */
  body.ui-compacto #patientDetail { align-items: start !important; }
  body.ui-compacto #patientDetail > .pd-section.pd-empty-card { padding: 9px 14px !important; }
  body.ui-compacto #patientDetail > .pd-section.pd-empty-card .pd-sec-head { margin: 0 0 2px !important; }
  body.ui-compacto #patientDetail > .pd-section.pd-empty-card .pd-empty-line { margin: 0 !important; font-size: .78rem; color: var(--muted); }
}

/* ===== Formulario «Nuevo paciente» original, versión compacta (solo clínica de Barreno; ver plantilla patientModalClasico2) ===== */
#patientModal[data-fc] .fc-row { display: grid; gap: 8px 10px; margin-bottom: 8px; }
#patientModal[data-fc] .fc-r1 { grid-template-columns: 2fr 1.2fr .8fr; }
#patientModal[data-fc] .fc-r2 { grid-template-columns: 1fr 1.3fr 1fr 1fr; }
#patientModal[data-fc] .fc-r3 { grid-template-columns: 1fr 1fr 1fr 1fr; }
#patientModal[data-fc] .fc-row .m-label { display: block; margin: 0; min-width: 0; }
#patientModal[data-fc] .fc-row input, #patientModal[data-fc] .fc-row select { margin-top: 3px; width: 100%; }
@media (max-width: 760px) {
  #patientModal[data-fc] .fc-r1, #patientModal[data-fc] .fc-r2 { grid-template-columns: 1fr 1fr; }
  #patientModal[data-fc] .fc-r3 { grid-template-columns: 1fr; }
}
/* Botones «Dictar» del formulario compacto: pequeños, en la misma línea del título del campo (antes ocupaban una fila entera) */
#patientModal[data-fc] .ddf-dic { min-height: 24px !important; height: 24px !important; padding: 0 9px !important; margin: 0 0 2px 6px !important; font-size: .72rem !important; line-height: 1 !important; border-radius: 8px !important; }
#patientModal[data-fc] .ddf-dic svg { width: 12px; height: 12px; }
#patientModal[data-fc] .fc-r3 { grid-template-columns: 1fr 1fr 1fr 1fr; }

/* ===== Formulario de Barreno v3 (maqueta 20, 2026-11-14): orden clínico, botones de un toque, signos vitales, opciones plegadas ===== */
#patientModal[data-fc="3"] .fc3-body { padding: 0 !important; }
#patientModal[data-fc="3"] .fc3-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0; align-items: start; }
#patientModal[data-fc="3"] .fc3-col { padding: 14px 22px 10px; min-width: 0; }
#patientModal[data-fc="3"] .fc3-right { border-left: 1px solid var(--line); background: color-mix(in srgb, var(--card-2, #f8fafc) 60%, transparent); }
#patientModal[data-fc="3"] .mf-step { margin: 2px 0 8px; }
#patientModal[data-fc="3"] .m-label { display: block; margin: 0; min-width: 0; }
#patientModal[data-fc="3"] .m-label > b { display: block; margin-bottom: 3px; font-size: .74rem; color: var(--ink-soft, #475569); }
#patientModal[data-fc="3"] .fc3-req { color: #dc2626; font-style: normal; }
#patientModal[data-fc="3"] .fc3-sub { font-weight: 500; color: var(--muted); }
/* Filas: las cajas de una fila miden lo mismo y se alinean por el borde de abajo */
#patientModal[data-fc="3"] .fc3-row { display: grid; gap: 8px 10px; margin-bottom: 9px; align-items: end; }
#patientModal[data-fc="3"] .fc3-a { grid-template-columns: 1.6fr 1fr; }
#patientModal[data-fc="3"] .fc3-b { grid-template-columns: 1fr 1.2fr; }
#patientModal[data-fc="3"] .fc3-c { grid-template-columns: 1fr 64px 1.5fr; }
#patientModal[data-fc="3"] .fc3-d { grid-template-columns: 1fr; }
#patientModal[data-fc="3"] input:not([type=checkbox]):not([type=hidden]), #patientModal[data-fc="3"] select { width: 100%; height: 36px; min-height: 36px; box-sizing: border-box; margin: 0; }
#patientModal[data-fc="3"] .fc3-edad { background: color-mix(in srgb, #0284c7 9%, var(--card)) !important; color: #0369a1; font-weight: 800; text-align: center; border-color: color-mix(in srgb, #0284c7 25%, var(--line)) !important; }
#patientModal[data-fc="3"] textarea { width: 100%; box-sizing: border-box; margin: 0; resize: vertical; min-height: 36px; }
#patientModal[data-fc="3"] .fc3-mot { margin-bottom: 9px; }
/* Botones de un toque (sexo, estado) */
#patientModal[data-fc="3"] .fc3-seg { display: flex; gap: 6px; }
#patientModal[data-fc="3"] .fc3-seg.fc3-wrap { flex-wrap: wrap; }
#patientModal[data-fc="3"] .fc3-seg button { flex: 1 1 0; min-width: 0; height: 36px; min-height: 36px; padding: 0 10px; border: 1.5px solid var(--line); border-radius: 9px; background: var(--card-2, #f1f5f9); color: var(--ink-soft, #475569); font: inherit; font-size: .78rem; font-weight: 700; cursor: pointer; white-space: nowrap; display: inline-flex; align-items: center; justify-content: center; }
#patientModal[data-fc="3"] .fc3-seg.fc3-wrap button { flex: 0 1 auto; padding: 0 12px; height: 32px; min-height: 32px; border-radius: 99px; }
#patientModal[data-fc="3"] .fc3-seg button.fc3-none { flex: 1.6 1 0; font-weight: 600; font-size: .72rem; }
#patientModal[data-fc="3"] .fc3-seg button.on { background: #0284c7; border-color: #0284c7; color: #fff; }
/* Signos vitales: 4 tarjetas iguales, cifra grande y unidad al lado */
#patientModal[data-fc="3"] .fc3-vit { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 9px; }
#patientModal[data-fc="3"] .fc3-v { display: block; min-width: 0; margin: 0; padding: 7px 10px 6px; border: 1.5px solid var(--line); border-radius: 11px; background: var(--card); cursor: text; }
#patientModal[data-fc="3"] .fc3-v small { display: block; font-size: .6rem; font-weight: 800; letter-spacing: .05em; color: var(--muted); }
#patientModal[data-fc="3"] .fc3-v span { display: flex; align-items: baseline; gap: 4px; margin-top: 2px; }
#patientModal[data-fc="3"] .fc3-v input { height: 28px !important; min-height: 28px !important; padding: 0 !important; border: 0 !important; background: transparent !important; box-shadow: none !important; font-size: 1.15rem; font-weight: 800; min-width: 0; }
#patientModal[data-fc="3"] .fc3-v u { text-decoration: none; font-size: .65rem; color: var(--muted); flex: none; }
#patientModal[data-fc="3"] .fc3-v:focus-within { border-color: #0284c7; box-shadow: 0 0 0 3px rgba(2, 132, 199, .15); }
#patientModal[data-fc="3"] .fc3-v.hi { border-color: #fca5a5; background: #fef2f2; }
#patientModal[data-fc="3"] .fc3-v.hi input { color: #b91c1c; }
/* Alergias y condiciones: casillas como botones redondos */
#patientModal[data-fc="3"] .fc3-lab { margin: 2px 0 5px; }
#patientModal[data-fc="3"] .fc3-lab b { font-size: .74rem; color: var(--ink-soft, #475569); }
#patientModal[data-fc="3"] .quick-checks { display: flex !important; flex-wrap: wrap; gap: 6px; margin: 0 0 6px; }
#patientModal[data-fc="3"] .quick-checks label { position: relative; display: inline-flex; align-items: center; height: 28px; min-height: 28px; padding: 0 11px; margin: 0; border: 1.5px solid var(--line); border-radius: 99px; background: var(--card); font-size: .74rem; font-weight: 600; color: var(--ink-soft, #334155); cursor: pointer; line-height: 1; }
#patientModal[data-fc="3"] .quick-checks label input { position: absolute; opacity: 0; width: 0; height: 0; margin: 0; pointer-events: none; }
#patientModal[data-fc="3"] .quick-checks label:has(input:checked) { background: #fee2e2; border-color: #fca5a5; color: #b91c1c; }
#patientModal[data-fc="3"] .quick-checks label:has(input[value^="Sin "]:checked) { background: #dcfce7; border-color: #86efac; color: #15803d; }
#patientModal[data-fc="3"] .quick-checks label:has(input:focus-visible) { outline: 2px solid #0284c7; outline-offset: 1px; }
#patientModal[data-fc="3"] .fc3-extra { margin: 0 0 9px; min-height: 32px !important; height: 32px; font-size: .78rem; }
#patientModal[data-fc="3"] #clinicalExtraBlock { margin-bottom: 9px; }
/* Opciones plegadas (barras) */
#patientModal[data-fc="3"] .fc3-folds { display: grid; gap: 6px; }
#patientModal[data-fc="3"] .fc3-fold { border: 1.5px dashed var(--line); border-radius: 10px; background: var(--card); padding: 0; margin: 0 !important; }
#patientModal[data-fc="3"] .fc3-fold > summary { list-style: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; height: 38px; min-height: 38px; padding: 0 12px; cursor: pointer; font-weight: 700; font-size: .78rem; color: var(--ink-soft, #475569); }
#patientModal[data-fc="3"] .fc3-fold > summary::-webkit-details-marker { display: none; }
#patientModal[data-fc="3"] .fc3-fold > summary::after { content: "▸ abrir"; font-size: .7rem; font-weight: 600; color: var(--muted); }
#patientModal[data-fc="3"] .fc3-fold[open] > summary::after { content: "▾ cerrar"; }
#patientModal[data-fc="3"] .fc3-fold[open] { border-style: solid; padding-bottom: 10px; }
#patientModal[data-fc="3"] .fc3-fold[open] > :not(summary) { margin-left: 12px; margin-right: 12px; }
#patientModal[data-fc="3"] .fc3-two { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
/* Pie: confirmaciones a la izquierda, botones a la derecha, todo alineado al centro */
#patientModal[data-fc="3"] .fc3-foot { display: flex; align-items: center; gap: 12px; }
#patientModal[data-fc="3"] .fc3-sp { flex: 1; }
#patientModal[data-fc="3"] .fc3-ck { display: inline-flex; align-items: center; gap: 7px; margin: 0 !important; font-size: .76rem; font-weight: 600; cursor: pointer; }
#patientModal[data-fc="3"] .fc3-ck input[type=checkbox] { width: 18px; height: 18px; min-height: 0; margin: 0; flex: none; }
#patientModal[data-fc="3"] .fc3-foot button { height: 38px; min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
@media (max-width: 900px) {
  #patientModal[data-fc="3"] .fc3-grid { grid-template-columns: 1fr; }
  #patientModal[data-fc="3"] .fc3-right { border-left: 0; border-top: 1px solid var(--line); }
  #patientModal[data-fc="3"] .fc3-vit { grid-template-columns: repeat(2, 1fr); }
  #patientModal[data-fc="3"] .fc3-foot { flex-wrap: wrap; }
}
#patientModal[data-fc="3"] .mf-step { align-items: center; }
#patientModal[data-fc="3"] .fc3-pid { margin-left: auto; }
#patientModal[data-fc="3"] .fc3-pid input { width: 92px !important; height: 26px !important; min-height: 26px !important; padding: 0 8px !important; border-radius: 8px; background: var(--card-2, #f1f5f9) !important; color: var(--muted); font: 600 .72rem "IBM Plex Mono", ui-monospace, monospace; text-align: center; }
/* v3 — alineación: etiquetas de la misma altura, controles de la misma altura, filas alineadas por arriba */
#patientModal[data-fc="3"] .fc3-row { align-items: start !important; }
#patientModal[data-fc="3"] .m-label > b { font-size: .74rem !important; line-height: 16px !important; height: 16px; margin: 0 0 3px !important; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#patientModal[data-fc="3"] .fc3-seg button { height: 36px !important; min-height: 36px !important; max-height: 36px; padding: 0 8px !important; line-height: 1 !important; box-sizing: border-box; }
#patientModal[data-fc="3"] .fc3-seg.fc3-wrap button { height: 32px !important; min-height: 32px !important; max-height: 32px; padding: 0 9px !important; font-size: .72rem; }
#patientModal[data-fc="3"] .fc3-seg.fc3-wrap { gap: 5px; }
#patientModal[data-fc="3"] .fc3-fold > summary { justify-content: flex-start !important; }
#patientModal[data-fc="3"] .fc3-fold > summary > span { margin: 0 0 0 .3em !important; }
#patientModal[data-fc="3"] .fc3-fold > summary::after { margin-left: auto; }
#patientModal[data-fc="3"] .fc3-fold > summary:focus-visible { outline: 2px solid #0284c7; outline-offset: 1px; border-radius: 9px; }
#patientModal[data-fc="3"] .fc3-foot .fc3-ck { height: 38px; }
#patientModal[data-fc="3"] .fc3-fold > summary::after { background: none !important; -webkit-mask: none !important; mask: none !important; width: auto !important; height: auto !important; flex: none; line-height: 1; transform: none !important; border: 0 !important; }

/* v3 — rejilla común: Cédula, Email y Sexo arrancan en la misma vertical (revisión de Opus, 2026-11-14) */
#patientModal[data-fc="3"] .fc3-a, #patientModal[data-fc="3"] .fc3-b, #patientModal[data-fc="3"] .fc3-c { grid-template-columns: minmax(0,1fr) 64px minmax(0,1fr); }
#patientModal[data-fc="3"] .fc3-a > :first-child, #patientModal[data-fc="3"] .fc3-b > :first-child { grid-column: 1 / 3; }
#patientModal[data-fc="3"] .fc3-grid { grid-template-columns: minmax(0,1fr) minmax(0,1fr); align-items: stretch; }
#patientModal[data-fc="3"] .fc3-fold > summary > span { margin-left: 0 !important; }
@media (max-width: 1200px) {
  #patientModal[data-fc="3"] .fc3-col { padding: 12px 16px 8px; }
  #patientModal[data-fc="3"] .fc3-row, #patientModal[data-fc="3"] .fc3-vit, #patientModal[data-fc="3"] .fc3-mot { margin-bottom: 8px; }
  #patientModal[data-fc="3"] .fc3-vit { gap: 6px; }
  #patientModal[data-fc="3"] .fc3-v { padding: 6px 8px 5px; }
  #patientModal[data-fc="3"] .fc3-v input { font-size: 1.05rem; }
  #patientModal[data-fc="3"] .quick-checks { gap: 5px; }
  #patientModal[data-fc="3"] .quick-checks label { padding: 0 9px; }
}
/* 835-900: dos columnas siempre (anula el corte viejo a 1 columna) */
@media (min-width: 835px) and (max-width: 900px) {
  #patientModal[data-fc="3"] .fc3-grid { grid-template-columns: minmax(0,1fr) minmax(0,1fr); }
  #patientModal[data-fc="3"] .fc3-right { border-left: 1px solid var(--line); border-top: 0; }
  #patientModal[data-fc="3"] .fc3-vit { grid-template-columns: repeat(4, 1fr); }
  #patientModal[data-fc="3"] .fc3-foot { flex-wrap: nowrap; }
  #patientModal[data-fc="3"] .fc3-seg button.fc3-none { font-size: .68rem; }
}
@media (min-width: 601px) and (max-width: 834px) { #patientModal[data-fc="3"] .fc3-vit { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 600px) {
  #patientModal[data-fc="3"] .fc3-a, #patientModal[data-fc="3"] .fc3-b { grid-template-columns: 1fr; }
  #patientModal[data-fc="3"] .fc3-a > :first-child, #patientModal[data-fc="3"] .fc3-b > :first-child { grid-column: auto; }
  #patientModal[data-fc="3"] .fc3-c { grid-template-columns: minmax(0,1fr) 64px; }
  #patientModal[data-fc="3"] .fc3-c > :last-child { grid-column: 1 / -1; }
}
/* Ventanas bajas: menos aire vertical para que lo no plegado quepa sin desplazar */
@media (max-height: 820px) and (min-width: 835px) {
  #patientModal[data-fc="3"] .fc3-col { padding-top: 8px; padding-bottom: 6px; }
  #patientModal[data-fc="3"] .fc3-row, #patientModal[data-fc="3"] .fc3-vit, #patientModal[data-fc="3"] .fc3-mot { margin-bottom: 6px; }
  #patientModal[data-fc="3"] .mf-step { margin-bottom: 5px; }
  #patientModal[data-fc="3"] .fc3-extra { margin-bottom: 6px; height: 28px; min-height: 28px !important; }
  #patientModal[data-fc="3"] .fc3-fold > summary { height: 32px; min-height: 32px; }
  #patientModal[data-fc="3"] .fc3-folds { gap: 4px; }
}

/* ===== Dictar todo (DEMO): botón junto a la X, globo de estado y casillas recién llenadas ===== */
#patientModal[data-fc="3"] .modal-head { position: relative; }
#patientModal[data-fc="3"] .fc3-dic { position: absolute; right: 62px; top: 50%; transform: translateY(-50%); z-index: 3; display: inline-flex; align-items: center; gap: 7px; height: 34px; min-height: 34px; padding: 0 12px; border: 1.5px solid color-mix(in srgb, #0284c7 40%, var(--line)); border-radius: 99px; background: color-mix(in srgb, #0284c7 9%, var(--card)); color: #0369a1; font: inherit; font-size: .78rem; font-weight: 700; cursor: pointer; white-space: nowrap; line-height: 1; }
#patientModal[data-fc="3"] .fc3-dic:hover { background: color-mix(in srgb, #0284c7 16%, var(--card)); }
#patientModal[data-fc="3"] .fc3-dic svg { width: 14px; height: 14px; flex: none; }
#patientModal[data-fc="3"] .fc3-dic .fc3-demo { font-style: normal; font-size: .58rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; padding: 2px 6px; border-radius: 99px; background: #fef3c7; color: #92400e; }
#patientModal[data-fc="3"] .fc3-dic.rec { background: #fee2e2; border-color: #fca5a5; color: #b91c1c; animation: fc3pulse 1.4s ease-in-out infinite; }
#patientModal[data-fc="3"] .fc3-dic.busy { opacity: .8; cursor: progress; }
@keyframes fc3pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, .35); } 50% { box-shadow: 0 0 0 6px rgba(220, 38, 38, 0); } }
@media (prefers-reduced-motion: reduce) { #patientModal[data-fc="3"] .fc3-dic.rec { animation: none; } }
#patientModal[data-fc="3"] .fc3-pop { position: absolute; right: 20px; top: calc(100% - 6px); z-index: 6; width: min(420px, calc(100% - 40px)); max-height: 42vh; overflow: auto; padding: 9px 11px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); box-shadow: 0 12px 34px rgba(15, 23, 42, .22); font-size: .78rem; line-height: 1.4; color: var(--ink); }
#patientModal[data-fc="3"] .fc3-pop[hidden] { display: none; }
#patientModal[data-fc="3"] .fc3-pop.err { border-color: #fca5a5; background: #fef2f2; }
#patientModal[data-fc="3"] .fc3-pop.ok { border-color: #86efac; background: #f0fdf4; }
#patientModal[data-fc="3"] .fc3-pop-live { margin-top: 7px; padding: 7px 9px; border-radius: 8px; background: var(--card-2, #f1f5f9); color: var(--ink-soft, #334155); font-size: .76rem; min-height: 32px; }
#patientModal[data-fc="3"] .fc3-pop-or, #patientModal[data-fc="3"] .fc3-pop-dudas { margin-top: 6px; font-size: .74rem; color: var(--ink-soft, #475569); }
#patientModal[data-fc="3"] .fc3-pop-ft { display: flex; gap: 6px; margin-top: 9px; }
#patientModal[data-fc="3"] .fc3-pop-ft button { height: 30px; min-height: 30px; padding: 0 11px; border: 1.5px solid var(--line); border-radius: 8px; background: var(--card); font: inherit; font-size: .74rem; font-weight: 700; cursor: pointer; color: var(--ink); }
#patientModal[data-fc="3"] .fc3-pop-ft button:first-child { background: #0284c7; border-color: #0284c7; color: #fff; }
#patientModal[data-fc="3"] .fc3-spin { display: inline-block; width: 12px; height: 12px; border: 2px solid #bae6fd; border-top-color: #0284c7; border-radius: 50%; vertical-align: -2px; animation: fc3spin .8s linear infinite; }
@keyframes fc3spin { to { transform: rotate(360deg); } }
/* casillas recién llenadas por el dictado: resplandor suave que se apaga solo */
#patientModal[data-fc="3"] .fc3-filled input:not([type=checkbox]), #patientModal[data-fc="3"] .fc3-filled textarea, #patientModal[data-fc="3"] .fc3-filled .fc3-seg button.on, #patientModal[data-fc="3"] .fc3-v.fc3-filled { box-shadow: 0 0 0 3px rgba(34, 197, 94, .28); border-color: #4ade80 !important; transition: box-shadow .4s, border-color .4s; }
#patientModal[data-fc="3"] .quick-checks label.fc3-filled { box-shadow: 0 0 0 3px rgba(34, 197, 94, .28); }
/* Dictado: lo dudoso queda en ámbar hasta que el doctor lo toque o lo corrija */
#patientModal[data-fc="3"] .fc3-revisar input:not([type=checkbox]), #patientModal[data-fc="3"] .fc3-revisar textarea, #patientModal[data-fc="3"] input.fc3-revisar, #patientModal[data-fc="3"] .fc3-v.fc3-revisar { border-color: #f59e0b !important; background: #fffbeb !important; box-shadow: 0 0 0 3px rgba(245, 158, 11, .22); }
#patientModal[data-fc="3"] .fc3-v.fc3-revisar input { background: transparent !important; box-shadow: none !important; }
#patientModal[data-fc="3"] .fc3-seg.fc3-revisar, #patientModal[data-fc="3"] .quick-checks.fc3-revisar { outline: 2px solid #f59e0b; outline-offset: 3px; border-radius: 10px; }
#patientModal[data-fc="3"] .fc3-revisar > b::after { content: " · revisar"; color: #b45309; font-weight: 700; }
#patientModal[data-fc="3"] .fc3-pop.warn { border-color: #fcd34d; background: #fffbeb; }
#patientModal[data-fc="3"] .fc3-pop-rev { margin-top: 7px; display: flex; flex-wrap: wrap; gap: 5px; align-items: center; font-size: .74rem; }
#patientModal[data-fc="3"] .fc3-pop-rev button { height: 24px; min-height: 24px; padding: 0 9px; border: 1.5px solid #f59e0b; border-radius: 99px; background: #fff; color: #92400e; font: inherit; font-size: .7rem; font-weight: 700; cursor: pointer; }
#patientModal[data-fc="3"] .fc3-pop-txt { margin-top: 7px; font-size: .72rem; color: var(--ink-soft, #475569); }
#patientModal[data-fc="3"] .fc3-pop-txt summary { cursor: pointer; font-weight: 700; }
#patientModal[data-fc="3"] .fc3-pop-ft { flex-wrap: wrap; }

/* Aviso del dictado compacto: botones arriba (siempre visibles), detalles plegados */
#patientModal[data-fc="3"] .fc3-pop-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
#patientModal[data-fc="3"] .fc3-pop-top .fc3-pop-ft { margin-top: 0; flex-wrap: wrap; }
#patientModal[data-fc="3"] .fc3-pop-top .fc3-pop-ft button { height: 26px; min-height: 26px; padding: 0 9px; }
#patientModal[data-fc="3"] .fc3-pop-msg { flex: 1 1 140px; min-width: 0; }
#patientModal[data-fc="3"] .fc3-pop-rev { margin-top: 6px; }
#patientModal[data-fc="3"] .fc3-pop-det { margin-top: 6px; font-size: .72rem; }
#patientModal[data-fc="3"] .fc3-pop-det summary { cursor: pointer; font-weight: 700; color: var(--ink-soft, #475569); }

/* Aviso del dictado: barra en el encabezado, a la izquierda del botón (no tapa el formulario) */
#patientModal[data-fc="3"] .modal-head.fc3-barra-on .modal-sub { display: none; }
#patientModal[data-fc="3"] .fc3-pop { top: 50%; transform: translateY(-50%); left: 250px; right: 252px; width: auto; max-height: none; overflow: visible; display: flex; align-items: center; flex-wrap: wrap; gap: 5px 8px; padding: 4px 8px; border-radius: 10px; box-shadow: none; z-index: 4; }
#patientModal[data-fc="3"] .fc3-pop[hidden] { display: none; }
#patientModal[data-fc="3"] .fc3-pop .fc3-pop-msg { flex: 0 1 auto; white-space: nowrap; }
#patientModal[data-fc="3"] .fc3-pop .fc3-pop-rev { margin: 0; display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
#patientModal[data-fc="3"] .fc3-pop .fc3-pop-ft { margin: 0 0 0 auto; display: flex; gap: 4px; flex-wrap: nowrap; }
#patientModal[data-fc="3"] .fc3-pop .fc3-pop-ft button { height: 24px; min-height: 24px; padding: 0 8px; white-space: nowrap; }
#patientModal[data-fc="3"] .fc3-pop-live { margin: 0; padding: 0; background: none; min-height: 0; flex: 1 1 0; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; color: var(--ink-soft, #475569); }
#patientModal[data-fc="3"] .fc3-pop-detbox { position: absolute; top: calc(100% + 4px); left: 0; right: 0; padding: 7px 9px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); box-shadow: 0 8px 22px rgba(15, 23, 42, .18); font-size: .72rem; max-height: 150px; overflow: auto; }
#patientModal[data-fc="3"] .fc3-pop-detbox[hidden] { display: none; }
#patientModal[data-fc="3"] .fc3-pop-detbox > div { margin: 2px 0; }
/* Ajuste: la barra no pisa el título ni el botón; botones más justos, sin cortarse entre sí */
#patientModal[data-fc="3"] .fc3-pop { left: 296px; right: 262px; gap: 4px 6px; padding: 3px 7px; line-height: 1.2; }
#patientModal[data-fc="3"] .fc3-pop > * { flex: none; }
#patientModal[data-fc="3"] .fc3-pop .fc3-pop-live { flex: 1 1 0; }
#patientModal[data-fc="3"] .fc3-pop .fc3-pop-ft { gap: 3px; }
#patientModal[data-fc="3"] .fc3-pop .fc3-pop-ft button { padding: 0 7px; font-size: .72rem; }
#patientModal[data-fc="3"] .fc3-pop .fc3-pop-ft button:last-child { padding: 0 6px; }
#patientModal[data-fc="3"] .fc3-pop .fc3-pop-rev { gap: 3px; font-size: .72rem; }
#patientModal[data-fc="3"] .fc3-pop .fc3-pop-rev button { height: 22px; min-height: 22px; padding: 0 7px; font-size: .68rem; }
#patientModal[data-fc="3"] .fc3-pop .fc3-pop-msg { font-size: .74rem; }
/* Simetría y alineación del encabezado (Nuevo paciente v3): fila flex, todo centrado en la misma línea, huecos iguales de 14px */
#patientModal[data-fc="3"] .modal-head { display: flex; align-items: center; gap: 14px; }
#patientModal[data-fc="3"] .modal-head .mf-headrow { order: 0; flex: 0 1 auto; margin: 0; }
#patientModal[data-fc="3"] .modal-head .fc3-pop { order: 1; position: relative; top: auto; left: auto; right: auto; transform: none; flex: 1 1 0; min-width: 0; width: auto; min-height: 34px; margin: 0; padding: 4px 8px; box-sizing: border-box; }
#patientModal[data-fc="3"] .modal-head .fc3-dic { order: 2; position: static; transform: none; margin: 0 0 0 auto; flex: none; }
#patientModal[data-fc="3"] .modal-head .modal-close { order: 3; position: static; transform: none; margin: 0; flex: none; align-self: center; }
#patientModal[data-fc="3"] .fc3-pop > * { align-self: center; margin-top: 0; margin-bottom: 0; }
#patientModal[data-fc="3"] .fc3-pop .fc3-pop-rev button, #patientModal[data-fc="3"] .fc3-pop .fc3-pop-ft button { height: 24px; min-height: 24px; margin: 0; line-height: 1; display: inline-flex; align-items: center; justify-content: center; }
#patientModal[data-fc="3"] .fc3-pop .fc3-pop-rev b, #patientModal[data-fc="3"] .fc3-pop .fc3-pop-msg { line-height: 24px; }
