/* ============================================================
   WILLYLABS v2 - HOJA DE ESTILO OFICIAL (TOP-NAV OVERRIDES)
   ============================================================ */

:root {
    --bg-white: #ffffff;
    --bg-light: #f8fafc;
    --bg-dash: #f4f7fe;
    --primary: #8b5cf6;
    --primary-light: #a78bfa;
    --primary-dark: #7c3aed;
    --text-dark: #1e1b4b;
    --text-muted: #64748b;
    --radius: 12px;
    --transition: all 0.3s ease;
    --shadow: 0 4px 15px rgba(139, 92, 246, 0.1);
}

body {
    font-family: 'Inter', 'Source Sans Pro', sans-serif;
    background-color: var(--bg-dash);
}

/* ============================================================
   FIX DEFINITIVO: AUTO-EXPANSIÓN Y STICKY NAV (SAAS UX)
   ============================================================ */

/* 1. Liberar el scroll del body principal */
html, body.layout-top-nav {
    height: auto !important;
    min-height: 100vh;
    overflow-y: auto !important;
    overflow-x: hidden;
}

.wrapper, .content-wrapper.willy-workspace {
    height: auto !important;
    min-height: 100vh;
    overflow: visible !important;
}

/* Permitir que solo el content-wrapper (debajo del header) se encoja para dar paso a Dobbi */
.content-wrapper {
    transition: padding-right 0.3s ease;
}

/* 2. Fijar el Header Global arriba (Efecto Sticky) */
.main-header.navbar {
    position: sticky !important;
    top: 0;
    z-index: 1040;
    border-bottom: 1px solid rgba(139, 92, 246, 0.1) !important;
    background-color: var(--bg-white);
}

/* 3. Fijar la Barra de Pestañas debajo del Header */
.content-wrapper.willy-workspace .nav-navbar {
    position: sticky !important;
    top: 57px;
    z-index: 1030;
    background-color: #f1f5f9 !important;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    border-bottom: 1px solid #cbd5e1 !important;
    height: 48px;
    display: flex;
    align-items: stretch;
}

/* Evitar que el nombre de la App se rompa en dos líneas */
#appIndicatorContainer {
    white-space: nowrap !important;
    min-width: fit-content;
    background: linear-gradient(135deg, rgba(139, 92, 246, 0.05), rgba(124, 58, 237, 0.02));
    border-right: 1px solid #cbd5e1 !important;
    display: flex;
    align-items: center;
    padding: 0 20px !important;
    color: var(--primary-dark) !important;
}

/* 4. Liberar las capas internas y los iframes */
.content-wrapper.willy-workspace .tab-content,
.content-wrapper.willy-workspace .tab-pane,
.content-wrapper.willy-workspace .tab-empty,
.content-wrapper.willy-workspace .tab-loading {
    height: auto !important;
    min-height: calc(100vh - 105px);
    overflow: visible !important;
    padding: 0;
    margin: 0;
}

/* FIX OVERLAPPING: Solo mostramos la pestaña estrictamente activa */
.content-wrapper.willy-workspace .tab-content > .tab-pane {
    display: none !important;
}
.content-wrapper.willy-workspace .tab-content > .tab-pane.active {
    display: block !important;
}

.content-wrapper.willy-workspace iframe {
    min-height: calc(100vh - 105px) !important;
    width: 100% !important;
    border: none;
    display: block;
    overflow: hidden !important;
}

/* BARRA DE BÚSQUEDA GLOBAL */
#globalSearchForm .form-control {
    border-radius: 20px 0 0 20px;
    border: 1px solid #e2e8f0;
    border-right: none;
    padding-left: 20px;
}
#globalSearchForm .btn {
    border-radius: 0 20px 20px 0;
    border: 1px solid #e2e8f0;
    border-left: none;
}
#globalSearchForm .form-control:focus {
    box-shadow: none;
    border-color: var(--primary-light);
}

/* TABS SUPERIORES WILLYLABS */
.content-wrapper.willy-workspace .nav-navbar .nav-link[data-widget^="iframe-"] {
    background-color: transparent !important;
    color: var(--text-muted) !important;
    border: none !important;
    border-right: 1px solid #cbd5e1 !important;
    border-left: 1px solid #cbd5e1 !important;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    transition: var(--transition);
}
.content-wrapper.willy-workspace .nav-navbar .nav-link[data-widget^="iframe-"]:hover {
    background-color: rgba(139, 92, 246, 0.1) !important;
    color: var(--primary) !important;
}

