:root {
    --bg-color: #e2e8f0;
    --card-bg: #ffffff;
    --card-border: rgba(0, 0, 0, 0.08);
    --border-color: rgba(0, 0, 0, 0.1);
    --surface-color: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --primary: #3b82f6;
    --primary-rgb: 59, 130, 246;
    --primary-glow: rgba(59, 130, 246, 0.2);
    --icon-bg: rgba(59, 130, 246, 0.1);

    /* Breakpoints */
    --mobile: 480px;
    --tablet: 768px;
    --desktop: 1024px;
    --sidebar-collapsed-width: 80px;

    /* Glassmorphism */
    --glass-bg: rgba(255, 255, 255, 0.85);
    --glass-border: rgba(255, 255, 255, 0.5);
    --glass-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.07);
}

[data-theme="dark"] {
    --bg-color: #0f172a; 
    --card-bg: #1e293b; 
    --card-border: rgba(255, 255, 255, 0.08);
    --border-color: rgba(255, 255, 255, 0.12);
    --surface-color: #1e293b;
    --text-main: #f8fafc; 
    --text-muted: #94a3b8; 
    --primary: #60a5fa; 
    --primary-rgb: 96, 165, 250;
    --primary-glow: rgba(96, 165, 250, 0.15);
    --icon-bg: rgba(96, 165, 250, 0.1);

    /* Glassmorphism Dark */
    --glass-bg: rgba(30, 41, 59, 0.8);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.2);
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start; /* Cambio de center a flex-start para aprovechar espacio superior */
    padding: 2rem;
    overflow-x: hidden;
    transition: padding 0.3s ease;
}

@media (max-width: 768px) {
    body {
        padding: 1rem;
        flex-direction: column;
        align-items: stretch;
    }
}

/* Mantener centrado para páginas sin sidebar (como Login) */
body:not(.has-sidebar) {
    align-items: center;
}

/* Contenedor de grilla adaptativo */
.cards-container {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 2rem;
    width: 100%;
    max-width: 1400px;
}

@media (max-width: 1200px) {
    .cards-container {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 900px) {
    .cards-container {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .cards-container {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
}

.cards-container > a {
    text-decoration: none;
    color: inherit;
    display: block;
    height: 100%;
}

/* Estilos de la tarjeta */
.card {
    background-color: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 2.5rem 2rem;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    height: 100%;

    /* Estado inicial para la animación de entrada */
    opacity: 0;
    transform: translateY(40px);

    /* Transiciones fluidas para el hover */
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275),
        box-shadow 0.4s ease,
        border-color 0.4s ease,
        background-color 0.4s ease;
}

/* Efecto de luz dinámico al pasar el ratón (controlado por JS) */
.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(800px circle at var(--mouse-x, 50%) var(--mouse-y, 50%), rgba(59, 130, 246, 0.06), transparent 40%);
    opacity: 0;
    transition: opacity 0.3s ease;
    z-index: 1;
    pointer-events: none;
}

.card:hover::before {
    opacity: 1;
}

/* Hover de la tarjeta */
.card:hover {
    transform: translateY(-12px);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.1), 0 0 30px var(--primary-glow);
    border-color: rgba(59, 130, 246, 0.4);
    /* Bordes resplandecientes */
}

/* Icono de la tarjeta */
.card-icon {
    width: 60px;
    height: 60px;
    border-radius: 14px;
    background: var(--icon-bg);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--primary);
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1),
        background-color 0.4s ease,
        color 0.4s ease;
    z-index: 2;
    /* Sobre el resplandor ::before */
}

.card-icon svg {
    width: 28px;
    height: 28px;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}

/* Animación del icono al hacer hover en la tarjeta */
.card:hover .card-icon {
    transform: scale(1.15) translateY(-5px);
    background: var(--primary);
    color: #ffffff;
    box-shadow: 0 10px 20px -5px var(--primary-glow);
}

/* Textos */
.card-title {
    font-size: 1.35rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    z-index: 2;
    transition: color 0.3s ease;
}

.card:hover .card-title {
    color: var(--primary);
}

.card-desc {
    font-size: 1rem;
    line-height: 1.6;
    color: var(--text-muted);
    z-index: 2;
    font-weight: 400;
}

/* Clase de animación para mostrar las tarjetas con JS */
.card.show {
    opacity: 1;
    transform: translateY(0);
}

/* Pequeño detalle: borde inferior en hover estilo 'tab' tecnológico */
.card::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 10%;
    width: 80%;
    height: 2px;
    background: var(--primary);
    opacity: 0;
    transform: translateY(2px);
    transition: all 0.4s ease;
    border-radius: 2px 2px 0 0;
    box-shadow: 0 -2px 10px var(--primary);
}

.card:hover::after {
    opacity: 1;
    transform: translateY(0);
}

/* =========================================
   ESTILOS GESTIÓN DE CONTACTOS (DATA GRID)
   ========================================= */

.grid-layout-wrapper {
    width: 100%;
    max-width: 100%; /* Maximizado para eficiencia en monitores modernos */
    display: flex;
    flex-direction: column;
    gap: 1.5rem; /* Reducido de 2.5rem para compactar el layout */
    animation: fadeInDown 0.6s ease-out forwards;
}

.page-header {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.95rem;
    font-weight: 500;
    transition: color 0.3s;
    width: fit-content;
}

.back-link:hover {
    color: var(--primary);
}

.back-link svg {
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.page-header h1 {
    font-size: 1.85rem; /* Reducido de 2.2rem para ahorrar espacio vertical */
    color: var(--text-main);
    letter-spacing: -0.02em;
}

.page-header p {
    color: var(--text-muted);
    font-size: 0.95rem; /* Ligeramente reducido */
}

/* Encabezados Superiores Globales (Título + Botones) */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 24px;
    gap: 1rem;
}

@media (max-width: 768px) {
    .section-header {
        flex-direction: column !important;
        align-items: stretch !important;
        gap: 1.25rem;
    }
    .section-header-actions {
        display: flex !important;
        flex-direction: column !important;
        width: 100% !important;
        gap: 0.75rem !important;
    }
    .section-header-actions button, 
    .section-header-actions a,
    .section-header-actions .btn {
        width: 100% !important;
        justify-content: center !important;
    }
}

/* Títulos de sección global y responsivos (DRY Principle) */
.section-title {
    font-size: 2.4rem;
    color: var(--text-main);
    font-weight: 800;
    letter-spacing: -0.04em;
    margin-bottom: 0.5rem;
    line-height: 1.2;
}

@media (max-width: 768px) {
    .page-header h1 {
        font-size: 1.5rem;
    }
    .page-header {
        margin-top: 1rem;
    }
    .section-title {
        font-size: 1.8rem;
    }
}

@media (max-width: 480px) {
    .section-title {
        font-size: 1.6rem;
    }
}

/* Data Grid Container */
.data-grid-container {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.05);
}

