/**
 * CIMA Móvil — Shell de navegación (m.appcima.com)
 * Archivo  : app/movil/shell.css
 * Función  : Header + pila de vistas (stack) + dock de 5 destinos (Consulta al centro,
 *            elevada) + bottom sheet + modal + toast + componentes base. Mobile-first real:
 *            una mano, tap targets ≥44px, safe-area (notch / barra de gestos), sin hover.
 *            CERO colores literales: todo sale de app/movil/palettes.css.
 * Autores  : CIMA Development Group
 * Copyright: © 2024–2026 CIMA Development Group. Todos los derechos reservados.
 */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { background: var(--bg); }
body {
    font-family: var(--font); font-size: 16px; line-height: 1.35;
    background: var(--bg); color: var(--text);
    -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none; touch-action: manipulation;
    user-select: none; -webkit-user-select: none;
}
input, textarea, [contenteditable] { user-select: text; -webkit-user-select: text; }
button { font-family: inherit; }
.bi { flex-shrink: 0; }

/* ── Aplicación (pantalla completa fija; el scroll vive en cada vista) ── */
#cm-app { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }

/* ── Header ── */
.cm-hdr {
    flex: 0 0 auto; position: relative; z-index: 5;
    display: flex; align-items: center; gap: 8px;
    padding: env(safe-area-inset-top) 12px 0 12px; min-height: calc(var(--hdr-h) + env(safe-area-inset-top));
    background: var(--surface); border-bottom: 1px solid var(--line);
}
.cm-hdr[hidden] { display: none; }
.cm-hdr h1 { flex: 1; min-width: 0; margin: 0; font-size: 1.15rem; font-weight: 800; letter-spacing: .2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cm-hdr .cm-back, .cm-hdr .cm-act {
    width: var(--tap); height: var(--tap); border-radius: var(--radius-sm); border: 1px solid var(--line);
    background: var(--surface-2); color: var(--text); display: grid; place-items: center; font-size: 1.15rem;
    padding: 0; cursor: pointer; transition: transform .12s var(--ease), opacity .15s;
}
.cm-hdr .cm-back { border-color: transparent; background: transparent; }
.cm-hdr .cm-back[hidden], .cm-hdr .cm-act[hidden] { display: none; }
.cm-hdr .cm-act.cm-act-avatar { padding: 0; overflow: hidden; background: var(--surface-2); }
.cm-hdr .cm-act .cm-avatar-btn { width: 100%; height: 100%; object-fit: cover; display: block; border-radius: var(--radius-sm); }
.cm-hdr .cm-back:active, .cm-hdr .cm-act:active { transform: scale(.92); }
.cm-hdr .cm-sub { display: block; font-size: .72rem; font-weight: 600; color: var(--muted); letter-spacing: .04em; }

/* ── Pila de vistas ── */
.cm-stack { flex: 1 1 auto; position: relative; overflow: hidden; }
.cm-view {
    position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain;
    padding: 14px 16px calc(var(--dock-h) + env(safe-area-inset-bottom) + 28px);
    background: var(--bg); will-change: transform;
}
.cm-view[hidden] { display: none; }
.cm-view.cm-root.cm-in { animation: cmFade .2s var(--ease); }
.cm-view.cm-pushed { z-index: 2; animation: cmSlideIn .26s var(--ease); box-shadow: var(--shadow); }
.cm-view.cm-pushed.cm-out { animation: cmSlideOut .22s var(--ease) forwards; pointer-events: none; }
/* Dock SIEMPRE visible (decisión 2026-09-07): fullscreen ya no lo oculta; toda vista reserva su
   alto. cm-fullscreen queda SOLO para noDock (login, sin sesión). */
body.cm-fullscreen .cm-view { padding-bottom: calc(env(safe-area-inset-bottom) + 20px); }
@keyframes cmFade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes cmSlideIn { from { transform: translateX(100%); } to { transform: none; } }
@keyframes cmSlideOut { from { transform: none; } to { transform: translateX(100%); } }

/* Tirar para refrescar */
.cm-ptr {
    position: absolute; top: 0; left: 0; right: 0; height: 0; z-index: 3; display: grid; place-items: center;
    pointer-events: none; overflow: visible;
}
.cm-ptr i {
    width: 34px; height: 34px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line);
    display: grid; place-items: center; color: var(--primary); font-size: 1rem; box-shadow: var(--shadow);
    transform: translateY(-46px); opacity: 0; transition: transform .18s var(--ease), opacity .18s;
}
.cm-ptr.cm-arm i { opacity: 1; }
.cm-ptr.cm-busy i { opacity: 1; transform: translateY(12px); animation: cmSpin .8s linear infinite; }
@keyframes cmSpin { to { transform: translateY(12px) rotate(360deg); } }

/* Aviso sin conexión */
.cm-offline {
    position: absolute; left: 12px; right: 12px; top: 8px; z-index: 4; display: flex; align-items: center; gap: 8px;
    padding: 9px 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line);
    color: var(--muted); font-size: .82rem; font-weight: 600; transform: translateY(-140%); transition: transform .25s var(--ease);
}
.cm-offline.on { transform: none; }
.cm-offline .bi { color: var(--warn); }

/* ── Dock (5 destinos; Consulta al centro, elevada y más grande) ── */
body.cm-fullscreen .cm-dock { transform: translateY(calc(100% + 48px)); } /* solo noDock (login) */
.cm-dock {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 6;
    height: calc(var(--dock-h) + env(safe-area-inset-bottom));
    padding: 6px 4px env(safe-area-inset-bottom);
    background: var(--surface); border-top: 1px solid var(--line);
    display: flex; align-items: flex-start; justify-content: space-around;
    transition: transform .25s var(--ease);
}
/* Dock icon-only: sin etiquetas (los nombres quedan en aria-label y en el header de cada vista) */
.cm-tab {
    flex: 1; min-width: 0; min-height: var(--tap); background: none; border: 0; padding: 0; cursor: pointer;
    color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center;
    position: relative; -webkit-user-select: none;
    transition: color .15s;
}
.cm-tab .bi { font-size: 1.55rem; line-height: 1; transition: transform .15s var(--ease); }
.cm-tab .cm-dock-avatar { width: 26px; height: 26px; border-radius: 50%; object-fit: cover; display: block; border: 2px solid transparent; background: var(--surface-2); }
.cm-tab.active .cm-dock-avatar { border-color: var(--primary); }
.cm-tab.active { color: var(--primary); }
.cm-tab:active .bi { transform: scale(.9); }
.cm-tab .cm-badge {
    position: absolute; top: 2px; left: calc(50% + 6px); min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
    background: var(--danger); color: var(--surface); font-size: .62rem; font-weight: 800; display: grid; place-items: center;
}
.cm-tab.cm-center .cm-fab {
    position: absolute; top: -28px; left: 50%; transform: translateX(-50%);
    width: 62px; height: 62px; border-radius: 50%; background: var(--primary); color: var(--primary-ink);
    display: grid; place-items: center; box-shadow: var(--shadow-fab); border: 4px solid var(--bg);
    transition: transform .15s var(--ease);
}
.cm-tab.cm-center .cm-fab .bi { font-size: 1.55rem; }
.cm-tab.cm-center:active .cm-fab { transform: translateX(-50%) scale(.93); }
.cm-tab.cm-center.active .cm-fab { box-shadow: var(--shadow-fab), var(--focus); }

