:root {
    --primary: #1e4d8c;
    --primary-light: #2c6cbf;
    --success: #2e7d32;
    --danger: #c62828;
    --warning: #ef6c00;
    --info: #0277bd;
    --bg: #f4f6f9;
    --card: #ffffff;
    --border: #d0d7e2;
    --text: #1a2332;
    --text-light: #5a6577;
    --weekend: #f0e9e0;
    --festivo: #fff4d6;
    --hover: #e8f0fe;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.4;
    font-size: 14px;
}

.app-container { max-width: 1500px; margin: 0 auto; padding: 20px; }

/* HEADER */
.app-header {
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    color: white;
    padding: 20px 30px;
    border-radius: 12px;
    margin-bottom: 20px;
    box-shadow: 0 4px 15px rgba(30, 77, 140, 0.3);
}

.header-content { display: flex; align-items: center; gap: 20px; }

.logo-circle {
    width: 70px; height: 70px;
    background: white;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 2.2rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.2);
}

.header-titles h1 { font-size: 1.6rem; margin-bottom: 4px; }
.subtitle { opacity: 0.9; font-size: 0.95rem; }

/* CONTROLES */
.controls-panel {
    background: var(--card);
    padding: 20px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: flex-end;
    margin-bottom: 15px;
}

.control-group { display: flex; flex-direction: column; gap: 5px; min-width: 150px; flex: 1; }
.control-group label { font-weight: 600; color: var(--text-light); font-size: 0.85rem; text-transform: uppercase; }
.control-group select {
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    background: white;
    cursor: pointer;
}
.control-group select:focus { outline: none; border-color: var(--primary); }

.control-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* BOTONES */
.btn {
    padding: 10px 18px;
    border: none;
    border-radius: 6px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    color: white;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 4px 8px rgba(0,0,0,0.15); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--primary); }
