:root {
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --accent: #0668E1;
    --bg-main: #f8fafc;
    --bg-sidebar: #ffffff; /* Retained from original */
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --border: rgba(0, 0, 0, 0.08);
    --glass-bg: rgba(255, 255, 255, 0.7);
    --danger: #ef4444; /* Retained from original */
    --sidebar-width: 70px; /* Retained from original */
}

[data-theme="dark"] {
    --bg-main: #0f172a;
    --bg-sidebar: #1e293b; /* Retained from original */
    --bg-card: #1e293b;
    --text-main: #f1f5f9;
    --text-muted: #94a3b8;
    --border: rgba(255, 255, 255, 0.1);
    --glass-bg: rgba(15, 23, 42, 0.8);
    --sidebar-width: 70px; /* Retained from original */
}

/* Custom Scrollbar - Diseño Minimalista y Premium */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.2); /* Color primario suave por defecto */
    border-radius: 20px;
    border: none;
    transition: background 0.3s;
}

/* Ocultar botones de flecha (Los de tu imagen) */
::-webkit-scrollbar-button {
    display: none;
    width: 0;
    height: 0;
}

/* Esquinas de la barra */
::-webkit-scrollbar-corner {
    background: transparent;
}

[data-theme="dark"] ::-webkit-scrollbar-thumb {
    background: rgba(99, 102, 241, 0.3); /* Un poco más visible en oscuro */
}

::-webkit-scrollbar-thumb:hover {
    background: var(--primary); /* Se vuelve sólido al pasar el ratón */
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}

/* Soporte para Firefox (Scrollbar-width y color) */
* {
    scrollbar-width: thin;
    scrollbar-color: rgba(99, 102, 241, 0.3) transparent;
}

[data-theme="dark"], [data-theme="dark"] * {
    scrollbar-color: rgba(99, 102, 241, 0.4) transparent;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Outfit', sans-serif;
}

body {
    background-color: var(--bg-main);
    color: var(--text-main);
    display: flex;
    height: 100vh;
    overflow: hidden;
    transition: background-color 0.3s, color 0.3s;
}

/* Sidebar Navigation */
#navbar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px 0;
    z-index: 1000;
    transition: all 0.3s;
}

.nav-item {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 20px;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    font-size: 1.2rem;
}

.nav-item:hover {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
    transform: scale(1.1);
}

.nav-item.active {
    background: var(--primary);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
}

.nav-item::after {
    content: attr(title);
    position: absolute;
    left: 60px;
    background: #1e293b;
    color: white;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s;
    box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1);
}

.nav-item:hover::after {
    opacity: 1;
}

/* Main Content Container */
.crm-main-container {
    flex: 1;
    height: 100vh;
    overflow-y: auto;
    padding: 40px;
}

[data-theme="dark"] .crm-main-container {
    background-color: var(--bg-main);
}

.crm-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 24px;
    max-width: 1200px;
    margin: 0 auto;
}
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 20px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh; /* Limitar altura al 90% de la pantalla */
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
    position: relative;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 24px;
    overflow-y: auto; /* Scroll interno si el contenido es largo */
    flex: 1;
}

/* Generic Card Style */
.card {
    background: var(--bg-card);
    border-radius: 16px;
    border: 1px solid var(--border);
    padding: 20px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    transition: transform 0.2s, box-shadow 0.2s;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0,0,0,0.05);
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border-radius: 10px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }

/* Card & Modal Action Buttons */
.btn-action {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border);
    cursor: pointer;
    transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    background: var(--bg-card);
    color: var(--text-muted);
}

.btn-action:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.btn-action-success {
    color: #10b981;
    background: rgba(16, 185, 129, 0.05);
}

.btn-action-success:hover {
    background: #10b981;
    color: white;
    border-color: #10b981;
}

.btn-action-primary {
    color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

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

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

.btn-close-modal:hover {
    background: #ef4444;
    color: white;
    transform: rotate(90deg);
}

[data-theme="dark"] .btn-close-modal {
    background: rgba(255,255,255,0.05);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.animate-fade {
    animation: fadeIn 0.5s ease forwards;
}

/* ========================================================
   RESPONSIVO / MOBILE (Tablets & Phones)
   ======================================================== */
@media (max-width: 768px) {
    body {
        flex-direction: column;
    }

    #navbar {
        position: fixed;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 65px;
        min-height: 65px;
        flex-direction: row;
        justify-content: space-around;
        padding: 5px 10px;
        border-right: none;
        border-top: 1px solid var(--border);
        box-shadow: 0 -4px 10px rgba(0,0,0,0.05);
        background: var(--bg-sidebar);
        z-index: 9999;
    }

    .nav-item {
        width: 44px;
        height: 44px;
        margin-bottom: 0;
        font-size: 1.1rem;
    }

    .nav-item::after {
        display: none !important; /* Deshabilitar tooltips en móvil */
    }

    .crm-main-container {
        padding: 15px;
        padding-bottom: 80px; /* Respetamos el panel fijo inferior */
        width: 100%;
        height: 100dvh; /* Adaptación dinámica si lo soporta el navegador, evitamos 100vh puro */
        overflow-y: auto;
    }

    .crm-grid {
        grid-template-columns: 1fr; /* Una sola columna en móvil */
        gap: 16px;
    }

    .modal-content {
        width: 95%;
        padding: 20px 15px;
        max-height: 85vh;
    }
}

.hidden-item {
    display: none !important;
}