/* ── Bottom sheet ── */
.cm-sheet-mask {
    position: absolute; inset: 0; z-index: 8; background: var(--mask); opacity: 0; pointer-events: none; transition: opacity .25s;
}
.cm-sheet-mask.on { opacity: 1; pointer-events: auto; }
.cm-sheet {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 9; max-height: 82%; overflow-y: auto;
    background: var(--surface); border-radius: 22px 22px 0 0; border-top: 1px solid var(--line);
    padding: 8px 16px calc(env(safe-area-inset-bottom) + 18px);
    transform: translateY(105%); transition: transform .28s var(--ease);
}
.cm-sheet.on { transform: none; }
.cm-sheet .cm-grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 6px auto 12px; }
.cm-sheet h2 { margin: 2px 0 8px; font-size: 1.05rem; font-weight: 800; }
.cm-sheet .cm-row { min-height: 56px; }

/* ── Modal (nunca confirm/alert nativos) ── */
.cm-modal-mask {
    position: absolute; inset: 0; z-index: 20; background: var(--mask); display: flex; align-items: center; justify-content: center;
    padding: 24px; opacity: 0; pointer-events: none; transition: opacity .2s;
}
.cm-modal-mask.on { opacity: 1; pointer-events: auto; }
.cm-modal {
    width: 100%; max-width: 340px; background: var(--surface); border: 1px solid var(--line); border-radius: 18px;
    padding: 20px; text-align: center; transform: scale(.96); transition: transform .2s var(--ease); box-shadow: var(--shadow);
}
.cm-modal-mask.on .cm-modal { transform: none; }
.cm-modal .cm-mic { font-size: 1.9rem; color: var(--primary); margin-bottom: 6px; }
.cm-modal .cm-mic.danger { color: var(--danger); }
.cm-modal h3 { margin: 0 0 6px; font-size: 1.05rem; }
.cm-modal p { color: var(--muted); margin: 0 0 16px; font-size: .92rem; line-height: 1.45; }
.cm-modal .cm-actions { display: flex; gap: 10px; }
.cm-modal .cm-actions .cm-btn { margin: 0; }

/* ── Toast ── */
.cm-toasts {
    position: absolute; left: 12px; right: 12px; bottom: calc(var(--dock-h) + env(safe-area-inset-bottom) + 14px);
    z-index: 30; display: flex; flex-direction: column; gap: 8px; pointer-events: none; transition: bottom .25s var(--ease);
}
body.cm-fullscreen .cm-toasts { bottom: calc(env(safe-area-inset-bottom) + 14px); }
.cm-toast {
    pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 14px;
    background: var(--surface-2); border: 1px solid var(--line); color: var(--text); font-size: .9rem; font-weight: 600;
    box-shadow: var(--shadow); animation: cmToastIn .22s var(--ease);
}
.cm-toast.cm-out { animation: cmToastOut .2s var(--ease) forwards; }
.cm-toast .bi { font-size: 1.1rem; color: var(--primary); }
.cm-toast.ok .bi { color: var(--accent); }
.cm-toast.warn .bi { color: var(--warn); }
.cm-toast.error .bi { color: var(--danger); }
.cm-toast span { flex: 1; min-width: 0; }
.cm-toast button {
    border: 0; background: var(--tint-primary); color: var(--primary); font-weight: 800; padding: 8px 12px; border-radius: 10px;
    min-height: 36px; cursor: pointer; font-size: .85rem;
}
@keyframes cmToastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes cmToastOut { to { opacity: 0; transform: translateY(10px); } }

/* ── Componentes base ── */
/* Estilo plano (IG/Threads/X): las "cards" pierden borde y fondo; el contenido se apoya en el
   padding de .cm-view y en los separadores finos de .cm-row. NO reintroducir cajas con borde. */