.custom-iframe-tabs {
    display: flex;
    align-items: flex-end;
    padding-left: 10px;
    height: 100%;
}

.custom-iframe-tabs .nav-item {
    margin-right: 4px;
    height: 40px;
}

.custom-iframe-tabs .nav-link {
    background-color: #e2e8f0 !important;
    color: #64748b !important;
    border: 1px solid #cbd5e1 !important;
    border-bottom: none !important;
    border-radius: 8px 8px 0 0;
    padding: 0 35px 0 15px !important;
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    height: 100%;
    transition: all 0.2s ease;
}

.custom-iframe-tabs .nav-link:hover {
    background-color: #f8fafc !important;
    color: var(--text-dark) !important;
}

.custom-iframe-tabs .nav-link.active {
    background-color: var(--bg-white) !important;
    color: var(--primary-dark) !important;
    border-top: 3px solid var(--primary) !important;
    border-left: 1px solid #cbd5e1 !important;
    border-right: 1px solid #cbd5e1 !important;
    font-weight: 700;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.02);
    height: 41px;
    transform: translateY(1px);
}

.custom-iframe-tabs .nav-link .btn-iframe-close {
    display: none !important;
}

/* HOME: TARJETAS DE APLICACIONES */
.app-card-hover {
    transition: var(--transition);
    border: 1px solid rgba(139, 92, 246, 0.08);
    border-radius: var(--radius);
}
.app-card-hover:hover {
    transform: translateY(-5px);
    box-shadow: 0 15px 30px rgba(139, 92, 246, 0.15) !important;
    border-color: var(--primary-light);
}
.bg-primary-light {
    background-color: rgba(139, 92, 246, 0.1);
}
.bg-primary-light i {
    color: var(--primary) !important;
}

/* BOTONES GLOBALES */
.btn-violet { background-color: var(--primary); color: white; border-color: var(--primary); border-radius: 8px; }
.btn-violet:hover { background-color: var(--primary-dark); color: white; }
.btn-violet-gradient { background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: white !important; border: none; }

/* SCROLLBARS PERSONALIZADOS */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-light); }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary-light); }

/* ============================================================
   ESTILOS DE AUTENTICACIÓN (LOGIN & 2FA)
   ============================================================ */

.login-split {
    display: flex;
    min-height: 100vh;
    width: 100%;
    margin: 0;
    padding: 0;
    background-color: var(--bg-white);
}

.login-split .login-form-side {
    flex: 1;
    background: white;
    display: flex;
    flex-direction: column;
    padding: 40px;
    position: relative;
    min-height: 100vh;
}

.login-split .login-box {
    width: 100%;
    max-width: 420px;
    margin: auto; /* Centra horizontal y verticalmente sin "romper" el scroll hacia arriba */
    animation: fadeIn 0.8s ease;
}

.login-split .login-box h1 {
    font-size: 2.2rem;
    font-weight: 800;
    margin-bottom: 5px;
    letter-spacing: -1px;
    color: var(--text-dark);
}

.login-split .login-box p {
    color: var(--text-muted);
    margin-bottom: 25px;
    font-size: 0.95rem;
}

.login-split .form-group { margin-bottom: 20px; }

.login-split .form-control {
    width: 100%;
    padding: 14px 16px;
    height: auto;
    border-radius: var(--radius);
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    font-size: 1rem;
    transition: var(--transition);
}

.login-split .form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(139, 92, 246, 0.1);
    background: white;
}

.login-split .btn-primary-login {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 10px 15px -3px rgba(139, 92, 246, 0.3);
}

.login-split .btn-primary-login:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 25px -5px rgba(139, 92, 246, 0.4);
}

.login-split .login-image-side {
    flex: 1.2;
    background-color: var(--bg-dash);
    display: flex;
    align-items: center;
    justify-content: center;
    border-left: 1px solid #e2e8f0;
    position: sticky;
    top: 0;
    height: 100vh;
}

.login-logo {
    height: 70%;
    width: auto;
    object-fit: contain;
    filter: drop-shadow(0 20px 30px rgba(0,0,0,0.05));
}

.alert-error {
    background-color: #fef2f2;
    color: #991b1b;
    border: 1px solid #fee2e2;
    padding: 12px 16px;
    border-radius: var(--radius);
    margin-bottom: 20px;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 12px;
}

.input-wrapper { position: relative; width: 100%; }
.has-icon { padding-right: 45px !important; }
.help-icon-container {
    position: absolute; right: 15px; top: 50%; transform: translateY(-50%);
    font-size: 1.1rem; z-index: 10;
}
.help-icon {
    cursor: pointer; color: var(--primary-light); transition: var(--transition);
}
.help-icon:hover { color: var(--primary); transform: scale(1.1); }

