/* System Font & Core Reset */
@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700;800&display=swap');

:root {
    --bg-dark: #0B0F19;
    --bg-card: rgba(17, 24, 39, 0.7);
    --border-color: rgba(255, 255, 255, 0.08);
    --primary-gradient: linear-gradient(135deg, #6366F1 0%, #14B8A6 100%);
    --primary-color: #6366F1;
    --accent-color: #14B8A6;
    --danger-color: #EF4444;
    --warning-color: #F59E0B;
    --success-color: #10B981;
    --text-white: #F9FAFB;
    --text-gray: #9CA3AF;
    --text-muted: #6B7280;
    --transition-fast: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Outfit', sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-white);
    min-height: 100vh;
    overflow-x: hidden;
    background-image: 
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.15) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(20, 184, 166, 0.15) 0px, transparent 50%);
}

/* Layout Grid */
.app-container {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: 100vh;
}

/* Sidebar Navigation */
.sidebar {
    background-color: rgba(10, 15, 30, 0.85);
    border-right: 1px solid var(--border-color);
    padding: 2rem 1.5rem;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    backdrop-filter: blur(20px);
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 3rem;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: var(--primary-gradient);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.25rem;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.nav-links {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex-grow: 1;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1rem;
    border-radius: 10px;
    color: var(--text-gray);
    text-decoration: none;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-fast);
}

.nav-item:hover, .nav-item.active {
    color: var(--text-white);
    background: rgba(255, 255, 255, 0.05);
}

.nav-item.active {
    border-left: 3px solid #14B8A6;
    background: rgba(99, 102, 241, 0.1);
}

.nav-item svg {
    width: 20px;
    height: 20px;
    stroke: currentColor;
}

.sidebar-footer {
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

/* Main Content Area */
main {
    padding: 2.5rem;
    overflow-y: auto;
    max-height: 100vh;
}

/* Header Component */
.top-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2.5rem;
}

.top-header h1 {
    font-size: 2.25rem;
    font-weight: 800;
    letter-spacing: -0.5px;
}

.top-header p {
    color: var(--text-gray);
    margin-top: 0.25rem;
}

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

/* Custom Premium Buttons */
.btn-primary {
    background: var(--primary-gradient);
    color: var(--text-white);
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
    transition: var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.45);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-white);
    border: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem;
    border-radius: 10px;
    font-weight: 600;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition-fast);
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.btn-danger {
    background: var(--danger-color);
    color: var(--text-white);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition-fast);
}

.btn-danger:hover {
    background: #DC2626;
}

/* Dashboard Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2.5rem;
}

.stat-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 1.5rem;
    backdrop-filter: blur(16px);
    display: flex;
    align-items: center;
    gap: 1.25rem;
    position: relative;
    overflow: hidden;
    transition: var(--transition-fast);
}

.stat-card:hover {
    transform: translateY(-5px);
    border-color: rgba(255, 255, 255, 0.15);
}

/* Tarjetas del dashboard que actúan como accesos rápidos: cursor pointer + realce */
.stat-card.stat-clickable {
    cursor: pointer;
    user-select: none;
}

.stat-card.stat-clickable:hover {
    border-color: rgba(6, 182, 212, 0.45);
    box-shadow: 0 8px 24px rgba(6, 182, 212, 0.15);
}

.stat-card.stat-clickable:active {
    transform: translateY(-2px);
}

/* Accesibilidad — foco visible al usar teclado */
.stat-card.stat-clickable:focus-visible {
    outline: 2px solid var(--accent-color, #06b6d4);
    outline-offset: 3px;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: var(--primary-gradient);
    opacity: 0;
    transition: var(--transition-fast);
}

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

.stat-icon {
    width: 48px;
    height: 48px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-color);
}

.stat-icon svg {
    width: 24px;
    height: 24px;
    stroke: currentColor;
}

.stat-info h3 {
    font-size: 0.85rem;
    color: var(--text-gray);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.25rem;
}

.stat-info p {
    font-size: 1.75rem;
    font-weight: 700;
}

/* Sections Structure */
.content-section {
    display: none;
    animation: fadeIn 0.4s ease-out forwards;
}

.content-section.active {
    display: block;
}

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

/* Glass Card containers */
.glass-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 18px;
    padding: 2rem;
    backdrop-filter: blur(16px);
    margin-bottom: 2rem;
}