.data-grid {
    display: flex;
    flex-direction: column;
    width: 100%;
}
.grid-header {
    display: grid;
    grid-template-columns: 2fr 2fr 1.5fr 1fr 60px;
    background: var(--bg-color);
    border-bottom: 1px solid var(--card-border);
    padding: 1rem 1.75rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

@media (max-width: 768px) {
    .grid-header {
        display: none; /* Hide header on mobile */
    }
}

.grid-row {
    display: grid;
    grid-template-columns: 2fr 2fr 1.5fr 1fr 60px;
    padding: 0 1.75rem; /* Ajustado al header */
    border-bottom: 1px solid var(--card-border);
    transition: background-color 0.3s ease;
    opacity: 0;
    transform: translateY(20px);
}

@media (max-width: 768px) {
    .grid-row {
        display: flex;
        flex-direction: column;
        padding: 1.5rem 1rem;
        gap: 0.75rem;
        border-bottom: 8px solid var(--bg-color); /* Separación visual entre tarjetas */
    }

    .grid-cell {
        padding: 0 !important;
    }
}

.grid-row.show {
    animation: fadeInUpRow 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.grid-row:last-child {
    border-bottom: none;
}

.grid-row:hover {
    background-color: var(--bg-color);
}

.grid-cell {
    padding: 0.85rem 0; /* Reducido de 1.25rem para mayor densidad */
    display: flex;
    align-items: center;
    position: relative;
    padding-right: 1.5rem;
    font-size: 0.95rem;
    color: var(--text-main);
}

/* Editable Cell */
.editable-cell {
    cursor: pointer;
    border-radius: 8px;
    transition: background-color 0.2s, color 0.2s;
    padding: 0.5rem 0.75rem;
    margin: -0.5rem -0.75rem; /* Compensar padding */
    width: calc(100% + 1.5rem);
    position: relative;
    border: 1px solid transparent;
}

.editable-cell:hover {
    background-color: var(--bg-color);
}

.editable-cell::after {
    content: '✏️';
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8rem;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: none;
}

.editable-cell:hover::after {
    opacity: 0.6;
    transform: translateY(-50%) scale(1.1);
}

.editable-cell.is-editing::after {
    display: none;
}

/* Input Inline */
.editable-input {
    width: 100%;
    padding: 0.6rem 0.75rem;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text-main);
    background: var(--card-bg);
    border: 1px solid var(--primary);
    border-radius: 8px;
    outline: none;
    box-shadow: 0 0 0 4px var(--primary-glow);
    animation: popInInput 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* State Badges */
.status-badge {
    padding: 0.4rem 0.8rem;
    border-radius: 30px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: uppercase;
}

.status-active { background-color: rgba(34, 197, 94, 0.1); color: #16a34a; }
.status-pending { background-color: rgba(245, 158, 11, 0.1); color: #d97706; }
.status-closed { background-color: rgba(100, 116, 139, 0.1); color: #475569; }

/* Grid Animations */
@keyframes fadeInUpRow {
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeInDown {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes popInInput {
    from { opacity: 0; transform: scale(0.95) translateY(2px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes successHighlight {
    0% { background-color: rgba(34, 197, 94, 0.15); box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.3); }
    100% { background-color: transparent; box-shadow: inset 0 0 0 1px transparent; }
}

.edit-success {
    animation: successHighlight 1.5s ease-out;
}

/* =========================================
   ESTILOS PARA ICONO PDF Y MODAL DE VISTA PREVIA
   ========================================= */

.pdf-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: transparent;
    cursor: pointer;
    border: none;
    outline: none;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.pdf-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    transition: transform 0.2s ease;
}

.pdf-btn:hover {
    transform: scale(1.2);
}

/* Colores específicos para acciones */
.btn-edit { color: var(--primary); }
.btn-pdf { color: #ef4444; }
.btn-delete { color: var(--text-muted); }

.btn-edit:hover { filter: brightness(1.2); }
.btn-pdf:hover { filter: brightness(1.1); }
.btn-delete:hover { color: #ef4444; }

/* Modal Overlay */
.pdf-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.4); /* Fondo oscuro semitransparente (Slate 900) */
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.pdf-modal.active {
    opacity: 1;
    pointer-events: auto;
}

/* Modal Content */
.pdf-modal-content {
    width: 90%;
    max-width: 800px;
    height: 85vh;
    background: var(--card-bg);
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.pdf-modal.active .pdf-modal-content {
    transform: scale(1);
}

.pdf-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--card-border);
    background: var(--bg-color);
    opacity: 0.95;
}

.pdf-modal-header h3 {
    font-size: 1.15rem;
    color: var(--text-main);
    margin: 0;
}

.pdf-close-btn {
    background: var(--border-color);
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.2s;
}

.pdf-close-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.pdf-modal-body {
    flex: 1;
    width: 100%;
    background: var(--bg-color);
}

.pdf-iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* =========================================
   ESTILOS DEL SIDEBAR
   ========================================= */

body.has-sidebar {
    padding-left: calc(84px + 2rem);
    transition: padding-left 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

body.has-sidebar.sidebar-expanded,
.sidebar-pre-expanded body.has-sidebar {
    padding-left: calc(260px + 2rem);
}

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    height: 100dvh;
    width: 84px;
    background: var(--card-bg);
    border-right: 1px solid var(--card-border);
    transition: width 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    z-index: 100;
    display: flex;
    flex-direction: column;
    box-shadow: 5px 0 20px rgba(0,0,0,0.03);
    overflow-x: hidden; /* Evita que el contenido desbordado genere scroll horizontal */
    overscroll-behavior: contain; /* Evita que el scroll se propague al fondo */
}

.sidebar.expanded,
.sidebar-pre-expanded .sidebar {
    width: 260px;
}

.user-info-sidebar {
    flex-shrink: 0;
}

.sidebar-header {
    display: flex;
    align-items: center;
    padding: 1.5rem 24px;
    border-bottom: 1px solid var(--card-border);
    min-height: 84px;
    gap: 1rem;
    flex-shrink: 0;
}

.toggle-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.3s;
    width: 36px;
    height: 36px;
    flex-shrink: 0;
}

.toggle-btn:hover {
    background: rgba(59, 130, 246, 0.1);
    color: var(--primary);
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--primary);
    font-weight: 700;
    font-size: 1.25rem;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden; /* Oculto por defecto para no afectar el scroll */
    transform: translateX(-10px);
    transition: opacity 0.3s, visibility 0.3s, transform 0.3s;
}

.sidebar.expanded .sidebar-logo,
.sidebar-pre-expanded .sidebar .sidebar-logo {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}


.sidebar-nav {
    flex: 1;
    padding: 1.5rem 0;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    overflow-y: auto;
    overflow-x: hidden;
    overscroll-behavior: contain;
    padding-bottom: 3rem; /* Espacio extra al final para que los últimos items no se peguen al footer */
    min-height: 0; /* Gotcha de Flexbox para permitir que el contenedor se encoja y use el overflow */
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    padding: 1rem 0;
    border-top: 1px solid var(--card-border);
    background: var(--card-bg); /* Asegura que tape el scroll si pasara por debajo */
    flex-shrink: 0;
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px));
}

/* Custom Scrollbar for Sidebar */
.sidebar-nav::-webkit-scrollbar {
    width: 6px;
}
.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}
.sidebar-nav::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 10px;
}
.sidebar-nav::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

.nav-item {
    display: flex;
    align-items: center;
    padding: 0.85rem 24px;
    color: var(--text-muted);
    text-decoration: none;
    transition: all 0.3s ease;
    white-space: nowrap;
    position: relative;
    gap: 1.25rem;
}

.nav-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 10%;
    height: 80%;
    width: 3px;
    background: var(--primary);
    border-radius: 0 4px 4px 0;
    opacity: 0;
    transform: scaleY(0);
    transition: all 0.3s ease;
    z-index: 1; /* Aseguramos que no interfiera */
}

.nav-item:hover {
    color: var(--primary);
    background: rgba(59, 130, 246, 0.04);
}

.nav-item:hover::before, .nav-item.active::before {
    opacity: 1;
    transform: scaleY(1);
}

.nav-item.active {
    color: var(--primary);
    background: rgba(59, 130, 246, 0.08);
}

.nav-icon {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.nav-icon svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.nav-item:hover .nav-icon svg {
    transform: scale(1.15) rotate(-5deg);
}

.nav-text {
    font-weight: 500;
    font-size: 0.95rem;
    opacity: 0;
    visibility: hidden; /* CRÍTICO: Elimina el elemento del flujo de renderizado visual para evitar scroll */
    transform: translateX(-10px);
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
}

.sidebar.expanded .nav-text, .sidebar.mobile-open .nav-text,
.sidebar-pre-expanded .sidebar .nav-text {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

/* Tooltip Global inyectado por JS */
.global-tooltip {
    position: fixed;
    background: var(--card-bg);
    color: var(--text-main);
    padding: 0.5rem 0.9rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    pointer-events: none;
    box-shadow: 0 4px 15px -3px rgba(0, 0, 0, 0.1), 0 0 0 1px var(--card-border);
    z-index: 9999;
    
    /* Estado Oculto */
    opacity: 0;
    visibility: hidden;
    transform: translateY(-50%) scale(0.8) translateX(-10px);
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.global-tooltip.visible {
    opacity: 1;
    visibility: visible;
    transform: translateY(-50%) scale(1) translateX(0);
}

/* =========================================
   ESTILOS PARA ANÁLISIS DE VENTAS (CHART.JS)
   ========================================= */

.analytics-container {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.chart-controls {
    display: flex;
    gap: 1rem;
    background: #f8fafc;
    padding: 0.5rem;
    border-radius: 12px;
    width: fit-content;
    border: 1px solid var(--card-border);
}

.chart-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s ease;
    outline: none;
}

.chart-btn svg {
    width: 18px;
    height: 18px;
    stroke: currentColor;
    stroke-width: 2;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: transform 0.3s;
}

.chart-btn:hover {
    color: var(--primary);
    background: rgba(59, 130, 246, 0.05);
}

.chart-btn.active {
    background: #ffffff;
    color: var(--primary);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
}

/* Dark Mode Overrides for Analytics Controls */
[data-theme="dark"] .chart-controls {
    background: rgba(255, 255, 255, 0.03);
    border-color: var(--border-color);
}
[data-theme="dark"] .chart-btn.active {
    background: var(--card-bg);
    color: var(--primary);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
}
[data-theme="dark"] .chart-btn:hover:not(.active) {
    background: rgba(255, 255, 255, 0.05);
}

/* =========================================
   ESTILOS PARA TIMELINE (INTERACCIONES)
   ========================================= */

.timeline {
    position: relative;
    padding-left: 20px;
}

.timeline::before {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 40px;
    width: 2px;
    background: var(--border-color);
    border-radius: 2px;
}

.timeline-item {
    position: relative;
    padding-left: 70px;
    margin-bottom: 30px;
}

.timeline-item:last-child {
    margin-bottom: 0;
}

.timeline-item:last-child::after {
    content: '';
    position: absolute;
    top: 40px;
    bottom: 0;
    left: 40px;
    width: 2px;
    background: var(--bg-color); /* Hide the line below last dot */
    z-index: 1;
}

.timeline-dot {
    position: absolute;
    left: 24px;
    top: 0;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--card-bg);
    z-index: 2;
    box-shadow: 0 0 0 4px var(--bg-color); /* Gives breathing room to the line */
}

.timeline-content {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.02);
    transition: transform 0.2s, box-shadow 0.2s;
}

.timeline-content:hover {
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.05);
    border-color: rgba(59, 130, 246, 0.3);
}

.timeline-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.timeline-type {
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
    display: block;
}

.timeline-title {
    font-size: 1.15rem;
    color: var(--text-main);
    margin: 0;
}

.timeline-meta {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
}

.timeline-date {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.timeline-actions button {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    border-radius: 4px;
    transition: all 0.2s;
}

.timeline-actions button:hover {
    color: var(--primary);
    background: var(--icon-bg);
}

.timeline-actions button.delete:hover {
    color: #ef4444;
    background: rgba(239, 68, 68, 0.1);
}

.timeline-body {
    border-top: 1px dashed var(--border-color);
    padding-top: 12px;
}

.timeline-client {
    font-size: 0.9rem;
    color: var(--text-muted);
    display: block;
    margin-bottom: 8px;
}

.timeline-client strong {
    color: var(--text-main);
}

.timeline-desc {
    font-size: 0.95rem;
    color: var(--text-main);
    line-height: 1.5;
    margin: 0;
}

/* =========================================
   ESTILOS PARA MODALES DE FORMULARIO
   ========================================= */

.modal {
    display: none;
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    justify-content: center;
    align-items: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--surface-color);
    border-radius: 12px;
    width: 100%;
    max-width: 500px;
    padding: 24px;
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.modal-header h2 { margin: 0; font-size: 1.25rem; }

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--text-main);
}

