/* Estilos base — mobile-first, botones grandes para uso con el dedo en barra. */

:root {
    --azul: #0b5fa5;
    --azul-oscuro: #084a82;
    --verde: #1a7a3c;
    --rojo: #b3261e;
    --gris-fondo: #f4f5f7;
    --gris-borde: #d9dce1;
    --gris-texto: #4a4f57;
    --radio: 12px;
    --sombra: 0 2px 8px rgba(0, 0, 0, 0.08);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--gris-fondo);
    color: #1c1e21;
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

button, input, select {
    font-family: inherit;
    font-size: 1rem;
}

/* ---------- Cabecera y navegación ---------- */

/* Sin "position: sticky": al no fijarse arriba, la cabecera desplaza hacia
   arriba con el scroll y deja más espacio útil en pantallas pequeñas. */
.cabecera {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--azul);
    color: #fff;
    padding: 0.55rem 1rem;
}

.cabecera h1 {
    font-size: 1.05rem;
    margin: 0;
    font-weight: 600;
}

.cabecera nav {
    display: flex;
    gap: 0.5rem;
}

.cabecera button {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 0.4rem 0.6rem;
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
}

/* ---------- Contenedor general de pantalla ---------- */

.pantalla {
    display: none;
    padding: 0.6rem 0.8rem;
    max-width: 640px;
    margin: 0 auto;
    padding-bottom: 1.5rem;
}

.pantalla.activa { display: block; }

.tarjeta {
    background: #fff;
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    padding: 0.9rem 1rem;
    margin-bottom: 0.7rem;
}

/* ---------- Formulario principal ---------- */

.grupo-campo {
    margin-bottom: 0.9rem;
}

.grupo-campo > label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.35rem;
    color: var(--gris-texto);
}

.selector-barra {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
}

.opcion-barra {
    border: 2px solid var(--gris-borde);
    background: #fff;
    border-radius: var(--radio);
    padding: 0.85rem 0.5rem;
    font-size: 1.1rem;
    font-weight: 700;
    text-align: center;
    cursor: pointer;
    color: #1c1e21;
}

.opcion-barra.seleccionada {
    border-color: var(--azul);
    background: #e8f1fb;
    color: var(--azul-oscuro);
}

input[type="text"], input[type="number"], input[type="password"], input[type="datetime-local"] {
    width: 100%;
    padding: 0.65rem 0.85rem;
    border: 2px solid var(--gris-borde);
    border-radius: var(--radio);
    background: #fff;
}

input:focus { outline: 2px solid var(--azul); }

