/* =========================================================
   ESTILOS - Sistema de Control de Asistencia RRHH
   Tema: ERP Enterprise (SAP B1 / Fiori)
   Sidebar colapsable + Dark Mode + Mobile First
   ========================================================= */

:root {
    /* Paleta corporativa RRHH: teal (gestión de personas) */
    --erp-shell-bg: linear-gradient(90deg, #0f766e 0%, #0d9488 100%);
    --erp-shell-solido: #0f766e;
    --erp-shell-color: #ffffff;
    --erp-primary: #0d9488;
    --erp-primary-hover: #0b7c72;
    --erp-primary-soft: #e6f7f5;
    --erp-bg: #f4f7f6;
    --erp-sidebar-bg: #ffffff;
    --erp-sidebar-border: #e2e8f0;
    --erp-texto: #32363a;
    --erp-texto-suave: #6a6d70;
    --erp-shell-alto: 52px;
    --erp-sidebar-ancho: 240px;
    --erp-sidebar-colapsado: 64px;
    --erp-radio: .5rem;
    --erp-sombra: 0 1px 2px rgba(15, 23, 42, .05);
    --erp-sombra-hover: 0 6px 16px rgba(15, 23, 42, .10);
    --erp-transicion: .25s ease;
}

body {
    background-color: var(--erp-bg);
    color: var(--erp-texto);
    font-size: .925rem;
}

h4 { font-weight: 600; letter-spacing: -.01em; }

/* Accesibilidad: focus visible consistente */
a:focus-visible,
button:focus-visible,
.form-control:focus-visible,
.form-select:focus-visible {
    outline: 2px solid var(--erp-primary);
    outline-offset: 1px;
}

/* =========================================================
   SHELL BAR (header fijo)
   ========================================================= */
.shell-bar {
    background: var(--erp-shell-bg);
    color: var(--erp-shell-color);
    height: var(--erp-shell-alto);
    z-index: 1050;
}

.shell-bar .shell-titulo {
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: .02em;
    white-space: nowrap;
}

.shell-bar .shell-empresa {
    color: #ccf2ed;
    font-size: .85rem;
    border-left: 1px solid rgba(255, 255, 255, .25);
    padding-left: .75rem;
    margin-left: .75rem;
    white-space: nowrap;
}

.shell-bar .btn-shell {
    color: #e0f5f2;
    border: 0;
    background: transparent;
    width: 38px;
    height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: .375rem;
    position: relative;
    transition: background var(--erp-transicion);
}

.shell-bar .btn-shell.con-texto { width: auto; padding: 0 .6rem; }

.shell-bar .btn-shell:hover {
    background: rgba(255, 255, 255, .12);
    color: #fff;
}

.shell-bar .punto-notificacion {
    position: absolute;
    top: 7px;
    right: 8px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #e9730c;
    display: none; /* preparado: visible cuando existan notificaciones */
}

/* =========================================================
   SIDEBAR (expandible / colapsable / offcanvas móvil)
   ========================================================= */
.sidebar {
    width: var(--erp-sidebar-ancho);
    background-color: var(--erp-sidebar-bg);
    border-right: 1px solid var(--erp-sidebar-border);
    display: flex;
    flex-direction: column;
    transition: width var(--erp-transicion), left var(--erp-transicion);
}

.sidebar-menu {
    flex-wrap: nowrap !important;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1 1 auto;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 transparent;
}

.sidebar-menu::-webkit-scrollbar { width: 6px; }
.sidebar-menu::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }

.sidebar-grupo {
    font-size: .68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--erp-texto-suave);
    padding: .85rem 1rem .35rem;
    white-space: nowrap;
}

.sidebar-link {
    display: flex;
    align-items: center;
    color: var(--erp-texto);
    font-size: .875rem;
    padding: .5rem 1rem;
    border-left: 3px solid transparent;
    white-space: nowrap;
    transition: background var(--erp-transicion), color var(--erp-transicion);
}

