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

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background-color: #e5ddd5;
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
}

.chat-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 428px;
    height: 100vh;
    max-height: 926px;
    margin: 0 auto;
    background-color: #e5ddd5;
    position: relative;
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
    border-radius: 0;
    overflow: hidden;
    justify-content: space-between;
}

/* Desktop: formato mobile centralizado */
@media (min-width: 768px) {
    body {
        background-color: #d1d4d8;
    }
    
    .chat-container {
        border-radius: 0.5rem;
        box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    }
}

/* Mobile: fullscreen */
@media (max-width: 767px) {
    html, body {
        margin: 0;
        padding: 0;
        height: 100%;
        overflow: hidden;
    }
    
    body {
        padding: 0;
        background-color: #e5ddd5;
        align-items: flex-start;
        height: 100dvh; /* Dynamic viewport height para mobile */
    }
    
    .chat-container {
        max-width: 100%;
        width: 100%;
        height: 100dvh; /* Dynamic viewport height */
        max-height: 100dvh;
        border-radius: 0;
        box-shadow: none;
        margin: 0;
        padding-bottom: env(safe-area-inset-bottom, 0px); /* Considera área segura do iPhone */
    }
}

/* Header do Chat */
.chat-header {
    background-color: #075e54;
    color: white;
    padding: 0.6rem 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
    z-index: 10;
    flex-shrink: 0;
}

.back-btn {
    color: white;
    text-decoration: none;
    font-size: 1.5rem;
    font-weight: 300;
    padding: 0.25rem;
    display: flex;
    align-items: center;
}

.back-btn:hover {
    opacity: 0.8;
}

.header-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
}

.avatar {
    width: 40px;
    height: 40px;
}

.avatar-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: 600;
    font-size: 1.125rem;
}

.contact-info {
    flex: 1;
}

.contact-name {
    font-size: 1rem;
    font-weight: 500;
    margin-bottom: 0.125rem;
}

.contact-status {
    font-size: 0.8125rem;
    opacity: 0.9;
}

.header-menu {
    font-size: 1.25rem;
    cursor: pointer;
    padding: 0.25rem;
    opacity: 0.9;
}

.header-menu:hover {
    opacity: 1;
}

/* Área de Mensagens */
.chat-messages {
    flex: 1;
    overflow-y: scroll;
    overflow-x: hidden;
    padding: 0.5rem 0.75rem;
    padding-bottom: 0.25rem;
    background-color: #e5ddd5;
    background-image: 
        url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23c8c8c8' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    -ms-overflow-style: none;  /* IE and Edge */
    scrollbar-width: none;  /* Firefox */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.chat-messages::-webkit-scrollbar {
    width: 0px;
    background: transparent;
}

/* Estilização da Scrollbar - Escondida */
.chat-messages::-webkit-scrollbar {
    width: 0 !important;
    display: none !important;
    background: transparent !important;
}

.chat-messages::-webkit-scrollbar-track {
    display: none !important;
    background: transparent !important;
}

.chat-messages::-webkit-scrollbar-thumb {
    display: none !important;
    background: transparent !important;
}

/* Mensagens */
.message {
    display: flex;
    margin-bottom: 0.15rem;
    animation: fadeIn 0.3s ease-in;
}

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

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

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

.message-bubble {
    max-width: 70%;
    padding: 0.35rem 0.6rem;
    border-radius: 0.5rem;
    word-wrap: break-word;
    position: relative;
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.13);
    line-height: 1.3;
}

.message.received .message-bubble {
    background-color: #ffffff;
    border-top-left-radius: 0.25rem;
}

.message.sent .message-bubble {
    background-color: #dcf8c6;
    border-top-right-radius: 0.25rem;
}

.message-text {
    font-size: 0.9375rem;
    line-height: 1.25;
    color: #303030;
    margin: 0;
}

.message-time {
    font-size: 0.65rem;
    color: rgba(0, 0, 0, 0.45);
    text-align: right;
    margin-top: 0.1rem;
    display: block;
    line-height: 1;
}