.card-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

/* Tables Styling */
.table-container {
    overflow-x: auto;
}

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

th {
    padding: 1rem;
    color: var(--text-gray);
    font-weight: 600;
    border-bottom: 1px solid var(--border-color);
    font-size: 0.9rem;
}

td {
    padding: 1.15rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    font-size: 0.95rem;
}

tr:hover td {
    background: rgba(255, 255, 255, 0.01);
}

/* Badges */
.badge {
    padding: 0.35rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-block;
    text-transform: uppercase;
}

.badge-success {
    background-color: rgba(16, 185, 129, 0.15);
    color: #34D399;
}

.badge-info {
    background-color: rgba(6, 182, 212, 0.15);
    color: #22D3EE;
}

.badge-warning {
    background-color: rgba(245, 158, 11, 0.15);
    color: #FBBF24;
}

.badge-danger {
    background-color: rgba(239, 68, 110, 0.15);
    color: #F87171;
}

.badge-primary {
    background-color: rgba(99, 102, 241, 0.15);
    color: #818CF8;
}

/* Voice Call Simulator Panel */
.voice-console-grid {
    display: grid;
    grid-template-columns: 1fr 350px;
    gap: 2rem;
}

.terminal-box {
    background-color: #05070F;
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 12px;
    height: 380px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Courier New', Courier, monospace;
}

.terminal-header {
    background-color: #0A0D1A;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.terminal-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.dot-red { background-color: var(--danger-color); }
.dot-yellow { background-color: var(--warning-color); }
.dot-green { background-color: var(--success-color); }

.terminal-title {
    color: var(--text-gray);
    font-size: 0.8rem;
    margin-left: 0.5rem;
}

.terminal-body {
    padding: 1rem;
    flex-grow: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    font-size: 0.9rem;
}

.terminal-line {
    line-height: 1.4;
}

.line-system { color: #818CF8; }
.line-agent { color: #34D399; }
.line-user { color: #FBBF24; }

.call-control-panel {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.dial-animation {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: rgba(99, 102, 241, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-color);
    position: relative;
    margin-bottom: 1rem;
}

.dial-animation svg {
    width: 32px;
    height: 32px;
    animation: shake 0.5s infinite alternate;
}

@keyframes shake {
    0% { transform: rotate(-10deg); }
    100% { transform: rotate(10deg); }
}

.dial-pulse {
    position: absolute;
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 2px solid var(--accent-color);
    animation: pulse 1.5s infinite ease-out;
    opacity: 0;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.8; }
    100% { transform: scale(1.6); opacity: 0; }
}

/* Modals */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(5, 7, 15, 0.8);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background-color: #0E1322;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    width: 500px;
    padding: 2rem;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
    animation: modalSlideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    /* Si el contenido no cabe en la ventana, permitir scroll interno */
    max-height: 90vh;
    overflow-y: auto;
}

/* Modal ancha para formularios de 2 columnas (inventario, ventas complejas) */
.modal-content.modal-wide {
    width: 780px;
    max-width: 92vw;
}

/* Cuadrícula de 2 columnas dentro de una modal */
.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0 1rem;
}

/* Ocupa las 2 columnas — útil para campos largos (notas, textarea) */
.form-grid-2 .form-full {
    grid-column: 1 / -1;
}

/* En móviles, la cuadrícula colapsa a 1 columna */
@media (max-width: 640px) {
    .form-grid-2 {
        grid-template-columns: 1fr;
    }
}

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

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

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-gray);
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-control {
    width: 100%;
    background-color: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    color: var(--text-white);
    font-family: inherit;
    font-size: 0.95rem;
    transition: var(--transition-fast);
}

.form-control:focus {
    outline: none;
    border-color: var(--accent-color);
    background-color: rgba(255, 255, 255, 0.08);
}

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

/* Tablero Kanban */
.kanban-board {
    display: flex;
    gap: 1rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    align-items: flex-start;
}

.kanban-column {
    flex: 1 0 240px;
    min-width: 240px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 1rem;
    transition: var(--transition-fast);
}

.kanban-column.drag-over {
    border-color: var(--accent-color);
    background: rgba(20, 184, 166, 0.08);
}

.kanban-col-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.kanban-count {
    color: var(--text-gray);
    font-size: 0.85rem;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 20px;
    padding: 0.1rem 0.6rem;
}

.kanban-cards {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    min-height: 80px;
    max-height: 62vh;
    overflow-y: auto;
    padding-right: 4px;
}

.kanban-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.85rem;
    cursor: grab;
    transition: var(--transition-fast);
}