@media (max-width: 992px) {
    .login-split .login-image-side { display: none; }
}

.custom-popover {
    border-radius: var(--radius); border: none;
    box-shadow: 0 10px 25px rgba(30,27,75,0.15); font-family: inherit;
}
.custom-popover .popover-header {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white; font-weight: 700; border-bottom: none;
    border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0;
}
.custom-popover .popover-body { padding: 15px; font-size: 0.85rem; }

/* ============================================================
   WILLYLABS SMART TABS (TRES PUNTITOS Y CONFIG MODE)
   ============================================================ */

/* Contenedor relativo para la pestaña */
#willyTabsNav .nav-item {
    position: relative;
    display: flex;
    align-items: flex-end;
}

/* El botón de los 3 puntitos (oculto por defecto) */
.willy-tab-options {
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translateY(-50%);
    opacity: 0;
    transition: all 0.2s ease;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    z-index: 10;
}

.willy-tab-options:hover {
    background: rgba(139, 92, 246, 0.1);
    color: var(--primary);
}

/* Mostrar al pasar el mouse sobre el LI */
#willyTabsNav .nav-item:hover .willy-tab-options {
    opacity: 1;
}

/* Padding extra a la derecha para que el texto no pise los 3 puntitos */
.custom-iframe-tabs .nav-link {
    padding-right: 30px !important;
}

/* Transiciones para el Flip de Configuración */
.panel-view-mode, .panel-config-mode {
    animation: fadeIn 0.3s ease-in-out;
}

.config-header {
    background: linear-gradient(135deg, var(--bg-dash), var(--bg-white));
    border-bottom: 2px solid var(--primary-light);
    padding: 15px 20px;
    border-radius: var(--radius) var(--radius) 0 0;
}

/* ============================================================
   ESTILOS DE VALIDACIÓN DE FORMULARIO (ERRORES)
   ============================================================ */

.login-split .invalid-feedback.d-block {
    display: flex !important;
    align-items: center;
    gap: 8px;
    background-color: #fef2f2;
    color: #ef4444;
    border: 1px solid #fee2e2;
    padding: 10px 12px;
    border-radius: var(--radius);
    margin-top: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    animation: fadeInDown 0.3s ease;
}

.login-split .invalid-feedback i {
    font-size: 1.1rem;
}

/* Resaltar el input cuando tiene error */
.login-split .form-control.is-invalid {
    border-color: #ef4444 !important;
    background-color: #fffafb;
}

.login-split .form-control.is-invalid:focus {
    box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.15) !important;
}

.external-link {
    font-size: 9px;
    vertical-align: middle;
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   DOBBI PANEL (SPLIT SCREEN & AJAX READY)
   ============================================================ */

#dobbi-sidebar {
    position: fixed;
    top: 57px; /* Debajo del Header nativo */
    right: 0;
    height: calc(100vh - 57px);
    width: 400px; /* Ancho por defecto */
    background: #fff;
    z-index: 1035;
    display: flex;
    flex-direction: column;
    transform: translateX(100%); /* Oculto por defecto */
    /* Agregamos la transición del width para la animación de Fullscreen fluida */
    transition: transform 0.3s ease, width 0.3s ease;
    border-left: 1px solid #cbd5e1;
}

#dobbi-sidebar.dobbi-sidebar-open {
    transform: translateX(0);
}

#dobbi-sidebar.dobbi-fullscreen {
    /* Al usar 100vw y NO tener un left: 0 fijado, el panel anclado a la derecha crece orgánicamente hacia la izquierda */
    width: 100vw !important;
    border-left: none;
}

#dobbi-resizer {
    position: absolute;
    top: 0;
    bottom: 0;
    left: -3px; /* Cubre un poco fuera del borde para hacerlo clickeable fácil */
    width: 6px;
    cursor: ew-resize;
    background: transparent;
    z-index: 10;
    transition: background 0.2s ease;
}

#dobbi-resizer:hover, #dobbi-resizer.resizing {
    background: var(--primary-light);
}

.dobbi-header-controls button {
    padding: 0 6px;
    font-size: 1rem;
    transition: var(--transition);
}

.dobbi-header-controls button:hover {
    color: var(--primary-light) !important;
    transform: scale(1.1);
}

/* ============================================================
   BUSCADOR LOCAL Y FILTROS (TABLAS GRIDJS)
   ============================================================ */

