/* Variables CSS para colores y tamaños */
:root {
    --bg-dark: #2a2a2a;
    --bg-light: #3a3a3a;
    --text-color: #e0e0e0;
    --accent-color: #406fa5;
    --message-bg-received: #4a4a4a;
    --message-bg-sent: #406fa5;
    --border-color: #555;
    --sidebar-width-desktop: 300px;
}

body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 0;
    background-color: #1e1e1e;
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.chat-container {
    display: flex;
    width: 95%;
    max-width: 1200px;
    height: 90vh;
    max-height: 800px;
    border-radius: 15px;
    overflow: hidden;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
    background-color: var(--bg-dark);
}

/* ===== SIDEBAR ===== */
.chat-sidebar {
    width: var(--sidebar-width-desktop);
    background-color: var(--bg-light);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 20px;
    box-sizing: border-box;
    transition: transform 0.3s ease-in-out;
}

.chat-header-mobile {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
}

.chat-header-mobile .back-button,
.chat-header-mobile .menu-button {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.5rem;
    cursor: pointer;
}

.chat-title {
    margin: 0;
    font-size: 1.2rem;
    font-weight: normal;
}

.chat-sidebar-content {
    flex-grow: 1;
    overflow-y: auto;
}

.profile-info {
    display: flex;
    align-items: center;
    margin-bottom: 30px;
}

.profile-avatar {
    width: auto;
    height: 30px;
    margin-right: 15px;
}

.profile-name {
    margin: 0;
    font-size: 1.3rem;
}

.chat-options h3,
.chat-orders h3 {
    font-size: 1rem;
    color: #aaa;
    margin-top: 20px;
    margin-bottom: 10px;
}

.chat-options ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.chat-options li {
    margin-bottom: 8px;
}

.quick-option {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-color);
    padding: 10px 15px;
    border-radius: 8px;
    width: 100%;
    text-align: left;
    cursor: pointer;
    transition: background-color 0.2s ease;
    font-size: 0.95rem;
}

.quick-option:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.view-orders-button {
    background-color: var(--accent-color);
    color: white;
    border: none;
    padding: 12px 15px;
    border-radius: 8px;
    width: 100%;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 15px;
    transition: background-color 0.2s ease;
}

.view-orders-button i {
    margin-right: 8px;
}

.view-orders-button:hover {
    background-color: #293777;
}

/* ===== CHAT MAIN AREA ===== */
.chat-main {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-dark);
    transition: transform 0.3s ease-in-out;
}

/* Header Desktop */
.chat-header-desktop {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border-bottom: 1px solid var(--border-color);
    background-color: var(--bg-light);
    flex-shrink: 0;
}

.chat-header-desktop .header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.chat-header-desktop .header-title {
    font-size: 1.1rem;
    font-weight: 500;
}

.back-to-store-button {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 5px;
    transition: background-color 0.2s ease, color 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.back-to-store-button:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--accent-color);
}

.back-to-store-button .back-text {
    display: none; /* Oculto por defecto en desktop */
    font-size: 0.9rem;
    font-weight: 500;
}

.chat-header-desktop .header-actions button {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.2rem;
    cursor: pointer;
    transition: color 0.2s ease;
}

.chat-header-desktop .header-actions button:hover {
    color: var(--accent-color);
}

.toggle-sidebar-button {
    background: none;
    border: none;
    color: var(--text-color);
    cursor: pointer;
    display: none; /* Oculto por defecto en desktop */
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 5px;
    transition: background-color 0.2s ease;
}

.toggle-sidebar-button:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.toggle-sidebar-button .menu-text {
    font-size: 0.95rem;
    font-weight: 500;
}

.toggle-sidebar-button i {
    font-size: 1.2rem;
}

/* Ocultar el profile-info del sidebar en desktop */
.chat-sidebar .profile-info {
    display: none;
}