.sidebar-link i {
    flex-shrink: 0;
    width: 1.5rem;
    text-align: center;
    margin-right: .55rem;
    color: var(--erp-texto-suave);
    font-size: 1.05rem;
    transition: margin var(--erp-transicion);
}

.sidebar-link:hover { background-color: #f1f5f9; color: var(--erp-primary); }
.sidebar-link:hover i { color: var(--erp-primary); }

.sidebar-link.active {
    background-color: var(--erp-primary-soft);
    border-left-color: var(--erp-primary);
    color: var(--erp-primary);
    font-weight: 600;
}

.sidebar-link.active i { color: var(--erp-primary); }

.sidebar-pie {
    border-top: 1px solid var(--erp-sidebar-border);
    padding: .4rem 0;
}

/* ---------- Móvil (<992px): offcanvas ---------- */
@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        top: var(--erp-shell-alto);
        left: calc(-1 * var(--erp-sidebar-ancho) - 10px);
        height: calc(100vh - var(--erp-shell-alto));
        z-index: 1045;
        box-shadow: none;
    }

    .sidebar.abierto {
        left: 0;
        box-shadow: 0 0 24px rgba(15, 23, 42, .25);
    }

    .sidebar-backdrop {
        display: none;
        position: fixed;
        inset: var(--erp-shell-alto) 0 0 0;
        background: rgba(15, 23, 42, .45);
        z-index: 1040;
    }

    .sidebar.abierto ~ .sidebar-backdrop { display: block; }
}

/* ---------- Escritorio (≥992px): fijo y colapsable ---------- */
@media (min-width: 992px) {
    .sidebar {
        position: sticky;
        top: var(--erp-shell-alto);
        height: calc(100vh - var(--erp-shell-alto));
        flex-shrink: 0;
    }

    .sidebar-backdrop { display: none !important; }

    #panelPrincipal {
        min-width: 0;
        transition: margin var(--erp-transicion);
    }

    /* --- Estado colapsado: solo iconos --- */
    body.sidebar-colapsado .sidebar { width: var(--erp-sidebar-colapsado); }

    body.sidebar-colapsado .sidebar .sidebar-grupo {
        padding: .5rem 0;
        font-size: 0;
        border-top: 1px solid var(--erp-sidebar-border);
        margin: .25rem .9rem 0;
    }

    body.sidebar-colapsado .sidebar .sidebar-grupo:first-child { border-top: 0; margin-top: 0; }

    body.sidebar-colapsado .sidebar .sidebar-link {
        justify-content: center;
        padding: .55rem 0;
    }

    body.sidebar-colapsado .sidebar .sidebar-link i { margin-right: 0; font-size: 1.15rem; }
    body.sidebar-colapsado .sidebar .sidebar-link span { display: none; }

    /* --- Expansión temporal (clic sobre el sidebar colapsado) --- */
    body.sidebar-colapsado .sidebar.sidebar-flotante {
        width: var(--erp-sidebar-ancho);
        position: fixed;
        left: 0;
        box-shadow: 0 0 24px rgba(15, 23, 42, .22);
        z-index: 1046;
    }

    body.sidebar-colapsado .sidebar.sidebar-flotante .sidebar-grupo {
        padding: .85rem 1rem .35rem;
        font-size: .68rem;
        border-top: 0;
        margin: 0;
    }

    body.sidebar-colapsado .sidebar.sidebar-flotante .sidebar-link {
        justify-content: flex-start;
        padding: .5rem 1rem;
    }

    body.sidebar-colapsado .sidebar.sidebar-flotante .sidebar-link i { margin-right: .55rem; font-size: 1.05rem; }
    body.sidebar-colapsado .sidebar.sidebar-flotante .sidebar-link span { display: inline; }

    /* Mantiene el contenido en su sitio cuando el sidebar flota */
    body.sidebar-colapsado .sidebar.sidebar-flotante + #panelPrincipal,
    body.sidebar-colapsado:has(.sidebar.sidebar-flotante) #panelPrincipal {
        margin-left: var(--erp-sidebar-colapsado);
    }
}

