:root {
    --primary-color: #004F9F; /* Azul corporativo Sacyr */
    --primary-light: #e6f0fa;
    --text-main: #333333;
    --text-muted: #666666;
    --bg-main: #f4f7f6;
    --white: #ffffff;
    --border-color: #dddddd;
    --danger: #dc3545;
    --success: #28a745;
    --shadow: 0 4px 6px rgba(0,0,0,0.05);
    --radius: 8px;
}

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

body {
    font-family: 'Roboto', sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
}

/* UTILIDADES */
.hidden { display: none !important; }
#pdf-container.hidden { display: block !important; position: absolute; top: -9999px; left: -9999px; z-index: -100; opacity: 0; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.spacer-bottom { height: 80px; } /* Espacio para scroll en movil */

/* HEADER */
.app-header {
    background-color: var(--primary-color);
    color: var(--white);
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow);
}
#header-title { font-size: 1.2rem; font-weight: 500; }
.header-logo { font-weight: 700; font-size: 1.2rem; letter-spacing: 1px;}

/* LAYOUT PRINCIPAL */
#app-container {
    padding: 1rem;
    max-width: 600px;
    margin: 0 auto;
}

.section-title {
    font-size: 1.1rem;
    color: var(--primary-color);
    margin: 1.5rem 0 0.5rem;
    font-weight: 700;
    border-bottom: 2px solid var(--primary-light);
    padding-bottom: 0.3rem;
}

/* TARJETAS (CARDS) */
.card {
    background-color: var(--white);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow);
}

/* FORMULARIOS */
.input-group {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
}
.input-group label {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
    font-weight: 500;
}
input[type="date"], input[type="time"], input[type="number"], input[type="text"], textarea, select {
    width: 100%;
    padding: 0.85rem 1rem;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    font-size: 1rem;
    font-family: 'Roboto', sans-serif;
    background-color: #f8fafc;
    color: var(--text-main);
    transition: all 0.2s ease-in-out;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    outline: none;
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.02);
}

select {
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 1rem center;
    background-size: 1.2rem;
    padding-right: 2.5rem;
}

input:focus, textarea:focus, select:focus {
    border-color: var(--primary-color);
    background-color: var(--white);
    box-shadow: 0 0 0 3px rgba(0, 79, 159, 0.15);
}
.row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}
.half { flex: 1 1 100%; min-width: 120px; }
.third { flex: 1 1 calc(33% - 1rem); min-width: 80px; }
.col-6 { flex: 1 1 calc(50% - 1rem); min-width: 100px; }

/* ASISTENCIA LISTA */
.asistencia-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.worker-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}
.worker-item:last-child { border-bottom: none; }
.worker-name { font-size: 0.95rem; }

/* SWITCH TIPO IOS/ANDROID */
.switch {
    position: relative;
    display: inline-block;
    width: 46px;
    height: 24px;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}
.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}
input:checked + .slider { background-color: var(--primary-color); }
input:checked + .slider:before { transform: translateX(22px); }

/* BOTONES */
button {
    width: 100%;
    padding: 0.9rem;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: background-color 0.2s;
}
.btn-primary {
    background-color: var(--primary-color);
    color: var(--white);
}
.btn-primary:active { background-color: #003a7a; }
.btn-secondary {
    background-color: var(--primary-light);
    color: var(--primary-color);
}
.btn-danger {
    background-color: var(--danger);
    color: var(--white);
}
.action-bar {
    display: flex;
    gap: 1rem;
}

/* PILAS GRID */
.pilas-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}
.pila-btn {
    background-color: var(--white);
    border: 2px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1.5rem 1rem;
    font-size: 1.1rem;
    font-weight: 500;
    color: var(--text-main);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}
.pila-btn.has-data {
    border-color: var(--success);
    background-color: #f0fff4;
}

