@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');

:root {
    --primary-color: #00CC99;
    --secondary-color: #EB2D8C;
    --background-color: #f0f2f5;
    --card-background: #ffffff;
    --text-color: #333;
    --light-gray: #e9e9e9;
    --dark-gray: #65676b;
    --font-family: 'Poppins', sans-serif;
}

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

html, body {
    font-family: var(--font-family);
    background-color: var(--background-color);
    color: var(--text-color);
    line-height: 1.6;
    margin: 0;
    padding: 0;
    width: 100%;
    max-width: 100vw; /* Asegura que nunca sea más ancho que la ventana gráfica */
    overflow-x: hidden; /* Elimina el scroll horizontal y evita cortes en el fondo */
}

/* Regla global para evitar desbordamientos de imágenes y multimedia */
img, video, canvas, iframe {
    max-width: 100%;
    height: auto;
}

header {
    background: var(--card-background);
    /* Centrado inteligente: Mantiene 5% de margen mínimo o centra el contenido a 1200px */
    padding-left: max(5%, calc((100% - 1200px) / 2));
    padding-right: max(5%, calc((100% - 1200px) / 2));
    padding-top: 1rem;
    padding-bottom: 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--light-gray);
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    width: 100%;
}

.logo-container .logo {
    height: auto;
    width: auto;
    max-height: 120px; /* Altura óptima para escritorio */
    max-width: 100%;   /* Evita desbordamientos */
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--dark-gray);
}

.app-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    /* Mismo centrado inteligente que el header */
    padding-left: max(5%, calc((100% - 1200px) / 2));
    padding-right: max(5%, calc((100% - 1200px) / 2));
    padding-top: 2rem;
    padding-bottom: 2rem;
    align-items: flex-start;
    width: 100%;
}

.analytics-panel {
    grid-column: 1 / -1;
}

.card {
    background: var(--card-background);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
    margin-bottom: 2rem;
    min-width: 0; /* CRÍTICO: Permite que la tarjeta se encoja en Grid para activar el scroll interno */
}

.card h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--primary-color);
    display: flex;
    align-items: center;
}

.card h2 .icon {
    margin-right: 0.75rem;
}

.card p {
    font-size: 0.9rem;
    color: var(--dark-gray);
    margin-bottom: 1rem;
}

input[type="file"],
textarea,
input[type="text"],
input[type="password"],
select {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--light-gray);
    border-radius: 8px;
    font-family: var(--font-family);
    font-size: 0.95rem;
    margin-bottom: 1rem;
}

textarea {
    min-height: 120px;
    resize: vertical;
}

button, .cta-button {
    background: var(--primary-color);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-family: var(--font-family);
    font-weight: 500;
    font-size: 1rem;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease;
}

button:hover, .cta-button:hover {
    background-color: #00b386;
    transform: translateY(-2px);
}

.cta-button {
    width: 100%;
    background-color: var(--secondary-color);
    font-size: 1.1rem;
    padding: 0.85rem;
}

.cta-button:hover {
    background-color: #d0287a;
}

#contact-count {
    font-weight: 500;
    color: var(--primary-color);
}

/* Preview Panel */
.phone-preview {
    background: #1e1e1e;
    border-radius: 30px;
    padding: 15px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    max-width: 350px;
    width: 100%; /* Permite que se encoja en pantallas pequeñas para no romper el diseño */
    margin: 0 auto;
}

.screen {
    background: #f0f2f5;
    border-radius: 20px;
    padding: 20px;
    min-height: 400px;
    display: flex;
    flex-direction: column;
}

.message-bubble {
    background: #dcf8c6;
    padding: 10px 15px;
    border-radius: 15px;
    max-width: 85%;
    align-self: flex-end;
    word-wrap: break-word;
    box-shadow: 0 1px 1px rgba(0,0,0,0.1);
}

#preview-media-container img,
#preview-media-container video {
    max-width: 100%;
    border-radius: 10px;
    margin-bottom: 5px;
}

.message-bubble .timestamp {
    font-size: 0.75rem;
    color: var(--dark-gray);
    text-align: right;
    margin-top: 5px;
}

