:root {
    /* 🪐 1. TOKENS DE IDENTIDAD CORPORATIVA (SaaS Core 2026) */
    --brand-primary: #00b4d8;       /* Azul Océano SaaS (Botones principales, Focus) */
    --brand-success: #2bc48a;       /* Verde Esmeralda (Etiquetas ACTIVO, Éxito) */
    --brand-danger: #f76c6c;        /* Coral Elegante (Alertas, Inhabilitar, Borrar) */
    --radius-universal: 8px;        /* Bordes suavizados consistentes en todo el sistema */

    /* 🌓 2. PALETA GLOBAL - MODO CLARO (Default) */
    --bg-main: #f1f5f9;             /* Gris pizarra muy suave para el fondo general */
    --bg-card: #ffffff;             /* Blanco puro para tarjetas, tablas y modales */
    --bg-sidebar: #1e293b;          /* 🛡️ SELLO: Azul Slate Oscuro inmutable para el menú izquierdo */
    --text-main: #0f172a;           /* Texto principal ultra-legible */
    --text-muted: #64748b;          /* Texto secundario / gris descriptivo */
    --border-color: #e2e8f0;        /* Gris unificado para bordes de inputs y líneas de tablas */
}

body.dark-mode {
    /* 🌗 3. PALETA GLOBAL - MODO OSCURO (Sincronizada por Clase) */
    --bg-main: #0f172a;             /* Negro azulado profundo para el fondo general */
    --bg-card: #1e293b;             /* Gris Slate oscuro para componentes y modales */
    --bg-sidebar: #0f172a;          /* El menú se mimetiza con el fondo en la noche */
    --text-main: #f8fafc;           /* Texto brillante */
    --text-muted: #94a3b8;          /* Texto secundario atenuado */
    --border-color: #334155;        /* Líneas de división oscuras */
}

/* ============================================================================
   🏛️ 4. BLINDAJE DE COMPONENTES GLOBALES (Impacta a todo ByteCobrador)
   ============================================================================ */

/* 📋 A. Estándar de Inputs y Selects del Sistema */
input[type="text"], input[type="password"], input[type="number"], select, .w3-input, .w3-select {
    background-color: var(--bg-card) !important;
    color: var(--text-main) !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-universal) !important;
    padding: 10px 14px !important;
    font-size: 0.95em !important;
    transition: all 0.2s ease-in-out !important;
}

/* Efecto Focus unificado de alta gama al escribir */
input:focus, select:focus, .w3-input:focus, .w3-select:focus {
    border-color: var(--brand-primary) !important;
    outline: none !important;
    box-shadow: 0 0 0 3px rgba(0, 180, 216, 0.15) !important;
}

/* 🔘 B. Estándar de Botones del Sistema */
.w3-button, button {
    border-radius: var(--radius-universal) !important;
    transition: all 0.2s ease !important;
}

/* 🛡️ C. Reparación y Blindaje de la Barra Lateral Izquierda */
.w3-sidebar, #sidebar, [class*="sidebar"] {
    background-color: var(--bg-sidebar) !important;
    color: #ffffff !important;
}

/* Asegurar que los links del menú no se alteren en modo claro */
.w3-sidebar a, #sidebar a {
    color: #cbd5e1 !important;
}
.w3-sidebar a:hover, #sidebar a:hover {
    background-color: rgba(255, 255, 255, 0.08) !important;
    color: #ffffff !important;
}
/* ============================================================================*/

/* [v6.18.6] PROTOCOLO DE AUTORIDAD ÚNICA (Anti-Doble Scroll)
           La técnica definitiva: el HTML es un marco rígido y el BODY es el único scroller. */
html {
    height: 100%;
    overflow: hidden !important;
}

body {
    font-family: 'Inter', "Segoe UI", sans-serif;
    background-color: var(--bg-main);
    color: var(--text-main);
    letter-spacing: -0.01em;
    transition: background-color 0.3s, color 0.3s;
    margin: 0;
    padding: 0;
    height: 100%;
    overflow-x: hidden;
    overflow-y: auto !important;
    /* El body es el ÚNICO que scrollea */
    display: flex;
    flex-direction: column;
}

/* 🚀 SPLASH SCREEN MASTER (ByteCobrador Premium Loading) */
#app-splash-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: #2c3e50;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    transition: opacity 0.5s ease, visibility 0.5s;
}

.splash-logo {
    width: 80px;
    height: 80px;
    margin-bottom: 24px;
    animation: pulse 2s infinite ease-in-out;
}

