/* ===== UX IMPROVEMENTS ===== */

/* 1. MELHOR FEEDBACK VISUAL */
.btn:active {
    transform: scale(0.95);
    transition: transform 0.1s ease;
}

.message-sending {
    opacity: 0.7;
    transform: scale(0.98);
    transition: all 0.3s ease;
}

.message-sent {
    animation: messageSent 0.5s ease;
}

@keyframes messageSent {
    0% { transform: scale(0.98); opacity: 0.7; }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); opacity: 1; }
}

/* 2. BOTÕES DE TOQUE MAIORES (MOBILE) */
@media (max-width: 768px) {
    .chat-input .btn {
        min-width: 44px !important;
        min-height: 44px !important;
        touch-action: manipulation;
    }
    
    .contact-item, .group-item {
        min-height: 60px;
        padding: 12px 16px;
    }
}

/* Message status - canonical definition in style.css (uses FontAwesome icons from chat.js) */

/* 4. DRAG & DROP VISUAL */
.file-drop-zone {
    position: relative;
    transition: all 0.3s ease;
}

.file-drop-zone.drag-over {
    border: 2px dashed var(--whatsapp-green);
    background-color: rgba(37, 211, 102, 0.1);
}

.file-drop-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(37, 211, 102, 0.9);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 1.2rem;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: 1000;
}

.file-drop-zone.drag-over .file-drop-overlay {
    opacity: 1;
    visibility: visible;
}