/* Chat Messages Area */
.chat-messages {
    flex-grow: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.message {
    width: fit-content;
    max-width: 70%;
    margin-bottom: 15px;
    padding: 10px 15px;
    border-radius: 10px;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.message-text {
    margin: 0;
    word-wrap: break-word;
}

.message-time {
    font-size: 0.75rem;
    color: #bbb;
    align-self: flex-end;
    margin-top: 5px;
}

.message.received {
    background-color: var(--message-bg-received);
    align-self: flex-start;
    margin-right: auto;
}

.message.sent {
    background-color: var(--message-bg-sent);
    align-self: flex-end;
    margin-left: auto;
}

/* Chat Input Area */
.chat-input-area {
    display: flex;
    align-items: center;
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
    background-color: var(--bg-light);
    flex-shrink: 0;
}

.attach-button,
.send-button {
    background: none;
    border: none;
    color: var(--text-color);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 8px;
    border-radius: 5px;
    transition: background-color 0.2s ease, color 0.2s ease;
}

.attach-button:hover,
.send-button:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: var(--accent-color);
}

#message-input {
    flex-grow: 1;
    margin: 0 15px;
    padding: 10px 15px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background-color: #333;
    color: var(--text-color);
    font-size: 1rem;
    resize: none;
    min-height: 40px;
    max-height: 100px;
    overflow-y: auto;
}

#message-input::placeholder {
    color: #999;
}

.mobile-toggle-sidebar {
    display: none;
}

/* ===== BOTÓN CARGAR MÁS MENSAJES ===== */
.btn-cargar-mas {
    width: 90%;
    margin: 10px auto;
    padding: 10px;
    background-color: var(--bg-light);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: background-color 0.2s;
}

.btn-cargar-mas:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.btn-cargar-mas:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-cargar-mas i {
    font-size: 0.9rem;
}

/* ===== MODAL DE PEDIDOS ===== */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    align-items: center;
    justify-content: center;
}

.modal-content {
    background-color: #fefefe;
    padding: 0;
    border: 1px solid #888;
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    margin: 0;
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid #eee;
    flex-shrink: 0;
    color: #333333;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    flex-grow: 1;
}

.close-button {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    float: right;
}

.close-button:hover,
.close-button:focus {
    color: black;
}

/* Estilos para cada registro de pedido */
.order-record {
    background-color: #fff;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.order-record:hover {
    background-color: #f9f9f9;
}

.order-details span {
    display: block;
    color: #333333;
    font-size: 0.95rem;
    line-height: 1.3;
    margin-bottom: 0.2rem;
}