.form-control {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-color);
    color: var(--text-main);
    font-family: inherit;
    outline: none;
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.form-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    width: 100%;
}

.actions-right {
    display: flex;
    gap: 1rem;
}

/* Chip Selection System */
.chip-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 8px;
}

.chip {
    cursor: pointer;
    position: relative;
    user-select: none;
}

.chip input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}

.chip-label {
    display: inline-flex;
    align-items: center;
    padding: 0.5rem 1rem;
    border-radius: 50px;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    border: 2px solid transparent;
    opacity: 0.6;
}

/* Base styles for labels (reusing existing colors) */
.chip-label.tier-starter { background-color: rgba(100, 116, 139, 0.1); color: #475569; }
.chip-label.tier-professional { background-color: rgba(245, 158, 11, 0.1); color: #d97706; }
.chip-label.tier-business { background-color: rgba(34, 197, 94, 0.1); color: #16a34a; }
.chip-label.role-agent { background: #f1f5f9; color: #64748b; }
.chip-label.role-admin { background: #eff6ff; color: #3b82f6; }

/* Selected State */
.chip input[type="radio"]:checked + .chip-label {
    opacity: 1;
    transform: translateY(-2px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
}

.chip input[type="radio"]:checked + .chip-label.tier-starter { border-color: #64748b; }
.chip input[type="radio"]:checked + .chip-label.tier-professional { border-color: #f59e0b; }
.chip input[type="radio"]:checked + .chip-label.tier-business { border-color: #22c55e; }
.chip input[type="radio"]:checked + .chip-label.role-agent { border-color: #94a3b8; }
.chip input[type="radio"]:checked + .chip-label.role-admin { border-color: #3b82f6; }

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    margin-top: 24px;
}

.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    grid-column: 1 / -1;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    outline: none;
}

.btn-primary {
    background: var(--primary);
    color: #ffffff;
}

.btn-primary:hover {
    background: #2563eb;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
    transform: translateY(-1px);
}

.chart-btn.active svg {
    transform: scale(1.1);
}

.chart-wrapper {
    width: 100%;
    height: 350px;
    position: relative;
}

/* Tarjetas de Estadística bajo el Gráfico */
.stats-overview {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
    padding-top: 2rem;
    border-top: 1px solid var(--card-border);
}

.stat-card {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    padding: 1.5rem;
    background: var(--bg-color); /* Se adapta al modo oscuro */
    border-radius: 16px;
    border: 1px solid var(--card-border);
    transition: transform 0.3s, box-shadow 0.3s, background-color 0.3s;
}

.stat-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.05);
    background: var(--card-bg); /* Resalta sutilmente en hover en ambos modos */
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.stat-value {
    font-size: 1.8rem;
    font-weight: 700;
    color: var(--text-main);
    letter-spacing: -0.02em;
}

.stat-trend {
    font-size: 0.85rem;
    font-weight: 500;
}

.stat-trend.positive { color: #10b981; /* Verde */ }
.stat-trend.negative { color: #ef4444; /* Rojo */ }

/* =========================================
   ESTILOS PARA BÚSQUEDA Y PAGINACIÓN (GRID)
   ========================================= */

.grid-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--card-border);
    background: var(--card-bg);
    gap: 1rem;
    flex-wrap: wrap;
}

.search-container {
    position: relative;
    flex: 1;
    max-width: 400px;
}

.search-icon {
    position: absolute;
    left: 1rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    width: 18px;
    height: 18px;
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.75rem;
    border-radius: 10px;
    border: 1px solid var(--card-border);
    background: var(--bg-color);
    color: var(--text-main);
    font-size: 0.95rem;
    font-family: inherit;
    transition: all 0.3s;
    outline: none;
}

.search-input:focus {
    background: var(--card-bg);
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.pagination-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 2rem;
    background: var(--card-bg); /* Cambiado de bg-color a card-bg para uniformidad */
    border-top: 1px solid var(--card-border);
}

.pagination-info {
    color: var(--text-muted);
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.page-size-select {
    height: 32px;
    padding: 0 2rem 0 0.6rem;
    border-radius: 8px;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    font-family: inherit;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-main);
    outline: none;
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2.5' 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 0.5rem center;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.page-size-select:hover {
    border-color: var(--primary);
}

.page-size-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.pagination-buttons {
    display: flex;
    gap: 0.5rem;
}

/* UTILIDADES DE TEXTO */
.text-truncate {
    white-space: nowrap !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    display: block !important;
    max-width: 100% !important;
    min-width: 0 !important;
}

.page-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--card-border);
    background: var(--card-bg);
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s;
}

.page-btn:hover:not(:disabled) {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

.page-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    background: var(--bg-color);
}

/* =========================================
   ESTILOS PARA CALENDARIO DE TAREAS
   ========================================= */

.add-event-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: var(--primary);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s ease;
    box-shadow: 0 4px 10px -2px var(--primary-glow);
}

.add-event-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px -2px var(--primary-glow);
}

.calendar-container {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    padding: 2rem;
    box-shadow: 0 20px 40px -15px rgba(0, 0, 0, 0.05);
}

.calendar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
}

.calendar-header h2 {
    font-size: 1.5rem;
    color: var(--text-main);
    font-weight: 700;
}

.calendar-nav-btn {
    background: var(--bg-color);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-main);
    cursor: pointer;
    transition: all 0.2s;
}

.calendar-nav-btn:hover {
    background: var(--primary);
    color: #ffffff;
    border-color: var(--primary);
}

.calendar-nav-btn svg {
    width: 18px;
    height: 18px;
}

.calendar-grid {
    display: flex;
    flex-direction: column;
}

.calendar-days-wrapper {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 1px; /* Para simular bordes con fondo gris */
    background: var(--card-border);
    border: 1px solid var(--card-border);
    border-radius: 0 0 12px 12px;
    overflow: hidden;
}

.calendar-day-header {
    display: grid;
    /* Los encabezados arriba de los días */
}

/* Encabezados de días se muestran arriba como grid también */
.calendar-grid > div:first-child {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    background: var(--bg-color);
    border: 1px solid var(--card-border);
    border-bottom: none;
    border-radius: 12px 12px 0 0;
}

.calendar-day-header {
    padding: 1rem;
    text-align: center;
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.9rem;
    border-right: 1px solid var(--card-border);
}
.calendar-day-header:last-child { border-right: none; }

.calendar-day {
    background: var(--card-bg);
    min-height: 120px;
    padding: 0.5rem;
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.calendar-day:hover {
    background: var(--bg-color);
}

.calendar-day.prev-month, .calendar-day.next-month {
    background: var(--bg-color);
}

.calendar-day.prev-month .day-number, .calendar-day.next-month .day-number {
    color: var(--text-muted);
}

.day-number {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    margin-left: auto;
}

.day-number.today {
    background: var(--primary);
    color: var(--bg-color);
}

.day-events {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1;
}

.event-pill {
    background: var(--primary-glow);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    color: var(--primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: all 0.2s;
}

.event-pill:hover {
    background: var(--primary);
    color: #ffffff;
    transform: scale(1.02);
}

/* Animaciones de Calendario */
@keyframes eventPopIn {
    0% { opacity: 0; transform: scale(0.9) translateY(10px); }
    100% { opacity: 1; transform: scale(1) translateY(0); }
}

@keyframes eventUpdateFlash {
    0%, 100% { background-color: var(--primary-glow); transform: scale(1); }
    50% { background-color: rgba(59, 130, 246, 0.4); transform: scale(1.05); }
}

@keyframes eventFadeOut {
    0% { opacity: 1; transform: scale(1); }
    100% { opacity: 0; transform: scale(0.8) translateY(-10px); }
}

.event-pill.new-event {
    animation: eventPopIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* Sub-menus Sidebar */
.user-info-sidebar {
    overflow: hidden;
}

.user-info-content {
    opacity: 0;
    visibility: hidden;
    transform: translateX(-10px);
    transition: opacity 0.3s ease, visibility 0.3s ease, transform 0.3s ease;
    white-space: nowrap;
}

.sidebar.expanded .user-info-content,
.sidebar-pre-expanded .sidebar .user-info-content,
.sidebar.mobile-open .user-info-content {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
}

.sidebar:not(.expanded):not(.mobile-open) .user-info-sidebar {
    padding: 1.5rem 0 !important;
}

.sidebar:not(.expanded):not(.mobile-open) .user-info-content {
    display: none;
}

.sidebar:not(.expanded):not(.mobile-open) .user-info-collapsed-status {
    display: flex !important;
}

.nav-item-dropdown {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.dropdown-trigger {
    cursor: pointer;
    user-select: none;
}

.chevron-icon {
    margin-left: auto;
    width: 16px;
    height: 16px;
    stroke: currentColor;
    stroke-width: 2.5;
    fill: none;
    transition: transform 0.3s ease;
}

.nav-item-dropdown.open .chevron-icon {
    transform: rotate(180deg);
}

.sub-menu {
    display: flex;
    flex-direction: column;
    max-height: 0;
    transition: max-height 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    background: rgba(0, 0, 0, 0.02);
}

.nav-item-dropdown.open .sub-menu {
    max-height: 200px;
}

.sub-nav-item {
    display: flex;
    align-items: center;
    padding: 0.7rem 24px 0.7rem 52px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.sub-nav-item:hover {
    color: var(--primary);
    background: rgba(59, 130, 246, 0.04);
}

.sub-nav-item.active {
    color: var(--primary);
    background: rgba(59, 130, 246, 0.08);
}

.sidebar:not(.expanded) .nav-item-dropdown .sub-menu {
    display: none;
}

.event-pill.updated-event {
    animation: eventUpdateFlash 0.6s ease-in-out forwards;
}

.event-pill.deleting-event {
    animation: eventFadeOut 0.3s ease-out forwards;
}

/* Dots and Mobile Agenda Styles */
.event-dots-mobile {
    display: none;
    justify-content: center;
    gap: 4px;
    margin-top: auto;
    padding-bottom: 2px;
}

.event-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--primary);
}

.event-dot.plus {
    background: var(--text-muted);
}

.calendar-agenda {
    margin-top: 2rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.05);
    display: none; /* Oculto por defecto en desktop */
}

.agenda-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--card-border);
}

.agenda-header h3 {
    font-size: 1.1rem;
    margin: 0;
}

#agendaDateDisplay {
    font-size: 0.9rem;
    color: var(--primary);
    font-weight: 600;
}

.agenda-items {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.agenda-item {
    display: flex;
    align-items: center;
    gap: 15px;
    padding: 12px;
    border-radius: 12px;
    background: var(--bg-color);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    animation: fadeInSlide 0.3s ease-out forwards;
}

.agenda-item:hover {
    transform: scale(1.01);
    box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}

.agenda-time {
    font-size: 0.85rem;
    font-weight: 700;
    color: var(--primary);
    min-width: 60px;
}

.agenda-info {
    flex: 1;
}

.agenda-title {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
}

.agenda-desc {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.agenda-empty {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
    font-style: italic;
}

@keyframes fadeInSlide {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Mobile Responsive Overrides for Calendar */
@media (max-width: 768px) {
    .calendar-page .page-header {
        flex-direction: column !important;
        align-items: flex-start !important;
        gap: 1rem;
    }

    .calendar-day {
        min-height: 60px !important;
        padding: 4px !important;
    }

    .day-number {
        width: 24px;
        height: 24px;
        font-size: 0.8rem;
    }

    .day-events {
        display: none !important;
    }

    .event-dots-mobile {
        display: flex !important;
    }

    .calendar-container {
        padding: 1rem !important;
        margin: 0 -0.5rem; /* Pequeño ajuste para ganar espacio si el body tiene padding */
        width: calc(100% + 1rem); /* Compensar el margin negativo */
        border-radius: 12px;
    }

    .calendar-day-header {
        padding: 0.5rem 0.2rem !important;
        font-size: 0.7rem !important;
    }

    .calendar-day {
        min-height: 50px !important;
        padding: 2px !important;
    }

    .day-number {
        width: 20px;
        height: 20px;
        font-size: 0.75rem;
    }

    .calendar-day.selected {
        background: var(--primary-glow) !important;
        outline: 2px solid var(--primary);
        border-radius: 8px;
        z-index: 1;
    }

    .calendar-agenda.mobile-only {
        display: block !important;
        padding: 1rem !important;
    }

    .calendar-header h2 {
        font-size: 1.1rem !important;
    }

    .calendar-nav-btn {
        width: 32px !important;
        height: 32px !important;
    }
}

/* Fix for horizontal overflow in layout wrappers */
.grid-layout-wrapper {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    padding-bottom: 2rem; /* Espacio extra al final */
}

/* =========================================
   ESTILOS GENERALES PARA MODALES (CRM)
   ========================================= */

.custom-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.4);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.custom-modal.active {
    opacity: 1;
    visibility: visible;
}

.custom-modal-content {
    background: var(--card-bg);
    width: 100%;
    max-width: 500px;
    border-radius: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.15);
    transform: scale(0.95) translateY(20px);
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.custom-modal.active .custom-modal-content {
    transform: scale(1) translateY(0);
}

/* Modal Responsiveness Improvements */
@media (max-width: 768px) {
    .custom-modal {
        padding: 10px;
        align-items: flex-end; /* Aparece desde abajo como un sheet */
    }

    .custom-modal-content {
        max-height: 92vh;
        border-radius: 24px 24px 0 0;
        transform: translateY(100%);
    }

    .custom-modal.active .custom-modal-content {
        transform: translateY(0);
    }

    .custom-modal-body {
        padding: 1.5rem;
        overflow-y: auto;
        flex: 1;
    }

    .custom-modal-header {
        padding: 1.25rem 1.5rem;
        flex-shrink: 0;
    }

    .form-row {
        grid-template-columns: 1fr !important;
        gap: 1.25rem;
    }

    .form-actions {
        flex-direction: column-reverse;
        gap: 10px;
    }

    .form-actions > div {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .btn-save, .btn-cancel, .btn-danger {
        width: 100%;
        padding: 14px !important;
    }
}

.custom-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--card-border);
    background: var(--bg-color);
}

.custom-modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    color: var(--text-main);
}

.close-modal-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
}

