/**
 * 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 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-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; }
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) ── */
.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);
}
body.cm-fullscreen .cm-dock { transform: translateY(calc(100% + 48px)); } /* +48px: el FAB central sobresale 22px del dock y lleva sombra */
.cm-tab {
    flex: 1; min-width: 0; min-height: var(--tap); background: none; border: 0; padding: 4px 0 0; cursor: pointer;
    color: var(--muted); display: flex; flex-direction: column; align-items: center; gap: 3px;
    font-size: .66rem; font-weight: 600; letter-spacing: .01em; position: relative; -webkit-user-select: none;
    transition: color .15s;
}
.cm-tab .bi { font-size: 1.4rem; line-height: 1; transition: transform .15s var(--ease); }
.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 .cm-lbl { margin-top: 36px; }
.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 ── */
.cm-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px 16px; margin-bottom: 13px; }
.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; }

/* Acordeón (Configuración: todo en la MISMA vista) */
.cm-acc { border: 1px solid var(--line); border-radius: 14px; overflow: hidden; margin-bottom: 10px; background: var(--surface); }
.cm-acc .cm-hd { display: flex; align-items: center; gap: 12px; padding: 13px 15px; min-height: 52px; cursor: pointer; -webkit-user-select: none; }
.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 15px 14px; color: var(--muted); font-size: .88rem; line-height: 1.5; }
.cm-acc.open .cm-bd { display: block; animation: cmFade .18s var(--ease); }

/* 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 */
.cm-profile { display: flex; align-items: center; gap: 14px; }
.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; }
.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; }
.cm-login-logo { display: block; max-height: 64px; width: auto; margin: 0 auto 18px; }
.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-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; }

.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); }

/* 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; }
}