.splash-loader {
    width: 200px;
    height: 3px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

.splash-loader::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    width: 50%;
    background: #009688;
    border-radius: 10px;
    animation: loading-bar 1.5s infinite ease-in-out;
}

.splash-text {
    color: #bdc3c7;
    font-size: 0.8em;
    margin-top: 15px;
    font-weight: 600;
    letter-spacing: 1px;
    text-transform: uppercase;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.05);
        opacity: 0.9;
    }
}

@keyframes loading-bar {
    0% {
        left: -50%;
    }

    100% {
        left: 100%;
    }
}

/* OVERRIDES PARA MODO OSCURO */
body.dark-mode .w3-white,
body.dark-mode .w3-card,
body.dark-mode .w3-card-2,
body.dark-mode .w3-card-4,
body.dark-mode .top-bar {
    background-color: var(--bg-card) !important;
    color: var(--text-main) !important;
    border-color: var(--border-color) !important;
}

body.dark-mode .w3-light-grey,
body.dark-mode .w3-modal-content {
    background-color: #252525 !important;
    color: var(--text-main) !important;
}

body.dark-mode .w3-input,
body.dark-mode .w3-select,
body.dark-mode .w3-border {
    background-color: #2c2c2c !important;
    color: white !important;
    border-color: #444 !important;
}

body.dark-mode table.w3-table-all tr {
    background-color: var(--bg-card) !important;
    color: var(--text-main) !important;
}

body.dark-mode .w3-text-grey {
    color: #aaa !important;
}

/* ESTILO DINÁMICO DE CÁPSULAS (SSOT UI) */
.plan-capsule,
.plan-opt {
    background: var(--plan-bg) !important;
    color: var(--plan-text) !important;
    border: 1px solid var(--plan-border) !important;
    border-radius: 6px;
    padding: 10px;
    margin-bottom: 8px;
    font-size: 0.85em;
    display: flex;
    flex-direction: column;
    transition: 0.2s;
    cursor: pointer;
}

/* En tarjetas es horizontal */
.product-card .plan-capsule {
    flex-direction: row;
    justify-content: space-between;
    align-items: center;
    padding: 6px 10px;
}

.plan-capsule b,
.plan-opt b {
    color: var(--plan-accent) !important;
}

/* ESTADO SELECCIONADO (Hotfix v3.2.3) */
.plan-opt.selected {
    background-color: var(--sel-bg) !important;
    border-color: var(--sel-border) !important;
    color: var(--sel-text) !important;
}

.plan-opt.selected b,
.plan-opt.selected span {
    color: var(--sel-text) !important;
}

.plan-capsule:hover,
.plan-opt:hover {
    filter: brightness(1.1);
    border-color: var(--accent-color) !important;
}

/* Custom styles for Payment Plan CRUD */

/* Table Header */
.table-header-custom {
    background-color: #e6e6e6 !important;
    /* Ligeramente más oscuro que w3-light-grey */
    border-bottom: 2px solid #ccc;
}

body.dark-mode .table-header-custom {
    background-color: #333 !important;
    border-bottom: 2px solid #555;
}

/* Status Chips */
.status-chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75em;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin: auto;
    /* Centrar el chip en la celda */
}

.status-chip-active {
    background-color: #e8f5e9;
    /* Light green */
    color: #2e7d32;
    /* Darker green */
    border: 1px solid #a5d6a7;
}

body.dark-mode .status-chip-active {
    background-color: #1b5e20;
    /* Dark green */
    color: #a5d6a7;
    /* Light green */
    border: 1px solid #4caf50;
}

.status-chip-inactive {
    background-color: #ffebee;
    /* Light red */
    color: #c62828;
    /* Darker red */
    border: 1px solid #ef9a9a;
}

body.dark-mode .status-chip-inactive {
    background-color: #b71c1c;
    /* Dark red */
    color: #ef9a9a;
    /* Light red */
    border: 1px solid #d32f2f;
}

/* Action Buttons */
.w3-blue-edit {
    background-color: #2196F3 !important;
    /* Azul estándar para editar */
    color: white !important;
}

.w3-blue-edit:hover {
    background-color: #0d8bf2 !important;
}

body.dark-mode .w3-blue-edit {
    background-color: #64b5f6 !important;
    /* Azul más claro para modo oscuro */
    color: white !important;
}

body.dark-mode .w3-blue-edit:hover {
    background-color: #42a5f5 !important;
}


.w3-red-delete {
    background-color: #f44336 !important;
    /* Rojo estándar para eliminar */
    color: white !important;
}