/* 5. PROGRESS BARS MELHORADAS */
.upload-progress-container {
    padding: 8px 12px;
    background: var(--bs-light, #f8f9fa);
    border-bottom: 1px solid var(--bs-border-color, #dee2e6);
}

.upload-progress-container .upload-filename {
    max-width: 200px;
    font-weight: 500;
}

.upload-progress-container .upload-cancel-btn {
    min-width: 28px !important;
    min-height: 28px !important;
    padding: 2px 6px;
    font-size: 0.75rem;
}

body.dark .upload-progress-container {
    background: var(--whatsapp-dark-header, #202c33);
}

.upload-progress {
    background: var(--bs-light);
    border-radius: 10px;
    overflow: hidden;
    margin: 0;
    position: relative;
    height: 6px;
}

.upload-progress-bar {
    height: 6px;
    background: linear-gradient(90deg, var(--whatsapp-green), #20c997);
    border-radius: 10px;
    transition: width 0.3s ease;
}

/* 6. SKELETON LOADING */
.skeleton {
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

.skeleton-message {
    height: 20px;
    border-radius: 4px;
    margin-bottom: 8px;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

/* 7. TOAST NOTIFICATIONS */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 9999;
    max-width: 350px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast-custom {
    margin-bottom: 10px;
    border: none;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.15);
    animation: slideInRight 0.3s ease;
}

.toast-success {
    background: linear-gradient(135deg, #28a745, #20c997);
    color: white;
}

.toast-error {
    background: linear-gradient(135deg, #dc3545, #e74c3c);
    color: white;
}

.toast-info {
    background: linear-gradient(135deg, #17a2b8, #20c997);
    color: white;
}

@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* 8. MELHOR FOCUS PARA ACESSIBILIDADE */
.btn:focus-visible,
.form-control:focus-visible,
.contact-item:focus-visible {
    outline: 2px solid var(--whatsapp-green);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(37, 211, 102, 0.2);
}

/* 9. TEMA ESCURO APRIMORADO */
body.dark {
    transition: background-color 0.3s ease, color 0.3s ease;
}

body.dark .skeleton {
    background: linear-gradient(90deg, #2d3748 25%, #4a5568 50%, #2d3748 75%);
    background-size: 200% 100%;
}

/* 10. INDICADORES DE DIGITAÇÃO MELHORADOS */
.typing-indicator {
    display: flex;
    align-items: center;
    padding: 8px 16px;
    color: var(--bs-secondary);
    font-style: italic;
    animation: fadeIn 0.3s ease;
}

.typing-dots {
    display: inline-flex;
    margin-left: 8px;
}

.typing-dots span {
    width: 4px;
    height: 4px;
    background: var(--bs-secondary);
    border-radius: 50%;
    margin: 0 1px;
    animation: typingDots 1.4s infinite;
}

.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingDots {
    0%, 60%, 100% { transform: scale(1); opacity: 0.4; }
    30% { transform: scale(1.2); opacity: 1; }
}

/* 11. SELEÇÃO DE EMOJIS MELHORADA */
.emoji-picker {
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0,0,0,0.2);
    border: 1px solid var(--bs-border-color);
    overflow: hidden;
}

.emoji-category {
    padding: 8px;
    border-bottom: 1px solid var(--bs-border-color);
}

.emoji-item {
    padding: 8px;
    border-radius: 8px;
    transition: background-color 0.2s ease;
    cursor: pointer;
}

.emoji-item:hover {
    background-color: var(--bs-light);
    transform: scale(1.1);
}

/* 12. RESPONSIVIDADE APRIMORADA */
@media (max-width: 576px) {
    .modal-dialog {
        margin: 10px;
        max-width: calc(100% - 20px);
    }
    
    .chat-input {
        padding: 8px;
    }
    
    .message-bubble {
        max-width: calc(100vw - 80px);
        font-size: 16px; /* Evita zoom no iOS */
    }
}

/* 13. ANIMAÇÕES SUAVES */
.fade-in {
    animation: fadeIn 0.5s ease;
}

.slide-up {
    animation: slideUp 0.3s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes slideInLeft {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* 14. ESTADOS DE CARREGAMENTO */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid var(--whatsapp-green);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* 15. MELHOR CONTRASTE PARA ACESSIBILIDADE */
.high-contrast {
    --whatsapp-green: #0d7377;
    --whatsapp-light-green: #14a085;
}

body.dark.high-contrast {
    --whatsapp-dark-text: #ffffff;
    --whatsapp-dark-text-secondary: #e0e0e0;
}

/* 16. RETRY BUTTON FOR FAILED MESSAGES */
.retry-button {
    font-size: 0.75rem;
    padding: 4px 8px;
    border-radius: 12px;
    border: 1px solid #dc3545;
    background: transparent;
    color: #dc3545;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.retry-button:hover {
    background: #dc3545;
    color: white;
    transform: scale(1.05);
}

.retry-button:active {
    transform: scale(0.95);
}

/* 17. MESSAGE ERROR STATE */
.message-bubble.error {
    border-left: 3px solid #dc3545;
    opacity: 0.8;
}

.message-bubble.error .message-content {
    position: relative;
}

/* Dark theme support for error states */
body.dark .retry-button {
    border-color: #ff6b6b;
    color: #ff6b6b;
}

body.dark .retry-button:hover {
    background: #ff6b6b;
    color: white;
}

body.dark .message-bubble.error {
    border-left-color: #ff6b6b;
}

/* ===== CONNECTION STATUS ===== */
.connection-banner.connected {
    background: #25D366;
    color: #fff;
}

.connection-pulse {
    animation: connectionPulse 1.5s infinite;
}

@keyframes connectionPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* ===== MESSAGE ERROR TEXT ===== */
.message-error-text {
    font-size: 0.75rem;
    color: #dc3545;
    margin-top: 4px;
    padding-left: 4px;
}

body.dark .message-error-text {
    color: #ff6b6b;
}

/* ===== IMAGE LIGHTBOX ===== */
.lightbox-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    z-index: 10000;
    display: flex;
    flex-direction: column;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.lightbox-overlay.active {
    opacity: 1;
}

.lightbox-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    color: white;
}

.lightbox-filename {
    font-size: 0.9rem;
    opacity: 0.8;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 60%;
}

.lightbox-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    cursor: pointer;
}

.lightbox-content img {
    max-width: 90vw;
    max-height: 85vh;
    object-fit: contain;
    border-radius: 4px;
    cursor: default;
}

/* ===== USER PROFILE CARD ===== */
.user-profile-card {
    position: fixed;
    z-index: 9999;
    background: white;
    border-radius: 12px;
    padding: 12px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    width: 200px;
    animation: fadeIn 0.2s ease;
}

body.dark .user-profile-card {
    background: var(--whatsapp-dark-header, #202c33);
    color: white;
}

/* ===== UNREAD BADGE PULSE ===== */
@keyframes badgePulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); }
}

.unread-count.pulse {
    animation: badgePulse 0.6s ease;
}

/* ===== SERVICE CENTER DISCOVERY ===== */
.service-hint-pulse {
    animation: hintPulse 2s infinite;
}

@keyframes hintPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(37, 211, 102, 0.4); }
    50% { box-shadow: 0 0 0 8px rgba(37, 211, 102, 0); }
}

.service-hint-tooltip {
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: #fff;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.75rem;
    white-space: nowrap;
    z-index: 10;
    margin-top: 6px;
    animation: fadeIn 0.3s ease;
}

.service-hint-tooltip::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-bottom-color: #333;
}

/* ===== SCROLL BUTTON UNREAD BADGE ===== */
.scroll-unread-count {
    position: absolute;
    top: -8px;
    right: -8px;
    background: #25D366;
    color: white;
    font-size: 0.7rem;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    font-weight: bold;
}