.kanban-card:hover {
    border-color: rgba(255, 255, 255, 0.18);
    transform: translateY(-2px);
}

.kanban-card.dragging {
    opacity: 0.45;
    cursor: grabbing;
}

.kanban-card-name {
    font-weight: 600;
    font-size: 0.92rem;
    margin-bottom: 0.2rem;
}

.kanban-card-sub {
    color: var(--text-gray);
    font-size: 0.8rem;
    margin-bottom: 0.6rem;
}

.kanban-card-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
}

.kanban-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.35rem;
}

.kanban-card-id {
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.kanban-card-meta {
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-bottom: 0.5rem;
}

.kanban-card-dates {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    font-size: 0.68rem;
    color: var(--text-muted);
    border-top: 1px solid var(--border-color);
    padding-top: 0.45rem;
}

/* KPIs de rendimiento por agente */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 0.75rem;
    margin-top: 0.5rem;
}
.kpi-card {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.85rem 1rem;
}
.kpi-label {
    color: var(--text-muted);
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
}
.kpi-value {
    color: var(--text-light, #fff);
    font-size: 1.65rem;
    font-weight: 700;
    margin-top: 0.35rem;
}
.channel-pills {
    display: inline-flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}
.channel-pill {
    display: inline-flex;
    align-items: center;
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border-color);
    color: var(--text-gray);
}

/* Barra de filtros de Leads (CRM) */
.leads-filters {
    display: grid;
    grid-template-columns: 2fr repeat(4, 1fr) auto;
    gap: 0.65rem 0.85rem;
    align-items: end;
    margin: 1rem 0 0.5rem 0;
    padding: 0.9rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 12px;
}
.leads-filters .filter-item {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    min-width: 0;
}
.leads-filters .filter-item label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    font-weight: 600;
}
.leads-filters .filter-item .form-control {
    padding: 0.45rem 0.6rem;
    font-size: 0.85rem;
}
.leads-filters .filter-item-grow { grid-column: 1 / 3; }
.leads-filters .filter-item-actions { align-self: end; }

/* En móvil colapsa a 2 columnas */
@media (max-width: 780px) {
    .leads-filters {
        grid-template-columns: 1fr 1fr;
    }
    .leads-filters .filter-item-grow { grid-column: 1 / -1; }
    .leads-filters .filter-item-actions { grid-column: 1 / -1; }
}

/* Badge del agente asignado en las tarjetas del Kanban (solo visible para admin) */
.kanban-card-agent {
    display: inline-flex;
    align-items: center;
    font-size: 0.72rem;
    color: var(--primary-color, #6366f1);
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.28);
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    margin-bottom: 0.45rem;
    font-weight: 500;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.kanban-empty {
    color: var(--text-muted);
    text-align: center;
    font-size: 0.85rem;
    padding: 0.75rem 0;
}

/* Login Overlay */
.login-overlay {
    position: fixed;
    inset: 0;
    background-color: var(--bg-dark);
    background-image:
        radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.18) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(20, 184, 166, 0.18) 0px, transparent 50%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
}

.login-card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 2.5rem;
    width: 380px;
    max-width: 90vw;
    backdrop-filter: blur(16px);
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.login-logo {
    width: 56px;
    height: 56px;
    margin: 0 auto 1rem auto;
    background: var(--primary-gradient);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 800;
    font-size: 1.5rem;
    color: #fff;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}

/* Logo oficial en el modal de login */
.login-logo-img {
    display: block;
    width: 96px;
    height: 96px;
    object-fit: contain;
    margin: 0 auto 1rem auto;
    border-radius: 50%;
    background: #111;
    padding: 4px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.35);
}

/* Logo oficial en el sidebar */
.logo-img {
    display: block;
    width: 100%;
    max-width: 200px;
    height: auto;
    object-fit: contain;
    margin: 0 auto;
}

.login-card h2 {
    background: var(--primary-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 0.25rem;
}

.login-card .form-group {
    text-align: left;
}

/* Conversaciones (Chat de WhatsApp) */
.chat-layout {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: 600px;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.01);
}