.campo-importe {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.campo-importe input { font-size: 1.3rem; font-weight: 700; text-align: right; }
.campo-importe span { font-size: 1.2rem; font-weight: 700; color: var(--gris-texto); }

.enlace-discreto {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    color: var(--azul-oscuro);
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.3rem 0;
    cursor: pointer;
}

/* ---------- Combobox de personas ---------- */

.combo { position: relative; }

.combo-lista {
    display: none;
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    background: #fff;
    border: 1px solid var(--gris-borde);
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    max-height: 220px;
    overflow-y: auto;
    z-index: 5;
}

.combo-lista.abierta { display: block; }

.combo-item {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    padding: 0.75rem 0.9rem;
    border-bottom: 1px solid #f0f0f0;
    cursor: pointer;
}

.combo-item:last-child { border-bottom: none; }
.combo-item:hover, .combo-item:active { background: var(--gris-fondo); }
.combo-item.nuevo { color: var(--azul-oscuro); font-weight: 600; }

/* ---------- Botones ---------- */

.boton {
    display: block;
    width: 100%;
    padding: 0.75rem;
    border-radius: var(--radio);
    border: none;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    text-align: center;
}

.boton-primario { background: var(--azul); color: #fff; }
.boton-secundario { background: #fff; color: var(--gris-texto); border: 2px solid var(--gris-borde); }
.boton-peligro { background: #fff; color: var(--rojo); border: 2px solid var(--rojo); }
.boton-exito { background: var(--verde); color: #fff; }
.boton:disabled { opacity: 0.5; cursor: not-allowed; }

.fila-botones { display: grid; grid-template-columns: 1fr 1fr; gap: 0.6rem; margin-top: 0.7rem; }

/* ---------- Pantalla de resumen/confirmación ---------- */

.resumen-grande {
    text-align: center;
    padding: 0.4rem 0 0.7rem;
}

.resumen-barra { font-size: 1.15rem; font-weight: 700; color: var(--azul-oscuro); }
.resumen-importe { font-size: 2.2rem; font-weight: 800; margin: 0.1rem 0; }
.resumen-hora { color: var(--gris-texto); font-size: 0.9rem; }
.resumen-conformidad { text-align: center; font-size: 0.85rem; color: var(--gris-texto); margin-bottom: 0.6rem; }

.selector-modo-firma {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.selector-modo-firma button {
    padding: 0.5rem;
    border-radius: 8px;
    border: 2px solid var(--gris-borde);
    background: #fff;
    font-weight: 600;
}

.selector-modo-firma button.activo { border-color: var(--azul); background: #e8f1fb; color: var(--azul-oscuro); }

.zona-firma canvas {
    width: 100%;
    height: 170px;
    background: #fff;
    border: 2px dashed var(--gris-borde);
    border-radius: var(--radio);
    touch-action: none;
}

.zona-firma video, .zona-firma .foto-previa {
    width: 100%;
    max-height: 200px;
    border-radius: var(--radio);
    background: #000;
    object-fit: cover;
}

.acciones-firma { display: flex; justify-content: flex-end; margin-top: 0.25rem; }
.acciones-firma button { background: none; border: none; color: var(--azul-oscuro); font-weight: 600; padding: 0.3rem; }

/* ---------- Pantalla de éxito ---------- */

.pantalla-exito {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    background: var(--verde);
    color: #fff;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
}

.pantalla-exito.activa { display: flex; }
.pantalla-exito .icono { font-size: 5rem; }
.pantalla-exito h2 { font-size: 1.8rem; margin: 0.5rem 0; }

/* ---------- Historial ---------- */

.totales-historial {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 0.6rem;
    margin-bottom: 1rem;
}

.total-tarjeta {
    background: #fff;
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    padding: 0.8rem 0.5rem;
    text-align: center;
}

.total-tarjeta .etiqueta { font-size: 0.75rem; color: var(--gris-texto); text-transform: uppercase; }
.total-tarjeta .valor { font-size: 1.1rem; font-weight: 800; margin-top: 0.2rem; }

.filtros-historial { display: flex; gap: 0.5rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filtros-historial button {
    flex: 1;
    padding: 0.55rem;
    border-radius: 8px;
    border: 2px solid var(--gris-borde);
    background: #fff;
    font-weight: 600;
}
.filtros-historial button.activo { border-color: var(--azul); background: #e8f1fb; color: var(--azul-oscuro); }

.lista-retiradas { list-style: none; margin: 0; padding: 0; }

.fila-retirada {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fff;
    border-radius: var(--radio);
    box-shadow: var(--sombra);
    padding: 0.8rem 1rem;
    margin-bottom: 0.6rem;
    cursor: pointer;
}

.fila-retirada .info-izq { display: flex; flex-direction: column; }
.fila-retirada .persona { font-weight: 600; }
.fila-retirada .fecha { font-size: 0.8rem; color: var(--gris-texto); }
.fila-retirada .importe { font-weight: 800; font-size: 1.1rem; }
.etiqueta-barra {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 0.15rem 0.45rem;
    border-radius: 6px;
    background: var(--gris-fondo);
    margin-right: 0.4rem;
}

.vacio { text-align: center; color: var(--gris-texto); padding: 2rem 0; }

/* ---------- Modal de detalle / identidad de dispositivo ---------- */

.superposicion {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(0, 0, 0, 0.5);
    align-items: flex-end;
    justify-content: center;
}

.superposicion.activa { display: flex; }

.hoja-modal {
    background: #fff;
    border-radius: var(--radio) var(--radio) 0 0;
    padding: 1.2rem;
    width: 100%;
    max-width: 640px;
    max-height: 88vh;
    overflow-y: auto;
}

.hoja-modal.centrada {
    border-radius: var(--radio);
    margin: auto 1rem;
}

.superposicion.centrar { align-items: center; }

.fila-detalle { display: flex; justify-content: space-between; padding: 0.4rem 0; border-bottom: 1px solid #f0f0f0; }
.fila-detalle span:first-child { color: var(--gris-texto); }
.firma-detalle-img { width: 100%; border-radius: 8px; margin-top: 0.8rem; border: 1px solid var(--gris-borde); }

/* ---------- Login ---------- */

.pantalla-login {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--azul);
    padding: 1rem;
}

.tarjeta-login {
    background: #fff;
    border-radius: var(--radio);
    padding: 1.6rem;
    width: 100%;
    max-width: 380px;
    text-align: center;
    box-shadow: var(--sombra);
}

.tarjeta-login h1 { font-size: 1.3rem; margin-top: 0; }
.tarjeta-login input { margin: 1rem 0; }
.mensaje-error { color: var(--rojo); font-weight: 600; }

/* ---------- QR de acceso (Ajustes) ---------- */

.contenedor-qr {
    display: flex;
    justify-content: center;
    padding: 0.75rem 0;
}

.contenedor-qr canvas {
    max-width: 100%;
    height: auto;
    border: 1px solid var(--gris-borde);
    border-radius: 8px;
}

/* ---------- Utilidades ---------- */

.texto-ayuda { font-size: 0.85rem; color: var(--gris-texto); margin-top: 0.3rem; }
.oculto { display: none !important; }
.centrado { text-align: center; }