.cm-card { background: transparent; border: 0; border-radius: 0; padding: 12px 0; margin-bottom: 10px; }
.cm-card.tight { padding-bottom: 4px; }
.cm-h { margin: 4px 2px 9px; font-size: .72rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); font-weight: 700; }
.cm-card > .cm-h { margin: 0 0 6px; }
.cm-big { font-size: 1.55rem; font-weight: 800; margin: 2px 0; }
.cm-muted { color: var(--muted); }
.cm-strong { color: var(--text); font-weight: 700; }
.cm-accent { color: var(--accent); }
.cm-row {
    display: flex; align-items: center; gap: 12px; padding: 11px 0; min-height: 60px; border-bottom: 1px solid var(--line);
    cursor: pointer; transition: opacity .12s; -webkit-user-select: none;
}
.cm-row:last-child { border-bottom: 0; }
.cm-row:active { opacity: .7; }
.cm-row.static { cursor: default; }
.cm-row.static:active { opacity: 1; }
.cm-row .cm-ic {
    width: 40px; height: 40px; flex: 0 0 40px; border-radius: 11px; background: var(--surface-2); color: var(--primary);
    display: grid; place-items: center; font-size: 1.2rem; font-weight: 800;
}
.cm-row .cm-ic.accent { background: var(--tint-accent); color: var(--accent); }
.cm-row .cm-tx { flex: 1; min-width: 0; }
.cm-row .cm-tx b { display: block; font-size: .95rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cm-row .cm-tx small { display: block; color: var(--muted); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cm-row .cm-chev { color: var(--muted); font-size: .95rem; }
.cm-pill { flex-shrink: 0; font-size: .68rem; font-weight: 700; padding: 3px 9px; border-radius: 20px; background: var(--tint-accent); color: var(--accent); }
.cm-pill.primary { background: var(--tint-primary); color: var(--primary); }
.cm-pill.danger { background: var(--tint-danger); color: var(--danger); }
.cm-pill.muted { background: var(--surface-2); color: var(--muted); }
.cm-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 13px; }
.cm-stat { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px 8px; text-align: center; }
.cm-stat .n { font-size: 1.35rem; font-weight: 800; color: var(--primary); }
.cm-stat .l { font-size: .66rem; color: var(--muted); text-transform: uppercase; letter-spacing: .08em; margin-top: 2px; }
.cm-btn {
    width: 100%; min-height: 48px; border: 0; border-radius: 13px; padding: 12px 14px; font-weight: 700; font-size: .98rem; cursor: pointer;
    background: var(--primary); color: var(--primary-ink); display: flex; align-items: center; justify-content: center; gap: 9px;
    transition: transform .12s var(--ease), opacity .15s; margin-top: 10px;
}
.cm-btn:active { transform: scale(.98); }
.cm-btn.ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--line); }
.cm-btn.danger { background: var(--tint-danger); color: var(--danger); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); }
.cm-btn:disabled { opacity: .55; cursor: default; }
.cm-input {
    width: 100%; min-height: 48px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
    border-radius: var(--radius-sm); padding: 12px 14px; font-family: inherit; font-size: 16px; margin-bottom: 10px; outline: 0;
}
.cm-input::placeholder { color: var(--muted); }
.cm-input:focus { box-shadow: var(--focus); border-color: var(--primary); }
.cm-search { position: relative; }
.cm-search .bi { position: absolute; left: 14px; top: 15px; color: var(--muted); pointer-events: none; }
.cm-search .cm-input { padding-left: 40px; }
.cm-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.cm-chip {
    min-height: 36px; padding: 6px 12px; border-radius: 20px; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
    font-size: .85rem; font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.cm-chip.active { background: var(--tint-primary); color: var(--primary); border-color: transparent; }
/* Chips del buscador de pacientes (T8, D4: botones del buscador de escritorio) — tap target ≥44px */
.cm-search-chips { margin-bottom: 4px; }
.cm-search-chips .cm-chip { min-height: 44px; }

/* ── Agenda: tira de 7 días (T7) ── */
.cm-days-wrap { display: flex; align-items: center; gap: 4px; margin: 2px 0 14px; }
.cm-days { flex: 1; min-width: 0; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.cm-days::-webkit-scrollbar { display: none; }
.cm-days .cm-chip {
    flex: 0 0 auto; min-width: 44px; min-height: 44px; flex-direction: column; gap: 1px; padding: 6px 10px;
    line-height: 1.15; text-transform: capitalize;
}
.cm-days .cm-chip b { font-size: .68rem; font-weight: 700; }
.cm-days .cm-chip small { font-size: .82rem; font-weight: 800; }
.cm-days .cm-chip.cm-hoy:not(.active) { border-color: var(--primary); color: var(--primary); }
.cm-days-nav {
    flex: 0 0 auto; width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2);
    color: var(--text); display: grid; place-items: center; font-size: 1rem; cursor: pointer; padding: 0;
}
.cm-days-nav:active { transform: scale(.92); }

/* ── Formularios en bottom sheet (Nueva cita, T7) ── */
.cm-form { padding-top: 2px; }
.cm-field { margin-bottom: 14px; }
.cm-field label { display: block; font-size: .78rem; font-weight: 700; color: var(--muted); margin: 0 0 6px 2px; }
.cm-field #cmNcResultados { margin-top: 4px; }
.cm-field .cm-btn.ghost { margin-top: 8px; }
textarea.cm-input { min-height: 64px; resize: vertical; padding-top: 12px; }

/* ── Consulta clínica por etapas (T8b) ── */
.cm-etapas { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 0 0 14px; padding-bottom: 2px; }
.cm-etapas::-webkit-scrollbar { display: none; }
.cm-etapas .cm-chip { flex: 0 0 auto; min-height: 44px; }
.cm-vitals { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 4px; }
.cm-vitals .cm-field { margin-bottom: 0; }
.cm-vitals-ta { display: flex; align-items: center; gap: 4px; }
.cm-vitals-ta .cm-input { margin-bottom: 0; padding-left: 8px; padding-right: 8px; text-align: center; }
.cm-vitals-ta span { color: var(--muted); font-weight: 700; }
.cm-dx-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.cm-dx-list .cm-chip { cursor: pointer; }
.cm-interim { color: var(--muted); font-size: .85rem; font-style: italic; padding: 0 2px 10px; margin-top: -6px; }
.cm-interim[hidden] { display: none; }

/* ── Manos libres (T17): grabadora, panel de revisión, tabla de laboratorio ── */
.cm-rec-wrap { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 6px 4px 10px; }
.cm-rec {
    width: 84px; height: 84px; border-radius: 50%; border: 0; background: var(--tint-primary); color: var(--primary);
    display: grid; place-items: center; font-size: 2rem; transition: transform .15s var(--ease), background .2s, color .2s;
}
.cm-rec:active { transform: scale(.94); }
.cm-rec.on { background: var(--tint-danger); color: var(--danger); animation: cmRecPulse 1.4s ease-in-out infinite; }
@keyframes cmRecPulse {
    0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--danger) 35%, transparent); }
    50% { box-shadow: 0 0 0 14px color-mix(in srgb, var(--danger) 0%, transparent); }
}
.cm-rec-time { font-size: 1.1rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--text); }
.cm-rec-hint { font-size: .82rem; color: var(--muted); text-align: center; max-width: 260px; }
.cm-wave { display: flex; align-items: flex-end; gap: 3px; height: 28px; }
.cm-wave[hidden] { display: none; }
.cm-wave span { width: 4px; border-radius: 2px; background: var(--danger); animation: cmWave .9s ease-in-out infinite; opacity: .85; }
.cm-wave span:nth-child(2) { animation-delay: .1s; }
.cm-wave span:nth-child(3) { animation-delay: .2s; }
.cm-wave span:nth-child(4) { animation-delay: .3s; }
.cm-wave span:nth-child(5) { animation-delay: .4s; }
@keyframes cmWave { 0%, 100% { height: 6px; } 50% { height: 26px; } }

.cm-review { display: flex; flex-direction: column; gap: 10px; margin: 10px 0 4px; }
.cm-review-item { background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px; }
.cm-review-item .cm-rv-h { font-size: .78rem; font-weight: 700; color: var(--muted); margin-bottom: 4px; }
.cm-review-item .cm-rv-act { display: flex; gap: 8px; }
.cm-review-item .cm-rv-act .cm-btn { flex: 1; margin: 0; padding: 9px 10px; font-size: .85rem; }
.cm-rv-v { font-size: .92rem; white-space: pre-wrap; margin-bottom: 8px; word-break: break-word; }

.cm-rol-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px dashed var(--line); }
.cm-rol-row:last-child { border-bottom: 0; }
.cm-rol-row .cm-rv-v { flex: 1; margin-bottom: 0; font-size: .86rem; color: var(--muted); }
.cm-rol-chip { flex-shrink: 0; min-height: 36px; padding: 6px 12px; }

.cm-lab-table { display: flex; flex-direction: column; gap: 2px; margin: 6px 0 12px; }
.cm-lab-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid var(--line); }
.cm-lab-row:last-child { border-bottom: 0; }
.cm-lab-name { flex: 1; min-width: 0; font-size: .9rem; font-weight: 700; }
.cm-lab-ref { font-size: .72rem; color: var(--muted); font-weight: 500; }
.cm-lab-val { font-size: .85rem; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.cm-lab-flag { flex-shrink: 0; font-size: .68rem; font-weight: 700; padding: 3px 9px; border-radius: 20px; background: var(--tint-accent); color: var(--accent); }
.cm-lab-flag.alto { background: var(--tint-danger); color: var(--danger); }
.cm-lab-flag.bajo { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }

.cm-check-row { display: flex; align-items: center; gap: 10px; padding: 8px 2px 14px; }
.cm-check-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary); flex-shrink: 0; }
.cm-check-row label { font-size: .88rem; color: var(--text); }

/* Acordeón (Configuración: todo en la MISMA vista) */
/* Acordeones planos (IG/Threads/X): filas sin caja; feedback al tocar con fondo redondeado */
.cm-acc { border: 0; border-radius: 0; overflow: hidden; margin-bottom: 0; background: transparent; }
.cm-acc .cm-hd { display: flex; align-items: center; gap: 12px; padding: 15px 4px; min-height: 54px; cursor: pointer; -webkit-user-select: none; border-radius: 12px; }
.cm-acc .cm-hd:active { background: var(--surface-2); }
.cm-acc .cm-hd .bi:first-child { color: var(--primary); font-size: 1.15rem; width: 26px; text-align: center; }
.cm-acc .cm-hd b { flex: 1; font-size: .95rem; }
.cm-acc .cm-hd .cm-chev { color: var(--muted); transition: transform .2s var(--ease); font-size: .9rem; }
.cm-acc.open .cm-hd .cm-chev { transform: rotate(90deg); }
.cm-acc .cm-bd { display: none; padding: 0 4px 14px; color: var(--muted); font-size: .88rem; line-height: 1.5; }
.cm-acc.open .cm-bd { display: block; animation: cmFade .18s var(--ease); }
/* T10: contenido REAL (formularios/filas) dentro de un acordeón usa el color de texto normal —
   el gris de .cm-bd es solo para el copy descriptivo simple (Plantillas, notas de ayuda). */