.chat-list {
    border-right: 1px solid var(--border-color);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.chat-empty-hint {
    padding: 1.5rem;
    color: var(--text-muted);
    font-size: 0.9rem;
    text-align: center;
    line-height: 1.5;
}

.chat-list-item {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.85rem 1rem;
    cursor: pointer;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    transition: var(--transition-fast);
}

.chat-list-item:hover {
    background: rgba(255, 255, 255, 0.04);
}

.chat-list-item.active {
    background: rgba(99, 102, 241, 0.12);
    border-left: 3px solid var(--accent-color);
}

.chat-avatar {
    width: 42px;
    height: 42px;
    min-width: 42px;
    border-radius: 50%;
    background: var(--primary-gradient);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #fff;
}

.chat-list-info {
    overflow: hidden;
    flex-grow: 1;
}

.chat-list-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}

.chat-list-name {
    font-weight: 600;
    font-size: 0.92rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-list-preview {
    color: var(--text-gray);
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-top: 0.15rem;
}

.chat-thread {
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.chat-thread-empty {
    margin: auto;
    color: var(--text-muted);
    font-size: 0.95rem;
    padding: 2rem;
    text-align: center;
}

.chat-thread-header {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.02);
}

.chat-thread-name {
    font-weight: 600;
}

.chat-thread-sub {
    color: var(--text-gray);
    font-size: 0.8rem;
    margin-top: 0.15rem;
}

.chat-messages {
    flex-grow: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.chat-bubble {
    max-width: 72%;
    padding: 0.65rem 0.9rem;
    border-radius: 14px;
    font-size: 0.9rem;
    line-height: 1.4;
}

.bubble-text {
    white-space: pre-wrap;
    word-wrap: break-word;
}

.bubble-time {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
    text-align: right;
}

.bubble-in {
    align-self: flex-start;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

.bubble-out {
    align-self: flex-end;
    background: rgba(20, 184, 166, 0.18);
    border: 1px solid rgba(20, 184, 166, 0.35);
    border-bottom-right-radius: 4px;
}

.chat-note {
    align-self: center;
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-gray);
    font-size: 0.78rem;
    padding: 0.4rem 0.85rem;
    border-radius: 20px;
    text-align: center;
    max-width: 85%;
}

/* =========================================================
   Botón hamburguesa (solo se ve en móvil)
   ========================================================= */
.hamburger-btn {
    display: none;
    background: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-light, #fff);
    width: 40px;
    height: 40px;
    border-radius: 10px;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: var(--transition-fast);
}
.hamburger-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.2);
}
.hamburger-btn svg { width: 22px; height: 22px; }

.header-title-wrap {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    min-width: 0;
    flex: 1;
}

/* Overlay que aparece detrás del sidebar en móvil */
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    z-index: 995;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}
.sidebar-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

/* =========================================================
   Tablets — pantallas medianas
   ========================================================= */
@media(max-width: 1024px) {
    .voice-console-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

/* =========================================================
   Móvil — sidebar deslizable + hamburguesa
   ========================================================= */
@media(max-width: 900px) {
    .app-container {
        grid-template-columns: 1fr;
    }

    .hamburger-btn { display: inline-flex; }

    /* Sidebar oculto por defecto (fuera de pantalla) */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 260px;
        transform: translateX(-100%);
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
        z-index: 1000;
        overflow-y: auto;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.35);
    }
    .sidebar.sidebar-open {
        transform: translateX(0);
    }

    main {
        padding: 1.25rem 1rem;
    }

    .top-header {
        flex-direction: column;
        align-items: stretch;
        gap: 0.85rem;
    }
    .header-actions {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    .header-actions .btn-primary,
    .header-actions .btn-secondary {
        flex: 1 1 auto;
        min-width: 120px;
        justify-content: center;
    }

    /* Título más compacto en móvil */
    #main-title { font-size: 1.4rem; }
    #main-subtitle { font-size: 0.85rem; }

    /* Tablas con scroll horizontal para que no rompan el layout */
    .glass-card { overflow-x: auto; }
    table { min-width: 640px; }

    /* Kanban en móvil: columnas apiladas */
    .kanban-board {
        grid-template-columns: 1fr;
    }
}

/* =========================================================
   Móvil pequeño (celulares angostos)
   ========================================================= */