/* =========================================================
   CARDS / CONTENIDO
   ========================================================= */
.card {
    border: 1px solid var(--erp-sidebar-border);
    border-radius: var(--erp-radio);
    box-shadow: var(--erp-sombra);
    transition: box-shadow var(--erp-transicion);
}

.card-header {
    background-color: transparent;
    border-bottom: 1px solid var(--erp-sidebar-border);
    font-weight: 600;
    font-size: .9rem;
}

.titulo-modulo {
    border-bottom: 2px solid var(--erp-sidebar-border);
    padding-bottom: .65rem;
    margin-bottom: 1.1rem;
}

/* Animación de entrada suave del contenido */
@keyframes aparecer {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

main > * { animation: aparecer .25s ease both; }

@media (prefers-reduced-motion: reduce) {
    main > * { animation: none; }
    * { transition-duration: .01ms !important; }
}

/* =========================================================
   BOTONES (uniformes, hover, loading, disabled)
   ========================================================= */
.btn {
    border-radius: .4rem;
    transition: background var(--erp-transicion), box-shadow var(--erp-transicion), transform .1s ease;
}

.btn:not(.btn-sm):not(.btn-lg) { min-height: 38px; }

.btn:hover:not(:disabled) { box-shadow: var(--erp-sombra); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .55; }

.btn-primary { background-color: var(--erp-primary); border-color: var(--erp-primary); }
.btn-primary:hover { background-color: var(--erp-primary-hover); border-color: var(--erp-primary-hover); }

.text-primary { color: var(--erp-primary) !important; }
.bg-primary { background-color: var(--erp-primary) !important; }

.btn-outline-primary {
    color: var(--erp-primary);
    border-color: var(--erp-primary);
}

.btn-outline-primary:hover,
.btn-outline-primary:active {
    background-color: var(--erp-primary) !important;
    border-color: var(--erp-primary) !important;
    color: #fff;
}

.nav-pills .nav-link.active { background-color: var(--erp-primary); }
.page-link { color: var(--erp-primary); }
.page-item.active .page-link { background-color: var(--erp-primary); border-color: var(--erp-primary); }
.form-check-input:checked { background-color: var(--erp-primary); border-color: var(--erp-primary); }

/* Spinner de carga inyectado por setCargando() */
.btn .spinner-border-sm { width: .9rem; height: .9rem; border-width: .12em; }

/* =========================================================
   FORMULARIOS (alturas y espaciados uniformes)
   ========================================================= */
.form-label {
    font-size: .8rem;
    font-weight: 600;
    color: var(--erp-texto-suave);
    margin-bottom: .3rem;
}

.form-control,
.form-select {
    min-height: 38px;
    border-radius: .4rem;
    font-size: .9rem;
}

.form-control-sm { min-height: 31px; }

textarea.form-control { min-height: auto; }

.input-group-text { border-radius: .4rem; }

/* =========================================================
   SELECT2 (alineado exactamente con Bootstrap)
   ========================================================= */
.select2-container--bootstrap-5 .select2-selection {
    min-height: 38px !important;
    border-radius: .4rem !important;
    border-color: var(--bs-border-color, #dee2e6) !important;
    font-size: .9rem;
    display: flex;
    align-items: center;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
    line-height: 1.5;
    padding-top: 0;
    padding-bottom: 0;
    display: flex;
    align-items: center;
    width: 100%;
}

.select2-container--bootstrap-5.select2-container--focus .select2-selection,
.select2-container--bootstrap-5.select2-container--open .select2-selection {
    border-color: var(--erp-primary) !important;
    box-shadow: 0 0 0 .2rem rgba(13, 148, 136, .15) !important;
}

/* Focus de inputs y selects alineado a la paleta */
.form-control:focus,
.form-select:focus {
    border-color: var(--erp-primary);
    box-shadow: 0 0 0 .2rem rgba(13, 148, 136, .15);
}

.select2-container--bootstrap-5 .select2-dropdown {
    border-radius: .4rem;
    border-color: var(--erp-sidebar-border);
    box-shadow: var(--erp-sombra-hover);
    font-size: .9rem;
}

.select2-container--bootstrap-5 .select2-results__option--highlighted {
    background-color: var(--erp-primary) !important;
}

/* =========================================================
   MODALES
   ========================================================= */
.modal-content {
    border: 0;
    border-radius: .65rem;
    box-shadow: 0 16px 48px rgba(13, 148, 136, .18), 0 4px 12px rgba(15, 23, 42, .12);
}

.modal-header {
    background: var(--erp-primary-soft);
    color: var(--erp-primary);
    border-bottom: 2px solid var(--erp-primary);
    border-radius: .65rem .65rem 0 0;
    padding: .85rem 1.15rem;
}

.modal-header .modal-title {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: .45rem;
}

.modal-body { padding: 1.15rem; }

.modal-footer {
    border-top: 1px solid var(--erp-sidebar-border);
    justify-content: flex-end;
    padding: .7rem 1.15rem;
    background: var(--erp-bg);
    border-radius: 0 0 .65rem .65rem;
}

/* =========================================================
   TABLAS (sticky header, hover moderno, responsive)
   ========================================================= */
.table { font-size: .875rem; margin-bottom: .5rem; }

.table thead th {
    white-space: nowrap;
    font-size: .76rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--erp-texto-suave);
    border-bottom-width: 2px;
    background: var(--bs-body-bg, #fff);
    position: sticky;
    top: 0;
    z-index: 1;
}

.table-responsive { max-height: 68vh; }

.table-hover > tbody > tr { transition: background .12s ease; }

.table-hover > tbody > tr:hover > * {
    background-color: var(--erp-primary-soft);
    --bs-table-bg-state: var(--erp-primary-soft);
}

/* DataTables: controles modernos */
div.dataTables_wrapper div.dataTables_filter input,
div.dataTables_wrapper div.dataTables_length select {
    font-size: .85rem;
    border-radius: .4rem;
}

div.dataTables_wrapper .dataTables_paginate .paginate_button .page-link {
    border-radius: .35rem;
    margin: 0 2px;
    font-size: .83rem;
}

div.dataTables_wrapper .dataTables_info { font-size: .8rem; color: var(--erp-texto-suave); }

/* Estado vacío elegante */
.dataTables_empty {
    padding: 2.2rem 0 !important;
    color: var(--erp-texto-suave);
    font-size: .9rem;
}

/* =========================================================
   BADGES
   ========================================================= */
.badge { font-weight: 600; letter-spacing: .02em; border-radius: .35rem; }

/* =========================================================
   KPI TILES (animados)
   ========================================================= */
.kpi-tile {
    background: var(--bs-body-bg, #fff);
    border: 1px solid var(--erp-sidebar-border);
    border-top: 3px solid var(--kpi-color, var(--erp-primary));
    border-radius: var(--erp-radio);
    padding: .9rem 1rem;
    height: 100%;
    transition: box-shadow var(--erp-transicion), transform var(--erp-transicion);
}

.kpi-tile:hover { box-shadow: var(--erp-sombra-hover); transform: translateY(-2px); }

.kpi-tile .kpi-etiqueta {
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--erp-texto-suave);
}

.kpi-tile .kpi-valor {
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.15;
    color: var(--kpi-color, var(--erp-primary));
    font-variant-numeric: tabular-nums;
}

.kpi-tile .kpi-icono {
    font-size: 1.6rem;
    color: var(--kpi-color, var(--erp-primary));
    background: color-mix(in srgb, var(--kpi-color, var(--erp-primary)) 12%, transparent);
    border-radius: var(--erp-radio);
    width: 2.7rem;
    height: 2.7rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.kpi-presentes  { --kpi-color: #107e3e; }
.kpi-tarde      { --kpi-color: #e9730c; }
.kpi-faltas     { --kpi-color: #bb0000; }
.kpi-vacaciones { --kpi-color: #0d9488; }
.kpi-permisos   { --kpi-color: #6c32a9; }

/* Widget Top tardanzas */
.widget-lista .item-ranking {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .55rem .25rem;
    border-bottom: 1px solid var(--erp-sidebar-border);
}

.widget-lista .item-ranking:last-child { border-bottom: 0; }

.widget-lista .avatar-iniciales {
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 50%;
    background: var(--erp-primary-soft);
    color: var(--erp-primary);
    font-weight: 700;
    font-size: .8rem;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* Estado vacío de widgets */
.estado-vacio {
    text-align: center;
    color: var(--erp-texto-suave);
    padding: 2rem 1rem;
}

.estado-vacio i { font-size: 2rem; opacity: .5; display: block; margin-bottom: .5rem; }

/* Contenedores de gráficos */
.grafico-contenedor { position: relative; height: 300px; width: 100%; }
.grafico-contenedor.bajo { height: 250px; }

@media (max-width: 575.98px) {
    .grafico-contenedor { height: 230px; }
    .kpi-tile .kpi-valor { font-size: 1.5rem; }
}

/* =========================================================
   LOGIN
   ========================================================= */
.login-body {
    background: linear-gradient(135deg, #0f766e 0%, #0d9488 55%, #14b8a6 100%);
    padding: 1rem;
}

.login-card { border-radius: .75rem; border: 0; }

/* =========================================================
   RELOJ DE MARCACIÓN
   ========================================================= */
.reloj-marcacion {
    font-size: clamp(2.2rem, 8vw, 3.6rem);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    color: var(--erp-shell-solido);
}

[data-bs-theme="dark"] .reloj-marcacion { color: #7eded3; }

/* =========================================================
   FOOTER
   ========================================================= */
footer {
    background: var(--bs-body-bg, #fff);
    border-top: 1px solid var(--erp-sidebar-border);
    font-size: .78rem;
}

/* =========================================================
   DARK MODE
   ========================================================= */
[data-bs-theme="dark"] {
    --erp-bg: #15191a;
    --erp-sidebar-bg: #1c2322;
    --erp-sidebar-border: #2b3534;
    --erp-texto: #e5e7eb;
    --erp-texto-suave: #9aa3ad;
    --erp-primary-soft: #0e3733;
    --erp-shell-bg: linear-gradient(90deg, #0b4f4a 0%, #0f766e 100%);
}

[data-bs-theme="dark"] body { background-color: var(--erp-bg); }
[data-bs-theme="dark"] .sidebar-link { color: var(--erp-texto); }
[data-bs-theme="dark"] .sidebar-link:hover { background-color: #243230; }
[data-bs-theme="dark"] .kpi-tile { background: #1c2322; }
[data-bs-theme="dark"] .table thead th { background: #1c2322; }
[data-bs-theme="dark"] .table-hover > tbody > tr:hover > * { background-color: #0e3733; }
[data-bs-theme="dark"] .modal-footer { background: #15191a; }

[data-bs-theme="dark"] .login-body {
    background: linear-gradient(135deg, #042f2c 0%, #0b4f4a 60%, #0f766e 100%);
}

[data-bs-theme="dark"] .select2-container--bootstrap-5 .select2-selection {
    background-color: #1c2322;
    color: var(--erp-texto);
}

/* =========================================================
   IMPRESIÓN (export PDF desde navegador)
   ========================================================= */
@media print {
    .sidebar,
    .shell-bar,
    footer,
    .no-imprimir { display: none !important; }

    main { padding: 0 !important; }
}
