/* WhatsApp Web Chat Styles with Nota Fiscal Features */
:root {
    --whatsapp-green: #25D366;
    --whatsapp-dark: #128C7E;
    --whatsapp-teal: #075E54;
    --chat-bg: #E5DDD5;
    --chat-bg-pattern: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" opacity="0.05"><rect fill="%23ffffff" width="100" height="100"/></svg>');
    --header-bg: #075E54;
    --received-bg: #FFFFFF;
    --sent-bg: #DCF8C6;
    --text-primary: #111111;
    --text-secondary: #667781;
    --time-color: #667781;
    --input-bg: #F0F2F5;
    --icon-color: #54656F;
    --nota-fiscal-bg: #E3F2FD;
    --nota-fiscal-border: #2196F3;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* Phone Frame */
.phone-frame {
    width: 100%;
    max-width: 420px;
    height: 85vh;
    max-height: 850px;
    background: var(--chat-bg);
    border-radius: 20px;
    overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Chat Header */
.chat-header {
    background: var(--header-bg);
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: white;
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
    flex: 1;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    overflow: hidden;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-details h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 2px;
}

.user-details .status {
    font-size: 13px;
    opacity: 0.9;
}

.header-right {
    display: flex;
    gap: 5px;
}

.icon-btn {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.2s;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Chat Background */
.chat-background {
    position: absolute;
    top: 60px;
    left: 0;
    right: 0;
    bottom: 60px;
    background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="400" height="400" viewBox="0 0 400 400"><g fill="%23000" fill-opacity="0.03"><path d="M0,200 Q100,150 200,200 T400,200 L400,400 L0,400 Z"/></g></svg>');
    opacity: 0.5;
    pointer-events: none;
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 1;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.2) transparent;
}

.messages-container::-webkit-scrollbar {
    width: 6px;
}

.messages-container::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 3px;
}

/* Date Separator */
.date-separator {
    text-align: center;
    margin: 10px 0;
}

.date-separator span {
    background: rgba(225, 245, 254, 0.9);
    color: #54656F;
    font-size: 12px;
    padding: 5px 12px;
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Messages */
.message {
    display: flex;
    margin: 2px 0;
    max-width: 85%;
    animation: messageAppear 0.3s ease-out;
}

@keyframes messageAppear {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.sent {
    align-self: flex-end;
    margin-left: auto;
}

.message.received {
    align-self: flex-start;
}

.message-bubble {
    padding: 8px 12px;
    border-radius: 8px;
    position: relative;
    word-wrap: break-word;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

.message.sent .message-bubble {
    background: var(--sent-bg);
    border-top-right-radius: 2px;
}

.message.received .message-bubble {
    background: var(--received-bg);
    border-top-left-radius: 2px;
}

/* Nota Fiscal Message Styling */
.message.nota-fiscal .message-bubble {
    background: var(--nota-fiscal-bg);
    border-left: 4px solid var(--nota-fiscal-border);
}

.message-bubble p {
    font-size: 14px;
    line-height: 1.4;
    color: var(--text-primary);
    margin-bottom: 4px;
    white-space: pre-wrap;
}

.message-time {
    font-size: 11px;
    color: var(--time-color);
    float: right;
    margin-left: 8px;
    margin-top: 2px;
}

.message.sent .message-time::after {
    content: ' \2713\2713';
    color: #53BDEB;
    letter-spacing: -2px;
    margin-left: 3px;
}

/* Image Message Styling */
.message-image {
    max-width: 100%;
    border-radius: 6px;
    margin-bottom: 4px;
    cursor: pointer;
}

/* Typing Indicator */
.typing-indicator .message-bubble {
    padding: 15px 20px;
    min-width: 60px;
}

.dots {
    display: flex;
    gap: 4px;
    align-items: center;
    height: 10px;
}

.dots span {
    width: 8px;
    height: 8px;
    background: #9EA4AC;
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out;
}

.dots span:nth-child(1) { animation-delay: -0.32s; }
.dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes bounce {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40% { transform: scale(1.2); opacity: 1; }
}

/* Image Preview Container */
.image-preview-container {
    background: var(--input-bg);
    padding: 10px 15px;
    border-top: 1px solid #ddd;
}

.image-preview {
    position: relative;
    display: inline-block;
    max-width: 150px;
}

.image-preview img {
    max-width: 100%;
    max-height: 100px;
    border-radius: 8px;
    border: 2px solid var(--whatsapp-green);
}

.remove-image-btn {
    position: absolute;
    top: -8px;
    right: -8px;
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: #FF6B6B;
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.remove-image-btn:hover {
    background: #ff5252;
}

/* Input Area */
.input-area {
    background: var(--input-bg);
    padding: 10px 15px;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 10;
}

.input-container {
    flex: 1;
    display: flex;
    align-items: center;
    background: white;
    border-radius: 25px;
    padding: 5px 10px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

.text-input-wrapper {
    flex: 1;
}

#messageInput {
    width: 100%;
    border: none;
    outline: none;
    font-size: 15px;
    padding: 8px;
    background: transparent;
}

#messageInput::placeholder {
    color: #9EA4AC;
}

.emoji-btn, .attach-btn, .camera-btn {
    color: var(--icon-color);
    font-size: 20px;
}

.emoji-btn:hover, .attach-btn:hover, .camera-btn:hover {
    background: rgba(0,0,0,0.05);
}

.send-btn {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    border: none;
    background: var(--whatsapp-green);
    color: white;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s, background 0.2s;
}

.send-btn:hover {
    background: var(--whatsapp-dark);
    transform: scale(1.05);
}

.send-btn:active {
    transform: scale(0.95);
}

/* Connection Status */
.connection-status {
    margin-top: 15px;
    background: rgba(255, 255, 255, 0.9);
    padding: 8px 16px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: #333;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot.connected {
    background: var(--whatsapp-green);
    animation: pulse 2s infinite;
}

.status-dot.disconnected {
    background: #FF6B6B;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Phone Info */
.phone-info {
    margin-top: 10px;
    background: rgba(255, 255, 255, 0.9);
    padding: 12px 20px;
    border-radius: 10px;
    text-align: center;
    font-size: 13px;
    color: #333;
    max-width: 420px;
}

.phone-info p {
    margin: 4px 0;
}

.phone-info .hint {
    color: #666;
    font-style: italic;
}

#phoneNumber {
    font-weight: 600;
    color: var(--whatsapp-teal);
    cursor: pointer;
}

#phoneNumber:hover {
    text-decoration: underline;
}

/* Modal / Help Dialog */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 400px;
    width: 100%;
    max-height: 80vh;
    overflow: hidden;
    animation: modalAppear 0.3s ease-out;
}

@keyframes modalAppear {
    from {
        opacity: 0;
        transform: scale(0.9);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    background: var(--whatsapp-green);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 18px;
    font-weight: 600;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: rgba(255,255,255,0.2);
    border-radius: 50%;
}

.modal-body {
    padding: 20px;
    overflow-y: auto;
    max-height: 60vh;
}

.modal-body h4 {
    color: var(--whatsapp-teal);
    margin: 15px 0 10px 0;
    font-size: 14px;
    font-weight: 600;
}

.modal-body h4:first-child {
    margin-top: 0;
}

.modal-body ol, .modal-body ul {
    margin-left: 20px;
    font-size: 13px;
    line-height: 1.6;
    color: #333;
}

.modal-body li {
    margin-bottom: 5px;
}

.modal-body p {
    font-size: 13px;
    line-height: 1.6;
    color: #333;
    margin-bottom: 10px;
}

/* Mobile Responsive */
@media (max-width: 480px) {
    body {
        padding: 0;
    }
    
    .phone-frame {
        width: 100%;
        height: 100vh;
        max-height: none;
        border-radius: 0;
    }
    
    .connection-status,
    .phone-info {
        display: none;
    }
}

/* Quick Replies */
.quick-replies {
    display: flex;
    gap: 8px;
    padding: 10px;
    overflow-x: auto;
    scrollbar-width: none;
}

.quick-replies::-webkit-scrollbar {
    display: none;
}

.quick-reply {
    background: white;
    border: 1px solid var(--whatsapp-green);
    color: var(--whatsapp-green);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 13px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

.quick-reply:hover {
    background: var(--whatsapp-green);
    color: white;
}

/* Error Message */
.message.error .message-bubble {
    background: #FFEBEE;
    border-left: 4px solid #F44336;
}

/* Nota Fiscal Details Card */
.nota-fiscal-card {
    background: white;
    border-radius: 8px;
    padding: 12px;
    margin-top: 8px;
    border: 1px solid #e0e0e0;
}

.nota-fiscal-card h5 {
    color: var(--whatsapp-teal);
    font-size: 12px;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.nota-fiscal-card .info-row {
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    margin-bottom: 4px;
}

.nota-fiscal-card .info-label {
    color: #666;
}

.nota-fiscal-card .info-value {
    font-weight: 600;
    color: #333;
}