.close-modal-btn:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.close-modal-btn svg {
    width: 20px;
    height: 20px;
}

.custom-modal-body {
    padding: 2rem;
}

/* Formularios */
.contact-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.form-group input, .form-group textarea {
    padding: 0.75rem 1rem;
    border: 1px solid var(--card-border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text-main);
    outline: none;
    transition: all 0.3s;
    background: var(--bg-color);
}

.form-group input:focus, .form-group textarea:focus {
    background: var(--card-bg);
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 1rem;
}

.btn-cancel {
    padding: 0.75rem 1.5rem;
    background: transparent;
    border: 1px solid var(--card-border);
    border-radius: 8px;
    color: var(--text-main);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-cancel:hover {
    background: var(--bg-color);
}

.btn-secondary {
    padding: 0.75rem 1.5rem;
    background: var(--bg-color);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    color: var(--text-main);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
}

.btn-secondary:hover {
    background: var(--card-bg);
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px -4px rgba(0,0,0,0.1);
}

.btn-save {
    padding: 0.75rem 1.5rem;
    background: var(--primary);
    color: #ffffff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 10px -2px var(--primary-glow);
}

.btn-save:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px -2px var(--primary-glow);
}

/* Vista de Evento */
.event-details-body {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.event-meta {
    display: flex;
    gap: 1.5rem;
}

.event-meta-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary);
    font-weight: 600;
    font-size: 0.95rem;
    background: var(--primary-glow);
    padding: 0.5rem 1rem;
    border-radius: 8px;
}

