/* =====================================================================
   Selector de fotos comun (assets/js/fotos_selector.js).

   Dos overlays con prefijo .fs- para no chocar con Bootstrap ni con las
   escenas: el selector (.fs-overlay, z-index 1080) y el visor de camara en
   vivo (.fs-cam, z-index 1095). Ambos van por encima del modal de Bootstrap
   de la app (1075) porque la agenda los abre CON su modal todavia abierto.
   Los z-index tambien se ponen inline desde el JS: aqui quedan como respaldo
   documentado.

   Moviles primero (393 px de ancho es la referencia): el selector es una
   hoja pegada abajo con bordes de 16 px; en escritorio se centra. Botones
   de 48 px de alto minimo para que se atinen con el pulgar.
   ===================================================================== */

/* ---------- selector ---------- */

.fs-overlay {
    position: fixed;
    inset: 0;
    z-index: 1080;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 12px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    background: rgba(15, 23, 42, .55);
    -webkit-tap-highlight-color: transparent;
    animation: fs-aparece .15s ease-out;
}

.fs-dialogo {
    width: 100%;
    max-width: 520px;
    max-height: calc(100vh - 24px);
    max-height: calc(100dvh - 24px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    background: #fff;
    color: #1e293b;
    border-radius: 16px;
    padding: 16px;
    box-shadow: 0 18px 48px rgba(15, 23, 42, .35);
    font-family: inherit;
    outline: none;
    animation: fs-sube .18s ease-out;
}

.fs-cabecera {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.fs-titulo {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 800;
    line-height: 1.3;
    display: flex;
    align-items: center;
    gap: 8px;
}
.fs-titulo .bi { color: #0b5ed7; }

.fs-x {
    flex: none;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: #f1f5f9;
    color: #475569;
    font-size: 1rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.fs-x:hover { background: #e2e8f0; }

/* Boton "Tomar con la camara": un renglon ancho con icono en circulo. */
.fs-cam-btn {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 14px;
    margin-bottom: 10px;
    border: 1px solid #cbd5e1;
    border-radius: 16px;
    background: #fff;
    color: #1e293b;
    text-align: left;
    cursor: pointer;
    min-height: 64px;
    touch-action: manipulation;
}
.fs-cam-btn:hover { border-color: #0b5ed7; background: #f8fbff; }
.fs-cam-btn:focus-visible, .fs-zona:focus-visible, .fs-btn:focus-visible, .fs-x:focus-visible {
    outline: 3px solid rgba(11, 94, 215, .45);
    outline-offset: 2px;
}
.fs-cam-btn-icono {
    flex: none;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #0b5ed7;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
}
.fs-cam-btn-texto { display: flex; flex-direction: column; line-height: 1.3; }
.fs-cam-btn-texto b { font-size: 1rem; }
.fs-cam-btn-texto small { color: #64748b; font-size: .8rem; }

/* Zona de arrastrar y soltar / tocar para elegir. */
.fs-zona {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 22px 12px;
    border: 2px dashed #94a3b8;
    border-radius: 16px;
    background: #f8fafc;
    color: #334155;
    text-align: center;
    cursor: pointer;
    min-height: 120px;
    transition: border-color .15s, background .15s;
    touch-action: manipulation;
}
.fs-zona .bi { font-size: 2rem; color: #0b5ed7; line-height: 1; margin-bottom: 4px; }
.fs-zona b { font-size: 1rem; }
.fs-zona small { color: #64748b; font-size: .8rem; }
.fs-zona.fs-sobre { border-color: #0b5ed7; background: #eff6ff; }
.fs-zona.fs-llena { opacity: .5; cursor: not-allowed; }
.fs-zona.fs-llena small::after { content: " (ya tienes el máximo)"; }

.fs-aviso {
    margin-top: 10px;
    padding: 10px 12px;
    border-radius: 12px;
    background: #fef3c7;
    color: #92400e;
    font-size: .85rem;
    line-height: 1.35;
}

/* Parrilla de vistas previas: cuadros de 3 en 3 en telefono, 4 en escritorio. */
.fs-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 12px;
}
.fs-thumb {
    position: relative;
    aspect-ratio: 1 / 1;
    border-radius: 12px;
    background: #e2e8f0 center / cover no-repeat;
    overflow: hidden;
}
.fs-thumb button {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 30px;
    height: 30px;
    border: 0;
    border-radius: 50%;
    background: rgba(15, 23, 42, .7);
    color: #fff;
    font-size: .85rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.fs-thumb button:hover { background: #dc2626; }

.fs-pie {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 14px;
}
.fs-contador { font-size: .8rem; color: #64748b; font-weight: 700; }
.fs-acciones { display: flex; gap: 10px; }

/* Mientras se comprimen archivos el contador late; el boton de usar se deshabilita desde el JS. */
.fs-procesando .fs-contador::after { content: " · procesando…"; color: #0b5ed7; animation: fs-late 1s ease-in-out infinite; }

/* Botones grandes compartidos por los dos overlays. */
.fs-btn {
    flex: 1 1 0;
    min-height: 48px;
    padding: 10px 16px;
    border-radius: 12px;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: #1e293b;
    font-weight: 700;
    font-size: 1rem;
    line-height: 1.2;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    touch-action: manipulation;
    transition: background .15s, opacity .15s;
}
.fs-btn-sec:hover { background: #f1f5f9; }
.fs-btn-pri { background: #0b5ed7; border-color: #0b5ed7; color: #fff; }
.fs-btn-pri:hover { background: #0a53be; }
.fs-btn:disabled { opacity: .5; cursor: not-allowed; }

@media (min-width: 576px) {
    .fs-overlay { align-items: center; }
    .fs-dialogo { padding: 20px; }
    .fs-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .fs-pie { flex-direction: row; align-items: center; justify-content: space-between; }
    .fs-acciones { flex: none; }
    .fs-btn { flex: none; min-width: 140px; }
}

/* ---------- camara en vivo ---------- */

.fs-cam {
    position: fixed;
    inset: 0;
    z-index: 1095;
    display: flex;
    flex-direction: column;
    background: #000;
    color: #fff;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

.fs-cam-top {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: calc(10px + env(safe-area-inset-top, 0px)) 14px 10px;
    background: rgba(0, 0, 0, .78);
}
.fs-cam-titulo { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.fs-cam-titulo-linea { display: flex; align-items: center; gap: 8px; }
.fs-cam-titulo b { font-size: 1rem; }
.fs-cam-titulo small { color: rgba(255, 255, 255, .7); font-size: .78rem; }
.fs-cam-titulo .bi { color: #fff; }
.fs-cam-x {
    flex: none;
    width: 42px;
    height: 42px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .15);
    color: #fff;
    font-size: 1.1rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

/* El visor: el video se muestra COMPLETO (contain), no recortado, para que
   lo que se ve sea exactamente el cuadro que se captura. */
.fs-cam-vista {
    flex: 1 1 auto;
    position: relative;
    min-height: 0;
    overflow: hidden;
    background: #000;
}
.fs-cam-vista video, .fs-cam-vista img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: contain;
    background: #000;
}
.fs-cam-vista video[hidden], .fs-cam-vista img[hidden] { display: none; }

.fs-cam-error {
    position: absolute;
    left: 16px;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
    padding: 18px 16px;
    border-radius: 16px;
    background: rgba(255, 255, 255, .12);
    border: 1px solid rgba(255, 255, 255, .25);
    text-align: center;
    font-size: 1rem;
    line-height: 1.45;
}
.fs-cam-aviso {
    position: absolute;
    left: 16px;
    right: 16px;
    bottom: 16px;
    padding: 10px 12px;
    border-radius: 12px;
    background: rgba(220, 38, 38, .9);
    text-align: center;
    font-size: .9rem;
}

/* Destello al disparar: confirma que la foto fue ESE cuadro. */
.fs-cam.fs-flash .fs-cam-vista::after {
    content: "";
    position: absolute;
    inset: 0;
    background: #fff;
    animation: fs-destello .18s ease-out forwards;
}

.fs-cam-barra {
    flex: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 16px calc(20px + env(safe-area-inset-bottom, 0px));
    background: rgba(0, 0, 0, .78);
    min-height: 112px;
}
.fs-cam:focus, .fs-dialogo:focus { outline: none; }
.fs-cam-sec {
    flex: none;
    width: 54px;
    height: 54px;
    border: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, .15);
    color: #fff;
    font-size: 1.5rem;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.fs-cam-hueco { background: transparent; }
.fs-invisible { visibility: hidden; }

/* Disparador: anillo grande blanco con boton interior, como en las camaras nativas. */
.fs-cam-disparo {
    flex: none;
    width: 78px;
    height: 78px;
    border-radius: 50%;
    border: 4px solid #fff;
    background: transparent;
    padding: 0;
    cursor: pointer;
    position: relative;
    touch-action: manipulation;
}
.fs-cam-disparo::after {
    content: "";
    position: absolute;
    inset: 5px;
    border-radius: 50%;
    background: #fff;
    transition: transform .1s;
}
.fs-cam-disparo:active::after { transform: scale(.88); }
.fs-cam-disparo:disabled { opacity: .35; cursor: wait; }
.fs-cam-disparo:focus-visible { outline: 3px solid rgba(11, 94, 215, .8); outline-offset: 3px; }

/* A 393 px caben "Repetir" y "Usar esta foto" en un renglon: letra un pelo menor, sin partir, y el primario mas ancho. */
.fs-cam-barra .fs-btn { border-color: rgba(255, 255, 255, .35); font-size: .95rem; padding: 10px 12px; white-space: nowrap; }
.fs-cam-barra [data-usar] { flex: 1.5 1 0; }
.fs-cam-barra .fs-btn-sec { background: rgba(255, 255, 255, .12); color: #fff; }
.fs-cam-barra .fs-btn-sec:hover { background: rgba(255, 255, 255, .22); }
.fs-cam-barra .fs-btn-pri { border-color: #0b5ed7; }
.fs-cam-barra[data-modo="error"] .fs-btn { flex: 1 1 0; }

@media (min-width: 576px) {
    .fs-cam-barra { justify-content: center; gap: 28px; }
    .fs-cam-barra .fs-btn { min-width: 200px; }
}

/* ---------- animaciones ---------- */

@keyframes fs-aparece { from { opacity: 0; } to { opacity: 1; } }
@keyframes fs-sube { from { transform: translateY(12px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes fs-destello { from { opacity: .95; } to { opacity: 0; } }
@keyframes fs-late { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }

@media (prefers-reduced-motion: reduce) {
    .fs-overlay, .fs-dialogo, .fs-cam.fs-flash .fs-cam-vista::after, .fs-procesando .fs-contador::after { animation: none; }
}
