/**
 * Chat Widget CSS
 * Compatible with both Hyva (Tailwind) and Luma themes
 * Uses BEM-like class structure for better maintainability
 * ID selectors maintained for JavaScript compatibility
 */

@keyframes chat-trigger-circle-pulse {
    0%, 75% { box-shadow: 0 0 0 0 rgba(24, 113, 57, 0); }
    82% { box-shadow: 0 0 0 12px rgba(24, 113, 57, 0.35); }
    88% { box-shadow: 0 0 0 8px rgba(24, 113, 57, 0.2); }
    100% { box-shadow: 0 0 0 0 rgba(24, 113, 57, 0); }
}

@keyframes chat-icon-wiggle {
    0%, 75% { transform: translateX(0); }
    82% { transform: translateX(-5px); }
    86% { transform: translateX(5px); }
    90% { transform: translateX(-3px); }
    94%, 100% { transform: translateX(0); }
}

.chat-widget-trigger {
    position: fixed;
    inset: auto 20px 20px auto;
    width: 80px;
    height: 80px;
    padding: 0;
    border-radius: 9999px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    cursor: pointer;
    background: transparent;
    animation: chat-trigger-circle-pulse 4s ease-in-out infinite;
}

.chat-widget-trigger:hover {
    transform: scale(1.1);
    animation: none;
}
.chat-widget-trigger:hover .chat-widget-trigger__icon { animation: none; }
.chat-widget-trigger:active { transform: scale(0.9); }

.chat-widget-trigger.chat-open,
.chat-widget-trigger.chat-open .chat-widget-trigger__icon { animation: none; }

.chat-widget-trigger__icon {
    width: 36px;
    height: 36px;
    margin-bottom: 2px;
    fill: #187139;
    stroke: none;
    animation: chat-icon-wiggle 4s ease-in-out infinite;
}

.chat-widget-trigger__icon path { fill: #187139; stroke: none; }

.chat-widget-trigger__text {
    color: #187139;
    font-size: 12px;
    font-weight: 600;
}

/* Checkout: px because root font-size 10px */
.checkout-index-index .chat-widget-trigger {
    width: 80px;
    height: 80px;
}

.checkout-index-index .chat-widget-trigger__icon {
    width: 36px;
    height: 36px;
}

.checkout-index-index .chat-widget-trigger__text {
    font-size: 12px;
}

/* Chat Widget Container */
.chat-widget-container {
    position: fixed;
    bottom: 96px;
    right: 20px;
    width: 384px;
    max-width: calc(100vw - 40px);
    height: 500px;
    max-height: calc(100vh - 120px);
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: none;
    flex-direction: column;
    z-index: 1500;
    overflow: hidden;
}

.chat-widget-container:not(.hidden) {
    display: flex;
}

/* Chat Widget Header */
#chat-widget-header {
    background-color: #187139;
    color: #ffffff;
    padding: 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

#chat-widget-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.chat-widget-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

#chat-audio-toggle {
    background: transparent;
    border: none;
}

#chat-widget-close {
    background: transparent;
    border: 0;
    color: #ffffff;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#chat-widget-close:hover {
    opacity: 0.8;
}

/* Chat Messages Container */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background-color: #f3f4f5;
    position: relative;
}

#chat-messages-inner {
    padding: 20px;
}

.chat-message-wrapper {
    display: flex;
    margin-bottom: 16px;
}

.chat-message-wrapper.visitor-message {
    justify-content: flex-end;
}

.chat-message-wrapper.operator-message {
    justify-content: flex-start;
}

.chat-message-avatar {
    flex-shrink: 0;
    margin-right: 8px;
    align-self: flex-end;
}

.chat-avatar-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    font-size: 20px;
    line-height: 1;
}

.chat-message-bubble {
    max-width: 75%;
    padding: 12px;
    border-radius: 16px;
    overflow-wrap: break-word;
    color: #ffffff;
    font-size: 14px;
}

.chat-message-bubble.visitor-message {
    background-color: #187139;
}

.chat-message-bubble.operator-message {
    background-color: #ffffff;
    color: #1f2937;
    border: 1px solid #e7e7e7;
}

.chat-gpt-disclaimer {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 16px;
}