.cm-acc .cm-bd .cm-form, .cm-acc .cm-bd .cm-row { color: var(--text); }

/* Pasos numerados (T13a: guía de instalación iOS en Usuario) */
.cm-steps { display: flex; flex-direction: column; gap: 12px; margin-top: 4px; }
.cm-step { display: flex; align-items: center; gap: 12px; }
.cm-step-n {
    flex-shrink: 0; width: 24px; height: 24px; border-radius: 50%; background: var(--tint-primary); color: var(--primary);
    font-size: .8rem; font-weight: 800; display: flex; align-items: center; justify-content: center;
}
.cm-step .bi { flex-shrink: 0; color: var(--primary); font-size: 1.05rem; width: 22px; text-align: center; }
.cm-step span:last-child { font-size: .9rem; }

/* Selector de paleta (dentro de Usuario › Apariencia) */
.cm-paletas { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 8px; }
.cm-paleta {
    flex: 1 1 0; min-width: 56px; min-height: 64px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface-2);
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; cursor: pointer; padding: 6px 4px;
    font-size: .68rem; font-weight: 700; color: var(--muted);
}
.cm-paleta i { width: 22px; height: 22px; border-radius: 50%; display: block; border: 2px solid var(--surface); }
.cm-paleta.sel { border-color: var(--primary); color: var(--text); }

/* Perfil — la tarjeta ES la entrada a "Mi perfil" (única puerta; sin fila ni botón de header) */
.cm-profile { display: flex; align-items: center; gap: 14px; cursor: pointer; -webkit-user-select: none; }
.cm-profile:active { opacity: .7; }
.cm-profile .cm-tx { flex: 1; min-width: 0; }
.cm-profile .cm-chev { color: var(--muted); font-size: .95rem; }
.cm-profile .cm-avatar { width: 56px; height: 56px; flex: 0 0 56px; border-radius: 16px; font-size: 1.8rem; background: var(--surface-2); color: var(--primary); display: grid; place-items: center; overflow: hidden; }
.cm-profile .cm-avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cm-profile .cm-avatar img.cm-fb { object-fit: contain; padding: 12px; } /* fallback: isotipo CIMA */
.cm-profile b { display: block; font-size: 1.05rem; }
.cm-profile small { color: var(--muted); font-size: .85rem; }

/* Login (pantalla completa, sin dock) */
.cm-login { display: flex; flex-direction: column; min-height: calc(100% - 20px); padding-top: 8vh; }
/* Logo por máscara (T4b): toma el color del texto del tema activo, nunca un color fijo. */
.cm-logo-mask {
    display: block; width: min(60%, 240px); aspect-ratio: 251.5 / 76; margin: 0 auto 18px; background: var(--text);
    -webkit-mask: url('../style/icon/cima_logo.svg') center / contain no-repeat;
    mask: url('../style/icon/cima_logo.svg') center / contain no-repeat;
}
.cm-login-title { text-align: center; font-size: 1.15rem; font-weight: 800; margin: 0 0 22px; }
.cm-login-pass { position: relative; }
.cm-login-pass .cm-input { padding-right: 46px; }
.cm-login-eye {
    position: absolute; right: 4px; top: 4px; width: 40px; height: 40px; border: 0; background: transparent;
    color: var(--muted); font-size: 1.05rem; display: grid; place-items: center; cursor: pointer;
}
.cm-login-remember { display: flex; align-items: center; gap: 9px; font-size: .88rem; color: var(--muted); margin: 2px 0 4px; -webkit-user-select: none; user-select: none; }
.cm-login-remember input { width: 18px; height: 18px; accent-color: var(--primary); }
.cm-login #cm-login-passkey { margin-top: 10px; }
.cm-login-forgot { display: block; width: 100%; text-align: center; background: transparent; border: 0; color: var(--primary); font-size: .88rem; font-weight: 700; padding: 16px 8px 0; cursor: pointer; }
.cm-login-ver { text-align: center; color: var(--muted); font-size: .72rem; margin-top: auto; padding-top: 24px; }

/* Cuentas recientes (T4b): tarjetas encima del formulario para cambiar de cuenta rápido. */
.cm-cuentas { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; }
.cm-cuenta {
    display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 10px; cursor: pointer;
    background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); -webkit-user-select: none; user-select: none;
}
.cm-cuenta:active { opacity: .8; }
.cm-cuenta-av {
    flex: 0 0 auto; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
    background: var(--tint-primary); color: var(--primary); font-weight: 800; font-size: .95rem;
}
.cm-cuenta-tx { flex: 1; min-width: 0; }
.cm-cuenta-tx b { display: block; font-size: .92rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cm-cuenta-tx small { display: block; color: var(--muted); font-size: .78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cm-cuenta-x {
    flex: 0 0 auto; width: 30px; height: 30px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
    background: var(--surface-2); color: var(--muted); display: grid; place-items: center; font-size: .78rem;
}
.cm-cuenta-x:active { opacity: .7; }

.cm-error { color: var(--danger); background: var(--tint-danger); border-radius: var(--radius-sm); padding: 10px 12px; font-size: .86rem; font-weight: 600; margin-bottom: 10px; }

/* Vista de detalle genérica */
.cm-detail p { color: var(--muted); font-size: .92rem; line-height: 1.5; margin: 0 0 12px; }
.cm-empty { text-align: center; color: var(--muted); padding: 40px 16px; font-size: .92rem; }
.cm-empty .bi { display: block; font-size: 2.2rem; margin-bottom: 10px; color: var(--line); }

/* Botón pequeño de fila (T9: eliminar archivo por fila, sin usar el chevron de drill-down) */
.cm-row-del {
    flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; border: 0; padding: 0;
    background: var(--surface-2); color: var(--muted); display: grid; place-items: center; font-size: .85rem; cursor: pointer;
}
.cm-row-del:active { opacity: .7; transform: scale(.94); }

/* T9 — Chat: burbujas + barra de entrada fija abajo */
.cm-bubbles { display: flex; flex-direction: column; gap: 8px; padding: 4px 0 14px; }
.cm-bubble { max-width: 78%; align-self: flex-start; background: var(--surface-2); border-radius: 16px; padding: 9px 12px; }
.cm-bubble .cm-bubble-txt { font-size: .92rem; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.cm-bubble .cm-bubble-hora { font-size: .68rem; color: var(--muted); text-align: right; margin-top: 3px; }
.cm-bubble.mine { align-self: flex-end; background: var(--tint-primary); }
.cm-chatbar { position: sticky; bottom: calc(var(--dock-h) + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 8px; padding: 10px 0 2px; background: var(--bg); }
.cm-chatbar .cm-input { margin-bottom: 0; }
.cm-chatbar .cm-btn { width: 48px; height: 48px; min-height: 48px; flex: 0 0 48px; margin-top: 0; padding: 0; border-radius: 50%; }

/* T9 — Notas: barra lateral con el color GUARDADO de la nota (única excepción a cero color
   literal: la variable --nota-color la pone el propio dato de la nota, inline, por fila) */
.cm-note-row { position: relative; padding-left: 12px; }
.cm-note-color { position: absolute; left: 0; top: 8px; bottom: 8px; width: 4px; border-radius: 3px; background: var(--nota-color, var(--line)); }

/* Recursos del médico: firma/sello/header/footer/plantillas/logos (screens/recursos.js) */
.cm-res-preview {
    height: 80px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface);
    display: flex; align-items: center; justify-content: center; overflow: hidden; margin-bottom: 10px;
}
.cm-res-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }
.cm-res-preview-sq { height: 90px; width: 90px; margin-left: auto; margin-right: auto; }
.cm-res-wide {
    width: 100%; max-height: 140px; min-height: 64px; border-radius: var(--radius-sm); border: 1px solid var(--line);
    background: var(--surface); display: flex; align-items: center; justify-content: center; overflow: hidden; margin-bottom: 10px;
}
.cm-res-wide img { max-width: 100%; max-height: 140px; object-fit: contain; }
.cm-res-empty { display: flex; flex-direction: column; align-items: center; gap: 4px; color: var(--muted); font-size: .78rem; padding: 6px; text-align: center; }
.cm-res-empty .bi { font-size: 1.3rem; }
.cm-res-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.cm-res-actions .cm-btn { flex: 1 1 auto; margin: 0; }
.cm-block-btn { width: 100%; margin: 0 0 4px; }
.cm-res-nota { font-size: .76rem; margin-top: 8px; }
.cm-switch-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; font-size: .88rem; margin-bottom: 12px; }
.cm-switch-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--primary); }