.event-desc-box {
    background: var(--bg-color);
    border: 1px solid var(--card-border);
    padding: 1.5rem;
    border-radius: 12px;
}

.event-desc-box p {
    margin: 0;
    color: var(--text-main);
    line-height: 1.6;
}

.custom-modal-footer {
    padding: 1rem 2rem;
    border-top: 1px solid var(--card-border);
    background: var(--bg-color);
    display: flex;
    justify-content: space-between;
}

.btn-danger {
    padding: 0.6rem 1.25rem;
    background: transparent;
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-danger:hover {
    background: #ef4444;
    color: #ffffff;
}

/* =========================================
   ESTILOS PARA LISTA DE EVENTOS (TABLA MODAL)
   ========================================= */

.event-table-wrapper {
    overflow-x: auto;
    min-height: 380px; /* Suficiente para 5 filas estables */
}

.event-list-table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
}

.event-list-table th {
    padding: 1rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 2px solid var(--card-border);
    white-space: nowrap;
}

.event-list-table td {
    padding: 1rem;
    font-size: 0.95rem;
    color: var(--text-main);
    border-bottom: 1px solid var(--card-border);
    vertical-align: middle;
}

.event-table-row {
    background: transparent;
    cursor: pointer;
    transition: all 0.2s;
}

.event-table-row:hover {
    background: var(--bg-color);
}

.event-table-row:last-child td {
    border-bottom: none;
}

.event-table-action-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.event-table-row:hover .event-table-action-btn {
    color: var(--primary);
    background: var(--primary-glow);
}

/* =========================================
   ESTILOS PARA NOTIFICACIONES TOAST
   ========================================= */
   
.toast-container {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    pointer-events: none;
}

.toast {
    background: var(--card-bg);
    border-left: 4px solid var(--primary);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.4);
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--text-main);
    font-size: 0.95rem;
    font-weight: 500;
    transform: translateX(120%);
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast.removing {
    transform: translateX(120%);
    opacity: 0;
}

.toast-icon {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toast.success { border-left-color: #10b981; }
.toast.success .toast-icon { color: #10b981; }

.toast.warning { border-left-color: #f59e0b; }
.toast.warning .toast-icon { color: #f59e0b; }

.toast.error, .toast.delete { border-left-color: #ef4444; }
.toast.error .toast-icon, .toast.delete .toast-icon { color: #ef4444; }

/* =========================================
   ESTILOS PARA BOTON DE TEMA DARK/LIGHT
   ========================================= */

.theme-toggle-btn {
    position: absolute;
    top: 2rem;
    right: 2rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-main);
    width: 46px;
    height: 46px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 1000;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 10px -2px rgba(0,0,0,0.1);
}

.theme-toggle-btn:hover {
    transform: scale(1.1) rotate(15deg);
    color: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 6px 15px -2px var(--primary-glow);
}

/* Contenedor del Icono SVG para su animación independiente */
.theme-toggle-btn svg {
    transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55), opacity 0.2s ease;
}

/* Animación de flip circular estilo monedas */
.theme-toggle-btn.animating svg {
    transform: rotate(180deg) scale(0);
    opacity: 0;
}

/* =========================================
   ESTILOS GENÉRICOS DE MODAL (OVERLAY)
   ========================================= */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(15, 23, 42, 0.5); /* Slate 900 con opacidad */
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95) translateY(20px);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.modal-overlay.active .modal-content {
    transform: scale(1) translateY(0);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--card-border);
    background: var(--bg-color);
}

.modal-header h2 {
    font-size: 1.35rem;
    color: var(--text-main);
    margin: 0;
    letter-spacing: -0.02em;
}

.close-modal {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    transition: all 0.2s;
}

.close-modal:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
}

.modal-body {
    padding: 2rem;
}

.form-group {
    margin-bottom: 1.5rem;
}

.form-label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.5rem;
}

.form-input {
    width: 100%;
    padding: 0.8rem 1rem;
    border: 1px solid var(--card-border);
    border-radius: 10px;
    background: var(--bg-color);
    color: var(--text-main);
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    transition: all 0.3s;
    outline: none;
}

.form-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px var(--primary-glow);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--card-border);
}

