/* ============================================================
   Analytics Dashboard - Estilos
   ============================================================ */

/* Login de Analíticas */
.analytics-login-overlay {
    position: fixed;
    z-index: 9999;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: linear-gradient(135deg, var(--whatsapp-green) 0%, var(--whatsapp-green-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
}

.analytics-login-card {
    background: white;
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    padding: 40px 32px;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 400px;
    max-width: 95vw;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.login-logo {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    margin-bottom: 20px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.analytics-login-card h2 {
    margin-bottom: 10px;
    font-weight: 700;
    font-size: 1.8rem;
    text-align: center;
    color: var(--whatsapp-green-dark);
}

.analytics-login-card h2 i {
    margin-right: 8px;
}

.login-subtitle {
    color: #666;
    margin-bottom: 24px;
    text-align: center;
    font-size: 0.95rem;
}

#analytics-login-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.analytics-password-input {
    padding: 14px 20px;
    border-radius: 30px;
    border: 2px solid #e0e0e0;
    width: 100%;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.analytics-password-input:focus {
    outline: none;
    border-color: var(--whatsapp-green);
}

.analytics-login-btn {
    background: var(--whatsapp-green);
    color: white;
    padding: 14px 36px;
    border: none;
    border-radius: 30px;
    font-size: 1.1rem;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
    cursor: pointer;
    transition: all 0.3s ease;
}

.analytics-login-btn:hover {
    background: var(--whatsapp-green-dark);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(37, 211, 102, 0.4);
}

.analytics-login-btn i {
    margin-right: 8px;
}

.login-error {
    color: #d32f2f;
    font-size: 0.9rem;
    text-align: center;
    padding: 8px;
    background: #ffebee;
    border-radius: 8px;
}

.back-to-chat {
    margin-top: 20px;
    color: var(--whatsapp-green-dark);
    text-decoration: none;
    font-size: 0.95rem;
    transition: color 0.3s ease;
}

.back-to-chat:hover {
    color: var(--whatsapp-green);
}

.back-to-chat i {
    margin-right: 6px;
}

/* Dashboard de Analíticas */
.analytics-dashboard {
    display: block; /* Cambio de flex a block para sidebar fija */
    height: 100vh;
    width: 100vw;
    background: #f5f5f5;
    overflow-x: hidden;
    position: relative; /* Para posicionar elementos hijos */
}

/* Nota: Los estilos del side-nav (.side-nav, .nav-item, .nav-logout, etc.) 
   están definidos en styles.css y son compartidos entre index.html y analytics.html */

/* Contenido principal */
.analytics-main-content {
    width: calc(100% - 70px); /* Ancho total menos sidebar */
    height: 100vh;
    margin-left: 70px; /* Compensar ancho de sidebar fija */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.analytics-header {
    background: white;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
    padding: 20px 30px;
    z-index: 50;
}

.analytics-header .header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.analytics-header h1 {
    font-size: 1.8rem;
    color: var(--whatsapp-dark);
    display: flex;
    align-items: center;
    gap: 12px;
}

.analytics-header h1 i {
    color: var(--whatsapp-green);
}

.last-update-indicator {
    font-size: 0.65rem;
    color: #666;
    background: rgba(0, 0, 0, 0.05);
    padding: 4px 12px;
    border-radius: 12px;
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.last-update-indicator i {
    color: #888;
}

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

/* Logout button ahora está en side-nav - estos estilos ya no se usan */

/* Loading Indicator */
.loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    gap: 20px;
}

.spinner {
    width: 60px;
    height: 60px;
    border: 5px solid #e0e0e0;
    border-top-color: var(--whatsapp-green);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-indicator p {
    color: #666;
    font-size: 1.1rem;
}

/* Contenedor de gráficos */
.charts-container {
    flex: 1;
    overflow-y: auto;
    padding: 30px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
    gap: 30px;
    align-content: start;
    box-sizing: border-box;
}

/* Tarjeta de gráfico */
.chart-card {
    background: white;
    border-radius: 16px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    padding: 24px;
    transition: box-shadow 0.3s ease;
    will-change: box-shadow;
    backface-visibility: hidden;
    transform: translateZ(0);
}

.chart-card:hover {
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.chart-header {
    margin-bottom: 20px;
}

.chart-header h2 {
    font-size: 1.4rem;
    color: var(--whatsapp-dark);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.chart-header h2 i {
    color: var(--whatsapp-green);
}

.chart-description {
    color: #666;
    font-size: 0.9rem;
    line-height: 1.5;
}

.chart-wrapper {
    position: relative;
    min-height: 300px;
    backface-visibility: hidden;
    transform: translateZ(0);
}

/* Contenedor con altura específica para el gráfico de usuarios por mes */
.chart-wrapper.monthly-chart {
    height: 40vh;
    min-height: 400px;
}

/* Contenedor con altura específica para el gráfico de tono emocional */
.chart-wrapper.tone-chart {
    height: 35vh;
    min-height: 350px;
}

.chart-wrapper canvas {
    width: 100% !important;
    height: 100% !important;
    max-height: 400px;
    display: block;
    backface-visibility: hidden;
    transform: translateZ(0);
}

/* Estilos para las tarjetas de estadísticas del promedio */
.avg-messages-wrapper {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    min-height: auto;
}

.avg-stat-card {
    background: linear-gradient(135deg, var(--whatsapp-green) 0%, var(--whatsapp-green-dark) 100%);
    border-radius: 12px;
    padding: 24px;
    color: white;
    display: flex;
    align-items: center;
    gap: 16px;
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.2);
    transition: box-shadow 0.3s ease;
    will-change: box-shadow;
    backface-visibility: hidden;
    transform: translateZ(0);
}

.avg-stat-card:hover {
    box-shadow: 0 6px 16px rgba(37, 211, 102, 0.3);
}

.stat-icon {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.2);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.stat-content {
    flex: 1;
}

.stat-label {
    font-size: 0.85rem;
    opacity: 0.9;
    margin-bottom: 4px;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
}

/* Error State */
.error-container {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    padding: 40px;
}

.error-card {
    background: white;
    border-radius: 16px;
    padding: 40px;
    text-align: center;
    max-width: 500px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.error-card i {
    font-size: 4rem;
    color: #ff6b6b;
    margin-bottom: 20px;
}

.error-card h3 {
    font-size: 1.5rem;
    color: var(--whatsapp-dark);
    margin-bottom: 12px;
}

.error-card p {
    color: #666;
    margin-bottom: 24px;
    line-height: 1.6;
}

.retry-btn {
    background: var(--whatsapp-green);
    color: white;
    padding: 12px 28px;
    border: none;
    border-radius: 24px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.retry-btn:hover {
    background: var(--whatsapp-green-dark);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

/* Responsive */
@media (max-width: 768px) {
    .analytics-dashboard {
        overflow-x: hidden;
    }
    
    /* Nota: Los estilos de .side-nav y .nav-item en móvil 
       están en styles.css y son compartidos */
    
    .analytics-main-content {
        width: calc(100% - 60px); /* Ancho total menos sidebar móvil */
        margin-left: 60px; /* Compensar ancho de sidebar móvil */
        overflow-x: hidden;
        overflow-y: auto;
        height: 100vh;
        display: flex;
        flex-direction: column;
    }
    
    .analytics-header {
        padding: 12px 15px;
        position: sticky;
        top: 0;
        background: white;
        z-index: 100;
    }
    
    .analytics-header h1 {
        font-size: 1.2rem;
        flex-wrap: wrap;
        gap: 8px;
    }
    
    .analytics-header h1 i {
        font-size: 1.1rem;
    }
    
    .last-update-indicator {
        font-size: 0.7rem;
        padding: 4px 8px;
    }
    
    .charts-container {
        grid-template-columns: 1fr;
        padding: 15px;
        padding-bottom: 100px;
        gap: 20px;
        width: 100%;
        box-sizing: border-box;
        overflow-y: visible;
        height: auto;
        flex: 1;
    }
    
    .chart-card {
        padding: 16px;
        width: 100%;
        box-sizing: border-box;
        overflow-x: hidden;
    }
    
    .chart-header h2 {
        font-size: 1.1rem;
    }
    
    .chart-description {
        font-size: 0.85rem;
    }
    
    .chart-wrapper {
        min-height: auto;
        height: auto;
        width: 100%;
        overflow-x: hidden;
    }
    
    /* Mantener altura específica para gráfico de usuarios por mes en móvil */
    .chart-wrapper.monthly-chart {
        height: 35vh;
        min-height: 300px;
    }
    
    /* Mayor altura para gráfico de tono en móvil */
    .chart-wrapper.tone-chart {
        height: 50vh;
        min-height: 400px;
    }
    
    .chart-wrapper canvas {
        max-height: 300px;
    }
    
    .avg-messages-wrapper {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .avg-stat-card {
        padding: 16px;
    }
    
    .stat-value {
        font-size: 1.8rem;
    }
    
    .analytics-login-card {
        min-width: 320px;
        padding: 30px 24px;
    }
}

/* ============================================================
   Tone Details - Detalles de categoría de tono
   ============================================================ */

.tone-details-container {
    margin-top: 25px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 12px;
    border: 2px solid #e0e0e0;
    max-height: 0;
    overflow: hidden;
    opacity: 0;
    transition: all 0.3s ease;
}

.tone-details-container.visible {
    max-height: 600px;
    opacity: 1;
    overflow-y: auto;
}

.tone-details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid #dee2e6;
}

.tone-details-header h3 {
    margin: 0;
    font-size: 1.2rem;
    color: #333;
    display: flex;
    align-items: center;
    gap: 10px;
}

.tone-details-header h3 i {
    font-size: 1.1rem;
}

.close-details-btn {
    background: transparent;
    border: none;
    font-size: 1.3rem;
    color: #666;
    cursor: pointer;
    padding: 5px 10px;
    border-radius: 6px;
    transition: all 0.2s;
}

.close-details-btn:hover {
    background: #e0e0e0;
    color: #333;
}

.tone-details-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.tone-user-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: white;
    border-radius: 10px;
    border: 1px solid #e0e0e0;
    transition: box-shadow 0.2s ease, border-color 0.2s ease;
    gap: 15px;
    overflow: hidden;
    backface-visibility: hidden;
    transform: translateZ(0);
}

.tone-user-item:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    border-color: var(--whatsapp-green);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    flex-wrap: wrap;
    min-width: 0;
}

.user-info i {
    color: var(--whatsapp-green);
    font-size: 1.1rem;
}

.user-phone {
    font-weight: 600;
    color: #333;
    font-size: 1rem;
}

.user-original-tone {
    color: #666;
    font-size: 0.85rem;
    font-style: italic;
}

.user-last-update {
    color: #999;
    font-size: 0.8rem;
    margin-left: 8px;
    padding: 2px 8px;
    background: #f5f5f5;
    border-radius: 4px;
}

.view-conversation-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 20px;
    background: var(--whatsapp-green);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    transition: background 0.2s ease, box-shadow 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
    min-width: fit-content;
    backface-visibility: hidden;
    transform: translateZ(0);
}

.view-conversation-btn:hover {
    background: var(--whatsapp-green-dark);
    box-shadow: 0 4px 12px rgba(37, 211, 102, 0.3);
}

.view-conversation-btn i {
    font-size: 1rem;
}

/* Responsive para detalles de tono */
@media (max-width: 768px) {
    .tone-user-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
        padding: 12px 15px;
    }
    
    .user-info {
        width: 100%;
        gap: 8px;
    }
    
    .user-last-update {
        margin-left: 0;
        margin-top: 4px;
    }
    
    .view-conversation-btn {
        width: 100%;
        justify-content: center;
    }
    
    .tone-details-container {
        padding: 15px;
        margin-top: 15px;
    }
    
    .tone-details-container.visible {
        max-height: 500px;
    }
    
    .tone-details-header h3 {
        font-size: 1rem;
    }
}

/* Pantallas muy pequeñas */
@media (max-width: 480px) {
    /* Nota: Los estilos de .side-nav y .nav-item en móvil 
       están en styles.css y son compartidos */
    
    .analytics-main-content {
        width: calc(100% - 50px); /* Ancho total menos sidebar móvil pequeño */
        margin-left: 50px; /* Compensar ancho de sidebar móvil pequeño */
        overflow-y: auto;
        height: 100vh;
        display: flex;
        flex-direction: column;
    }
    
    .analytics-header {
        padding: 10px 12px;
        position: sticky;
        top: 0;
        background: white;
        z-index: 100;
    }
    
    .analytics-header h1 {
        font-size: 1rem;
    }
    
    .charts-container {
        padding: 10px;
        padding-bottom: 120px;
        gap: 15px;
        grid-template-columns: 1fr;
        overflow-y: visible;
        height: auto;
        flex: 1;
    }
    
    .chart-card {
        padding: 12px;
    }
    
    .chart-header h2 {
        font-size: 1rem;
    }
    
    .avg-stat-card {
        padding: 12px;
    }
    
    .stat-label {
        font-size: 0.8rem;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
}