.order-items-preview {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.item-card-mini {
    width: 40px;
    height: 40px;
    background-size: cover;
    background-position: center;
    border-radius: 4px;
    border: 1px solid #eee;
}

/* Estilos para la tarjeta de pedido en el chat */
.message-card-order {
    background-color: #e8f0fe;
    border-left: 4px solid #4285f4;
    padding: 12px 15px;
    border-radius: 8px;
    max-width: 85%;
}

.message-card-order .card-header {
    font-weight: bold;
    color: #1a73e8;
    margin-bottom: 8px;
    font-size: 15px;
}

.message-card-order .card-body p {
    margin: 4px 0;
    font-size: 14px;
    color: #3c4043;
}

.message-card-order .order-items-preview {
    display: flex;
    gap: 5px;
    margin-top: 10px;
    flex-wrap: wrap;
}

.message-card-order .item-card-mini {
    width: 50px;
    height: 50px;
    background-size: cover;
    background-position: center;
    border-radius: 4px;
    border: 1px solid #ddd;
}

.status-line {
    display: inline-flex;
    align-items: center;
}

.status-icon {
    width: 16px;
    height: 16px;
    margin-left: 0.4rem;
}

/* ===== MODAL DE SELECCIÓN DE IMAGEN ===== */
.image-options-modal {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background-color: rgba(0, 0, 0, 0.8);
    z-index: 2000;
    padding: 20px;
    border-radius: 15px 15px 0 0;
    animation: slideUp 0.3s ease;
}

/* En desktop, centrar el modal */
@media (min-width: 769px) {
    .image-options-modal {
        bottom: auto;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%);
        border-radius: 15px;
        max-width: 400px;
        animation: fadeIn 0.3s ease;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(100%);
    }
    to {
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
    to {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

.image-options-content {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.image-option-button {
    background-color: var(--bg-light);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 15px;
    border-radius: 10px;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: background-color 0.2s ease;
}

.image-option-button:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.image-option-button i {
    font-size: 1.3rem;
}

.cancel-button {
    background-color: #d32f2f;
    margin-top: 10px;
}

.cancel-button:hover {
    background-color: #b71c1c;
}

/* ===== VISTA PREVIA DE IMAGEN ===== */
.image-preview-container {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.95);
    z-index: 2000;
    padding: 20px;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.image-preview-header {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(to bottom, rgba(0,0,0,0.8), transparent);
}

.image-preview-title {
    color: white;
    font-size: 1.1rem;
    font-weight: 500;
}

.close-preview-button {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
}

.image-preview-content {
    max-width: 90%;
    max-height: 70%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-preview-content img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 10px;
}

.image-preview-actions {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 15px;
}

.preview-action-button {
    padding: 12px 30px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.send-image-button {
    background-color: var(--accent-color);
    color: white;
}

.send-image-button:hover {
    background-color: #293777;
}

.cancel-image-button {
    background-color: #d32f2f;
    color: white;
}

.cancel-image-button:hover {
    background-color: #b71c1c;
}

/* Indicador de carga de imagen */
.image-uploading-indicator {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: rgba(0, 0, 0, 0.9);
    padding: 20px 30px;
    border-radius: 10px;
    z-index: 3000;
    display: none;
    flex-direction: column;
    align-items: center;
    gap: 15px;
}

.image-uploading-indicator.active {
    display: flex;
}

.spinner {
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top: 3px solid white;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.uploading-text {
    color: white;
    font-size: 0.95rem;
}

/* Mensaje de imagen en el chat */
.message-image-container {
    max-width: 300px;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s ease;
}

.message-image-container:hover {
    transform: scale(1.02);
}

.message-image-container img {
    width: 100%;
    height: auto;
    display: block;
}

/* ===== MEDIA QUERIES MÓVIL ===== */
@media (max-width: 768px) {
    .chat-container {
        width: 100%;
        height: 100vh;   /* Fallback para navegadores antiguos */
        height: 100dvh;  /* Altura dinámica del viewport - se ajusta con la barra del navegador */
        border-radius: 0;
        max-height: unset;
        position: relative;
        overflow: hidden;
    }

    /* Sidebar en móvil - Posicionamiento absoluto */
    .chat-sidebar {
        width: 100%;
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        z-index: 1000;
        transform: translateX(-100%);
        padding: 0;
    }

    .chat-sidebar.open {
        transform: translateX(0);
    }

    .chat-header-mobile {
        display: flex;
        padding: 15px 20px;
        background-color: var(--bg-light);
        flex-shrink: 0;
    }

    .chat-sidebar-content {
        padding: 20px;
    }

    /* Mostrar el profile-info del sidebar en móvil */
    .chat-sidebar .profile-info {
        display: flex;
    }

    .chat-header-desktop {
        display: flex;
        flex-shrink: 0;
    }

    /* Mostrar el botón de retroceso con texto en móvil */
    .back-to-store-button {
        display: flex;
    }

    .back-to-store-button .back-text {
        display: inline; /* Mostrar el texto en móvil */
    }

    .back-to-store-button i {
        font-size: 1rem;
    }

    .chat-main {
        width: 100%;
        height: 100%;
        display: flex;
        flex-direction: column;
    }

    .chat-messages {
        flex-grow: 1;
        overflow-y: auto;
        padding: 20px;
    }

    .chat-input-area {
        flex-shrink: 0;
    }

    /* Ocultar el chat-main cuando el sidebar está activo en móvil */
    .chat-container.sidebar-open .chat-main {
        transform: translateX(100%);
        pointer-events: none;
    }

    /* Mostrar el botón hamburguesa en móvil */
    .toggle-sidebar-button {
        display: flex !important;
    }

    .mobile-toggle-sidebar {
        display: none;
    }
}
/* ===== MEJORAS ADICIONALES PARA VIEWPORT MÓVIL ===== */
@media (max-width: 768px) {
    /* Soporte para "notch" y áreas seguras en dispositivos modernos */
    .chat-container {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* Asegurar que el header no quede oculto detrás de la barra del navegador */
    .chat-header-desktop {
        position: sticky;
        top: 0;
        z-index: 100;
    }

    /* Asegurar que el input area esté siempre visible */
    .chat-input-area {
        position: sticky;
        bottom: 0;
        z-index: 100;
    }

    /* Cuando el teclado aparece, ajustar el área de mensajes */
    .chat-messages {
        /* Usar flex-grow para que tome el espacio disponible */
        flex: 1 1 auto;
        min-height: 0; /* Importante para que flexbox funcione correctamente */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch; /* Scroll suave en iOS */
    }

    /* Prevenir zoom en iOS cuando se enfoca un input */
    #message-input {
        font-size: 16px; /* 16px o más previene el zoom en iOS */
    }
}