.btn {
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: all 0.3s;
    border: none;
    font-family: inherit;
}

.btn-primary {
    background: var(--primary);
    color: #ffffff;
    box-shadow: 0 4px 10px var(--primary-glow);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 15px var(--primary-glow);
    filter: brightness(1.1);
}

.btn-secondary {
    background: transparent;
    border: 1px solid var(--card-border);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: var(--bg-color);
}
/* === TIER-BASED UI ENHANCEMENTS === */
.card-locked {
    filter: grayscale(0.8) opacity(0.7);
    cursor: pointer;
    position: relative;
    transition: filter 0.3s ease, transform 0.3s ease;
}

.card-locked:hover {
    filter: grayscale(0.4) opacity(0.9);
}

.locked-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.1);
    backdrop-filter: blur(2px);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10;
    border-radius: 20px;
}

.lock-badge {
    background: var(--primary);
    color: white;
    padding: 6px 12px;
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: flex;
    align-items: center;
    gap: 6px;
    box-shadow: 0 4px 12px var(--primary-glow);
}

.lock-badge svg {
    width: 14px;
    height: 14px;
}

/* Upgrade Page Styles */
.upgrade-container {
    max-width: 1000px;
    margin: 2rem auto;
    text-align: center;
}

.upgrade-header {
    margin-bottom: 4rem;
}

.upgrade-header h1 {
    font-size: 2.5rem;
    margin-bottom: 1rem;
}

.pricing-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-top: 3rem;
}

.pricing-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 24px;
    padding: 2.5rem;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    transition: transform 0.3s ease, border-color 0.3s ease;
}

.pricing-card.featured {
    border-color: var(--primary);
    border-width: 2px;
    transform: scale(1.05);
    box-shadow: 0 20px 40px rgba(0,0,0,0.05);
}

.pricing-tier {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}
/* Kanban Responsive Optimization */
@media (max-width: 768px) {
    .kanban-board {
        gap: 1rem;
        padding: 1rem;
        background: transparent;
        border: none;
        box-shadow: none;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scroll-snap-type: x mandatory;
    }

    .kanban-column {
        min-width: 85vw;
        max-width: 85vw;
        background: var(--card-bg);
        border: 1px solid var(--card-border);
        border-radius: 16px;
        scroll-snap-align: center;
        height: calc(100vh - 250px);
    }

    .tabs-header {
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: 10px;
        -webkit-overflow-scrolling: touch;
    }
}

.pricing-price {
    font-size: 2.5rem;
    font-weight: 800;
}

.pricing-price span {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-muted);
}

.pricing-features {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.pricing-features li {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    color: var(--text-muted);
}

.pricing-features li svg {
    color: #10b981;
    flex-shrink: 0;
}

/* === RESPONSIVE SIDEBAR & MOBILE TOP-BAR === */
.mobile-top-bar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 60px;
    background: var(--card-bg);
    border-bottom: 1px solid var(--card-border);
    z-index: 900;
    align-items: center;
    padding: 0 1rem;
    gap: 1rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
}

.burger-btn {
    background: var(--icon-bg);
    border: none;
    color: var(--primary);
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.burger-btn svg { width: 24px; height: 24px; }

.mobile-logo {
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: -0.03em;
    color: var(--primary);
}

.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    z-index: 940;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-overlay.visible {
    display: block;
    opacity: 1;
}

@media (max-width: 768px) {
    .mobile-top-bar { display: flex; }
    
    .sidebar {
        position: fixed;
        left: -280px;
        top: 0;
        height: 100vh;
        height: 100dvh;
        z-index: 950;
        width: 280px !important;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        box-shadow: 20px 0 50px rgba(0,0,0,0.1);
        display: flex;
        flex-direction: column;
    }
    
    .sidebar.mobile-open {
        transform: translateX(280px);
    }
    
    .sidebar .toggle-btn { display: none; }
    
    body.has-sidebar {
        padding-top: 80px; padding-left: 1rem !important;
    }
    
    .grid-layout-wrapper {
        padding: 0;
    }
}

/* Sidebar Component Styles */
.nav-category {
    padding: 1.5rem 1.5rem 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-muted);
    opacity: 0.8;
}

.sidebar:not(.expanded) .nav-category {
    display: none;
}

.user-info-sidebar {
    padding: 1.25rem;
    margin: 0.5rem 1rem 1.5rem;
    background: rgba(var(--primary-rgb, 59, 130, 246), 0.05);
    border-radius: 16px;
    border: 1px solid var(--card-border);
    overflow: hidden;
    transition: all 0.3s ease;
}

.sidebar:not(.expanded) .user-info-sidebar {
    margin: 0.5rem;
    padding: 0.75rem 0;
    background: transparent;
    border-color: transparent;
}

.user-info-content {
    transition: opacity 0.2s ease;
}

.sidebar:not(.expanded) .user-info-content {
    display: none;
}

.user-info-label {
    font-size: 0.65rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 4px;
    letter-spacing: 0.05em;
}

.user-info-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

.user-info-details {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.user-info-role-line {
    display: flex;
    align-items: center;
    gap: 6px;
}

.user-info-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.dot-admin { background: #10b981; box-shadow: 0 0 10px rgba(16, 185, 129, 0.4); }
.dot-agent { background: #3b82f6; box-shadow: 0 0 10px rgba(59, 130, 246, 0.4); }

.user-info-role-text {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}

.user-info-tier-badge {
    display: inline-block;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--primary);
    background: rgba(var(--primary-rgb, 59, 130, 246), 0.1);
    padding: 2px 8px;
    border-radius: 6px;
    margin-top: 4px;
}

.user-info-collapsed-status {
    display: none;
    justify-content: center;
    width: 100%;
}

.sidebar:not(.expanded) .user-info-collapsed-status {
    display: flex;
}

.sidebar:not(.expanded) .user-info-collapsed-status .user-info-dot {
    width: 12px;
    height: 12px;
}

/* Estilos para etiquetas de campos en vista móvil */
.grid-cell::before {
    display: none;
    font-weight: 700;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 4px;
}

@media (max-width: 768px) {
    .grid-cell {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
    }
    
    .grid-cell::before {
        display: block;
    }
    
    /* Etiquetas dinámicas para contactos */
    .contacts-grid .grid-cell:nth-child(1)::before { content: "Nombre"; }
    .contacts-grid .grid-cell:nth-child(2)::before { content: "Empresa / Cargo"; }
    .contacts-grid .grid-cell:nth-child(3)::before { content: "Contacto"; }
    .contacts-grid .grid-cell:nth-child(4)::before { content: "Ubicación"; }

    /* Etiquetas dinámicas para ventas */
    .sales-grid .grid-cell:nth-child(1)::before { content: "Cliente"; }
    .sales-grid .grid-cell:nth-child(2)::before { content: "Categoría"; }
    .sales-grid .grid-cell:nth-child(3)::before { content: "Fecha"; }
    .sales-grid .grid-cell:nth-child(4)::before { content: "Total"; }
    .sales-grid .grid-cell:nth-child(5)::before { content: "Estado"; }

    #modalTable, #modalTable thead, #modalTable tbody, #modalTable th, #modalTable td, #modalTable tr { 
        display: block; 
        width: 100%;
    }

    #modalTable thead {
        display: none;
    }

    #modalTable tr {
        margin-bottom: 1rem;
        border: 1px solid var(--card-border);
        border-radius: 12px;
        padding: 1rem;
        background: var(--card-bg);
    }

    #modalTable td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 0;
        border-bottom: 1px dashed var(--card-border);
        text-align: right;
    }

    #modalTable td:last-child {
        border-bottom: none;
    }

    #modalTable td::before {
        content: attr(data-label);
        font-weight: 700;
        text-align: left;
        font-size: 0.8rem;
        color: var(--text-muted);
        text-transform: uppercase;
    }
}

