:root {
    /* Tema Claro (por defecto) */
    --primary: #3498db;
    --secondary: #2ecc71;
    --danger: #e74c3c;
    --light: #f8f9fa;
    --warning: #f39c12; /* Naranja/amarillo para advertencias */
    --dark: #343a40;
    --gray: #6c757d;
    --info: #17a2b8;
    --bg-gradient-start: #f5f7fa;
    --bg-gradient-end: #e4edf5;
    --container-bg: white;
    --card-bg: white;
    --card-shadow: rgba(0, 0, 0, 0.1);
    --input-bg: white;
    --input-border: #ddd;
    --table-border: #eee;
    --table-row-even-bg: #f8f9fa;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

body {
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-end) 100%);
    min-height: 100vh;
    padding: 20px;
    color: var(--dark);
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: var(--container-bg);
    border-radius: 12px;
    box-shadow: 0 10px 30px var(--card-shadow);
    overflow: hidden;
    padding: 25px;
}

header {
    text-align: center;
    padding: 20px 0;
    position: relative;
    margin-bottom: 30px;
    background: linear-gradient(to right, var(--primary), var(--secondary));
    color: white;
    border-radius: 10px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

header #theme-toggle {
    position: absolute;
    top: 15px;
    right: 15px;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    padding: 0;
}

h1 {
    font-size: 2.5rem;
    margin-bottom: 10px;
}

.subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

.card {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 20px;
    margin-bottom: 25px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(0, 0, 0, 0.05);
}

.card-title {
    font-size: 1.4rem;
    margin-bottom: 15px;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.card-title i {
    font-size: 1.6rem;
}

.connection-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.p2p-section, .data-section {
    padding: 20px;
    border-radius: 8px;
    background: var(--light);
}

.input-group {
    margin-bottom: 15px;
}

label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
}

input, select, button, textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--input-border);
    border-radius: 6px;
    font-size: 1rem;
    background-color: var(--input-bg);
    color: var(--dark);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

