/**
 * Chat Widget – single source of truth for layout and z-index.
 * Z-index below minicart (cart drawer uses z-30) so chat never overlaps it.
 * BEM: .chat-widget (block), .chat-widget__element, .chat-widget--modifier.
 */

:root {
    --chat-z: 20;
    --chat-primary: #187139;
    --chat-primary-hover: #005d22;
    --chat-border: #e5e7eb;
    --chat-bg-muted: #f3f4f5;
    --chat-text-muted: #6b7280;
    --chat-radius: 8px;
}

/* ---- Trigger (floating button) ---- */
.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: var(--chat-z);
    cursor: pointer;
    background: transparent;
    animation: chat-trigger-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: var(--chat-primary);
    stroke: none;
    animation: chat-icon-wiggle 4s ease-in-out infinite;
}

.chat-widget-trigger__icon path { fill: var(--chat-primary); stroke: none; }

.chat-widget-trigger__text {
    color: var(--chat-primary);
    font-size: 12px;
    font-weight: 600;
}

@keyframes chat-trigger-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); }
}

/* ---- Container (popup) ---- */
.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: #fff;
    border-radius: var(--chat-radius);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    display: none;
    flex-direction: column;
    z-index: var(--chat-z);
    overflow: hidden;
}

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

/* ---- Header ---- */
.chat-widget__header {
    background-color: var(--chat-primary);
    color: #fff;
    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-widget__header .chat-widget__btn-icon {
    background: transparent;
    border: 0;
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-widget__header .chat-widget__btn-icon:hover { opacity: 0.8; }

/* ---- Messages ---- */
.chat-widget__messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background-color: var(--chat-bg-muted);
}

.chat-widget__messages-inner { padding: 20px; }

.chat-widget__message-row { display: flex; margin-bottom: 16px; }
.chat-widget__message-row--visitor { justify-content: flex-end; }
.chat-widget__message-row--operator { justify-content: flex-start; }

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

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

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

.chat-widget__bubble--visitor { background-color: var(--chat-primary); color: #fff; }
.chat-widget__bubble--operator {
    background-color: #fff;
    color: #1f2937;
    border: 1px solid var(--chat-border);
}

.chat-widget__disclaimer { display: flex; justify-content: flex-start; margin-bottom: 16px; }
.chat-widget__disclaimer span { font-size: 11px; color: var(--chat-text-muted); max-width: 75%; }

.chat-widget__contact-msg { display: flex; justify-content: flex-start; margin-bottom: 16px; }
.chat-widget__contact-msg-bubble {
    max-width: 85%;
    padding: 16px;
    border-radius: 16px;
    overflow-wrap: break-word;
    background-color: #fff;
    color: #1f2937;
}

/* ---- Report bug button (footer only; inline link, no overlay) ---- */
#chat-report-bug.chat-widget__report-btn--footer,
.chat-widget__report-btn--footer {
    position: static !important;
    display: inline-flex !important;
    align-items: center !important;
    flex-wrap: nowrap;
    cursor: pointer;
    /* Padding/border/background from Tailwind in template (Hyva footer) */
}
.chat-widget__report-btn--footer svg {
    flex-shrink: 0;
    vertical-align: middle;
    align-self: center;
}

/* ---- Bug report form ---- */
.chat-widget__bug-form {
    display: none;
    flex-direction: column;
    gap: 12px;
}

.chat-widget__bug-form.hidden { display: none; }
.chat-widget__bug-form:not(.hidden) { display: flex; }

.chat-widget__bug-form .chat-widget__field { display: flex; flex-direction: column; gap: 4px; }
.chat-widget__bug-form label { font-size: 12px; font-weight: 600; color: #4b5563; margin-bottom: 0; }
.chat-widget__bug-form input,
.chat-widget__bug-form textarea {
    padding: 4px 8px;
    border: 1px solid var(--chat-border);
    border-radius: 4px;
    font-size: 12px;
}

.chat-widget__bug-form input:focus,
.chat-widget__bug-form textarea:focus {
    outline: none;
    border-color: var(--chat-primary);
}

.chat-widget__bug-form input[readonly] { background-color: #f9fafb; cursor: not-allowed; }
.chat-widget__bug-form .chat-widget__actions { display: flex; gap: 8px; }

.chat-widget__btn-primary {
    flex: 1;
    padding: 8px;
    background-color: var(--chat-primary);
    color: #fff;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background-color 0.3s ease;
}

.chat-widget__btn-primary:hover { background-color: var(--chat-primary-hover); }

.chat-widget__btn-secondary {
    padding: 8px;
    background-color: var(--chat-border);
    color: #374151;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background-color 0.3s ease;
}

.chat-widget__btn-secondary:hover { background-color: #d1d5db; }

/* ---- Input area ---- */
.chat-widget__input-wrap {
    position: relative;
    padding: 16px;
    background-color: #fff;
    border-top: 1px solid var(--chat-border);
}

.chat-widget__input {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--chat-border);
    border-radius: 9999px;
    resize: none;
    font-family: inherit;
    font-size: 14px;
    min-height: 40px;
    max-height: 96px;
}

.chat-widget__input:focus { outline: none; border-color: var(--chat-primary); }

.chat-widget__send {
    margin-top: 10px;
    width: 100%;
    padding: 10px;
    background-color: var(--chat-primary);
    color: #fff;
    border: 0;
    border-radius: 9999px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: background-color 0.3s ease;
}

.chat-widget__send:hover { background-color: var(--chat-primary-hover); }
.chat-widget__send:disabled { background-color: #d1d5db; cursor: not-allowed; }

/* ---- Contact form (post-chat) ---- */
.chat-widget__contact-wrap {
    padding: 16px;
    background-color: #fef3c7;
    border-top: 1px solid var(--chat-border);
    display: none;
}

.chat-widget__contact-wrap:not(.hidden) { display: block; }

.chat-widget__contact-form { display: flex; flex-direction: column; gap: 10px; }
.chat-widget__contact-form .chat-widget__contact-name,
.chat-widget__contact-form .chat-widget__contact-email {
    padding: 10px;
    border: 1px solid var(--chat-border);
    border-radius: 4px;
    font-size: 14px;
}

.chat-widget__contact-form button[type="submit"] {
    padding: 10px;
    background-color: var(--chat-primary);
    color: #fff;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
}

.chat-widget__contact-form button[type="submit"]:hover { background-color: var(--chat-primary-hover); }

/* ---- Dynamic content (classes set by JS – keep in sync with chat-widget-standalone.js) ---- */
.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; font-size: 14px; }
.chat-message-bubble.visitor-message { background-color: var(--chat-primary); color: #fff; }
.chat-message-bubble.operator-message { background-color: #fff; color: #1f2937; border: 1px solid var(--chat-border); }
.chat-gpt-disclaimer { display: flex; justify-content: flex-start; margin-bottom: 16px; }
.chat-gpt-disclaimer span { font-size: 11px; color: var(--chat-text-muted); max-width: 75%; }
#chat-contact-form-message { display: flex; justify-content: flex-start; margin-bottom: 12px; }
.chat-contact-form-message-bubble {
    max-width: 85%;
    padding: 10px 12px;
    border-radius: 12px;
    overflow-wrap: break-word;
    background-color: #fff;
    color: #1f2937;
}
/* Compact contact form (title + inputs + button) */
.chat-contact-form-message-bubble > div:first-child {
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    line-height: 1.3;
}
#chat-contact-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
#chat-contact-name,
#chat-contact-email,
#chat-contact-form button[type="submit"] {
    padding: 6px 10px !important;
    font-size: 13px !important;
    border-radius: 6px;
}
#chat-contact-form button[type="submit"] {
    margin-top: 0;
}
#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,
.chat-widget__bug-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 var(--chat-border); border-radius: 4px; font-size: 12px; }
#bug-report-form input:focus, #bug-report-form textarea:focus { outline: none; border-color: var(--chat-primary); }
#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: var(--chat-primary); color: #fff; border: 0; border-radius: 4px; cursor: pointer; font-size: 14px; font-weight: 600; }
#bug-report-submit:hover { background-color: var(--chat-primary-hover); }
#bug-report-cancel { padding: 8px; background-color: var(--chat-border); color: #374151; border: 0; border-radius: 4px; cursor: pointer; font-size: 14px; font-weight: 600; }
#bug-report-cancel:hover { background-color: #d1d5db; }

/* ---- Responsive ---- */
@media (min-width: 641px) {
    .chat-widget-container {
        width: 560px;
        height: 640px;
        max-height: calc(100vh - 120px);
    }
}

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

/* ---- CustomerNotify banner (logged-in customer with open availability requests) ---- */
.chat-widget__notify-banner {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
    background-color: #fff7ed;
    border-bottom: 1px solid #fed7aa;
    max-height: 40%;
    overflow-y: auto;
}

.chat-widget__notify-banner[hidden] {
    display: none;
}

.chat-widget__notify-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 10px;
    background-color: #fff;
    border: 1px solid #fed7aa;
    border-radius: var(--chat-radius);
}

.chat-widget__notify-title {
    font-size: 13px;
    font-weight: 600;
    color: #9a3412;
}

.chat-widget__notify-body {
    font-size: 13px;
    color: #374151;
    line-height: 1.3;
}

.chat-widget__notify-items {
    margin: 2px 0 0 0;
    padding-left: 18px;
    font-size: 12px;
    color: #4b5563;
    line-height: 1.3;
}

.chat-widget__notify-cta {
    align-self: flex-start;
    margin-top: 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--chat-primary);
    text-decoration: underline;
}

.chat-widget__notify-cta:hover {
    color: var(--chat-primary-hover);
}
