* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f0f2f5;
    color: #333;
    line-height: 1.6;
    padding: 16px;
}

.container {
    max-width: 600px;
    margin: 0 auto;
}

header {
    text-align: center;
    margin-bottom: 24px;
}

header h1 {
    font-size: 1.5rem;
    color: #1a1a1a;
}

.logo-container {
    margin-bottom: 16px;
}

.logo-img {
    max-width: 200px;
    height: auto;
}

.card {
    background: #fff;
    border-radius: 12px;
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.card h2 {
    font-size: 1.1rem;
    margin-bottom: 16px;
    color: #1a1a1a;
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 0.9rem;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #4a90d9;
}

.form-group input[readonly] {
    background: #f5f5f5;
    color: #666;
}

.error {
    color: #d32f2f;
    font-size: 0.8rem;
    margin-top: 4px;
    display: block;
}

.toggle-group {
    display: flex;
    gap: 8px;
}

.toggle-btn {
    flex: 1;
    padding: 12px;
    border: 2px solid #ddd;
    background: #fff;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.toggle-btn.active {
    background: #4a90d9;
    color: #fff;
    border-color: #4a90d9;
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: #4a90d9;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
}

.btn-primary:hover {
    background: #357abd;
}

.btn-secondary {
    padding: 8px 16px;
    background: #e8e8e8;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    cursor: pointer;
}

.btn-secondary:hover {
    background: #d0d0d0;
}

/* .gps-status y .preview ya no se usan: los mensajes de GPS y foto
   están ocultos en pantalla. Se conservan por si se reactivan. */

.horas-dia {
    font-size: 1.5rem;
    font-weight: 700;
    color: #4a90d9;
    text-align: center;
}

.db-status {
    font-size: 0.9rem;
    color: #666;
    text-align: center;
}

.db-status.connected {
    color: #2e7d32;
}

.db-status.error {
    color: #d32f2f;
}

.form-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
    align-items: center;
}

.form-inline input {
    flex: 1 1 140px;
    min-width: 0;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
}

.lista {
    list-style: none;
}

.lista li {
    padding: 10px 0;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.lista li:last-child {
    border-bottom: none;
}

.btn-eliminar {
    background: none;
    border: none;
    color: #d32f2f;
    cursor: pointer;
    font-size: 0.85rem;
}

.info-text {
    font-size: 0.85rem;
    color: #666;
    margin-bottom: 12px;
}

.info-empleado {
    display: block;
    margin-top: 8px;
    font-size: 0.9rem;
    font-weight: 600;
}

.ayuda {
    display: block;
    font-size: 0.8rem;
    color: #666;
    margin-top: 4px;
}

.falta {
    color: #d32f2f;
    font-weight: 600;
}

.nota-registro {
    margin-top: 4px;
    padding: 4px 8px;
    background: #fff8e1;
    border-left: 3px solid #f9a825;
    border-radius: 4px;
    font-size: 0.82rem;
    color: #6d4c00;
}

/* Calendario de fecha y selector de periodo, lado a lado */
.form-inline .etiqueta-fecha {
    font-weight: 600;
    font-size: 0.9rem;
    color: #334155;
    white-space: nowrap;
}

.form-inline input[type="date"] {
    flex: 1 1 150px;
    min-width: 150px;
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 0.95rem;
    font-family: inherit;
    background: #fff;
    color: #1e293b;
    min-height: 42px;
}

.form-inline input[type="date"]:focus {
    outline: none;
    border-color: #4a90d9;
    box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.2);
}

/* El selector de periodo, al lado del calendario */
.form-inline select {
    flex: 1 1 140px;
    min-width: 140px;
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 8px;
    font-size: 0.9rem;
    font-family: inherit;
    background: #fff;
    color: #1e293b;
    min-height: 42px;
    cursor: pointer;
}

.form-inline select:focus {
    outline: none;
    border-color: #4a90d9;
    box-shadow: 0 0 0 3px rgba(74, 144, 217, 0.2);
}

.form-inline .btn-secondary {
    flex: 0 0 auto;
    min-height: 42px;
}

/* El desplegable de empleado solo se ve en el modo "Un empleado" */
.oculto {
    display: none !important;
}

/* Cada pareja "Desde/Hasta" con su calendario */
.rango-fecha {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1 1 0;
    min-width: 0;
}

.rango-fecha .etiqueta-fecha {
    flex: 0 0 auto;
}

.rango-fecha input[type="date"] {
    flex: 1 1 auto;
    min-width: 0;
}

#resumenPeriodo {
    margin: 12px 0 0;
    padding: 8px 12px;
    background: #eef4fb;
    border-left: 3px solid #4a90d9;
    border-radius: 4px;
    font-size: 0.85rem;
    color: #1e3a8a;
    font-weight: 600;
}