@media(max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    main { padding: 1rem 0.75rem; }

    /* Login card ocupa toda la pantalla */
    .login-card {
        max-width: 92vw;
        padding: 1.5rem;
    }
}

/* Animations */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}


/* =========================================================
   LOGIN v2 — rediseño estilo Sanidad / Plug Connective
   Se activa cuando el overlay tiene la clase .login-v2.
   Convive con el login-overlay original sin romperlo.
   ========================================================= */

.login-overlay.login-v2 {
    /* Reemplaza el fondo del overlay viejo */
    background: transparent;
    padding: 0;
    overflow: hidden;
}

.login-bg-stage {
    position: fixed;
    inset: 0;
    z-index: 0;
    background:
        radial-gradient(1200px 800px at 20% 30%, rgba(163, 230, 53, 0.10), transparent 60%),
        radial-gradient(900px  700px at 85% 75%, rgba(6, 182, 212, 0.10), transparent 55%),
        radial-gradient(600px  500px at 50% 50%, rgba(99, 102, 241, 0.06), transparent 55%),
        #05070F;
    animation: v2-bg-drift 20s ease-in-out infinite alternate;
}

@keyframes v2-bg-drift {
    0%   { background-position: 0% 0%,  100% 100%, 50% 50%, 0 0; }
    100% { background-position: 10% 15%, 90%  85%, 55% 45%, 0 0; }
}

.login-bg-grid {
    position: fixed;
    inset: 0;
    z-index: 0;
    background-image:
        linear-gradient(rgba(163, 230, 53, 0.035) 1px, transparent 1px),
        linear-gradient(90deg, rgba(163, 230, 53, 0.035) 1px, transparent 1px);
    background-size: 60px 60px;
    mask-image: radial-gradient(ellipse at center, black 40%, transparent 85%);
    -webkit-mask-image: radial-gradient(ellipse at center, black 40%, transparent 85%);
    pointer-events: none;
}

#login-particles {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    opacity: 0.55;
}

/* Card v2 con glassmorphism + brackets */
.login-card.login-card-v2 {
    position: relative;
    z-index: 10;
    background: rgba(14, 19, 34, 0.72);
    backdrop-filter: blur(24px) saturate(140%);
    -webkit-backdrop-filter: blur(24px) saturate(140%);
    border: 1px solid rgba(163, 230, 53, 0.18);
    border-radius: 20px;
    padding: 2.75rem 2rem 2rem;
    box-shadow:
        0 30px 90px rgba(0, 0, 0, 0.55),
        0 0 60px rgba(163, 230, 53, 0.08),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
    animation: v2-card-in 0.9s cubic-bezier(0.16, 1, 0.3, 1) both;
    max-width: 420px;
    width: 100%;
}