.status-log {
    height: 150px;
    overflow-y: auto;
    background: #fafafa;
    border: 1px solid var(--light-gray);
    border-radius: 8px;
    padding: 1rem;
    font-size: 0.85rem;
}
.status-log p {
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--light-gray);
    padding-bottom: 0.5rem;
}

/* Analytics */
.analytics-panel .filters {
    margin-bottom: 1rem;
    display: flex;
    gap: 0.5rem;
}

.filter-btn {
    background: var(--light-gray);
    color: var(--dark-gray);
}

.filter-btn.active {
    background: var(--primary-color);
    color: white;
}

.manual-update {
    margin-top: 2rem;
    border-top: 1px solid var(--light-gray);
    padding-top: 1.5rem;
}

.manual-update h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

footer {
    text-align: center;
    padding: 2rem;
    font-size: 0.9rem;
    color: var(--dark-gray);
    margin-top: 2rem;
}

/* Estilos para Gráficos (Reemplazan estilos en línea) */
.chart-container {
    display: flex;
    gap: 20px;
    height: 500px;
    margin-bottom: 2rem;
}

.chart-box-main {
    flex: 2;
    position: relative;
}

.chart-box-dist {
    flex: 1;
    position: relative;
}

/* Responsive Design */
@media (max-width: 992px) {
    .app-container {
        grid-template-columns: 1fr;
        padding: 1.5rem 5%; /* Margen lateral fijo del 5% para móviles */
        width: 100%;
    }
    
    .card {
        width: 100%;
    }
    header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
        padding: 1.5rem 5%; /* Margen lateral fijo del 5% para móviles */
        width: 100%;
    }
    header h1 {
        white-space: normal; /* Permite saltos de línea para evitar cortes */
        font-size: 1.1rem;   /* Tamaño legible y fijo */
        padding: 0;          /* Eliminamos padding extra que podría descentrar */
        width: 100%;         /* Asegura que el texto use todo el ancho disponible */
        max-width: 100%;     /* Evita desbordamiento */
        word-wrap: break-word; /* Evita que palabras largas rompan el diseño */
    }

    /* Control estricto del logo en móvil */
    .logo-container .logo {
        max-height: 100px; /* Reducir ligeramente en móvil */
    }

    /* Ajustes Gráficos en Móvil */
    .chart-container {
        flex-direction: column;
        height: auto !important; /* Altura automática para apilar */
    }
    .chart-box-main, .chart-box-dist {
        width: 100%;
        height: 300px; /* Altura fija por gráfico en móvil */
        margin-bottom: 20px;
    }

    /* Pie de página en una sola línea */
    footer p {
        white-space: nowrap;
        font-size: clamp(0.5rem, 2.5vw, 0.8rem); /* Ajuste dinámico para que siempre quepa en una línea */
    }
}

/* --- ESTILOS DE AUTENTICACIÓN Y ADMIN --- */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 20px;
    background-color: var(--background-color);
}

.auth-card {
    background: white;
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
    width: 100%;
    max-width: 450px;
    text-align: center;
}

.auth-card h2 {
    color: var(--primary-color);
    margin-bottom: 1.5rem;
}

.auth-links {
    margin-top: 1rem;
    font-size: 0.9rem;
}

.auth-links a {
    color: var(--secondary-color);
    text-decoration: none;
    margin: 0 5px;
}

.alert {
    padding: 10px;
    border-radius: 6px;
    margin-bottom: 15px;
    font-size: 0.9rem;
}
.alert-error { background: #ffebee; color: #c62828; border: 1px solid #ef9a9a; }
.alert-success { background: #e8f5e9; color: #2e7d32; border: 1px solid #a5d6a7; }

/* Tabla de Admin */
.admin-table-container {
    overflow-x: auto;
    width: 100%;
    max-width: 100%;
    display: block;
    -webkit-overflow-scrolling: touch; /* Suaviza el scroll en móviles */
}

.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    background: white;
    min-width: 1000px; /* FUERZA EL SCROLL HORIZONTAL si la pantalla es pequeña */
}

.admin-table th, .admin-table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid var(--light-gray);
    white-space: nowrap; /* Mantiene el contenido en una línea para preservar el diseño */
}

.admin-table th {
    background-color: var(--primary-color);
    color: white;
}