#resumenPeriodo:empty {
    display: none;
}

/* Tabla compacta de registros */
.tabla-envoltura {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tabla-registros {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
    min-width: 580px;
}

.tabla-registros th {
    background: #4a90d9;
    color: #fff;
    padding: 8px 6px;
    text-align: left;
    font-size: 0.76rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.tabla-registros td {
    padding: 7px 6px;
    border-bottom: 1px solid #eee;
    vertical-align: middle;
}

.tabla-registros tbody tr:nth-child(even) {
    background: #f8fbff;
}

/* Dias sin entrada o sin salida */
.tabla-registros tbody tr.fila-incompleta {
    background: #fff8e1;
}

/* El nombre del empleado se repite visualmente en cada fila */
.tabla-registros .celda-empleado {
    font-size: 0.85rem;
    background: #4a90d9;
    color: #fff;
    width: 130px;
    min-width: 130px;
    border-bottom: 1px solid #3a7fc4;
    border-right: 2px solid #3a7fc4;
    /* Arriba y no centrado: en grupos de muchas filas el nombre debe
       quedar pegado a la primera fila, si no parece de otro empleado */
    vertical-align: top;
}

.tabla-registros .celda-empleado small {
    display: block;
    color: #dbeafe;
    font-size: 0.72rem;
    font-weight: normal;
}

.tabla-registros .celda-horas {
    font-weight: 600;
    color: #1e3a8a;
    white-space: nowrap;
}

.tabla-registros .celda-nota {
    font-size: 0.75rem;
    color: #6d4c00;
    max-width: 160px;
}

/* Numero de turno dentro del mismo dia */
.tabla-registros .celda-turno {
    color: #64748b;
    font-size: 0.75rem;
    text-align: center;
    width: 34px;
}

.tabla-registros .celda-fecha {
    white-space: nowrap;
    font-weight: 600;
    color: #334155;
}

/* Total del empleado, al pie de su celda azul */
.tabla-registros .celda-empleado .grupo-total {
    display: block;
    margin-top: 8px;
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.35);
    font-weight: 700;
    font-size: 0.85rem;
}

/* Badge del grupo asignado en la celda del empleado */
.celda-empleado .grupo-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
}

.celda-empleado .grupo-badge.sin-grupo {
    background: #e0e0e0;
    color: #666;
}

.celda-empleado .grupo-badge.con-grupo {
    background: #e3f2fd;
    color: #1565c0;
}

/* Separación visual entre empleados: borde inferior grueso en la primera fila */
.tabla-registros tbody tr.primer-fila-empleado {
    border-top: 3px solid #4a90d9;
}

/* Colores segun cumplimiento de horas minimas del grupo.
   Solo se aplican a las celdas que NO son del empleado, para que el
   nombre del empleado siga visible sobre fondo azul. */
.tabla-registros tbody tr.cumple-minimas td:not(.celda-empleado) {
    background: #e8f5e9 !important;
}

.tabla-registros tbody tr.incompleto-minimas td:not(.celda-empleado) {
    background: #fffde7 !important;
}

.tabla-registros tbody tr.sin-minimas td:not(.celda-empleado) {
    background: #ffebee !important;
}

/* Asegurar que la fila de total herede el color del día */
.tabla-registros tbody tr.fila-total.cumple-minimas td:not(.celda-empleado) {
    background: #e8f5e9 !important;
}

.tabla-registros tbody tr.fila-total.incompleto-minimas td:not(.celda-empleado) {
    background: #fffde7 !important;
}

.tabla-registros tbody tr.fila-total.sin-minimas td:not(.celda-empleado) {
    background: #ffebee !important;
}

/* La celda del empleado SIEMPRE mantiene fondo azul y texto blanco,
   sin importar el color de cumplimiento del día. */
.tabla-registros .celda-empleado {
    background: #4a90d9 !important;
    color: #fff !important;
}

/* Indicador visual en el nombre del grupo/empleado cuando hay grupo asignado */
.celda-empleado .grupo-badge {
    display: inline-block;
    margin-left: 6px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
}

.celda-empleado .grupo-badge.sin-grupo {
    background: #e0e0e0;
    color: #666;
}

.celda-empleado .grupo-badge.con-grupo {
    background: #e3f2fd;
    color: #1565c0;
}

.tabla-registros tr.fila-total .celda-total {
    text-align: right;
    font-size: 0.78rem;
    font-weight: 700;
    color: #1e3a8a;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    white-space: nowrap;
}

.tabla-registros tr.fila-total td {
    border-bottom: 2px solid #4a90d9;
}