/* === MEJORAS DE DISEÑO MODERNO & DATA GRID === */
@media (max-width: 768px) {
    .users-grid .grid-cell:nth-child(1)::before { content: "Nombre"; }
    .users-grid .grid-cell:nth-child(2)::before { content: "Apellido"; }
    .users-grid .grid-cell:nth-child(3)::before { content: "Usuario"; }
    .users-grid .grid-cell:nth-child(4)::before { content: "Correo"; }
    .users-grid .grid-cell:nth-child(5)::before { content: "Tier"; }
    .users-grid .grid-cell:nth-child(6)::before { content: "Rol"; }
    
    .grid-layout-wrapper {
        gap: 1rem;
    }
}

/* Botones con gradientes premium */
.btn-primary, .add-event-btn, .add-deal-btn:hover {
    background: linear-gradient(135deg, var(--primary) 0%, #2563eb 100%) !important;
    box-shadow: 0 4px 15px var(--primary-glow) !important;
    border: none !important;
    transition: all 0.3s ease !important;
}

.btn-primary:hover, .add-event-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--primary-glow) !important;
}

/* Unificación de Modales */
.custom-modal, .modal-overlay {
    backdrop-filter: blur(8px) !important;
    background: rgba(15, 23, 42, 0.4) !important;
}

.custom-modal-content, .modal-content {
    border: 1px solid var(--card-border) !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25) !important;
}

/* === ADVANCED MOBILE TABLE UX (Expandables & Action Sheets) === */
.action-sheet-overlay, .action-sheet {
    display: none; /* Hidden by default on desktop */
}

@media (max-width: 768px) {
    .action-sheet-overlay { display: block; }
    .action-sheet { display: block; }
    
    /* Ocultar celdas secundarias por defecto en móvil */
    .grid-row .grid-cell:nth-child(n+4):not(.actions-cell) {
        display: none;
    }

    /* Mostrar celdas secundarias cuando la fila está expandida */
    .grid-row.expanded .grid-cell:nth-child(n+4):not(.actions-cell) {
        display: flex;
        animation: slideDownFade 0.3s ease-out forwards;
    }

    /* Botón de expansión (Chevron) */
    .expand-btn {
        background: none;
        border: none;
        color: var(--text-muted);
        padding: 10px;
        transition: transform 0.3s ease;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .grid-row.expanded .expand-btn {
        transform: rotate(180deg);
        color: var(--primary);
    }

    /* Action Sheet (Menú Inferior) */
    .action-sheet-overlay {
        position: fixed;
        top: 0; left: 0; width: 100%; height: 100%;
        background: rgba(0,0,0,0.4);
        backdrop-filter: blur(4px);
        z-index: 2000;
        opacity: 0; visibility: hidden;
        transition: all 0.3s ease;
    }

    .action-sheet-overlay.active {
        opacity: 1; visibility: visible;
    }

    .action-sheet {
        position: fixed;
        bottom: -100%; left: 0; width: 100%;
        background: var(--card-bg);
        border-radius: 24px 24px 0 0;
        padding: 1.5rem;
        z-index: 2001;
        transition: bottom 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        box-shadow: 0 -10px 40px rgba(0,0,0,0.1);
    }

    .action-sheet.active {
        bottom: 0;
    }

    .action-sheet-header {
        text-align: center;
        margin-bottom: 1.5rem;
    }

    .action-sheet-handle {
        width: 40px; height: 4px;
        background: var(--card-border);
        border-radius: 2px;
        margin: 0 auto 1rem;
    }

    .action-sheet-title {
        font-weight: 700;
        font-size: 1.1rem;
        color: var(--text-main);
    }

    .action-sheet-options {
        display: grid;
        gap: 10px;
    }

    .action-option {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 1rem;
        background: var(--bg-color);
        border-radius: 12px;
        color: var(--text-main);
        font-weight: 600;
        text-decoration: none;
        border: none;
        width: 100%;
        font-size: 1rem;
        cursor: pointer;
    }

    .action-option.danger { color: #ef4444; background: rgba(239, 68, 68, 0.05); }

    /* Animación de entrada */
    @keyframes slideDownFade {
        from { opacity: 0; transform: translateY(-10px); }
        to { opacity: 1; transform: translateY(0); }
    }
}

/* === UTILITY CLASSES FOR RESPONSIVE VISIBILITY === */
@media (max-width: 768px) {
    .desktop-only { display: none !important; }
    .mobile-only { display: flex !important; }
}

@media (min-width: 769px) {
    .mobile-only { display: none !important; }
    .desktop-only { display: flex !important; }
    
    /* Evitar que el botón de expandir ocupe espacio en desktop */
    .expand-btn.mobile-only, .action-sheet-btn.mobile-only { display: none !important; }
}

/* Base Ghost Button Style */
.btn-ghost {
    background: transparent !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-muted) !important;
    box-shadow: none !important;
}
.btn-ghost:hover {
    background: rgba(var(--primary-rgb, 59, 130, 246), 0.05) !important;
    color: var(--primary) !important;
    border-color: var(--primary) !important;
}

/* Ajustes finales de interactividad */
.grid-row {
    transition: all 0.2s ease;
    cursor: default;
}

.grid-row:hover {
    background: rgba(var(--primary-rgb, 59, 130, 246), 0.02);
}

.action-sheet-btn {
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s;
}

.action-sheet-btn:active {
    background: rgba(0,0,0,0.05);
}

/* === RESPONSIVE TABLES (Modal & General) === */
@media (max-width: 768px) {
    .responsive-table thead {
        display: none;
    }

    .responsive-table tr {
        display: block;
        margin-bottom: 1rem;
        background: var(--card-bg);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 0.5rem;
    }

    .responsive-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 15px !important;
        border-bottom: 1px solid rgba(0,0,0,0.03) !important;
        text-align: right !important;
    }

    .responsive-table td:last-child {
        border-bottom: none !important;
    }

    .responsive-table td::before {
        content: attr(data-label);
        font-weight: 600;
        text-transform: uppercase;
        font-size: 0.75rem;
        color: var(--text-muted);
        text-align: left;
    }

    /* Expandable logic for tables */
    .responsive-table tr .td-secondary {
        display: none;
    }

    .responsive-table tr.expanded .td-secondary {
        display: flex;
    }

    /* Form & Modal Mobile Stacking */
    .form-row {
        grid-template-columns: 1fr !important;
        gap: 12px !important;
    }

    .form-actions {
        flex-direction: column-reverse !important;
        align-items: stretch !important;
        gap: 1rem !important;
    }

    .actions-left, .actions-right {
        width: 100%;
        display: flex;
        flex-direction: column;
        gap: 0.75rem;
    }

    .form-actions button {
        width: 100% !important;
        justify-content: center;
        padding: 0.8rem !important;
    }
}


@media (max-width: 768px) {
    .grid-cell {
        display: flex;
        flex-direction: column;
        align-items: flex-start;
    }
    
    .grid-cell::before {
        display: block;
    }
    
    /* Etiquetas dinámicas para contactos */
    .contacts-grid .grid-cell:nth-child(1)::before { content: "Nombre"; }
    .contacts-grid .grid-cell:nth-child(2)::before { content: "Empresa / Cargo"; }
    .contacts-grid .grid-cell:nth-child(3)::before { content: "Contacto"; }
    .contacts-grid .grid-cell:nth-child(4)::before { content: "Ubicación"; }

    /* Etiquetas dinámicas para ventas */
    .sales-grid .grid-cell:nth-child(1)::before { content: "Cliente"; }
    .sales-grid .grid-cell:nth-child(2)::before { content: "Categoría"; }
    .sales-grid .grid-cell:nth-child(3)::before { content: "Fecha"; }
    .sales-grid .grid-cell:nth-child(4)::before { content: "Total"; }
    .sales-grid .grid-cell:nth-child(5)::before { content: "Estado"; }

    #modalTable, #modalTable thead, #modalTable tbody, #modalTable th, #modalTable td, #modalTable tr { 
        display: block; 
        width: 100%;
    }

    #modalTable thead {
        display: none;
    }

    #modalTable tr {
        margin-bottom: 1rem;
        border: 1px solid var(--card-border);
        border-radius: 12px;
        padding: 1rem;
        background: var(--card-bg);
    }

    #modalTable td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.5rem 0;
        border-bottom: 1px dashed var(--card-border);
        text-align: right;
    }

    #modalTable td:last-child {
        border-bottom: none;
    }

    #modalTable td::before {
        content: attr(data-label);
        font-weight: 700;
        text-align: left;
        font-size: 0.8rem;
        color: var(--text-muted);
        text-transform: uppercase;
    }
}