.w3-red-delete:hover {
    background-color: #da190b !important;
}

body.dark-mode .w3-red-delete {
    background-color: #e57373 !important;
    /* Rojo más claro para modo oscuro */
    color: white !important;
}

body.dark-mode .w3-red-delete:hover {
    background-color: #ef5350 !important;
}

/* [v5.8.4] BLINDAJE DE CAPAS DE DIÁLOGO (SSOT UX)
           Asegura que SweetAlert2 siempre esté por encima de cualquier modal CRUD o Visor. */
.swal2-container {
    z-index: 100000 !important;
}

/* MODAL FIX */
@media (min-width: 993px) {
    .w3-modal {
        padding-left: 250px;
        transition: padding-left 0.3s ease;
    }

    .main-content.expanded .w3-modal {
        padding-left: 70px;
    }
}

@media (max-width: 992px) {
    .w3-modal {
        padding-left: 0 !important;
        padding-top: 10px !important;
    }

    .w3-modal-content {
        margin: 10px auto !important;
        width: 95% !important;
    }
}

/* INDICADOR DE RED */
#network-status-bar {
    display: none;
    background-color: var(--error-color);
    color: white;
    text-align: center;
    padding: 4px;
    font-size: 0.85em;
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 2000;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
    }

    to {
        transform: translateY(0);
    }
}

/* SIDEBAR FLEXIBLE */
.sidebar {
    height: 100vh;
    width: 250px;
    background-color: var(--sidebar-bg);
    position: fixed !important;
    top: 0;
    left: 0;
    z-index: 1100;
    overflow: hidden;
    color: white;
    display: flex;
    flex-direction: column;
    transition: transform 0.3s ease, width 0.3s ease;
}

.sidebar.collapsed {
    width: 70px !important;
}

.sidebar.collapsed .nav-text,
.sidebar.collapsed #company-name-label,
.sidebar.collapsed .sidebar-footer span,
.sidebar.collapsed .sidebar-footer b,
.sidebar.collapsed .sidebar-footer p,
.sidebar.collapsed h3 {
    display: none !important;
}

.sidebar.collapsed .sidebar-logo-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 15px 0;
    text-align: center;
}

.sidebar.collapsed .sidebar-logo {
    margin-right: 0;
    margin-bottom: 20px;
    width: 30px;
    height: 30px;
}