/* Foto en miniatura dentro de la tabla */
.tabla-registros .celda-foto {
    text-align: center;
    width: 56px;
}

.tabla-registros .foto-mini {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: 6px;
    border: 2px solid #4a90d9;
    transition: transform 0.15s;
}

.tabla-registros a.foto-link {
    display: inline-block;
    line-height: 0;
    border-radius: 6px;
}

.tabla-registros a.foto-link:hover .foto-mini {
    transform: scale(1.08);
    border-color: #2e7d32;
}

.tabla-registros .foto-mini:hover {
    transform: scale(1.08);
}

.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
}

.form-group textarea:focus {
    outline: none;
    border-color: #4a90d9;
}

.aviso-error {
    background: #fdecea;
    border: 2px solid #d32f2f;
    border-left: 6px solid #d32f2f;
    border-radius: 8px;
    padding: 16px 18px;
    margin-bottom: 20px;
    color: #a01722;
    font-size: 1.1rem;
    font-weight: 600;
    box-shadow: 0 2px 8px rgba(211, 47, 47, 0.2);
}

.aviso-ok {
    background: #e8f5e9;
    border: 1px solid #b7dfb9;
    border-left: 4px solid #2e7d32;
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
    color: #1b5e20;
    font-size: 0.95rem;
    font-weight: 600;
}

.marcacion-info {
    font-size: 0.9rem;
}

.marcacion-tipo {
    font-weight: 600;
}

.marcacion-tipo.entrada {
    color: #2e7d32;
}

.marcacion-tipo.salida {
    color: #d32f2f;
}

.marcacion-hora {
    color: #4a90d9;
    font-weight: 600;
}

/* Historial: cada entrada y salida como línea propia */
.historial-dia {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.historial-dia .marcacion-info {
    flex: 1;
    min-width: 0;
}

.historial-dia .marcas-lista {
    margin-top: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.historial-dia .marca-linea {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85rem;
}

.historial-dia .marca-badge {
    display: inline-block;
    min-width: 56px;
    text-align: center;
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.historial-dia .marca-badge.entrada {
    background: #e8f5e9;
    color: #2e7d32;
    border: 1px solid #b7dfb9;
}

.historial-dia .marca-badge.salida {
    background: #fdecea;
    color: #d32f2f;
    border: 1px solid #f5c6cb;
}

.historial-dia .hoy-badge {
    background: #4a90d9;
    color: #fff;
    padding: 1px 8px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 700;
}

.historial-dia .marcacion-hora {
    flex-shrink: 0;
    text-align: right;
}

.preview {
    width: 100%;
    max-height: 150px;
    object-fit: cover;
    border-radius: 8px;
    margin-top: 8px;
}

/* ---------- Adaptacion a cada pantalla ---------- */

/* Celular: la marca de una sola columna, como esta */
body { padding: 12px; }

.container {
    max-width: 600px;
    margin: 0 auto;
}

.card {
    padding: 16px;
}

/* Pantalla de PC: la tabla de registros necesita espacio,
   asi que el contenido se ensancha por pasos. */
@media (min-width: 700px) {
    body { padding: 20px; }
    .container { max-width: 940px; }
    .card { padding: 20px; }
}

@media (min-width: 1100px) {
    .container { max-width: 1080px; }
}

/* El logo no debe comerse la pantalla en un movil pequeño */
@media (max-width: 420px) {
    .logo-img { max-width: 150px; }
    header h1 { font-size: 1.3rem; }
    .card { padding: 14px; }
}

/* En pantallas muy angostas, los controles del filtro
   bajan a la siguiente linea en vez de aplastarse. */
@media (max-width: 480px) {
    .form-inline {
        gap: 6px;
    }

    .form-inline .etiqueta-fecha {
        flex: 0 0 100%;
        margin-bottom: -2px;
    }

    .form-inline input[type="date"],
    .form-inline select {
        flex: 1 1 45%;
        min-width: 45%;
    }

    .form-inline .btn-secondary {
        flex: 1 1 100%;
    }

    /* En el movil, los dos calendarios van uno al lado del otro */
    .rango-fecha {
        flex: 1 1 0;
        min-width: 0;
    }

    .rango-fecha .etiqueta-fecha {
        flex: 0 0 44px;
        font-size: 0.8rem;
    }

    .rango-fecha input[type="date"] {
        flex: 1 1 auto;
        min-width: 0;
        padding: 10px 8px;
        font-size: 0.85rem;
    }

    .form-inline .btn-secondary {
        flex: 1 1 100%;
    }

    .tabla-registros {
        font-size: 0.78rem;
        min-width: 540px;
    }
}