.btn-success { background: var(--success); }
.btn-secondary { background: #546e7a; }
.btn-info { background: var(--info); }
.btn-warning { background: var(--warning); }
.btn-danger { background: var(--danger); }
.btn-sm { padding: 5px 10px; font-size: 0.8rem; }

/* LEYENDA */
.leyenda {
    background: var(--card);
    padding: 12px 20px;
    border-radius: 8px;
    margin-bottom: 15px;
    display: flex;
    flex-wrap: wrap;
    gap: 15px;
    align-items: center;
    box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}

.leg-item { display: inline-flex; align-items: center; gap: 5px; }

.badge {
    display: inline-block;
    width: 26px; height: 26px;
    line-height: 26px;
    text-align: center;
    border-radius: 4px;
    font-weight: 700;
    font-size: 0.8rem;
    color: white;
}
.badge-P { background: var(--success); }
.badge-A { background: var(--danger); }
.badge-J { background: var(--warning); }
.badge-R { background: var(--info); }
.badge-F { background: #f9a825; color: #333; }
.badge-WE { background: #9e9e9e; }

/* TABLA */
.tabla-container {
    background: var(--card);
    border-radius: 10px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.08);
    overflow: auto;
    max-height: 75vh;
}

.tabla-titulo {
    padding: 15px 20px;
    border-bottom: 3px solid var(--primary);
    background: #f8fafc;
    position: sticky;
    top: 0;
    z-index: 5;
}
.tabla-titulo h2 { color: var(--primary); margin-bottom: 3px; }
.tabla-titulo p { color: var(--text-light); font-size: 0.9rem; }

.tabla-asistencia { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.tabla-asistencia thead { position: sticky; top: 60px; z-index: 10; }
.tabla-asistencia th, .tabla-asistencia td { border: 1px solid var(--border); padding: 4px 6px; text-align: center; vertical-align: middle; }
.tabla-asistencia thead th { background: var(--primary); color: white; font-weight: 600; padding: 8px 4px; font-size: 0.8rem; }
.tabla-asistencia thead th.dia-header { min-width: 32px; }
.tabla-asistencia thead th.dia-header .dia-num { display: block; font-size: 0.95rem; }
.tabla-asistencia thead th.dia-header .dia-nom { display: block; font-size: 0.65rem; opacity: 0.85; font-weight: 400; }
.tabla-asistencia thead th.fin-semana { background: #7a8a9e; }
.tabla-asistencia thead th.festivo-col { background: #f9a825; color: #333; }
.tabla-asistencia tbody tr:nth-child(even) { background: #fafbfd; }
.tabla-asistencia tbody tr:hover { background: var(--hover); }
.tabla-asistencia td.col-num { background: #e3ecf7; font-weight: 600; width: 40px; }
.tabla-asistencia td.col-rut { background: #e3ecf7; font-size: 0.75rem; white-space: nowrap; }
.tabla-asistencia td.col-nombre { text-align: left; padding-left: 10px; font-weight: 500; min-width: 240px; white-space: nowrap; }

/* Celdas estado */
.tabla-asistencia td.estado-cell { cursor: pointer; font-weight: 700; user-select: none; transition: background 0.15s; min-width: 30px; }
.tabla-asistencia td.estado-cell:hover:not(.fin-semana):not(.festivo-cell) { background: var(--hover); transform: scale(1.05); }
.tabla-asistencia td.estado-cell.fin-semana { background: var(--weekend); color: #999; cursor: not-allowed; }
.tabla-asistencia td.estado-cell.festivo-cell { background: var(--festivo); color: #b8860b; cursor: not-allowed; }
.tabla-asistencia td.estado-cell[data-estado="P"] { background: #e8f5e9; color: var(--success); }
.tabla-asistencia td.estado-cell[data-estado="A"] { background: #ffebee; color: var(--danger); }
.tabla-asistencia td.estado-cell[data-estado="J"] { background: #fff3e0; color: var(--warning); }
.tabla-asistencia td.estado-cell[data-estado="R"] { background: #e1f5fe; color: var(--info); }

.empty-state { padding: 60px 20px; text-align: center; color: var(--text-light); font-size: 1.1rem; }
.empty-state .hint { font-size: 0.9rem; margin-top: 10px; color: #999; }

/* MODAL */
.modal { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 1000; align-items: center; justify-content: center; padding: 20px; }
.modal.active { display: flex; }
.modal-content { background: white; border-radius: 10px; max-width: 600px; width: 100%; max-height: 85vh; overflow-y: auto; box-shadow: 0 10px 40px rgba(0,0,0,0.3); }
.modal-large { max-width: 950px; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 15px 20px; background: var(--primary); color: white; border-radius: 10px 10px 0 0; }
.modal-header h2 { font-size: 1.2rem; }
.modal-close { background: transparent; border: none; color: white; font-size: 1.8rem; cursor: pointer; }
.modal-body { padding: 20px; }

.form-inline { display: flex; gap: 10px; margin-bottom: 15px; flex-wrap: wrap; }
.form-inline input { padding: 8px 12px; border: 2px solid var(--border); border-radius: 6px; font-size: 0.95rem; flex: 1; min-width: 150px; }
.form-inline input:focus { outline: none; border-color: var(--primary); }

.lista-festivos { max-height: 400px; overflow-y: auto; }
.festivo-item { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--border); background: #fffde7; border-radius: 4px; margin-bottom: 5px; }
.festivo-item .fecha { font-weight: 600; color: var(--warning); }
.festivo-item .desc { flex: 1; margin-left: 15px; }

/* TABLA RESUMEN */
.tabla-resumen { width: 100%; border-collapse: collapse; }
.tabla-resumen th, .tabla-resumen td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.tabla-resumen thead th { background: var(--primary); color: white; }
.tabla-resumen tbody tr:nth-child(even) { background: #fafbfd; }

/* TOAST */
.toast { position: fixed; bottom: 30px; right: 30px; background: var(--success); color: white; padding: 15px 25px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.2); z-index: 2000; animation: slideIn 0.3s ease; font-weight: 600; }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* PRINT */
@media print {
    body { background: white; }
    .app-header { background: white; color: black; box-shadow: none; border-bottom: 2px solid black; }
    .controls-panel, .leyenda, .btn, .modal { display: none !important; }
    .tabla-container { max-height: none; box-shadow: none; overflow: visible; }
    .tabla-asistencia { font-size: 0.7rem; }
    .tabla-asistencia th, .tabla-asistencia td { padding: 2px 3px; }
    @page { size: landscape; margin: 10mm; }
}

@media (max-width: 768px) {
    .controls-panel { flex-direction: column; }
    .control-actions .btn { flex: 1; justify-content: center; }
}