.search-wrapper-premium {
    position: relative;
    max-width: 450px;
    width: 100%;
}

.search-wrapper-premium i {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
    z-index: 4; /* Por encima del input */
}

.search-bar-premium {
    border-radius: 20px !important;
    background-color: var(--bg-light) !important;
    border: 1px solid #e2e8f0 !important;
    padding-left: 42px !important; /* Espacio para el icono */
    height: 42px !important;
    transition: var(--transition) !important;
    font-size: 0.95rem !important;
    box-shadow: none !important;
}

.search-bar-premium:focus {
    background-color: var(--bg-white) !important;
    border-color: var(--primary-light) !important;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.1) !important;
    outline: none !important;
}

.btn-action-premium {
    height: 42px;
    border-radius: 20px;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 8px;
    border: 1px solid #e2e8f0;
    color: var(--text-dark);
    background: var(--bg-white);
    transition: var(--transition);
}

.btn-action-premium:hover {
    border-color: var(--primary-light);
    color: var(--primary-dark);
    background: rgba(139, 92, 246, 0.05);
}

/* ============================================================
   CUSTOM SWITCHES Y CHECKBOXES TIPO MÓVIL (PREFERENCIAS)
   ============================================================ */

/* Cambiar el color del track al encender (Switch) */
.custom-switch-premium .custom-control-input:checked ~ .custom-control-label::before {
    background-color: var(--primary) !important;
    border-color: var(--primary) !important;
}

/* Sombra de focus (Switch) */
.custom-switch-premium .custom-control-input:focus ~ .custom-control-label::before {
    box-shadow: 0 0 0 0.2rem rgba(139, 92, 246, 0.25) !important;
}

/* ESTADO DISABLED & CHECKED: Violeta más claro y cursor prohibido */
.custom-switch-premium .custom-control-input:checked:disabled ~ .custom-control-label::before {
    background-color: var(--primary-light) !important;
    border-color: var(--primary-light) !important;
    opacity: 0.6;
}

.custom-switch-premium .custom-control-input:disabled ~ .custom-control-label {
    color: #94a3b8 !important; /* Gris intermedio para indicar que no es interactivo */
    cursor: not-allowed !important;
}

/* Checkbox normal con color primario */
.custom-checkbox-premium .custom-control-input:checked ~ .custom-control-label::before {
    background-color: var(--primary) !important;
    border-color: var(--primary) !important;
}

.custom-checkbox-premium .custom-control-input:focus ~ .custom-control-label::before {
    box-shadow: 0 0 0 0.2rem rgba(139, 92, 246, 0.25) !important;
}

/* COMPORTAMIENTO DE LOS ACORDEONES (Rotar flechita) */
.collapsible-header[aria-expanded="true"] .transition-chevron {
    transform: rotate(180deg);
}
.transition-chevron {
    transition: transform 0.3s ease;
}

/* UTILIDADES EXTRAS MODAL CONFIG */
.border-dashed { border: 1px dashed #cbd5e1 !important; }
.text-xs { font-size: 0.75rem !important; }
.gutters-sm { margin-right: -4px; margin-left: -4px; }
.gutters-sm > .col, .gutters-sm > [class*="col-"] { padding-right: 4px; padding-left: 4px; }
.cursor-pointer { cursor: pointer !important; }

/* Badge Sólido (Fondo violeta, texto blanco) */
.badge-violet {
    background-color: var(--primary);
    color: var(--bg-white);
}

/* Badge Suave (Fondo violeta translúcido, texto violeta oscuro) */
.badge-violet-light {
    background-color: rgba(139, 92, 246, 0.1); /* Usa la misma opacidad que tu bg-primary-light */
    color: var(--primary-dark);
}

/* Contenedor base */
.hover-icon {
    display: inline-flex;
    align-items: center;
    cursor: pointer;
}

/* Preparar el ícono (oculto por defecto) */
.hover-icon::after {
    content: '\f059'; /* Código Unicode para una flecha derecha (→). */
    opacity: 0;
    font-family: "Font Awesome 6 Free";
    margin-left: 8px;
}

/* Mostrar y animar el ícono en hover */
.hover-icon:hover::after {
    opacity: 1;
    transform: translateX(0); /* Desliza a su posición final */
}

.gridjs-tr {
    cursor: pointer;
    transition: background-color 0.2s ease;
}

/* Efecto visual cuando la fila tiene el checkbox marcado */
.gridjs-tr:has(.fila-checkbox-unica:checked) {
    background-color: rgba(139, 92, 246, 0.05) !important; /* Un toque de tu color violeta */
}