/* VivoRetailX - Responsive Utilities */

/* Fix para viewport mobile - especialmente iOS */
html {
    height: 100%;
    height: -webkit-fill-available;
}

body {
    min-height: 100vh;
    min-height: -webkit-fill-available;
}

/* Fix para problemas de zoom em iOS */
@media screen and (max-width: 768px) {
    html {
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
    }
    
    body {
        -webkit-touch-callout: none;
        -webkit-user-select: none;
        -khtml-user-select: none;
        -moz-user-select: none;
        -ms-user-select: none;
        user-select: none;
        -webkit-tap-highlight-color: transparent;
    }
    
    /* Permitir seleção de texto apenas nas mensagens */
    .message-content {
        -webkit-user-select: text;
        -khtml-user-select: text;
        -moz-user-select: text;
        -ms-user-select: text;
        user-select: text;
    }
    
    .message-input {
        -webkit-user-select: text;
        -khtml-user-select: text;
        -moz-user-select: text;
        -ms-user-select: text;
        user-select: text;
    }
}

/* Fix para scroll em mobile */
@media screen and (max-width: 768px) {
    .chat-messages {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
    }
    
    .chat-widget {
        -webkit-overflow-scrolling: touch;
        overscroll-behavior: contain;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
    }
}

/* Mobile optimizations */
.mobile-device {
    --vh: 1vh;
}

.mobile-optimized {
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    overflow: hidden;
    padding: 4px;
}

.mobile-optimized .chat-widget {
    height: calc(100vh - 8px);
    height: calc(var(--vh, 1vh) * 100 - 8px);
    max-height: calc(100vh - 8px);
    max-height: calc(var(--vh, 1vh) * 100 - 8px);
    position: relative;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: calc(100vw - 8px);
    max-width: calc(100vw - 8px);
    border-radius: 12px;
    border: 1px solid rgba(139, 92, 246, 0.2);
    margin: 0;
}