/* === MEJORAS DE DISEÑO MODERNO & DATA GRID === */
@media (max-width: 768px) {
    .users-grid .grid-cell:nth-child(1)::before { content: "Nombre"; }
    .users-grid .grid-cell:nth-child(2)::before { content: "Apellido"; }
    .users-grid .grid-cell:nth-child(3)::before { content: "Usuario"; }
    .users-grid .grid-cell:nth-child(4)::before { content: "Correo"; }
    .users-grid .grid-cell:nth-child(5)::before { content: "Tier"; }
    .users-grid .grid-cell:nth-child(6)::before { content: "Rol"; }
    
    .grid-layout-wrapper {
        gap: 1rem;
    }
}

/* Botones con gradientes premium */
.btn-primary, .add-event-btn, .add-deal-btn:hover {
    background: linear-gradient(135deg, var(--primary) 0%, #2563eb 100%) !important;
    box-shadow: 0 4px 15px var(--primary-glow) !important;
    border: none !important;
    transition: all 0.3s ease !important;
}

.btn-primary:hover, .add-event-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 25px var(--primary-glow) !important;
}

/* UnificaciÃ³n de Modales */
.custom-modal, .modal-overlay {
    backdrop-filter: blur(8px) !important;
    background: rgba(15, 23, 42, 0.4) !important;
}

.custom-modal-content, .modal-content {
    border: 1px solid var(--card-border) !important;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25) !important;
}

/* === ADVANCED MOBILE TABLE UX (Expandables & Action Sheets) === */
.action-sheet-overlay, .action-sheet {
    display: none; /* Hidden by default on desktop */
}

@media (max-width: 768px) {
    .action-sheet-overlay { display: block; }
    .action-sheet { display: block; }
    
    /* Ocultar celdas secundarias por defecto en mÃ³vil */
    .grid-row .grid-cell:nth-child(n+4):not(.actions-cell) {
        display: none;
    }

    /* Mostrar celdas secundarias cuando la fila estÃ¡ expandida */
    .grid-row.expanded .grid-cell:nth-child(n+4):not(.actions-cell) {
        display: flex;
        animation: slideDownFade 0.3s ease-out forwards;
    }

    /* BotÃ³n de expansiÃ³n (Chevron) */
    .expand-btn {
        background: none;
        border: none;
        color: var(--text-muted);
        padding: 10px;
        transition: transform 0.3s ease;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    .grid-row.expanded .expand-btn {
        transform: rotate(180deg);
        color: var(--primary);
    }

    /* Action Sheet (MenÃº Inferior) */
    .action-sheet-overlay {
        position: fixed;
        top: 0; left: 0; width: 100%; height: 100%;
        background: rgba(0,0,0,0.4);
        backdrop-filter: blur(4px);
        z-index: 2000;
        opacity: 0; visibility: hidden;
        transition: all 0.3s ease;
    }

    .action-sheet-overlay.active {
        opacity: 1; visibility: visible;
    }

    .action-sheet {
        position: fixed;
        bottom: -100%; left: 0; width: 100%;
        background: var(--card-bg);
        border-radius: 24px 24px 0 0;
        padding: 1.5rem;
        z-index: 2001;
        transition: bottom 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
        box-shadow: 0 -10px 40px rgba(0,0,0,0.1);
    }

    .action-sheet.active {
        bottom: 0;
    }

    .action-sheet-header {
        text-align: center;
        margin-bottom: 1.5rem;
    }

    .action-sheet-handle {
        width: 40px; height: 4px;
        background: var(--card-border);
        border-radius: 2px;
        margin: 0 auto 1rem;
    }

    .action-sheet-title {
        font-weight: 700;
        font-size: 1.1rem;
        color: var(--text-main);
    }

    .action-sheet-options {
        display: grid;
        gap: 10px;
    }

    .action-option {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 1rem;
        background: var(--bg-color);
        border-radius: 12px;
        color: var(--text-main);
        font-weight: 600;
        text-decoration: none;
        border: none;
        width: 100%;
        font-size: 1rem;
        cursor: pointer;
    }

    .action-option.danger { color: #ef4444; background: rgba(239, 68, 68, 0.05); }

    /* AnimaciÃ³n de entrada */
    @keyframes slideDownFade {
        from { opacity: 0; transform: translateY(-10px); }
        to { opacity: 1; transform: translateY(0); }
    }
}

/* === UTILITY CLASSES FOR RESPONSIVE VISIBILITY === */
@media (max-width: 768px) {
    .desktop-only { display: none !important; }
    .mobile-only { display: flex !important; }
}

@media (min-width: 769px) {
    .mobile-only { display: none !important; }
    .desktop-only { display: flex !important; }
    
    /* Evitar que el botÃ³n de expandir ocupe espacio en desktop */
    .expand-btn.mobile-only, .action-sheet-btn.mobile-only { display: none !important; }
}

/* Base Ghost Button Style */
.btn-ghost {
    background: transparent !important;
    border: 1px solid var(--border-color) !important;
    color: var(--text-muted) !important;
    box-shadow: none !important;
}
.btn-ghost:hover {
    background: rgba(var(--primary-rgb, 59, 130, 246), 0.05) !important;
    color: var(--primary) !important;
    border-color: var(--primary) !important;
}

/* Ajustes finales de interactividad */
.grid-row {
    transition: all 0.2s ease;
    cursor: default;
}

.grid-row:hover {
    background: rgba(var(--primary-rgb, 59, 130, 246), 0.02);
}

.action-sheet-btn {
    cursor: pointer;
    border-radius: 50%;
    transition: background 0.2s;
}

.action-sheet-btn:active {
    background: rgba(0,0,0,0.05);
}

/* === RESPONSIVE TABLES (Modal & General) === */
@media (max-width: 768px) {
    .responsive-table thead {
        display: none;
    }

    .responsive-table tr {
        display: block;
        margin-bottom: 1rem;
        background: var(--card-bg);
        border: 1px solid var(--border-color);
        border-radius: 12px;
        padding: 0.5rem;
    }

    .responsive-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 10px 15px !important;
        border-bottom: 1px solid rgba(0,0,0,0.03) !important;
        text-align: right !important;
    }

    .responsive-table td:last-child {
        border-bottom: none !important;
    }

    .responsive-table td::before {
        content: attr(data-label);
        font-weight: 600;
        text-transform: uppercase;
        font-size: 0.75rem;
        color: var(--text-muted);
        text-align: left;
    }

    /* Expandable logic for tables */
    .responsive-table tr .td-secondary {
        display: none;
    }

    .responsive-table tr.expanded .td-secondary {
        display: flex;
    }
}
/* === RESPONSIVE UTILITIES === */
.hide-mobile { display: block; }
.hide-tablet { display: block; }
.mobile-only { display: none !important; }
.desktop-only { display: flex !important; }

@media (max-width: 1100px) {
    .hide-tablet { display: none !important; }
}

@media (max-width: 768px) {
    .hide-mobile, .desktop-only { display: none !important; }
    .mobile-only { display: flex !important; }
}