/* Firma dibujada: lienzo táctil apaisado a pantalla completa */
.cm-sig-wrap { flex: 1 1 auto; min-height: 220px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); overflow: hidden; margin-bottom: 14px; }
.cm-sig-canvas { display: block; width: 100%; height: 100%; touch-action: none; }
.cm-sig-actions .cm-btn { flex: 1 1 0; }

/* Plantillas de documento: fila con miniatura + acciones */
.cm-tpl-row { display: flex; align-items: center; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--line); }
.cm-tpl-row:last-child { border-bottom: 0; }
.cm-tpl-thumb {
    flex: 0 0 auto; width: 44px; height: 44px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2);
    display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--muted);
}
.cm-tpl-thumb img { max-width: 100%; max-height: 100%; object-fit: contain; }
.cm-tpl-row .cm-tx { flex: 1; min-width: 0; }
.cm-tpl-row .cm-tx b { display: block; font-size: .92rem; font-weight: 700; }
.cm-tpl-row .cm-tx small { display: block; color: var(--muted); font-size: .78rem; }
.cm-tpl-star {
    flex: 0 0 auto; width: 34px; height: 34px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
    background: var(--surface-2); color: var(--muted); display: grid; place-items: center; font-size: .9rem;
}
.cm-tpl-star:active { opacity: .7; }

/* Logos: rejilla de miniaturas con borrado por celda */
.cm-logos-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: 10px; padding: 4px 0 2px; }
.cm-logo-item {
    position: relative; aspect-ratio: 1 / 1; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface);
    display: flex; align-items: center; justify-content: center; overflow: hidden; color: var(--muted);
}
.cm-logo-item img { max-width: 100%; max-height: 100%; object-fit: contain; }
.cm-logo-del {
    position: absolute; top: 4px; right: 4px; width: 24px; height: 24px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
    background: color-mix(in srgb, var(--bg) 70%, transparent); color: var(--text); display: grid; place-items: center; font-size: .68rem;
}
.cm-logo-del:active { opacity: .7; }

/* Mi perfil (T12) — foto grande + botón "Cambiar foto" */
.cm-perfil-foto { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.cm-perfil-foto-img {
    width: 96px; height: 96px; border-radius: 50%; background-color: var(--surface-2); border: 1px solid var(--line);
    background-size: cover; background-position: center;
}
.cm-perfil-foto .cm-btn { width: auto; margin-top: 0; padding: 10px 18px; }

/* Mi perfil (T12) — horario semanal: fila día + chip activo/inactivo + hora inicio/fin */
.cm-week { display: flex; align-items: center; gap: 8px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.cm-week:last-child { border-bottom: 0; }
.cm-week-dia { flex: 0 0 32px; font-size: .82rem; font-weight: 700; color: var(--text); }
.cm-week .cm-chip { flex: 0 0 auto; min-height: 36px; padding: 6px 10px; font-size: .78rem; }
.cm-week .cm-input { flex: 1; min-width: 0; margin-bottom: 0; padding: 8px 10px; }
.cm-week.off { opacity: .55; }

/* Mi perfil (T12) — lista desplegable del autocompletar de especialidad */
.cm-select-list { margin-top: 6px; border: 1px solid var(--line); border-radius: var(--radius-sm); max-height: 240px; overflow-y: auto; background: var(--surface); }

/* ── Consulta por modelo (Objetivo 1a) ── */

/* Etiqueta de grupo dentro de una tira de chips (motivo/antecedentes/exam agrupados) */
.cm-chip-group {
    width: 100%; font-size: .72rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
    color: var(--accent); border-bottom: 1px solid var(--line); padding-bottom: 4px; margin: 10px 0 2px;
}
.cm-chip-group:first-child { margin-top: 0; }

/* Chip de medición (antropometría: peso, talla, IMC…) y su variante calculada (IMC) */
.cm-chip.measure { gap: 5px; }
.cm-chip.measure .mv { font-weight: 800; }
.cm-chip.measure .mu { font-size: .72rem; font-weight: 600; color: var(--muted); }
.cm-chip-clear {
    display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px;
    margin: -6px -8px -6px 0; border: 0; background: none; color: inherit; font-size: .78rem; line-height: 1;
    cursor: pointer; border-radius: 50%; flex-shrink: 0;
}
.cm-chip.computed { cursor: default; }
.cm-chip.computed.wait { opacity: .55; }

/* Checklist de examen (Goldman y similares): casillas por grupo + subchips + puntaje */
.cm-checklist {
    border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 10px 12px;
    background: color-mix(in srgb, var(--primary) 5%, transparent);
}
.cl-group { font-size: .78rem; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 10px 0 4px; }
.cl-group:first-child { margin-top: 0; }
label.cl-item { display: flex; align-items: center; gap: 10px; min-height: 44px; }
label.cl-item input[type="checkbox"] { width: 20px; height: 20px; flex-shrink: 0; accent-color: var(--primary); }
.cl-item.auto { opacity: .85; }
.cl-sub { display: flex; flex-wrap: wrap; gap: 6px; padding-left: 30px; margin: 2px 0 8px; }
.cl-score { font-weight: 800; border-top: 1px solid var(--line); padding-top: 8px; margin-top: 8px; }

/* Bloque de estudio (Estudios): cabecera colapsable + chips del catálogo + textarea libre */
.cm-study-block {
    border: 1px solid var(--line); border-left: 3px solid var(--primary); border-radius: var(--radius-sm);
    background: var(--surface); padding: 10px 12px; margin-bottom: 10px;
}
.cm-study-head { display: flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; }
.cm-study-head .cm-study-name { font-weight: 700; flex-shrink: 0; }
.cm-study-sum { flex: 1; min-width: 0; color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cm-study-head .cm-study-del {
    flex-shrink: 0; width: 44px; height: 44px; margin: -8px -8px -8px 0; border: 0; background: none; color: var(--muted);
    cursor: pointer; display: inline-flex; align-items: center; justify-content: center;
}
.cm-study-body { padding-top: 8px; }
.cm-study-body[hidden] { display: none; }

/* Tratamiento: fila de medicamento activo con posología (tres selects) */
.cm-med-item { width: 100%; }
.cm-med-item.active .cm-chip { width: 100%; }
.cm-med-pos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0 4px; }
@media (max-width: 359px) { .cm-med-pos { grid-template-columns: 1fr; } }
.cm-select {
    width: 100%; min-height: 44px; border: 1px solid var(--input-border); background: var(--input-bg); color: var(--text);
    border-radius: var(--radius-sm); padding: 8px 10px; font-family: inherit; font-size: .88rem; outline: 0;
}
.cm-select:focus { box-shadow: var(--focus); border-color: var(--primary); }

/* Colapsable genérico (secciones de indicaciones, grupos de favoritos…) */
.cm-collapse { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 10px; margin-bottom: 10px; }
.cm-collapse-head { display: flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; font-weight: 700; }
.cm-collapse-head .bi { transition: transform .15s var(--ease); }
.cm-collapse-head.open .bi { transform: rotate(180deg); }
.cm-collapse-body { padding-top: 6px; }
.cm-collapse-body[hidden] { display: none; }

/* Estrella de favorito (estudios/dx/medicamentos) */
.cm-star {
    width: 44px; height: 44px; border: 0; background: none; color: var(--muted); cursor: pointer; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center; font-size: 1.05rem;
}
.cm-star.on { color: var(--accent); }

/* Contador +/- (chips de medición y duraciones en el bottom sheet) */
.cm-stepper { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 6px 0; }
.cm-stepper button {
    width: 44px; height: 44px; flex-shrink: 0; border-radius: 50%; border: 1px solid var(--line); background: var(--surface-2);
    color: var(--text); font-size: 1.2rem; font-weight: 700; cursor: pointer; padding: 0; display: grid; place-items: center;
}
.cm-stepper button:active { transform: scale(.92); }
.cm-stepper input {
    width: 80px; min-height: 44px; text-align: center; border: 1px solid var(--input-border); background: var(--input-bg);
    color: var(--text); border-radius: var(--radius-sm); font-size: 1.05rem; font-weight: 700; outline: 0; -moz-appearance: textfield;
}
.cm-stepper input::-webkit-outer-spin-button, .cm-stepper input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.cm-stepper input:focus { box-shadow: var(--focus); border-color: var(--primary); }
.cm-stepper-unit { color: var(--muted); font-size: .88rem; font-weight: 600; }

/* Texto auxiliar pequeño */
.cm-mini { font-size: .78rem; color: var(--muted); }

/* Tira de etapas: punto que marca una etapa con contenido */
.cm-etapa-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); flex-shrink: 0; }