@keyframes v2-card-in {
    from { opacity: 0; transform: translateY(24px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}

.login-card.login-card-v2::before,
.login-card.login-card-v2::after {
    content: "";
    position: absolute;
    width: 22px;
    height: 22px;
    border: 2px solid #A3E635;
    opacity: 0.55;
}
.login-card.login-card-v2::before {
    top: 10px; left: 10px;
    border-right: none; border-bottom: none;
    border-top-left-radius: 8px;
}
.login-card.login-card-v2::after {
    bottom: 10px; right: 10px;
    border-left: none; border-top: none;
    border-bottom-right-radius: 8px;
}

/* Logo con halo y anillos */
.login-logo-wrap {
    position: relative;
    width: 130px;
    height: 130px;
    margin: 0 auto 1.5rem;
    display: grid;
    place-items: center;
}

.login-halo {
    position: absolute;
    inset: -18px;
    border-radius: 50%;
    background: radial-gradient(closest-side, rgba(163, 230, 53, 0.35), transparent 70%);
    filter: blur(12px);
    animation: v2-halo-pulse 3.2s ease-in-out infinite;
}

@keyframes v2-halo-pulse {
    0%, 100% { transform: scale(1);    opacity: 0.5; }
    50%      { transform: scale(1.12); opacity: 0.95; }
}

.login-ring {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 1.5px dashed rgba(163, 230, 53, 0.4);
    animation: v2-ring-rotate 8s linear infinite;
}

.login-ring.login-ring-outer {
    inset: -10px;
    border: 1.5px solid rgba(163, 230, 53, 0.55);
    border-top-color: transparent;
    border-right-color: transparent;
    animation: v2-ring-rotate 5s linear infinite reverse;
    box-shadow: 0 0 12px rgba(163, 230, 53, 0.3);
}

@keyframes v2-ring-rotate { to { transform: rotate(360deg); } }

.login-logo-circle {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    background: #0b0f1a;
    display: grid;
    place-items: center;
    position: relative;
    z-index: 2;
    border: 2px solid rgba(163, 230, 53, 0.25);
    box-shadow:
        inset 0 0 0 4px #05070F,
        0 0 30px rgba(163, 230, 53, 0.35);
    animation: v2-logo-spin 12s linear infinite;
    overflow: hidden;
}

@keyframes v2-logo-spin { to { transform: rotate(360deg); } }

.login-logo-circle img {
    width: 88%;
    height: 88%;
    object-fit: contain;
    display: block;
}

/* Brand */
.login-brand {
    text-align: center;
    margin-bottom: 1.75rem;
}

.login-brand h1 {
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: 1.2px;
    background: linear-gradient(90deg, #A3E635, #06B6D4, #A3E635);
    background-size: 200% 100%;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: v2-gradient-shift 6s linear infinite;
    text-transform: uppercase;
    margin-bottom: 0.35rem;
}

@keyframes v2-gradient-shift { to { background-position: 200% 0; } }

.login-subtitle {
    color: #94A3B8;
    font-size: 0.85rem;
    min-height: 1.2em;
}

.login-cursor {
    display: inline-block;
    width: 8px;
    background: #A3E635;
    margin-left: 2px;
    animation: v2-blink 1s steps(2) infinite;
}

@keyframes v2-blink { to { opacity: 0; } }

/* Inputs y botón dentro del card v2 */
.login-card-v2 .form-group input {
    background: rgba(0, 0, 0, 0.35);
    border: 1px solid rgba(255, 255, 255, 0.08);
    transition: all 0.25s ease;
}
.login-card-v2 .form-group input:focus {
    border-color: #A3E635;
    background: rgba(0, 0, 0, 0.5);
    box-shadow:
        0 0 0 3px rgba(163, 230, 53, 0.15),
        0 0 25px rgba(163, 230, 53, 0.12);
    outline: none;
}

.login-card-v2 .btn-primary {
    background: linear-gradient(135deg, #A3E635, #4ADE80);
    color: #05070F;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    position: relative;
    overflow: hidden;
    border: none;
}

.login-card-v2 .btn-primary:hover {
    transform: translateY(-2px);
    box-shadow:
        0 12px 30px rgba(163, 230, 53, 0.35),
        0 0 40px rgba(163, 230, 53, 0.2);
}

.login-card-v2 .btn-primary::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(120deg,
        transparent 30%,
        rgba(255, 255, 255, 0.4) 50%,
        transparent 70%);
    transform: translateX(-100%);
    transition: transform 0.7s ease;
}
.login-card-v2 .btn-primary:hover::after { transform: translateX(100%); }

/* Responsive */
@media (max-width: 480px) {
    .login-card.login-card-v2 { padding: 2rem 1.25rem 1.5rem; }
    .login-brand h1 { font-size: 1.4rem; }
}


/* =========================================================
   LOGIN v4 — hero-banner de fondo + slogan flotante
   Sobreescribe .login-bg-stage del v2 cuando el overlay
   también tiene la clase .login-v4
   ========================================================= */

/* v4.2 — MUY nítida a la derecha, azul navy solo en la parte del card */
.login-overlay.login-v4 .login-bg-stage {
    background-image: url("assets/hero-banner.jpg");
    background-size: cover;
    background-position: center right;
    background-repeat: no-repeat;
    filter: saturate(1.2) brightness(1.05) contrast(1.05);
    transform: scale(1);
    animation: v4-hero-zoom 45s ease-in-out infinite alternate;
}

@keyframes v4-hero-zoom {
    0%   { transform: scale(1)     translate(0, 0); }
    100% { transform: scale(1.04)  translate(-0.4%, -0.4%); }
}

/* Overlay MUY agresivo hacia la izquierda, transparente casi total del 35% en adelante:
   - 0%–25%:  opaco azul navy (card zone)
   - 25%–35%: transición
   - 35%–100%: prácticamente transparente = se ven perfecto los celulares y la laptop */
.login-bg-overlay {
    position: fixed;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    background:
        linear-gradient(100deg,
            rgba(15, 23, 42, 0.96) 0%,
            rgba(15, 23, 42, 0.90) 20%,
            rgba(15, 23, 42, 0.55) 32%,
            rgba(15, 23, 42, 0.15) 45%,
            rgba(15, 23, 42, 0.00) 60%,
            rgba(15, 23, 42, 0.00) 100%),
        radial-gradient(1400px 900px at 15% 40%, rgba(99, 102, 241, 0.30), transparent 55%),
        radial-gradient(1000px 700px at 8% 75%,  rgba(163, 230, 53, 0.14), transparent 55%),
        radial-gradient(800px  600px at 30% 15%, rgba(6, 182, 212, 0.10), transparent 55%);
    animation: v4-overlay-drift 22s ease-in-out infinite alternate;
}

@keyframes v4-overlay-drift {
    0%   { background-position: 0% 0%,  18% 35%, 10% 70%, 40% 20%; }
    100% { background-position: 3% 8%,  22% 32%, 12% 68%, 44% 18%; }
}

/* En v4 empujamos el card a la izquierda para dejar respirar la imagen */
.login-overlay.login-v4 {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 2rem 5vw;
}

/* Slogan flotante inspirado en el banner */
.login-tagline {
    position: fixed;
    right: 5vw;
    bottom: 2.5rem;
    z-index: 5;
    text-align: right;
    pointer-events: none;
    animation: v4-fade-in 1.5s ease-out both;
}
@keyframes v4-fade-in {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}
.login-tagline .big {
    display: block;
    font-size: clamp(1.5rem, 4vw, 3.2rem);
    font-weight: 900;
    letter-spacing: 2px;
    line-height: 1.05;
    color: rgba(255, 255, 255, 0.9);
    text-shadow: 0 4px 30px rgba(0, 0, 0, 0.6);
}
.login-tagline .big em {
    font-style: normal;
    color: #A3E635;
    text-shadow: 0 0 25px rgba(163, 230, 53, 0.7);
}
.login-tagline .small {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.85rem;
    letter-spacing: 4px;
    color: rgba(148, 163, 184, 0.85);
    text-transform: uppercase;
}

/* Responsive: en móvil el overlay se vuelve top-bottom y el slogan se oculta */
/* =========================================================
   Templates de Mensajes — Compose area
   ========================================================= */
.chat-compose {
    border-top: 1px solid rgba(255,255,255,0.08);
    padding: 0.75rem 1rem;
    background: rgba(15, 23, 42, 0.6);
    border-radius: 0 0 12px 12px;
    flex-shrink: 0;
}

.compose-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

.compose-textarea {
    flex: 1;
    resize: none;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 8px;
    color: var(--text-primary, #e2e8f0);
    font-size: 0.9rem;
    padding: 0.55rem 0.75rem;
    font-family: inherit;
    line-height: 1.4;
    transition: border-color 0.2s;
}
.compose-textarea:focus {
    outline: none;
    border-color: rgba(99,102,241,0.6);
    background: rgba(255,255,255,0.08);
}
.compose-textarea::placeholder { color: var(--text-muted, #64748b); }

.compose-send-btn {
    padding: 0.55rem 1.1rem;
    font-size: 0.85rem;
    white-space: nowrap;
    align-self: flex-end;
}

/* Botón 📋 y dropdown */
.tpl-wrap {
    position: relative;
    flex-shrink: 0;
    align-self: flex-end;
}

.tpl-btn {
    background: rgba(99,102,241,0.15);
    border: 1px solid rgba(99,102,241,0.35);
    border-radius: 8px;
    color: #a5b4fc;
    font-size: 1.15rem;
    cursor: pointer;
    padding: 0.45rem 0.6rem;
    line-height: 1;
    transition: background 0.2s, border-color 0.2s;
}
.tpl-btn:hover {
    background: rgba(99,102,241,0.28);
    border-color: rgba(99,102,241,0.6);
}

.tpl-dropdown {
    position: absolute;
    bottom: calc(100% + 6px);
    left: 0;
    min-width: 280px;
    max-width: 340px;
    max-height: 340px;
    overflow-y: auto;
    background: #1e293b;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 10px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.45);
    z-index: 200;
    padding: 0.4rem 0;
}

.tpl-group-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted, #64748b);
    padding: 0.55rem 1rem 0.25rem;
    font-weight: 600;
}

.tpl-item {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    padding: 0.5rem 1rem;
    cursor: pointer;
    transition: background 0.15s;
    border-radius: 0;
}
.tpl-item:hover { background: rgba(99,102,241,0.18); }

.tpl-item-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-primary, #e2e8f0);
}
.tpl-item-preview {
    font-size: 0.76rem;
    color: var(--text-muted, #94a3b8);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.tpl-empty {
    padding: 1rem;
    font-size: 0.82rem;
    color: var(--text-muted, #64748b);
    text-align: center;
}

/* scrollbar del dropdown */
.tpl-dropdown::-webkit-scrollbar { width: 4px; }
.tpl-dropdown::-webkit-scrollbar-thumb { background: rgba(99,102,241,0.4); border-radius: 4px; }

/* Ajuste chat-thread para que el compose no empuje las burbujas */
.chat-thread {
    display: flex;
    flex-direction: column;
}
.chat-messages {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

@media (max-width: 900px) {
    .login-overlay.login-v4 {
        justify-content: center;
        padding: 2rem 1rem;
    }
    .login-overlay.login-v4 .login-bg-overlay {
        background:
            linear-gradient(180deg,
                rgba(15, 23, 42, 0.90) 0%,
                rgba(15, 23, 42, 0.72) 40%,
                rgba(15, 23, 42, 0.88) 100%),
            radial-gradient(1400px 900px at 15% 30%, rgba(99, 102, 241, 0.20), transparent 55%),
            radial-gradient(1000px 700px at 85% 80%, rgba(163, 230, 53, 0.12), transparent 55%);
    }
    /* En móvil sí ponemos blur porque no hay "lado derecho" donde mostrar productos */
    .login-overlay.login-v4 .login-bg-stage {
        filter: blur(4px) saturate(1.1) brightness(0.7);
    }
    .login-tagline { display: none; }
}

/* ============================================================
   MÓDULO DE REPORTES
   ============================================================ */

.reports-kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.kpi-tile {
    background: var(--glass-bg, rgba(30,41,59,0.7));
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 1.1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.kpi-label {
    font-size: 0.75rem;
    color: var(--text-gray, #94a3b8);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.kpi-value {
    font-size: 1.6rem;
    font-weight: 700;
    color: #e2e8f0;
    line-height: 1.1;
}

.kpi-delta {
    font-size: 0.72rem;
    color: var(--text-gray, #94a3b8);
}

.kpi-delta.delta-up {
    color: #10b981;
}

.kpi-delta.delta-down {
    color: #ef4444;
}

.reports-charts-row {
    display: flex;
    gap: 1.25rem;
    flex-wrap: wrap;
}

.reports-charts-row .glass-card {
    flex: 1;
    min-width: 280px;
}

@media (max-width: 640px) {
    .kpi-value {
        font-size: 1.25rem;
    }
}

/* Módulo de metas */
.goal-card { padding: 1.25rem 1.5rem; }

.goal-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.goal-set-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.goal-bar-bg {
    width: 100%;
    height: 10px;
    background: rgba(255,255,255,0.07);
    border-radius: 999px;
    overflow: hidden;
}

.goal-bar-fill {
    height: 100%;
    border-radius: 999px;
    background: #6366f1;
    transition: width 0.6s ease, background 0.4s ease;
}

.goal-kpis {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
    gap: 0.75rem;
    margin-top: 1rem;
}

.goal-kpi-item {
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 10px;
    padding: 0.65rem 1rem;
}

.goal-kpi-label {
    font-size: 0.72rem;
    color: #94a3b8;
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.goal-kpi-value {
    font-size: 1.05rem;
    font-weight: 700;
    color: #e2e8f0;
}

/* Botones de exportación */
.btn-export {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    height: 38px;
    padding: 0 1rem;
    border-radius: 8px;
    border: 1px solid #22c55e;
    background: rgba(34, 197, 94, 0.12);
    color: #4ade80;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
}
.btn-export:hover {
    background: rgba(34, 197, 94, 0.25);
    border-color: #4ade80;
}
.btn-export-pdf {
    border-color: #f97316;
    background: rgba(249, 115, 22, 0.12);
    color: #fb923c;
}
.btn-export-pdf:hover {
    background: rgba(249, 115, 22, 0.25);
    border-color: #fb923c;
}