button {
    background: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.icon-btn {
    width: 40px !important; 
    height: 40px;
}

button:hover {
    opacity: 0.9;
    transform: translateY(-2px);
}

button.secondary { background: var(--secondary); }
button.danger { background: var(--danger); }
button.info { background: var(--info); }

.status-indicator {
    padding: 10px;
    text-align: center;
    border-radius: 6px;
    margin-top: 15px;
    font-weight: 500;
}

.status-offline { background: #ffebee; color: var(--danger); }
.status-online { background: #e8f5e9; color: #2e7d32; }

.month-selector {
    display: flex;
    gap: 15px;
    margin-bottom: 20px;
    align-items: flex-end;
}

.schedule-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 800px;
}

th, td {
    padding: 12px 15px;
    text-align: center;
    border: 1px solid var(--table-border);
}

th {
    background: var(--primary);
    color: white;
    font-weight: 600;
}

tr:nth-child(even) { background: var(--table-row-even-bg); }
tr:hover { background: #e3f2fd; }

.day-header { min-width: 120px; }

.worker-row td:first-child {
    font-weight: 600;
    text-align: left;
    padding: 5px 15px;
}

.worker-cell-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.delete-worker-btn {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 1rem;
    padding: 5px;
    opacity: 0.4;
    transition: opacity 0.2s;
    width: auto;
}

.delete-worker-btn:hover {
    opacity: 1;
    transform: none; 
}

.time-cell {
    cursor: pointer;
    transition: all 0.2s;
}

.time-cell:hover { background: #d1e7ff; }

.signature-pad {
    border: 1px solid #ddd;
    border-radius: 6px;
    background: var(--input-bg);
    margin-bottom: 10px;
    cursor: crosshair;
}

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: var(--container-bg);
    padding: 30px;
    border-radius: 10px;
    max-width: 500px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-title {
    font-size: 1.5rem;
    color: var(--primary);
}

.close {
    font-size: 1.8rem;
    cursor: pointer;
    color: var(--gray);
}

.modal-body { margin-bottom: 20px; }

.buttons-group {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.buttons-group button { flex: 1; }

.notification {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 15px 25px;
    border-radius: 8px;
    color: white;
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 2000;
    transform: translateX(150%);
    transition: transform 0.3s ease;
}

.notification.show { transform: translateX(0); }
.notification.success { background: var(--secondary); }
.notification.error { background: var(--danger); }

footer {
    text-align: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1px solid #eee;
    color: var(--dark);
    font-size: 0.9rem;
}

.info-badge {
    display: inline-block;
    background: #e3f2fd;
    color: var(--primary);
    padding: 5px 10px;
    border-radius: 20px;
    font-size: 0.85rem;
    margin: 5px 0;
}

.highlight {
    background: linear-gradient(120deg, rgba(52, 152, 219, 0.2), rgba(46, 204, 113, 0.2));
    padding: 3px 6px;
    border-radius: 4px;
}

.time-input {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 15px;
}

.time-input input[type="time"] {
    width: 120px;
    padding: 8px;
}

.report-section {
    margin-top: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
}

.report-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 15px;
}

.report-table th, .report-table td {
    padding: 10px;
    border: 1px solid #ddd;
    text-align: left;
}

.report-table th {
    background-color: #3498db;
    color: white;
}

.report-table tr:nth-child(even) { background-color: #f2f2f2; }

/* --- MODO OSCURO --- */
body.dark-mode {
    --primary: #3498db;
    --secondary: #2ecc71;
    --danger: #e74c3c;
    --light: #4a4a4a;
    --warning: #f39c12;
    --dark: #f5f5f5;
    --gray: #9e9e9e;
    --info: #17a2b8;
    --bg-gradient-start: #2c3e50;
    --bg-gradient-end: #34495e;
    --container-bg: #424242;
    --card-bg: #3a3a3a;
    --card-shadow: rgba(0, 0, 0, 0.4);
    --input-bg: #525252;
    --input-border: #616161;
    --table-border: #515151;
    --table-row-even-bg: #424242;
}

body.dark-mode tr:hover { background: #535c68; }
body.dark-mode .p2p-section, body.dark-mode .data-section { background: var(--card-bg); }
body.dark-mode .info-badge { background: #2c3e50; color: var(--primary); }
body.dark-mode .highlight { background: linear-gradient(120deg, rgba(52, 152, 219, 0.3), rgba(46, 204, 113, 0.3)); }
body.dark-mode .report-section, body.dark-mode .report-table tr:nth-child(even) { background-color: #3a3a3a; }
body.dark-mode .day-filled-signed { background-color: #6d5f2b; }
body.dark-mode .day-pending-signature { background-color: #7f1d1d; }

/* --- ESTILOS PARA EL DASHBOARD Y CALENDARIO --- */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 20px;
}

.summary-card {
    display: flex;
    align-items: center;
    background: var(--light);
    padding: 20px;
    border-radius: 8px;
    border-left: 5px solid var(--primary);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.summary-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.08);
}

.summary-card:nth-child(2) { border-left-color: var(--secondary); }
.summary-card:nth-child(3) { border-left-color: var(--info); }

.summary-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.5rem;
    margin-right: 15px;
    flex-shrink: 0;
}

.summary-content {
    display: flex;
    flex-direction: column;
}

.summary-title {
    font-size: 0.9rem;
    color: var(--gray);
    margin-bottom: 5px;
    font-weight: 500;
}

.summary-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--dark);
}

/* --- ESTILOS PARA LA VISTA DE CALENDARIO --- */
#dashboard-schedule-table .calendar-day {
    height: 100px;
    vertical-align: top;
    padding: 5px;
    position: relative;
}

#dashboard-schedule-table .day-number {
    font-weight: 600;
    font-size: 0.9rem;
    text-align: left;
}

#dashboard-schedule-table .day-content {
    font-size: 0.85rem;
    margin-top: 5px;
}

.day-filled-signed { background-color: #ffecb3; }
.day-pending-signature { background-color: #ffcdd2; }
.incident-icon { opacity: 0.7; transition: opacity 0.2s; }

/* =======================================================
   ESTILOS DE AUDITORÍA Y PARCHES ESPECÍFICOS
   ======================================================= */
#login-modal {
    background-color: #2c3e50;
    background-image: linear-gradient(135deg, #2c3e50 0%, #2980b9 100%);
    z-index: 100000;
}

.audit-toolbar {
    background: var(--light);
    border: 1px solid var(--input-border);
    border-radius: 8px;
    padding: 10px 15px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    border-left: 4px solid var(--danger);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.audit-info h4 { margin: 0; font-size: 1rem; color: var(--dark); display: flex; align-items: center; }
.audit-info p { margin: 2px 0 0 0; font-size: 0.8rem; color: var(--gray); }
.audit-actions { display: flex; gap: 8px; align-items: center; }

.audit-btn {
    width: auto !important;
    padding: 8px 15px !important;
    font-size: 0.85rem !important;
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border-radius: 5px;
    margin: 0 !important;
    font-weight: 600;
    text-transform: none;
}

.btn-pdf { background-color: var(--danger) !important; color: white; }
.btn-pdf:hover { filter: brightness(0.9); }
.btn-json { background-color: var(--secondary) !important; color: white; }
.btn-json:hover { filter: brightness(0.9); }

.btn-trash {
    background-color: transparent !important;
    color: var(--gray);
    border: 1px solid var(--input-border) !important;
    padding: 8px 12px !important;
}
.btn-trash:hover {
    background-color: #fadbd8 !important;
    color: var(--danger) !important;
    border-color: var(--danger) !important;
}

.log-badge {
    background: rgba(0,0,0,0.05); 
    color: var(--dark); 
    padding: 2px 8px; 
    border-radius: 10px; 
    font-size: 0.75rem; 
    margin-left: 8px;
    border: 1px solid var(--input-border);
}

body.dark-mode .audit-toolbar { background: var(--card-bg); border-color: var(--table-border); }
body.dark-mode .log-badge { background: rgba(255,255,255,0.1); color: var(--light); }

#data-management-panel {
    grid-column: 1 / -1 !important; 
    width: 100% !important;
    max-width: none !important;
}

#p2p-panel { padding: 10px 15px !important; height: fit-content !important; }
#p2p-panel .card-title { font-size: 1.1rem !important; margin-bottom: 10px !important; }
#p2p-panel select, #p2p-panel input { padding: 6px 10px !important; font-size: 0.9rem !important; height: auto !important; }
#p2p-panel .input-group { margin-bottom: 8px !important; }
#p2p-panel button { margin-top: 5px !important; padding: 8px !important; }

/* Control del modal */
#time-modal .modal-content {
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    padding: 0;
    overflow: hidden;
    width: 95%;
    max-width: 550px;
}

#time-modal .modal-header {
    padding: 15px 25px;
    border-bottom: 1px solid var(--table-border);
    background: var(--container-bg);
    margin-bottom: 0;
    position: sticky;
    top: 0;
    z-index: 10;
}

#time-modal .modal-body {
    overflow-y: auto;
    padding: 20px 25px;
    flex-grow: 1;
}

#time-modal .photo-preview {
    max-width: 100%;
    max-height: 250px;
    width: auto;
    object-fit: contain;
    margin: 10px auto;
    border: 2px solid var(--primary);
}