/* Diagnóstico: supertexto y resultados del buscador CIE-10 */
.cm-dx-text { min-height: 90px; }
.cm-results { display: flex; flex-direction: column; margin-top: 6px; }
.cm-result { display: flex; align-items: center; gap: 8px; min-height: 44px; border-bottom: 1px solid var(--line); cursor: pointer; }
.cm-result:last-child { border-bottom: 0; }
.cm-result b { color: var(--primary); font-weight: 800; flex-shrink: 0; }

/* Ancho grande (tablet en vertical): centrar el contenido, el dock sigue abajo */
@media (min-width: 640px) {
    .cm-view { padding-left: max(16px, calc(50% - 300px)); padding-right: max(16px, calc(50% - 300px)); }
    .cm-hdr { padding-left: max(12px, calc(50% - 304px)); padding-right: max(12px, calc(50% - 304px)); }
    .cm-dock { padding-left: max(4px, calc(50% - 300px)); padding-right: max(4px, calc(50% - 300px)); }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* Documentos (1c.1): visor de hojas D1 (documento.js) + visor de archivos R2 */
.cm-doc-stage { padding: 12px; background: var(--bg); }
.cm-doc-sheets { transform-origin: top center; }
.cm-doc-sheet {
    background: var(--paper); color: var(--ink); box-shadow: var(--shadow); margin: 0 auto 14px auto;
    box-sizing: border-box; position: relative; flex: 0 0 auto;
}
.cm-doc-body { white-space: pre-wrap; word-wrap: break-word; font-family: Georgia, 'Times New Roman', serif; font-size: 13px; line-height: 1.5; }
/* Barra inferior fija dentro de la vista (pegada al fondo del scroll de .cm-view, no del documento) */
.cm-doc-bar {
    position: sticky; bottom: calc(var(--dock-h) + env(safe-area-inset-bottom)); z-index: 2; display: flex; background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px;
}
.cm-doc-bar button {
    flex: 1; min-height: 44px; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; border: 0; background: none; color: var(--text); font-family: inherit; font-size: .66rem; font-weight: 600; padding: 6px 4px 4px; cursor: pointer;
}
.cm-doc-bar button .bi { font-size: 1.25rem; line-height: 1; }
.cm-doc-bar button:active { opacity: .7; }
.cm-doc-bar-mas { font-size: 1.3rem; line-height: 1; font-weight: 800; }
/* Visor de archivo (imagen/video/PDF de R2) */
img.cm-doc-file, video.cm-doc-file { display: block; max-width: 100%; height: auto; margin: 0 auto; }
iframe.cm-doc-file { display: block; width: 100%; height: calc(100vh - 220px); min-height: 320px; border: 0; }
/* Fila de historial (sheet «Historial») */
.cm-hist-row { padding: 10px 2px; border-bottom: 1px solid var(--line); }
.cm-hist-row:last-child { border-bottom: 0; }
.cm-hist-row b { display: block; font-size: .92rem; font-weight: 700; }
.cm-hist-row small { display: block; color: var(--muted); font-size: .8rem; margin-top: 2px; }

/* Generar documentos (1c.2): sheet de tipo → estudios/días/especialidad → vista previa (generar.js) */
.cm-gen-opts {
    display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 10px 12px 8px;
    background: var(--surface); border-bottom: 1px solid var(--line);
}
.cm-gen-opts::-webkit-scrollbar { display: none; }
.cm-gen-opts .cm-chip { flex: 0 0 auto; min-height: 36px; white-space: nowrap; }
/* Barra inferior fija de la vista previa: mismo patrón que .cm-doc-bar (icono + rótulo, 44px) */
.cm-gen-bar {
    position: sticky; bottom: calc(var(--dock-h) + env(safe-area-inset-bottom)); z-index: 2; display: flex; background: var(--surface); border-top: 1px solid var(--line);
    padding: 6px 4px;
}
.cm-gen-bar button {
    flex: 1; min-height: 44px; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px; border: 0; background: none; color: var(--text); font-family: inherit; font-size: .66rem; font-weight: 600; padding: 6px 4px 4px; cursor: pointer;
}
.cm-gen-bar button .bi { font-size: 1.25rem; line-height: 1; }
.cm-gen-bar button:active { opacity: .7; }
#cmGenGuardar { color: var(--primary); }
/* Editor de texto plano a pantalla completa (regenera el documento al aceptar) */
.cm-gen-editor { min-height: 60vh; width: 100%; font-family: Georgia, 'Times New Roman', serif; font-size: .95rem; line-height: 1.5; }

/* ── Ficha del paciente (1b) ── */

/* Fila de segmentos (Datos · Antecedentes · Consultas · Archivos · Pediatría · Laboratorio) */
.cm-seg { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; margin: 10px 0 14px; padding-bottom: 2px; }
.cm-seg::-webkit-scrollbar { display: none; }
.cm-seg button {
    flex: 0 0 auto; min-height: 44px; padding: 8px 14px; border-radius: 20px; border: 1px solid var(--line);
    background: var(--surface-2); color: var(--text); font-size: .85rem; font-weight: 700; cursor: pointer;
    display: inline-flex; align-items: center; gap: 6px;
}
.cm-seg button.active { background: var(--tint-primary); color: var(--primary); border-color: transparent; }

/* Interruptor accesible (Normales/No contributorio, Adulto-Pediátrico, WhatsApp/Telegram…) */
.cm-switch { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 44px; cursor: pointer; -webkit-user-select: none; user-select: none; }
.cm-switch-label { flex: 1; min-width: 0; font-size: .9rem; font-weight: 600; }
.cm-switch input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.cm-switch-track {
    flex-shrink: 0; width: 46px; height: 26px; border-radius: 14px; background: var(--surface-2); border: 1px solid var(--line);
    position: relative; transition: background .15s, border-color .15s;
}
.cm-switch-thumb {
    position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: var(--surface);
    box-shadow: var(--shadow); transition: transform .15s var(--ease);
}
.cm-switch input:checked + .cm-switch-track { background: var(--primary); border-color: transparent; }
.cm-switch input:checked + .cm-switch-track .cm-switch-thumb { transform: translateX(20px); background: var(--primary-ink); }
.cm-switch input:focus-visible + .cm-switch-track { box-shadow: var(--focus); }

/* Rejilla de formulario (Datos, filiación…): 1 columna; `.dos` = 2 en ≥360px */
.cm-form-grid { display: grid; grid-template-columns: 1fr; gap: 4px 12px; }
@media (min-width: 360px) { .cm-form-grid.dos { grid-template-columns: 1fr 1fr; } }

/* Subpanel indentado (detalle de una condición/hábito activado) */
.cm-panel { border: 1px solid var(--line); border-radius: var(--radius-sm); background: color-mix(in srgb, var(--primary) 5%, transparent); padding: 10px 12px; margin: 6px 0 14px 14px; }

/* Vacunas: fila por biológico con celdas de dosis (fecha + lote apilados) */
.cm-imm-row { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 4px 12px; margin-bottom: 8px; }
.cm-imm-row-head { display: flex; align-items: center; gap: 8px; min-height: 44px; cursor: pointer; font-weight: 700; font-size: .9rem; }
.cm-imm-row-head .bi:last-child { margin-left: auto; color: var(--muted); transition: transform .15s var(--ease); }
.cm-imm-row.open .cm-imm-row-head .bi:last-child { transform: rotate(90deg); }
.cm-imm-cells { display: none; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; padding: 2px 0 10px; }
.cm-imm-row.open .cm-imm-cells { display: grid; }
.cm-imm-cell { display: flex; flex-direction: column; gap: 4px; }
.cm-imm-cell label { font-size: .66rem; color: var(--muted); font-weight: 700; text-align: center; }
.cm-imm-cell input { min-height: 38px; padding: 6px 6px; font-size: .78rem; margin-bottom: 0; text-align: center; }

/* Curva de crecimiento: SVG con percentiles P3–P97 */
.cm-curve { width: 100%; height: 260px; display: block; }
.cm-curve .cc-grid { stroke: var(--line); stroke-width: 1; }
.cm-curve .cc-p { fill: none; stroke: var(--muted); stroke-width: 1.3; }
.cm-curve .cc-p50 { stroke: var(--primary); stroke-width: 2.2; }
.cm-curve .cc-pt { fill: var(--accent); }
.cm-curve .cc-lbl { fill: var(--muted); font-size: 9px; }

/* Laboratorio: tarjeta de último valor por prueba */
.cm-lab-card { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 11px 12px; margin-bottom: 8px; cursor: pointer; }
.cm-lab-card .lc-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cm-lab-card .lc-name { font-weight: 700; font-size: .9rem; }
.cm-lab-card .lc-val { font-size: 1.05rem; font-weight: 800; flex-shrink: 0; }
.cm-lab-card .lc-meta { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: .76rem; margin-top: 2px; }
.cm-lab-hist { padding-top: 8px; margin-top: 4px; border-top: 1px dashed var(--line); }

/* Foto grande de cabecera (88px) */
.cm-avatar-lg {
    width: 88px; height: 88px; border-radius: 50%; background-color: var(--surface-2); border: 1px solid var(--line);
    background-size: cover; background-position: center; flex-shrink: 0; display: grid; place-items: center; color: var(--muted); font-size: 2rem;
}

/* ── Marca «va al informe» en cada campo de la consulta (Miguel 2026-09-07) ── */
.cm-h.cm-h-inf { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.cm-inf-mark {
    flex: 0 0 auto; width: 36px; height: 36px; margin: -8px -6px -8px 0; border-radius: var(--radius-sm); border: 0;
    background: transparent; color: var(--muted); display: grid; place-items: center; font-size: 1.15rem; cursor: pointer; padding: 0;
}
.cm-inf-mark.on { color: var(--primary); }
.cm-inf-mark:active { transform: scale(.92); }

/* ── Candado «desliza para editar» (ui/candado.js), igual que la web app ──
   Bloquea la EDICIÓN, no la lectura: el contenido se ve y se desplaza normal; los controles quedan
   inertes y una barra fija abajo ofrece deslizar para editar. Sin capa ni desenfoque. */
.cm-lock-host { position: relative; }
.cm-lock-host.cm-locked .cm-input, .cm-lock-host.cm-locked .cm-select, .cm-lock-host.cm-locked .cm-chip,
.cm-lock-host.cm-locked .cm-switch, .cm-lock-host.cm-locked .cm-row-del, .cm-lock-host.cm-locked .cm-inf-mark,
.cm-lock-host.cm-locked .cm-btn, .cm-lock-host.cm-locked .cm-star, .cm-lock-host.cm-locked .cm-stepper,
.cm-lock-host.cm-locked [data-medida], .cm-lock-host.cm-locked [data-frase], .cm-lock-host.cm-locked .cm-med-pos { pointer-events: none; }
.cm-lock-host.cm-locked .cm-input, .cm-lock-host.cm-locked .cm-select { opacity: .85; }
.cm-lock-host.cm-locked .cm-collapse-head, .cm-lock-host.cm-locked .cm-study-head, .cm-lock-host.cm-locked .cm-acc .cm-hd, .cm-lock-host.cm-locked .cm-seg, .cm-lock-host.cm-locked .cm-row[data-k] { pointer-events: auto; }
.cm-lock {
    position: sticky; bottom: calc(var(--dock-h) + env(safe-area-inset-bottom) + 8px); z-index: 4; display: flex; justify-content: center; padding: 10px 0 2px; pointer-events: none;
}
.cm-lock-card { display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: auto; }
.cm-lock-track {
    position: relative; width: min(280px, 80vw); height: 56px; border-radius: 28px; overflow: hidden;
    background: color-mix(in srgb, var(--surface) 92%, transparent); border: 1px solid color-mix(in srgb, var(--text) 18%, transparent); box-shadow: var(--shadow);
    backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.cm-lock-hint {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding-left: 44px;
    font-size: .8rem; font-weight: 700; color: var(--text); pointer-events: none; white-space: nowrap; transition: opacity .15s;
}
.cm-lock-knob {
    position: absolute; top: 4px; left: 4px; width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center;
    font-size: 1.35rem; color: var(--primary-ink); cursor: grab; touch-action: none; user-select: none;
    /* Rojo VIVO y traslúcido como el candado de la web app. */
    background: color-mix(in srgb, var(--danger) 78%, transparent); border: 1px solid color-mix(in srgb, var(--danger) 90%, transparent);
    box-shadow: var(--shadow); transition: background .2s;
}
.cm-lock-knob.open { background: color-mix(in srgb, var(--accent) 78%, transparent); border-color: color-mix(in srgb, var(--accent) 90%, transparent); }
.cm-lock-sub { display: none; }

/* ── Herramientas al lado de cada textbox de la consulta: micrófono, imagen y miniaturas ── */
.cm-ta-tools { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin: -6px 0 10px; }
.cm-ta-thumbs { display: flex; flex-wrap: wrap; gap: 6px; flex: 1; min-width: 0; }
.cm-ta-thumb { position: relative; width: 56px; height: 56px; border-radius: var(--radius-sm); overflow: hidden; border: 1px solid var(--line); background: var(--surface-2); display: grid; place-items: center; color: var(--muted); }
.cm-ta-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cm-ta-thumb-del { position: absolute; top: 0; right: 0; width: 22px; height: 22px; border: 0; border-radius: 0 0 0 var(--radius-sm); background: color-mix(in srgb, var(--bg) 70%, transparent); color: var(--text); display: grid; place-items: center; padding: 0; font-size: .8rem; }
.cm-ta-btns { display: flex; gap: 6px; flex: 0 0 auto; }
.cm-ta-btn { width: 40px; height: 40px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); display: grid; place-items: center; font-size: 1.1rem; padding: 0; cursor: pointer; }
.cm-ta-btn.on { color: var(--primary-ink); background: var(--primary); border-color: transparent; }
.cm-ta-btn:active { transform: scale(.94); }
.cm-lock-host.cm-locked .cm-ta-btn, .cm-lock-host.cm-locked .cm-ta-thumb-del { pointer-events: none; opacity: .5; }

/* ── Laboratorio: carga masiva (texto / foto / panel), revisión y pruebas dinámicas ── */
.cm-lab-acciones { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.cm-lab-acciones .cm-btn { margin: 0; font-size: .84rem; padding-left: 8px; padding-right: 8px; }
.cm-lab-foto { width: 100%; max-height: 220px; object-fit: contain; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--surface-2); margin-bottom: 10px; display: block; }
.cm-lab-fotobtns { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cm-lab-fotobtns .cm-btn { margin: 0; }
.cm-lab-panel { max-height: 52dvh; overflow-y: auto; margin: 8px 0 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 0 10px; }
.cm-lab-sub { font-size: .68rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 700; padding: 10px 0 4px; }
.cm-lab-prow { display: flex; align-items: center; gap: 10px; min-height: 46px; border-bottom: 1px solid var(--line); }
.cm-lab-prow:last-child { border-bottom: 0; }
.cm-lab-prow label { flex: 1; min-width: 0; font-size: .86rem; font-weight: 600; }
.cm-lab-prow .cm-input { flex: 0 0 96px; min-height: 38px; padding: 6px 8px; margin: 4px 0; text-align: right; font-size: .9rem; }
.cm-lab-rev { margin-bottom: 8px; }
.cm-lab-rrow { padding: 10px 0; border-bottom: 1px solid var(--line); }
.cm-lab-rrow:last-child { border-bottom: 0; }
.cm-lab-rrow.sin .cm-select { border-color: var(--warn); }
.cm-lab-rname { font-size: .8rem; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.cm-lab-rrow .cm-select { margin-bottom: 6px; }
.cm-lab-rvals { display: flex; gap: 8px; align-items: center; }
.cm-lab-rvals .cm-input { flex: 1; min-width: 0; margin: 0; }
.cm-lab-rvals .cm-row-del { flex: 0 0 auto; }
.cm-lab-opc .cm-check-row { padding: 4px 2px 8px; }
.cm-lab-dt { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 8px 12px; margin-bottom: 10px; }
.cm-lab-dt-h { font-weight: 700; font-size: .9rem; margin-bottom: 6px; }
.cm-lab-dt-h small { color: var(--muted); font-weight: 600; }
.cm-lab-dt-cells { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 8px; }
.cm-lab-dt-cell label { display: block; font-size: .66rem; color: var(--muted); font-weight: 700; text-align: center; margin-bottom: 3px; }
.cm-lab-dt-cell .cm-input { min-height: 40px; padding: 6px; text-align: center; margin: 0; font-size: .88rem; }
.cm-lab-curva { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 56px; padding: 8px 12px; margin-bottom: 8px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); text-align: left; cursor: pointer; }
.cm-lab-curva > .bi:first-child { color: var(--primary); font-size: 1.2rem; }
.cm-lab-curva > .bi:last-child { margin-left: auto; color: var(--muted); }
.cm-lab-curva span { display: flex; flex-direction: column; min-width: 0; }
.cm-lab-curva b { font-size: .88rem; }
.cm-lab-curva small { color: var(--muted); font-size: .74rem; }
.cm-lab-fecha { font-size: .8rem; color: var(--muted); margin: -4px 0 8px; }
.cm-lab-svg { height: 220px; }
.cm-lab-svg path { fill: none; stroke-width: 2.2; }
.cm-lab-svg .cc-grid { stroke: var(--line); stroke-width: 1; }
.cm-lab-svg .cc-lbl { fill: var(--muted); font-size: 9px; }
.cm-lab-svg .lc-s0, .cm-lab-leg .lc-s0 { stroke: var(--primary); }
.cm-lab-svg .lc-s1, .cm-lab-leg .lc-s1 { stroke: var(--accent); }
.cm-lab-svg .lc-s2, .cm-lab-leg .lc-s2 { stroke: var(--warn); }
.cm-lab-svg .lc-s3, .cm-lab-leg .lc-s3 { stroke: var(--danger); }
.cm-lab-svg circle.lc-s0 { fill: var(--primary); } .cm-lab-svg circle.lc-s1 { fill: var(--accent); } .cm-lab-svg circle.lc-s2 { fill: var(--warn); } .cm-lab-svg circle.lc-s3 { fill: var(--danger); }
.cm-lab-legs { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 8px 0 4px; }
.cm-lab-leg { display: inline-flex; align-items: center; gap: 6px; font-size: .8rem; font-weight: 600; }
.cm-lab-leg i { width: 14px; height: 3px; border-radius: 2px; display: inline-block; background: currentColor; }
.cm-lab-leg .lc-s0 { color: var(--primary); } .cm-lab-leg .lc-s1 { color: var(--accent); } .cm-lab-leg .lc-s2 { color: var(--warn); } .cm-lab-leg .lc-s3 { color: var(--danger); }
.cm-lab-leg small { color: var(--muted); font-weight: 500; }