/* MODAL */
.modal {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: rgba(0,0,0,0.5);
    z-index: 200;
    display: flex;
    justify-content: center;
    align-items: flex-end; /* Aparece desde abajo estilo movil */
}
.modal.hidden { display: none !important; }
.modal-content {
    background-color: var(--bg-main);
    width: 100%;
    max-height: 90vh;
    border-radius: 20px 20px 0 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    margin-bottom: 0;
    overflow: hidden;
}
.modal-header {
    background-color: var(--white);
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}
.modal-body {
    padding: 1rem;
    overflow-y: auto;
}
.modal-footer {
    padding: 1rem;
    background-color: var(--white);
    border-top: 1px solid var(--border-color);
}
.close-btn {
    background: none; border: none; font-size: 1.5rem; color: var(--text-muted); padding: 0; width: auto;
}
.form-section {
    background-color: var(--white);
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    border: 1px solid var(--border-color);
}
.form-section h4 {
    margin-bottom: 1rem;
    color: var(--primary-color);
    font-size: 0.95rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

/* FOTOS */
.photo-upload-container { text-align: center; }
.photo-preview {
    max-width: 100%;
    height: auto;
    border-radius: var(--radius);
    margin-top: 1rem;
    box-shadow: var(--shadow);
}

/* CHECKBOX PERSONALIZADO */
.checkbox-container {
    display: block; position: relative; padding-left: 30px; margin-top: 10px; cursor: pointer;
    font-size: 0.95rem; user-select: none;
}
.checkbox-container input { position: absolute; opacity: 0; cursor: pointer; height: 0; width: 0; }
.checkmark { position: absolute; top: 0; left: 0; height: 20px; width: 20px; background-color: #eee; border-radius: 4px; }
.checkbox-container:hover input ~ .checkmark { background-color: #ccc; }
.checkbox-container input:checked ~ .checkmark { background-color: var(--primary-color); }
.checkmark:after { content: ""; position: absolute; display: none; }
.checkbox-container input:checked ~ .checkmark:after { display: block; }
.checkbox-container .checkmark:after { left: 7px; top: 3px; width: 5px; height: 10px; border: solid white; border-width: 0 2px 2px 0; transform: rotate(45deg); }

/* OVERLAY LOADING */
#loading-overlay {
    position: fixed; top:0; left:0; width:100%; height:100%;
    background: rgba(255,255,255,0.9); z-index: 9999;
    display: flex; flex-direction: column; justify-content: center; align-items: center;
}
.spinner {
    border: 5px solid #f3f3f3; border-top: 5px solid var(--primary-color);
    border-radius: 50%; width: 50px; height: 50px; animation: spin 1s linear infinite;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* FIRMA DE AUTORÍA SUTIL */
.author-credits {
    margin-top: 2rem;
    padding: 1.5rem 1rem;
    text-align: center;
    border-top: 1px solid var(--border-color);
    font-size: 0.85rem;
    color: var(--text-muted);
    background-color: var(--white);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.author-credits p {
    margin-bottom: 0.3rem;
}
.author-credits strong {
    color: var(--primary-color);
    font-weight: 700;
}
.author-email {
    color: var(--text-muted);
    text-decoration: none;
}
.author-email:hover {
    text-decoration: underline;
}
.btn-whatsapp {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 0.8rem;
    padding: 0.5rem 1.2rem;
    background-color: #25D366;
    color: #ffffff;
    font-size: 0.85rem;
    font-weight: 700;
    text-decoration: none;
    border-radius: 20px;
    box-shadow: 0 2px 5px rgba(37, 211, 102, 0.3);
    transition: transform 0.2s ease, background-color 0.2s ease;
}
.btn-whatsapp:active {
    transform: scale(0.96);
    background-color: #1eb956;
}

/* PDF PREVIEW STYLES (Ocultos en pantalla normal) */
.pdf-page {
    width: 800px;
    padding: 40px;
    background: white;
    font-family: Arial, sans-serif;
    color: #333;
}
.pdf-header { text-align: center; margin-bottom: 20px; border-bottom: 2px solid var(--primary-color); padding-bottom: 10px; }
.pdf-title { color: var(--primary-color); font-size: 24px; margin: 0; }
.pdf-subtitle { color: #666; font-size: 14px; }
.pdf-section { margin-bottom: 20px; }
.pdf-section h3 { background: var(--primary-light); color: var(--primary-color); padding: 5px 10px; font-size: 16px; margin: 0 0 10px 0; }
.pdf-table { width: 100%; border-collapse: collapse; margin-bottom: 10px; font-size: 12px; }
.pdf-table th, .pdf-table td { border: 1px solid #ddd; padding: 6px; text-align: left; }
.pdf-table th { background-color: #f9f9f9; width: 30%; }
.pdf-pila-card { border: 1px solid #ccc; margin-bottom: 15px; page-break-inside: avoid; }
.pdf-pila-header { background: var(--primary-color); color: white; padding: 5px 10px; font-weight: bold; }
.pdf-pila-body { padding: 10px; display: flex; gap: 15px; }
.pdf-pila-data { flex: 1; }
.pdf-pila-photo { width: 250px; text-align: center; }
.pdf-pila-photo img { max-width: 100%; max-height: 200px; object-fit: contain; border: 1px solid #eee; }
