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

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #e5ddd5;
    position: relative;
}

.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height for mobile */
    max-width: 1000px;
    margin: 0 auto;
    background: white;
    box-shadow: 0 0 20px rgba(0,0,0,0.1);
    width: 100%;
    overflow-x: hidden;
    position: relative;
}

.chat-header {
    background: #075e54;
    color: white;
    padding: 15px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    flex-wrap: nowrap;
    min-height: 60px;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden;
    position: relative;
    z-index: 100;
    flex-shrink: 0;
}

.chat-header .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #ff6b6b, #ee5a24);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
    font-size: 18px;
    margin-right: 15px;
    flex-shrink: 0;
}

.chat-header .contact-info {
    flex: 1;
    min-width: 0;
    overflow: hidden;
}

.chat-header .contact-info h2 {
    font-size: 18px;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-header .contact-info p {
    font-size: 13px;
    opacity: 0.8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.company-id-container {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-left: 10px;
    flex-shrink: 0;
}

.company-id-label {
    font-size: 13px;
    opacity: 0.9;
    white-space: nowrap;
}

.company-id-input {
    width: 60px;
    padding: 6px 10px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 14px;
    font-weight: 600;
    text-align: center;
    outline: none;
    transition: all 0.2s;
    flex-shrink: 0;
}

.company-id-input:focus {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
}

.company-id-input::-webkit-inner-spin-button,
.company-id-input::-webkit-outer-spin-button {
    opacity: 1;
    cursor: pointer;
}

/* Responsive para móviles */
@media (max-width: 768px) {
    .chat-container {
        height: 100vh;
        height: 100dvh;
    }
    
    .chat-header {
        padding: 10px 12px;
        min-height: 52px;
        position: sticky;
        top: 0;
        z-index: 1000;
    }
    
    .chat-header .avatar {
        width: 32px;
        height: 32px;
        font-size: 14px;
        margin-right: 10px;
        flex-shrink: 0;
    }
    
    .chat-header .contact-info {
        flex: 1 1 auto;
        min-width: 0;
    }
    
    .chat-header .contact-info h2 {
        font-size: 15px;
    }
    
    .chat-header .contact-info p {
        font-size: 11px;
    }
    
    .company-id-container {
        gap: 4px;
        margin-left: 6px;
        flex-shrink: 0;
    }
    
    .company-id-label {
        font-size: 10px;
    }
    
    .company-id-input {
        width: 45px;
        padding: 4px 6px;
        font-size: 12px;
    }
}

@media (max-width: 480px) {
    .chat-header {
        padding: 8px 10px;
        min-height: 48px;
    }
    
    .chat-header .avatar {
        width: 28px;
        height: 28px;
        font-size: 12px;
        margin-right: 8px;
    }
    
    .chat-header .contact-info h2 {
        font-size: 14px;
    }
    
    .chat-header .contact-info p {
        font-size: 10px;
    }
    
    .company-id-container {
        gap: 3px;
        margin-left: 4px;
    }
    
    /* Ocultar el label en pantallas pequeñas */
    .company-id-label {
        display: none;
    }
    
    .company-id-input {
        width: 40px;
        padding: 3px 4px;
        font-size: 11px;
    }
}

@media (max-width: 360px) {
    .chat-header {
        padding: 6px 8px;
        min-height: 44px;
    }
    
    .chat-header .avatar {
        width: 26px;
        height: 26px;
        font-size: 11px;
        margin-right: 6px;
    }
    
    .chat-header .contact-info h2 {
        font-size: 13px;
    }
    
    /* Ocultar "En línea" en pantallas muy pequeñas */
    .chat-header .contact-info p {
        display: none;
    }
    
    .company-id-container {
        gap: 2px;
        margin-left: 4px;
    }
    
    .company-id-input {
        width: 35px;
        padding: 2px 3px;
        font-size: 10px;
    }
}

/* Asegurar que el header sea visible en todos los dispositivos */
@media (max-width: 1000px) {
    .chat-header {
        position: sticky;
        top: 0;
        z-index: 1000;
    }
}

.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    background: #e5ddd5;
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><defs><pattern id="grain" width="100" height="100" patternUnits="userSpaceOnUse"><circle cx="25" cy="25" r="1" fill="%23ffffff" opacity="0.1"/><circle cx="75" cy="75" r="1" fill="%23ffffff" opacity="0.1"/><circle cx="50" cy="10" r="0.5" fill="%23ffffff" opacity="0.1"/><circle cx="10" cy="60" r="0.5" fill="%23ffffff" opacity="0.1"/><circle cx="90" cy="40" r="0.5" fill="%23ffffff" opacity="0.1"/></pattern></defs><rect width="100" height="100" fill="url(%23grain)"/></svg>');
}

.message {
    margin-bottom: 15px;
    display: flex;
    align-items: flex-end;
}

.message.user {
    justify-content: flex-end;
}

.message.flash {
    justify-content: flex-start;
}

.message-bubble {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.message.user .message-bubble {
    background: #dcf8c6;
    border-bottom-right-radius: 4px;
}

.message.flash .message-bubble {
    background: white;
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 11px;
    color: #999;
    margin: 5px 8px 0 0;
    white-space: nowrap;
}

.message.user .message-time {
    order: -1;
    margin: 5px 0 0 8px;
}

.typing-indicator {
    display: none;
    align-items: center;
    margin-bottom: 15px;
}

.typing-indicator .message-bubble {
    background: white;
    padding: 12px 16px;
    border-bottom-left-radius: 4px;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #999;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(1) { animation-delay: -0.32s; }
.typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

.chat-input {
    background: white;
    padding: 15px 20px;
    border-top: 1px solid #e0e0e0;
    display: flex;
    align-items: center;
    gap: 10px;
}

.phone-input {
    width: 180px;
    border: none;
    outline: none;
    padding: 12px 16px;
    border-radius: 25px;
    background: #f0f0f0;
    font-size: 16px;
    margin-right: 10px;
}

.message-input {
    flex: 1;
    border: none;
    outline: none;
    padding: 12px 16px;
    border-radius: 25px;
    background: #f0f0f0;
    font-size: 16px;
    resize: none;
    max-height: 100px;
    min-height: 20px;
}

.send-button {
    background: #075e54;
    color: white;
    border: none;
    width: 45px;
    height: 45px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.send-button:hover {
    background: #064e46;
}

.send-button:disabled {
    background: #ccc;
    cursor: not-allowed;
}

.product-item {
    background: #f8f9fa;
    padding: 10px;
    margin: 8px 0;
    border-radius: 8px;
    border-left: 3px solid #075e54;
}

.product-name {
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.product-price {
    color: #25d366;
    font-weight: 600;
    font-size: 14px;
}

.welcome-message {
    text-align: center;
    color: #666;
    font-style: italic;
    margin: 20px 0;
}

/* Modal styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal {
    background: white;
    border-radius: 12px;
    padding: 30px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
    text-align: center;
}

.modal h2 {
    color: #075e54;
    margin-bottom: 10px;
    font-size: 24px;
}

.modal p {
    color: #666;
    margin-bottom: 25px;
    font-size: 16px;
}

.modal-input {
    width: 100%;
    padding: 15px;
    border: 2px solid #e0e0e0;
    border-radius: 8px;
    font-size: 16px;
    text-align: center;
    margin-bottom: 20px;
    transition: border-color 0.3s;
}

.modal-input:focus {
    outline: none;
    border-color: #075e54;
}

.modal-button {
    background: #075e54;
    color: white;
    border: none;
    padding: 12px 30px;
    border-radius: 8px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.3s;
    width: 100%;
}

.modal-button:hover {
    background: #064e46;
}

.modal-button:disabled {
    background: #ccc;
    cursor: not-allowed;
}