.chat-gpt-disclaimer span {
    font-size: 11px;
    color: #6b7280;
    max-width: 75%;
}

#chat-contact-form-message {
    display: flex;
    justify-content: start;
    margin-bottom: 16px;
}

.chat-contact-form-message-bubble{
    max-width: 85%;
    padding: 16px;
    border-radius: 16px;
    overflow-wrap: break-word;
    background-color: #ffffff;
    color: #1f2937;
}

.chat-report-bug-btn {
    position: fixed;
    bottom: 22px;
    left: 86px;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    width: auto;
    padding: 14px 16px 14px 14px;
    background: transparent;
    border: none;
    cursor: pointer;
    transition: all 0.3s ease;
}

.chat-report-bug-btn svg {
    width: 20px;
    height: 20px;
    color: #4b5563;
    transition: color 0.3s ease;
}

.chat-report-bug-btn:hover svg {
    color: #187139;
}

.chat-report-bug-text {
    margin-left: 8px;
    white-space: nowrap;
    font-size: 12px;
    font-weight: 500;
    color: #374151;
}

/* Bug Report Form */
#bug-report-form {
    display: none;
    flex-direction: column;
    gap: 12px;
}

#bug-report-form.hidden {
    display: none;
}

#bug-report-form:not(.hidden) {
    display: flex;
}

#bug-report-form .flex-col {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

#bug-report-form label {
    font-size: 12px;
    font-weight: 600;
    color: #4b5563;
    margin-bottom: 0;
}

#bug-report-form input,
#bug-report-form textarea {
    padding: 4px 8px;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    font-size: 12px;
}

#bug-report-form input:focus,
#bug-report-form textarea:focus {
    outline: none;
    border-color: #187139;
}

#bug-report-form input[readonly] {
    background-color: #f9fafb;
    cursor: not-allowed;
}

#bug-report-form .flex-gap-2 {
    display: flex;
    gap: 8px;
}

#bug-report-submit {
    flex: 1;
    padding: 8px;
    background-color: #187139;
    color: #ffffff;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background-color 0.3s ease;
}

#bug-report-submit:hover {
    background-color: #005d22;
}

#bug-report-cancel {
    padding: 8px;
    background-color: #e5e7eb;
    color: #374151;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background-color 0.3s ease;
}

#bug-report-cancel:hover {
    background-color: #d1d5db;
}

/* Chat Input Container */
#chat-input-container {
    position: relative;
    padding: 16px;
    background-color: #ffffff;
    border-top: 1px solid #e5e7eb;
}

#chat-message-input {
    width: 100%;
    padding: 12px;
    border: 1px solid #e5e7eb;
    border-radius: 9999px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    min-height: 40px;
    max-height: 96px;
}

#chat-message-input:focus {
    outline: none;
    border-color: #187139;
}

#chat-send-button {
    margin-top: 10px;
    width: 100%;
    padding: 10px;
    background-color: #187139;
    color: #ffffff;
    border: 0;
    border-radius: 9999px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background-color 0.3s ease;
}

#chat-send-button:hover {
    background-color: #005d22;
}

#chat-send-button:disabled {
    background-color: #d1d5db;
    cursor: not-allowed;
}

/* Chat Contact Form Container */
#chat-contact-form-container {
    padding: 16px;
    background-color: #fef3c7;
    border-top: 1px solid #e5e7eb;
    display: none;
}

#chat-contact-form-container:not(.hidden) {
    display: block;
}

#chat-contact-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#chat-contact-name,
#chat-contact-email {
    padding: 10px;
    border: 1px solid #e5e7eb;
    border-radius: 4px;
    font-size: 14px;
}

#chat-contact-form button[type="submit"] {
    padding: 10px;
    background-color: #187139;
    color: #ffffff;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

#chat-contact-form button[type="submit"]:hover {
    background-color: #005d22;
}

@media (min-width: 641px) {
    .chat-widget-container, #chat-widget-container {
        width: 512px;
        height: 600px;
        max-height: calc(100vh - 120px);
    }
}

@media (max-width: 640px) {
    .chat-widget-container,
    #chat-widget-container {
        width: calc(100vw - 40px);
        right: 20px;
        left: 20px;
    }

    .chat-report-bug-text {
        display: none;
    }
}