.mobile-optimized .chat-messages {
    height: calc(100vh - 160px);
    height: calc(var(--vh, 1vh) * 100 - 160px);
    max-height: calc(100vh - 160px);
    max-height: calc(var(--vh, 1vh) * 100 - 160px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.mobile-optimized .chat-input {
    padding: 16px 12px;
    gap: 10px;
    position: sticky;
    bottom: 0;
    background: white;
    border-top: 1px solid rgba(139, 92, 246, 0.1);
}

.mobile-optimized .input-container {
    flex: 1;
    min-height: 44px;
    padding: 10px 14px;
    border-radius: 20px;
}

.mobile-optimized .send-button {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
}

/* Classe específica para telas muito pequenas */
.very-small-screen .chat-widget {
    width: calc(100vw - 4px) !important;
    max-width: calc(100vw - 4px) !important;
    height: calc(100vh - 4px) !important;
    border-radius: 6px !important;
    margin: 2px !important;
}

.very-small-screen .chat-input {
    padding: 10px 6px !important;
    gap: 6px !important;
    position: sticky;
    bottom: 0;
    z-index: 100;
}

.very-small-screen .input-container {
    flex: 1;
    min-width: 0;
    max-width: calc(100% - 52px);
    padding: 8px 10px !important;
}

.very-small-screen .send-button {
    width: 38px !important;
    height: 38px !important;
    flex-shrink: 0;
}

.very-small-screen .chat-messages {
    height: calc(100vh - 150px) !important;
    padding-bottom: 10px;
}

/* Utility classes para diferentes estados */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Landscape mode adjustments */
.chat-widget.landscape-mode {
    height: 100vh;
    height: calc(var(--vh, 1vh) * 100);
    max-height: none;
}

.chat-widget.landscape-mode .chat-messages {
    max-height: calc(100vh - 200px);
    max-height: calc(var(--vh, 1vh) * 100 - 200px);
}

/* Estados de loading e erro */
.error-message {
    animation: slideInError 0.3s ease-out;
}

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

/* Melhorias para telas pequenas */
@media (max-height: 500px) {
    .chat-widget {
        max-height: 100vh;
    }
    
    .chat-header {
        padding: 10px 16px;
    }
    
    .quick-actions {
        padding: 8px 16px;
    }
    
    .chat-messages {
        padding: 8px 16px;
    }
    
    .chat-input {
        padding: 8px 16px;
    }
    
    .message-content {
        padding: 8px 12px;
        font-size: 12px;
        line-height: 1.4;
    }
}

/* High DPI displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .avatar,
    .message-avatar {
        border: 0.5px solid rgba(255, 255, 255, 0.1);
    }
}

/* Hover states para dispositivos com cursor */
@media (hover: hover) and (pointer: fine) {
    .action-chip:hover {
        transform: translateY(-2px);
    }
    
    .send-button:hover {
        transform: translateY(-2px);
    }
}

/* Touch devices */
@media (hover: none) and (pointer: coarse) {
    .action-chip:active {
        transform: scale(0.95);
    }
    
    .send-button:active {
        transform: scale(0.95);
    }
    
    /* Aumentar área de toque */
    .action-chip,
    .send-button,
    .voice-button,
    .action-button,
    .minimize-button {
        min-height: 44px;
        min-width: 44px;
    }
}

/* Reduced motion preferences */
@media (prefers-reduced-motion: reduce) {
    .chat-widget *,
    .chat-widget *::before,
    .chat-widget *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .typing-dot {
        animation: none;
    }
    
    .status-dot {
        animation: none;
    }
    
    .chat-header::before {
        animation: none;
    }
}

/* High contrast mode */
@media (prefers-contrast: high) {
    .chat-widget {
        border: 2px solid;
    }
    
    .bot-message {
        border: 2px solid;
    }
    
    .user-message {
        border: 2px solid;
    }
    
    .action-chip {
        border: 2px solid;
    }
}

/* Print styles */
@media print {
    .chat-widget {
        box-shadow: none;
        border: 1px solid #000;
        background: white !important;
    }
    
    .quick-actions,
    .chat-input,
    .typing-indicator {
        display: none !important;
    }
    
    .message-content {
        background: transparent !important;
        color: black !important;
        border: 1px solid #ccc;
    }
    
    .bot-message strong {
        color: black !important;
    }
}

/* Melhorias de contraste e legibilidade */
.high-contrast {
    --primary-color: #4c1d95;
    --secondary-color: #6b21a8;
    --accent-color: #7c3aed;
    --text-color: #1f2937;
    --bg-color: #ffffff;
}

/* Interface mais compacta para desktop */
@media (min-width: 1024px) {
    .chat-widget.ultra-compact {
        max-height: 95vh;
        height: 95vh;
    }
    
    .chat-widget.ultra-compact .chat-header {
        padding: 10px 20px;
    }
    
    .chat-widget.ultra-compact .quick-actions {
        padding: 10px 20px;
    }
    
    .chat-widget.ultra-compact .chat-messages {
        padding: 16px 20px;
    }
    
    .chat-widget.ultra-compact .chat-input {
        padding: 16px 20px;
    }
}

/* Melhor contraste para texto em fundos escuros */
@media (prefers-color-scheme: dark) {
    .message-content {
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
    }
    
    .bot-message {
        background: linear-gradient(135deg, #374151 0%, #4b5563 100%);
        color: #f9fafb;
        border-color: rgba(139, 92, 246, 0.5);
    }
    
    .bot-message strong {
        color: #ddd6fe;
        text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    }
}

/* Modo de alto contraste forçado */
.chat-widget.force-high-contrast .bot-message {
    background: #f8fafc !important;
    color: #1e293b !important;
    border: 2px solid #475569 !important;
}

.chat-widget.force-high-contrast .bot-message strong {
    color: #0f172a !important;
}

/* Remover espaçamentos desnecessários em desktop */
@media (min-width: 1024px) {
    body.minimal-padding {
        padding: 5px 15px;
    }
    
    .chat-widget.edge-to-edge {
        height: 97vh;
        max-height: 97vh;
        border-radius: 12px;
    }
}

/* Modo Tablet */
.tablet-mode .chat-widget {
    width: min(90vw, 600px);
    max-width: min(90vw, 600px);
    height: min(85vh, 700px);
    max-height: min(85vh, 700px);
    border-radius: 16px;
    margin: auto;
}

.tablet-mode .chat-messages {
    height: calc(100% - 160px);
    max-height: calc(100% - 160px);
}

/* Modo Desktop */
.desktop-mode {
    padding: 20px;
}

.desktop-mode .chat-widget {
    width: min(60vw, 800px);
    max-width: min(60vw, 800px);
    height: min(90vh, 850px);
    max-height: min(90vh, 850px);
    border-radius: 20px;
    margin: auto;
}

.desktop-mode .chat-messages {
    height: calc(100% - 180px);
    max-height: calc(100% - 180px);
}

.desktop-mode .chat-input {
    padding: 20px 24px;
}

.desktop-mode .send-button {
    width: 48px;
    height: 48px;
}

/* Transições suaves para mudanças de layout */
.chat-widget {
    transition: all 0.3s ease-in-out !important;
}

.chat-messages {
    transition: height 0.3s ease-in-out !important;
}

.chat-input {
    transition: padding 0.3s ease-in-out !important;
}

/* Media query universal para redimensionamento dinâmico */
@media screen {
    .chat-widget {
        container-type: inline-size;
    }
    
    /* Ajustes automáticos baseados no container */
    @container (max-width: 375px) {
        .chat-input {
            padding: 10px 6px !important;
            gap: 6px !important;
        }
        
        .send-button {
            width: 38px !important;
            height: 38px !important;
        }
    }
    
    @container (min-width: 376px) and (max-width: 768px) {
        .chat-input {
            padding: 16px 12px !important;
            gap: 10px !important;
        }
        
        .send-button {
            width: 44px !important;
            height: 44px !important;
        }
    }
    
    @container (min-width: 769px) {
        .chat-input {
            padding: 20px 24px !important;
            gap: 12px !important;
        }
        
        .send-button {
            width: 48px !important;
            height: 48px !important;
        }
    }
}

/* Fallback para navegadores que não suportam container queries */
@supports not (container-type: inline-size) {
    @media (max-width: 375px) {
        .chat-input {
            padding: 10px 6px !important;
            gap: 6px !important;
        }
        
        .send-button {
            width: 38px !important;
            height: 38px !important;
        }
    }
    
    @media (min-width: 376px) and (max-width: 768px) {
        .chat-input {
            padding: 16px 12px !important;
            gap: 10px !important;
        }
        
        .send-button {
            width: 44px !important;
            height: 44px !important;
        }
    }
    
    @media (min-width: 769px) {
        .chat-input {
            padding: 20px 24px !important;
            gap: 12px !important;
        }
        
        .send-button {
            width: 48px !important;
            height: 48px !important;
        }
    }
}