.message.sent .message-time {
    color: rgba(0, 0, 0, 0.6);
}

/* Opções de Resposta Rápida */
.quick-options {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.quick-option {
    background-color: #ffffff;
    border: 1px solid #e0e0e0;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: background-color 0.2s;
    text-align: left;
    font-size: 0.9375rem;
    color: #303030;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.quick-option:hover {
    background-color: #f5f5f5;
}

.quick-option:active {
    transform: scale(0.98);
}

/* Input de Mensagem */
.chat-input-container {
    background-color: #f0f0f0;
    padding: 0.4rem 0.75rem;
    padding-bottom: calc(0.4rem + env(safe-area-inset-bottom, 0px)); /* Espaço para botões do navegador */
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-top: 1px solid #d1d1d1;
    flex-shrink: 0;
    position: relative;
    z-index: 10;
    margin-bottom: 0;
}

.chat-input {
    flex: 1;
    border: none;
    background-color: #ffffff;
    padding: 0.625rem 1rem;
    border-radius: 1.3125rem;
    font-size: 0.9375rem;
    outline: none;
    resize: none;
    font-family: inherit;
}

.chat-input:focus {
    box-shadow: 0 0 0 2px rgba(37, 211, 102, 0.2);
}

.send-btn {
    background-color: #25d366;
    border: none;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: background-color 0.2s, transform 0.1s;
    flex-shrink: 0;
}

.send-btn:hover {
    background-color: #20ba5a;
}

.send-btn:active {
    transform: scale(0.95);
}

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

/* Loading indicator */
.typing-indicator {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
}

.typing-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.4);
    animation: typing 1.4s infinite;
}

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

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-10px);
    }
}

/* Ajustes específicos para mobile */
@media (max-width: 767px) {
    .chat-container {
        height: 100dvh;
        max-height: 100dvh;
        display: flex;
        flex-direction: column;
        padding-bottom: 0;
    }
    
    .chat-messages {
        padding: 0.4rem 0.6rem;
        padding-bottom: 0.15rem;
        gap: 0.15rem;
        -ms-overflow-style: none;
        scrollbar-width: none;
        overflow-y: scroll;
        -webkit-overflow-scrolling: touch;
        flex: 1;
        min-height: 0;
        max-height: calc(100dvh - 120px); /* Altura total menos header e input */
    }
    
    .chat-messages::-webkit-scrollbar {
        width: 0px;
        background: transparent;
    }
    
    .chat-messages::-webkit-scrollbar-track {
        background: transparent;
    }
    
    .chat-messages::-webkit-scrollbar-thumb {
        background: transparent;
    }
    
    .chat-input-container {
        flex-shrink: 0;
        position: relative;
        z-index: 10;
        padding-bottom: calc(0.4rem + max(env(safe-area-inset-bottom, 0px), 50px)); /* Espaço extra para botões do navegador mobile */
        margin-bottom: 0;
    }
    
    .message {
        margin-bottom: 0.1rem;
    }
    
    .message-bubble {
        max-width: 85%;
        padding: 0.3rem 0.55rem;
        line-height: 1.2;
    }
    
    .message-text {
        font-size: 0.9rem;
        line-height: 1.2;
    }
    
    .message-time {
        font-size: 0.6rem;
        margin-top: 0.08rem;
    }
    
    .chat-header {
        padding: 0.5rem 0.6rem;
        min-height: auto;
    }
    
    .chat-input-container {
        padding: 0.35rem 0.6rem;
        min-height: auto;
    }
    
    .chat-input {
        padding: 0.5rem 0.9rem;
        font-size: 0.9rem;
    }
    
    .send-btn {
        width: 2.25rem;
        height: 2.25rem;
    }
}

/* Ocultar input quando chatbot está respondendo */
.input-disabled .chat-input-container {
    opacity: 0.5;
    pointer-events: none;
}