.status-badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}
.status-approved { background: #e8f5e9; color: #2e7d32; }
.status-pending { background: #fff3e0; color: #ef6c00; }
.status-rejected { background: #ffebee; color: #c62828; }

.action-btn {
    padding: 5px 10px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.8rem;
    width: 100%; /* Ocupar todo el ancho de la celda de la grilla */
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 30px;
}
.btn-approve { background: #2e7d32; color: white; }
.btn-reject { background: #c62828; color: white; }
.btn-pause { background: #f9a825; color: white; } /* Amarillo oscuro para pausa */
.btn-delete { background: #212121; color: white; } /* Negro suave para eliminar */

.action-grid {
    display: grid;
    grid-template-columns: 1fr 1fr; /* 2 columnas */
    gap: 5px;
    min-width: 160px; /* Ancho mínimo para que los botones no se aplasten */
}

/* Ajustes para inputs pequeños en tablas */
.small-input {
    padding: 5px;
    font-size: 0.8rem;
    border: 1px solid #ccc;
    border-radius: 4px;
    width: 100%;
    margin-bottom: 5px;
}

/* --- ESTILOS MOSTRAR CONTRASEÑA --- */
.password-container {
    position: relative;
    width: 100%;
    margin-bottom: 1rem;
}
.password-container input {
    margin-bottom: 0 !important; /* El margen lo maneja el contenedor */
    padding-right: 40px; /* Espacio para el icono */
}
.toggle-icon {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    cursor: pointer;
    font-size: 1.2rem;
    user-select: none;
}

/* --- PAGINACIÓN --- */
.pagination-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--light-gray);
    flex-wrap: wrap;
    gap: 10px;
}

.page-info {
    font-size: 0.9rem;
    color: var(--dark-gray);
}

.pagination-controls {
    display: flex;
    gap: 10px;
}

/* --- FOTO DE PERFIL EN HEADER --- */
.header-right-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.profile-pic-trigger {
    width: 50px;
    height: 50px;
    border-radius: 12px; /* Esquinas redondeadas estéticas */
    background-color: #f0f2f5;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    cursor: pointer;
    border: 2px solid var(--light-gray);
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}
.profile-pic-trigger:hover {
    border-color: var(--primary-color);
    box-shadow: 0 0 8px rgba(0, 204, 153, 0.3);
}
.profile-pic-placeholder {
    font-size: 24px;
    color: #aaa;
}

.page-btn {
    padding: 8px 16px;
    background: var(--card-background);
    border: 1px solid var(--light-gray);
    border-radius: 6px;
    text-decoration: none;
    color: var(--text-color);
    font-size: 0.9rem;
    transition: all 0.2s;
}

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

.page-btn.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* --- LIGHTBOX (VISOR DE COMPROBANTES) --- */
.lightbox {
    display: none; /* Oculto por defecto */
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.85);
    justify-content: center;
    align-items: center;
    flex-direction: column;
}

.lightbox-content {
    max-width: 90%;
    max-height: 85vh;
    border-radius: 8px;
    box-shadow: 0 0 20px rgba(0,0,0,0.5);
    background: white;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

.lightbox-content img {
    max-width: 100%;
    max-height: 85vh;
    object-fit: contain;
}

.lightbox-content iframe {
    width: 80vw;
    height: 80vh;
    border: none;
}

.close-lightbox {
    position: absolute;
    top: 20px;
    right: 30px;
    color: #f1f1f1;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    transition: 0.3s;
    z-index: 1001;
}

.close-lightbox:hover,
.close-lightbox:focus {
    color: var(--secondary-color);
    text-decoration: none;
    cursor: pointer;
}

/* --- HEADER USUARIO (Nombre arriba, botones abajo) --- */
.header-user-section {
    display: flex;
    flex-direction: column;
    align-items: flex-end; /* Alinear a la derecha */
    gap: 5px;
}
.header-buttons {
    display: flex;
    gap: 10px;
}

/* --- GRID PARA CONFIGURACIÓN DE API --- */
.api-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    width: 100%;
}

@media (max-width: 768px) {
    .api-grid {
        grid-template-columns: 1fr;
    }
}