.sidebar.collapsed .sidebar-controls {
    position: static;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.sidebar.collapsed a {
    text-align: center;
    padding: 16px 0;
    width: 100%;
}

.sidebar.collapsed a i {
    margin-right: 0 !important;
    font-size: 1.2em;
    display: inline-block;
    width: 100%;
    text-align: center;
}

.sidebar-scrollable {
    flex-grow: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.sidebar-scrollable::-webkit-scrollbar {
    display: none;
}

.main-content {
    margin-left: 250px;
    padding: 0;
    transition: margin-left 0.3s ease;
    min-height: 100vh;
    flex: 1;
    display: flex;
    flex-direction: column;
}

.main-content.expanded {
    margin-left: 70px !important;
}

.sidebar a {
    padding: 16px;
    text-decoration: none;
    display: block;
    color: #bdc3c7;
    transition: 0.2s;
    cursor: pointer;
    white-space: nowrap;
}

.sidebar a:hover {
    background-color: var(--sidebar-hover);
    color: white;
}

.sidebar a.active {
    background-color: #009688 !important;
    color: white !important;
    border-left: 5px solid #fff;
}

.sidebar-logo-container {
    padding: 24px 16px;
    border-bottom: 1px solid #34495e;
    margin-bottom: 10px;
    position: relative;
}

.sidebar-logo {
    width: 32px;
    height: 32px;
    border-radius: 4px;
    background-color: white;
    padding: 2px;
    margin-right: 10px;
    display: inline-block;
    vertical-align: middle;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    object-fit: cover;
}

.sidebar-title-group {
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

.sidebar-controls {
    position: absolute;
    right: 10px;
    top: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.sidebar-controls i {
    cursor: pointer;
    color: #bdc3c7;
    font-size: 1.1em;
    transition: 0.3s;
    padding: 5px;
}

.sidebar-controls i:hover {
    color: white;
}

.sidebar-footer {
    padding: 15px;
    border-top: 1px solid #34495e;
    background-color: #243342;
    font-size: 0.75em;
    color: #7f8c8d;
    text-align: center;
}

.footer-brand-logo {
    width: 18px;
    height: 18px;
    opacity: 0.6;
    vertical-align: middle;
    margin-right: 5px;
    filter: grayscale(1);
}

.nav-link {
    display: none !important;
    animation: fadeIn 0.5s;
}

.nav-link.show {
    display: block !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.loader {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #009688;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    animation: spin 1s linear infinite;
    display: inline-block;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* Asegurar que la barra superior permita el paso de clics a elementos elevados */
.top-bar {
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    pointer-events: auto; /* Permite interacciones nativas */
}

#sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1050;
    backdrop-filter: blur(2px);
}

@media (max-width: 992px) {

    .main-content,
    .main-content.expanded {
        margin-left: 0 !important;
    }

    .sidebar {
        transform: translateX(-100%);
        width: 280px !important;
        box-shadow: 5px 0 15px rgba(0, 0, 0, 0.3);
    }

    .sidebar.mobile-open {
        transform: translateX(0) !important;
    }

    .sidebar.collapsed {
        transform: translateX(-100%) !important;
        width: 280px !important;
    }

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

.avatar-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
    font-size: 14px;
    margin-right: 12px;
    flex-shrink: 0;
}

.avatar-circle.w3-teal {
    background-color: #009688 !important;
}

.avatar-circle.w3-indigo {
    background-color: #3f51b5 !important;
}

.time-ago {
    display: block;
    font-size: 10px;
    color: #888;
}

/* 🎯 SMART-TIP COMPONENT GLOBAL (v5.7.8 - POSICIONAMIENTO ADAPTATIVO TRIPLE) */
.smart-tip {
    position: relative;
    display: inline-block;
    cursor: help;
    color: inherit;
}

.smart-tip-content {
    visibility: hidden;
    opacity: 0;
    position: absolute;
    z-index: 999999 !important;
    top: 100%;

    /* FUERZA BRUTA DE ANCHO */
    width: 550px !important;
    min-width: 550px !important;
    max-width: 85vw !important;

    background-color: #1a252f !important;
    color: #ffffff !important;
    text-align: left;
    border-radius: 12px;
    padding: 24px;
    box-shadow: 0 25px 70px rgba(0, 0, 0, 0.9);
    border: 1px solid rgba(255, 255, 255, 0.3);

    transition: all 0.25s ease-out;
    pointer-events: none;
    white-space: normal !important;
    display: block !important;
    font-size: 0.92em;
    line-height: 1.6;
    max-height: 500px;
    overflow-y: auto;
}

/* VARIANTE: LADO IZQUIERDO (Crece hacia la derecha) */
.smart-tip.tip-left .smart-tip-content {
    left: -20px;
    transform: translateY(10px);
}

.smart-tip.tip-left .smart-tip-content::after {
    left: 24px;
    margin-left: 0;
}

/* VARIANTE: LADO DERECHO (Crece hacia la izquierda) */
.smart-tip.tip-right .smart-tip-content {
    left: auto;
    right: -20px;
    transform: translateY(10px);
}

.smart-tip.tip-right .smart-tip-content::after {
    left: auto;
    right: 24px;
    margin-left: 0;
}

/* [NUEVO] VARIANTE: CENTRO (Evita cortes en tarjetas intermedias) */
.smart-tip.tip-center .smart-tip-content {
    left: 50%;
    transform: translateX(-50%) translateY(10px);
}

.smart-tip.tip-center .smart-tip-content::after {
    left: 50%;
    margin-left: -8px;
}

/* PUENTE SENSORIAL REFORZADO */
.smart-tip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: -15px;
    right: -15px;
    height: 25px;
    background: transparent;
    z-index: 999998;
    display: none;
}

.smart-tip:hover::after {
    display: block;
}

.smart-tip:hover .smart-tip-content {
    visibility: visible;
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.smart-tip.tip-center:hover .smart-tip-content {
    transform: translateX(-50%) translateY(0);
}

/* TRIÁNGULO INDICADOR COMÚN */
.smart-tip-content::after {
    content: "";
    position: absolute;
    bottom: 100%;
    border-width: 8px;
    border-style: solid;
    border-color: transparent transparent #1a252f transparent;
}

.smart-tip-title {
    display: block;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    margin-bottom: 15px;
    padding-bottom: 10px;
    font-weight: bold;
    color: #00d2ff !important;
    text-transform: uppercase;
    font-size: 1.1em;
    letter-spacing: 1.2px;
}

/* [CRÍTICO] Asegurar que NINGUNO de los padres recorte el tooltip absolute */
.billing-plan-card-wrapper,
.plan-card-main,
.plan-card-main .w3-container,
#billing-plans-comparison,
.w3-row-padding,
.w3-quarter,
.product-card {
    overflow: visible !important;
}

.plan-card-main:hover {
    z-index: 10001 !important;
}

/* ============================================================================
 * 🎭 COMPONENTES DE INTERFAZ GLOBAL: MODALES DE ALERTA Y NOTIFICACIONES (Swal2)
 * ============================================================================ */

/* 1. Pulverización absoluta del Checkbox parásito en cualquier alerta del SaaS */
body .swal2-container .swal2-checkbox,
body .swal2-container label.swal2-checkbox {
    display: none !important;
}

/* 2. Contenedor Base del Mensaje (Shadcn UI Minimalista Real) */
body .swal2-container .swal2-popup {
    border-radius: 14px !important;
    padding: 24px 16px !important;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04) !important;
    border: 1px solid #e2e8f0 !important;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif !important;
}

/* 3. Título de la Alerta */
body .swal2-container .swal2-title {
    font-size: 1.25rem !important;
    font-weight: 700 !important;
    color: #0f172a !important;
    letter-spacing: -0.025em !important;
}

/* 4. Cuerpo de Texto Explicativo */
body .swal2-container .swal2-html-container {
    font-size: 0.88rem !important;
    color: #475569 !important;
    line-height: 1.6 !important;
}

/* 5. Físicas y Distribución de la Botonera */
body .swal2-container .swal2-actions {
    margin-top: 20px !important;
    gap: 8px !important;
}

body .swal2-container button.swal2-styled {
    padding: 10px 24px !important;
    font-size: 0.82rem !important;
    font-weight: 600 !important;
    border-radius: 8px !important;
    margin: 0 !important;
    box-shadow: none !important;
    border: none !important;
    transition: background-color 0.15s ease-in-out !important;
}

/* Botón Aceptar / Confirmar (Teal Canónico de ByteCobrador) */
body .swal2-container button.swal2-confirm {
    background-color: #009688 !important;
    color: #ffffff !important;
}
body .swal2-container button.swal2-confirm:hover {
    background-color: #00796b !important;
}

/* Botón Cancelar / Rechazar (Gris Neutro Chato Moderno) */
body .swal2-container button.swal2-cancel {
    background-color: #f1f5f9 !important;
    color: #334155 !important;
    border: 1px solid #e2e8f0 !important;
}
body .swal2-container button.swal2-cancel:hover {
    background-color: #e2e8f0 !important;
}

/* 🌙 SOPORTE NATIVO ADAPTATIVO PARA MODO OSCURO */
body.dark-mode .swal2-container .swal2-popup {
    background-color: #1e293b !important;
    border-color: #334155 !important;
}
body.dark-mode .swal2-container .swal2-title {
    color: #f8fafc !important;
}
body.dark-mode .swal2-container .swal2-html-container {
    color: #94a3b8 !important;
}
body.dark-mode .swal2-container button.swal2-cancel {
    background-color: #334155 !important;
    color: #f1f5f9 !important;
    border-color: #475569 !important;
}
body.dark-mode .swal2-container button.swal2-cancel:hover {
    background-color: #475569 !important;
}

/* ============================================================================
   🛡️ FIX PERIMETRAL: BLINDAJE DE EVENTOS Y ESPECIFICIDAD MODO OSCURO (v16.5.1)
   ============================================================================ */

/* 1. Botón de escritorio (Aplica a pantallas grandes de forma nativa) */
#btn-toggle-dark {
    position: relative !important;
    z-index: 99999 !important;
    pointer-events: auto !important;
    cursor: pointer !important;
    display: inline-block !important; /* Fuerza una caja de colisión real para el mouse */
}

/* 2. Reglas que solo aplican cuando la pantalla es chica (Teléfonos y Tablets) */
@media (max-width: 992px) {
    .mobile-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
        width: 48px;
        height: 48px;
        cursor: pointer !important;
        color: var(--text-main);
        font-size: 1.3em;
        background: transparent;
        border: none;
        padding: 0;
        position: relative !important;
        z-index: 99999 !important; 
        pointer-events: auto !important;
    }

    /* Blindaje extra para asegurar que el icono herede la elevación en celular */
    #mobile-dark-icon {
        position: relative !important;
        z-index: 99999 !important;
        pointer-events: auto !important;
    }
}

/* 3. Comportamiento por defecto del botón móvil en computadoras */
.mobile-btn {
    display: none;
}