#modal-signature-pad {
    width: 100% !important;
    height: 120px !important;
}

#time-modal .buttons-group {
    background: var(--container-bg);
    padding: 15px 25px;
    border-top: 1px solid var(--table-border);
    margin-top: 0;
}

#time-modal .modal-body::-webkit-scrollbar { width: 6px; }
#time-modal .modal-body::-webkit-scrollbar-thumb { background: var(--primary); border-radius: 10px; }

/* =======================================================
   DISEÑO ADAPTATIVO PARA MÓVILES Y TABLETS (PWA)
   ======================================================= */
@media (max-width: 768px) {
    /* 1. Ajustes de Contenedor y Cabecera */
    body { padding: 5px; }
    .container { 
        padding: 10px !important; 
        width: 100% !important; 
        max-width: 100% !important; 
        border-radius: 0; 
    }
    header h1 { font-size: 1.5rem; }
    .subtitle { font-size: 0.9rem; }

    /* 2. Formularios e Inputs (Apilados para móvil) */
    .connection-panel { grid-template-columns: 1fr !important; display: block !important; }
    .input-group { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; }
    .input-group input, .input-group select, .input-group textarea { width: 100% !important; box-sizing: border-box; }
    
    .month-selector { flex-direction: column; align-items: stretch; }
    .month-selector .input-group { width: 100%; }

    /* 3. Dashboard y Tarjetas */
    .summary-cards { grid-template-columns: 1fr !important; gap: 10px; }
    .summary-card { width: 100%; margin: 0; }

    /* 4. CALENDARIO CON NOMBRE FIJO Y SCROLL */
    .schedule-container {
        display: block !important;
        width: 100% !important;
        overflow-x: auto !important; 
        -webkit-overflow-scrolling: touch; 
        border: 1px solid var(--table-border);
        border-radius: 5px;
        margin-bottom: 15px;
        position: relative;
    }

    /* Forzamos ancho para que el scroll se active */
    #schedule-table, #dashboard-schedule-table, table {
        min-width: 1200px !important; 
        width: auto !important;
        border-collapse: separate !important; 
        border-spacing: 0;
    }

    /* CONGELAR COLUMNA DE NOMBRES */
    #schedule-table th:first-child,
    #schedule-table td:first-child,
    .worker-row td:first-child {
        position: sticky !important;
        left: 0 !important;
        z-index: 10 !important;
        background-color: var(--container-bg) !important; 
        box-shadow: 2px 0 5px rgba(0,0,0,0.1) !important;
        min-width: 130px !important;
    }

    /* 5. AUDITORÍA LOCAL (Cuadrícula 2x2 + Botón de borrar ancho) */
    .audit-toolbar {
        flex-direction: column !important;
        align-items: stretch !important;
        padding: 15px !important;
    }

    .audit-actions {
        display: grid !important;
        grid-template-columns: 1fr 1fr !important; /* Dos columnas iguales */
        gap: 8px !important;
        width: 100% !important;
        margin-top: 10px !important;
    }

    /* Forzamos que todos los botones de auditoría se vean bien y centrados */
    .audit-actions button {
        width: 100% !important;
        margin: 0 !important;
        padding: 12px 5px !important;
        font-size: 0.85rem !important;
        display: flex !important;
        justify-content: center !important;
        align-items: center !important;
        gap: 6px !important;
    }

    /* El botón de borrar (papelera) ocupa toda la fila de abajo solo */
    #btn-clear-local-log, .btn-trash {
        grid-column: span 2 !important; /* Ocupa las 2 columnas */
        background-color: #fce4ec !important; 
        color: #c0392b !important;
        border: 1px solid #c0392b !important;
        margin-top: 5px !important;
    }

    /* 6. Modales y Edición */
    #time-modal .modal-content, #login-modal .modal-content, #create-access-modal .modal-content {
        width: 95% !important;
        margin: 2% auto !important;
        max-height: 95vh;
        overflow-y: auto;
    }
    
    #edit-view > div[style*="display: flex; gap: 15px"] {
        flex-direction: column !important;
        gap: 5px !important;
    }

    /* 7. Botones y Firma */
    .buttons-group { flex-direction: column !important; width: 100%; gap: 8px; }
    .buttons-group button { width: 100% !important; margin: 0 !important; }
    .signature-pad { width: 100% !important; height: 150px; }
}
