/**
 * Chat Widget Styles - Complete and Updated
 */

:root {
    --sagitta-primary-color: #9333ea;
    --sagitta-secondary-color: #ec4899;
    --sagitta-accent-color: #f97316;
}

.sagitta-chat-widget * {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

.sagitta-chat-widget {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1000;
}

.sagitta-chat-widget[data-position="bottom_left"] {
    right: auto;
    left: 20px;
}

.sagitta-chat-widget[data-position="top_right"] {
    bottom: auto;
    top: 20px;
}

.sagitta-chat-widget[data-position="top_left"] {
    bottom: auto;
    top: 20px;
    right: auto;
    left: 20px;
}

/* ===== LAUNCHER ===== */

.launcher-container {
    display: flex;
    align-items: center;
    gap: 12px;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.launcher-container.hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.9);
}

.chat-button {
    position: relative;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: linear-gradient(135deg, #9333ea 0%, #ec4899 50%, #f97316 100%);
    border: none;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(147, 51, 234, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    animation: pulse 2s infinite;
    overflow: visible;
    flex-shrink: 0;
    padding: 3px;
}

.chat-button:hover {
    transform: scale(1.1);
    box-shadow: 0 12px 32px rgba(147, 51, 234, 0.6);
}

.chat-button-avatar {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    border: 3px solid rgba(255, 255, 255, 0.3);
}

.chat-button-status {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    background: #10b981;
    border-radius: 50%;
    border: 3px solid #1a0b2e;
    z-index: 10;
}

@keyframes statusBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

@keyframes pulse {
    0%, 100% {
        box-shadow: 0 8px 24px rgba(147, 51, 234, 0.4);
    }
    50% {
        box-shadow: 0 8px 32px rgba(147, 51, 234, 0.7);
    }
}

/* ===== LAUNCHER MESSAGES ===== */

.message-bubble-container {
    display: flex;
    align-items: center;
    gap: 12px;
}

.attention-bubble {
    background: white;
    padding: 14px 18px;
    border-radius: 10px 10px 5px 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
    max-width: 280px;
    animation: bubbleIn 0.5s ease;
    display: none;
    position: relative;
    color: #1a0b2e;
    font-size: 13px;
    line-height: 1.5;
    font-weight: 500;
}

.attention-bubble.active {
    display: block;
}

.attention-bubble::after {
    content: '';
    position: absolute;
    bottom: 14px;
    right: -10px;
    width: 0;
    height: 0;
    border-top: 12px solid transparent;
    border-bottom: 12px solid transparent;
    border-left: 12px solid white;
}

@keyframes bubbleIn {
    from {
        opacity: 0;
        transform: translateX(20px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.typing-bubble {
    background: white;
    padding: 14px 18px;
    border-radius: 10px 10px 5px 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.3);
    animation: bubbleIn 0.5s ease;
    display: none;
    position: relative;
}

.typing-bubble.active {
    display: block;
}

.typing-bubble::after {
    content: '';
    position: absolute;
    bottom: 14px;
    right: -10px;
    width: 0;
    height: 0;
    border-top: 12px solid transparent;
    border-bottom: 12px solid transparent;
    border-left: 12px solid white;
}

.typing-dots {
    display: flex;
    gap: 5px;
    padding: 4px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: #9333ea;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* ===== CHAT CONTAINER ===== */

.chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 400px;
    height: 650px;
    max-height: calc(100vh - 40px);
    max-height: calc(100dvh - 40px); /* Dynamic viewport height for mobile */
    background: #0f0520;
    border-radius: 24px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
    border: 1px solid rgba(147, 51, 234, 0.2);
}

.chat-container.active {
    display: flex;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ===== CHAT HEADER ===== */

.chat-header {
    background: linear-gradient(135deg, #9333ea 0%, #ec4899 100%);
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    position: relative;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    overflow: visible;
    flex-shrink: 0;
}

.avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
    border: 3px solid rgba(255, 255, 255, 0.3);
}

.avatar-status {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 14px;
    height: 14px;
    background: #10b981;
    border-radius: 50%;
    border: 3px solid #ec4899;
    animation: statusBlink 2s infinite;
}

.header-text h3 {
    color: white;
    font-size: 18px;
    margin-bottom: 2px;
    font-weight: 600;
}

.header-text p {
    color: rgba(255, 255, 255, 0.9);
    font-size: 13px;
}

.close-btn {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.3s ease;
    font-size: 20px;
}

.close-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ===== CHAT MESSAGES ===== */

.chat-messages {
    flex: 1;
    padding: 24px;
    overflow-y: auto;
    background: #0f0520;
}

.chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: #9333ea;
    border-radius: 3px;
}

.message {
    margin-bottom: 24px;
}

.message.fade-in {
    animation: fadeIn 0.4s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.bot {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.message.user {
    display: flex;
    justify-content: flex-end;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    border: 2px solid #9333ea;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-content {
    background: #2d1b4e;
    padding: 14px 18px;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    max-width: 70%;
    color: white;
    font-size: 15px;
    line-height: 1.5;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.message.user .message-content {
    background: linear-gradient(135deg, #9333ea, #ec4899);
    border-radius: 18px;
    border-bottom-right-radius: 4px;
    border-bottom-left-radius: 18px;
    box-shadow: 0 4px 12px rgba(147, 51, 234, 0.3);
}

.typing-indicator {
    display: flex;
    gap: 5px;
    padding: 14px 18px;
    background: #2d1b4e;
    border-radius: 18px;
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: #9333ea;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

/* ===== INPUT AREA ===== */

.chat-input-area {
    padding: 20px;
    background: #1a0b2e;
    border-top: 1px solid rgba(147, 51, 234, 0.2);
    flex-shrink: 0; /* Prevent input area from being compressed */
    position: relative;
}

/* Input hint bubble - clean white tooltip pointing to input */
.input-hint {
    position: absolute;
    top: -48px;
    left: 24px;
    background: white;
    color: #1a0b2e;
    padding: 8px 16px;
    border-radius: 12px;
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    animation: hintFadeIn 0.4s ease forwards;
    pointer-events: none;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Arrow pointing down to input */
.input-hint::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 20px;
    width: 12px;
    height: 12px;
    background: white;
    transform: rotate(45deg);
    box-shadow: 2px 2px 4px rgba(0, 0, 0, 0.1);
}

@keyframes hintFadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes hintFadeOut {
    from {
        opacity: 1;
        transform: translateY(0);
    }
    to {
        opacity: 0;
        transform: translateY(-5px);
    }
}

/* Layout padrão: Input e botão lado a lado */
.input-wrapper {
    display: flex;
    gap: 12px;
    align-items: flex-end;
    transition: all 0.3s ease;
    opacity: 1;
    transform: translateY(0);
}

.input-group {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.input-label {
    color: rgba(255, 255, 255, 0.6);
    font-size: 12px;
    font-weight: 500;
    padding-left: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Chat input - protected from theme overrides */
.sagitta-chat-widget .chat-input,
.sagitta-chat-widget input.chat-input,
.sagitta-chat-widget textarea.chat-input {
    width: 100% !important;
    padding: 14px 18px !important;
    border: 2px solid rgba(147, 51, 234, 0.3) !important;
    border-radius: 24px !important;
    background: #0f0520 !important;
    color: white !important;
    font-size: 15px !important;
    outline: none !important;
    transition: all 0.3s ease !important;
    box-sizing: border-box !important;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif !important;
    line-height: 1.5 !important;
    margin: 0 !important;
    box-shadow: none !important;
}

.sagitta-chat-widget .chat-input:focus,
.sagitta-chat-widget input.chat-input:focus,
.sagitta-chat-widget textarea.chat-input:focus {
    border-color: #9333ea !important;
    background: #1a0b2e !important;
    box-shadow: 0 0 0 3px rgba(147, 51, 234, 0.1) !important;
    outline: none !important;
}

.sagitta-chat-widget .chat-input::placeholder,
.sagitta-chat-widget input.chat-input::placeholder,
.sagitta-chat-widget textarea.chat-input::placeholder {
    color: rgba(255, 255, 255, 0.3) !important;
    opacity: 1 !important;
}

.sagitta-chat-widget .chat-input[type="email"],
.sagitta-chat-widget input.chat-input[type="email"] {
    text-transform: lowercase !important;
}

.sagitta-chat-widget textarea.chat-input {
    resize: vertical !important;
    min-height: 80px !important;
    max-height: 200px !important;
    padding: 14px 18px !important;
    border-radius: 16px !important;
    overflow-y: auto !important;
    word-wrap: break-word !important;
    word-break: break-word !important;
}

textarea.chat-input::-webkit-scrollbar {
    width: 6px;
}

textarea.chat-input::-webkit-scrollbar-thumb {
    background: #9333ea;
    border-radius: 3px;
}

/* Phone Input - protected */
.sagitta-chat-widget .phone-input-container {
    display: flex !important;
    gap: 10px !important;
}

.sagitta-chat-widget .ddi-select,
.sagitta-chat-widget select.ddi-select {
    max-width: 90px !important;
    padding: 14px 12px !important;
    padding-right: 32px !important;
    border: 2px solid rgba(147, 51, 234, 0.3) !important;
    border-radius: 24px !important;
    background: #0f0520 !important;
    color: white !important;
    font-size: 14px !important;
    font-weight: 600 !important;
    outline: none !important;
    transition: all 0.3s ease !important;
    cursor: pointer !important;
    appearance: none !important;
    -webkit-appearance: none !important;
    -moz-appearance: none !important;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23ffffff' d='M6 9L1 4h10z'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 12px center !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    box-shadow: none !important;
}

.sagitta-chat-widget .ddi-select:focus,
.sagitta-chat-widget select.ddi-select:focus {
    border-color: #9333ea !important;
    background-color: #1a0b2e !important;
    box-shadow: 0 0 0 3px rgba(147, 51, 234, 0.1) !important;
    outline: none !important;
}

.sagitta-chat-widget .ddi-select option,
.sagitta-chat-widget select.ddi-select option {
    background: #1a0b2e !important;
    color: white !important;
    padding: 10px !important;
}

.phone-number-input {
    flex: 1;
}

/* ===== BUTTONS ===== */

/* Botão de envio padrão (ao lado do input) - protected from theme overrides */
.sagitta-chat-widget .send-btn,
.sagitta-chat-widget button.send-btn {
    width: 50px !important;
    height: 50px !important;
    min-width: 50px !important;
    min-height: 50px !important;
    border-radius: 50% !important;
    background: linear-gradient(135deg, #9333ea, #ec4899) !important;
    border: none !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: transform 0.3s ease !important;
    box-shadow: 0 4px 12px rgba(147, 51, 234, 0.3) !important;
    flex-shrink: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    outline: none !important;
    box-sizing: border-box !important;
}

.sagitta-chat-widget .send-btn:hover:not(:disabled),
.sagitta-chat-widget button.send-btn:hover:not(:disabled) {
    transform: scale(1.1) !important;
    box-shadow: 0 6px 16px rgba(147, 51, 234, 0.4) !important;
}

.sagitta-chat-widget .send-btn:disabled,
.sagitta-chat-widget button.send-btn:disabled {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
}

.sagitta-chat-widget .send-btn svg,
.sagitta-chat-widget button.send-btn svg {
    width: 22px !important;
    height: 22px !important;
    fill: white !important;
}

/* ===== BUTTON CONTAINER (Textarea com Skip) ===== */

/* Container para botões lado a lado */
.button-container {
    display: flex;
    gap: 12px;
    align-items: stretch;
    width: 100%;
    margin-top: 12px;
}

/* Muda layout do wrapper quando tem button-container */
.input-wrapper:has(.button-container) {
    flex-direction: column;
    align-items: stretch;
}

.input-wrapper:has(.button-container) .input-group {
    width: 100%;
}

/* Botões dentro do container (lado a lado, embaixo) - protected */
.sagitta-chat-widget .button-container .send-btn,
.sagitta-chat-widget .button-container button.send-btn {
    flex: 1 !important;
    width: auto !important;
    min-width: auto !important;
    height: 50px !important;
    min-height: 50px !important;
    border-radius: 25px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 8px !important;
    padding: 0 24px !important;
    font-size: 15px !important;
    font-weight: 500 !important;
    color: white !important;
    background: linear-gradient(135deg, #9333ea, #ec4899) !important;
    border: none !important;
    box-sizing: border-box !important;
    outline: none !important;
}

.sagitta-chat-widget .button-container .send-btn svg,
.sagitta-chat-widget .button-container button.send-btn svg {
    width: 20px !important;
    height: 20px !important;
    fill: white !important;
}

.sagitta-chat-widget .button-container .send-btn:hover:not(:disabled),
.sagitta-chat-widget .button-container button.send-btn:hover:not(:disabled) {
    transform: translateY(-2px) !important;
    box-shadow: 0 6px 16px rgba(147, 51, 234, 0.4) !important;
}

/* Skip Button - protected */
.sagitta-chat-widget .skip-btn,
.sagitta-chat-widget button.skip-btn {
    flex: 1 !important;
    height: 50px !important;
    min-height: 50px !important;
    padding: 0 24px !important;
    background: rgba(107, 114, 128, 0.25) !important;
    color: rgba(255, 255, 255, 0.8) !important;
    border: 1px solid rgba(107, 114, 128, 0.4) !important;
    border-radius: 25px !important;
    cursor: pointer !important;
    font-size: 15px !important;
    font-weight: 500 !important;
    transition: all 0.3s ease !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 6px !important;
    white-space: nowrap !important;
    box-sizing: border-box !important;
    outline: none !important;
}

.sagitta-chat-widget .skip-btn:hover,
.sagitta-chat-widget button.skip-btn:hover {
    background: rgba(107, 114, 128, 0.35) !important;
    color: rgba(255, 255, 255, 1) !important;
    border-color: rgba(107, 114, 128, 0.6) !important;
    transform: translateY(-2px) !important;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25) !important;
}

.sagitta-chat-widget .skip-btn:active,
.sagitta-chat-widget button.skip-btn:active {
    transform: translateY(0) !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2) !important;
}

/* ===== QUICK REPLIES ===== */

.quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.quick-reply-btn {
    padding: 10px 18px;
    border: 2px solid #9333ea;
    background: rgba(147, 51, 234, 0.1);
    color: #ec4899;
    border-radius: 20px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: all 0.3s ease;
    opacity: 1;
    transform: translateY(0);
}

.quick-reply-btn:hover {
    background: linear-gradient(135deg, #9333ea, #ec4899);
    color: white;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(147, 51, 234, 0.3);
}

/* ===== ERROR MESSAGE ===== */

.error-message {
    color: #ef4444;
    font-size: 12px;
    margin-top: 4px;
    padding-left: 4px;
    display: none;
}

.error-message.active {
    display: block;
}

/* ===== RESPONSIVE ===== */

@media (max-width: 480px) {
    .chat-container {
        width: 100%;
        height: 100%;
        height: 100dvh; /* Dynamic viewport height */
        right: 0;
        bottom: 0;
        border-radius: 0;
        max-width: 100vw;
        max-height: 100vh;
        max-height: 100dvh; /* Dynamic viewport height for mobile keyboards */
    }

    .sagitta-chat-widget {
        right: 0;
        bottom: 0;
    }

    .sagitta-chat-widget[data-position="bottom_left"] .chat-container,
    .sagitta-chat-widget[data-position="top_right"] .chat-container,
    .sagitta-chat-widget[data-position="top_left"] .chat-container {
        bottom: 0;
        right: 0;
        top: auto;
        left: auto;
    }

    .chat-header {
        border-radius: 0;
        flex-shrink: 0; /* Prevent header from shrinking */
    }

    .chat-messages {
        flex: 1;
        min-height: 0; /* Allow flex shrinking */
        overflow-y: auto;
    }

    .chat-input-area {
        flex-shrink: 0; /* Prevent input area from shrinking */
        padding-bottom: max(20px, env(safe-area-inset-bottom)); /* iOS safe area */
    }

    .message-content {
        max-width: 75%;
        font-size: 14px;
    }

    .attention-bubble,
    .typing-bubble {
        max-width: 220px;
        font-size: 12px;
    }

    .launcher-container {
        flex-direction: column;
        align-items: flex-end;
        gap: 8px;
    }

    .message-bubble-container {
        order: -1; /* Mensagem fica em cima */
    }

    .attention-bubble::after,
    .typing-bubble::after {
        bottom: -10px;
        right: 20px;
        left: auto;
        border-left: 12px solid transparent;
        border-right: 12px solid transparent;
        border-top: 12px solid white;
        border-bottom: none;
    }

    .button-container .send-btn,
    .button-container .skip-btn {
        padding: 0 16px;
        font-size: 13px;
    }

    .button-container .send-btn svg {
        width: 18px;
        height: 18px;
    }

    textarea.chat-input {
        min-height: 60px;
    }
}

@media (max-width: 360px) {
    .message-content {
        max-width: 65%;
        font-size: 14px;
    }

    .chat-input {
        font-size: 14px;
    }
}

/* Fallback para navegadores que não suportam :has() */
@supports not (selector(:has(*))) {
    .input-wrapper {
        flex-direction: column;
    }
    
    .input-wrapper > .input-group {
        width: 100%;
    }
    
    .input-wrapper > .send-btn {
        align-self: flex-end;
    }
}