/* Support chat widget (assets/js/chat-widget.js).
 * Selectors are scoped under .support-chat and kept more specific than the
 * global form rules of styles.css (button[type="submit"], input[type="text"]…). */

.support-chat {
    --chat-primary: var(--color-primary, #0047bb);
    --chat-primary-2: #2563a8;
    --chat-text: var(--color-text-primary, #333333);
    --chat-muted: var(--color-text-muted, #8a8a8a);
    --chat-border: var(--color-border, #e0e0e0);
    --chat-bg: var(--color-bg-lighter, #f8f9fa);
    font-family: 'Roboto', sans-serif;
    color: var(--chat-text);
}

.support-chat *,
.support-chat *::before,
.support-chat *::after {
    box-sizing: border-box;
}

/* ---------- launcher ---------- */
.support-chat .support-chat__launcher {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 9990;
    width: 60px;
    height: 60px;
    padding: 0;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-2) 100%);
    box-shadow: 0 6px 20px rgba(0, 71, 187, 0.4);
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.support-chat .support-chat__launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 26px rgba(0, 71, 187, 0.45);
}

.support-chat .support-chat__launcher:focus-visible {
    outline: 3px solid rgba(0, 71, 187, 0.35);
    outline-offset: 3px;
}

.support-chat__badge {
    position: fixed;
    right: 18px;
    bottom: 62px;
    z-index: 9991;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--color-accent, #ff671f);
    color: #ffffff;
    font-size: 12px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    pointer-events: none;
    opacity: 0;
    transform: scale(0.6);
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.support-chat.has-badge .support-chat__badge {
    opacity: 1;
    transform: scale(1);
}

/* ---------- panel ---------- */
.support-chat__panel {
    position: fixed;
    right: 20px;
    bottom: 92px;
    z-index: 9990;
    width: 370px;
    max-width: calc(100vw - 40px);
    height: 560px;
    max-height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #ffffff;
    border-radius: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
    opacity: 0;
    visibility: hidden;
    transform: translateY(16px) scale(0.98);
    transform-origin: bottom right;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s linear 0.2s;
}

.support-chat.is-open .support-chat__panel {
    opacity: 1;
    visibility: visible;
    transform: none;
    transition: opacity 0.2s ease, transform 0.2s ease, visibility 0s;
}

.support-chat__header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    color: #ffffff;
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-2) 100%);
}

.support-chat__avatar {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border-radius: 50%;
    background: #ffffff;
    padding: 4px;
    object-fit: contain;
}

.support-chat__heading {
    flex: 1 1 auto;
    min-width: 0;
}

.support-chat .support-chat__title {
    margin: 0;
    color: #ffffff;
    font-size: 16px;
    font-weight: 700;
    line-height: 1.25;
}

.support-chat .support-chat__status {
    margin: 2px 0 0;
    color: #ffffff;
    font-size: 12px;
    line-height: 1.3;
    opacity: 0.9;
}

.support-chat__status::before {
    content: "";
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-right: 6px;
    border-radius: 50%;
    background: #22c55e;
    vertical-align: 0;
}

.support-chat .support-chat__close {
    width: 36px;
    height: 36px;
    flex: 0 0 36px;
    padding: 0;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    background: rgba(255, 255, 255, 0.12);
    cursor: pointer;
}

.support-chat .support-chat__close:hover {
    background: rgba(255, 255, 255, 0.24);
}

.support-chat__body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px;
    background: var(--chat-bg);
}

.support-chat__log {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* ---------- messages ---------- */
.support-chat__msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 15px;
    line-height: 1.45;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.support-chat__msg--bot {
    align-self: flex-start;
    background: #ffffff;
    border: 1px solid var(--chat-border);
    border-bottom-left-radius: 4px;
}

.support-chat__msg--user {
    align-self: flex-end;
    color: #ffffff;
    background: var(--chat-primary);
    border-bottom-right-radius: 4px;
}

.support-chat__typing {
    display: inline-flex;
    gap: 4px;
    padding: 14px 16px;
}

.support-chat__typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--chat-muted);
    animation: support-chat-dot 1s infinite ease-in-out;
}

.support-chat__typing span:nth-child(2) { animation-delay: 0.15s; }
.support-chat__typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes support-chat-dot {
    0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
    40% { opacity: 1; transform: translateY(-3px); }
}

.support-chat__quick {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.support-chat .support-chat__chip {
    padding: 7px 12px;
    border: 1px solid var(--chat-primary);
    border-radius: 999px;
    color: var(--chat-primary);
    background: #ffffff;
    font-family: inherit;
    font-size: 14px;
    line-height: 1.3;
    cursor: pointer;
    transition: background 0.2s ease, color 0.2s ease;
}

.support-chat .support-chat__chip:hover {
    color: #ffffff;
    background: var(--chat-primary);
}

/* ---------- composer ---------- */
.support-chat__composer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--chat-border);
    background: #ffffff;
}

.support-chat .support-chat__input {
    flex: 1 1 auto;
    min-width: 0;
    height: 44px;
    padding: 0 16px;
    border: 1px solid var(--chat-border);
    border-radius: 22px;
    font-family: inherit;
    font-size: 15px;
    color: var(--chat-text);
    background: #ffffff;
    box-shadow: none;
    outline: none;
}

.support-chat .support-chat__input:focus {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(0, 71, 187, 0.1);
}

.support-chat .support-chat__input:disabled {
    opacity: 1;
    background: var(--chat-bg);
    cursor: not-allowed;
}

.support-chat .support-chat__send {
    width: 44px;
    height: 44px;
    flex: 0 0 44px;
    padding: 0;
    border: none;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffffff;
    background: var(--chat-primary);
    cursor: pointer;
    transition: background 0.2s ease;
}

.support-chat .support-chat__send:hover:not(:disabled) {
    background: var(--color-primary-dark, #003a95);
}

.support-chat .support-chat__send:disabled {
    background: #9ca3af;
    cursor: not-allowed;
}

/* ---------- lead form ---------- */
.support-chat .support-chat__form {
    position: relative;
    align-self: stretch;
    margin: 0;
    padding: 14px;
    border: 1px solid var(--chat-border);
    border-radius: 12px;
    background: #ffffff;
}

.support-chat__group + .support-chat__group {
    margin-top: 10px;
}

.support-chat__label {
    display: block;
    margin-bottom: 4px;
    font-size: 13px;
    font-weight: 600;
    color: var(--chat-primary);
}

.support-chat__required {
    color: #e74c3c;
}

.support-chat .support-chat__form .support-chat__field {
    display: block;
    width: 100%;
    height: 46px;
    padding: 0 14px;
    border: 2px solid var(--chat-border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 15px;
    color: var(--chat-text);
    background: #ffffff;
    outline: none;
}

.support-chat .support-chat__form .support-chat__field:focus {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(0, 71, 187, 0.1);
}

.support-chat .support-chat__form input[name="phone"] {
    height: 46px !important;
}

.support-chat .support-chat__form .iti__flag-container,
.support-chat .support-chat__form .iti__selected-flag {
    border-top-left-radius: 8px !important;
    border-bottom-left-radius: 8px !important;
}

.support-chat .support-chat__form .iti__country-list {
    max-height: 180px;
    font-size: 14px;
}

.support-chat .support-chat__form .support-chat__submit {
    display: block;
    width: 100%;
    margin: 14px 0 0;
    padding: 13px 16px;
    border: none;
    border-radius: 8px;
    color: #ffffff;
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-2) 100%);
    box-shadow: 0 4px 15px rgba(0, 71, 187, 0.3);
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.support-chat .support-chat__form .support-chat__submit:hover:not(:disabled) {
    transform: translateY(-1px);
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-2) 100%);
    box-shadow: 0 6px 20px rgba(0, 71, 187, 0.4);
}

.support-chat .support-chat__form .support-chat__submit:disabled {
    opacity: 0.6;
    border: none;
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-2) 100%);
    box-shadow: none;
    transform: none;
    cursor: not-allowed;
}

.support-chat .support-chat__form .support-chat__submit:focus-visible {
    outline: 3px solid rgba(0, 71, 187, 0.35);
    outline-offset: 2px;
    box-shadow: none;
}

.support-chat .support-chat__note {
    margin: 10px 0 0;
    font-size: 12px;
    line-height: 1.4;
    color: var(--color-text-secondary, #666666);
    text-align: center;
}

.support-chat .support-chat__note a {
    color: var(--chat-primary);
    text-decoration: underline;
}

/* ---------- mobile ---------- */
@media (max-width: 480px) {
    .support-chat .support-chat__launcher {
        right: 16px;
        bottom: 16px;
        width: 56px;
        height: 56px;
    }

    .support-chat__badge {
        right: 14px;
        bottom: 56px;
    }

    .support-chat__panel {
        inset: 0;
        width: 100%;
        max-width: none;
        height: 100%;
        max-height: none;
        border-radius: 0;
        transform: translateY(24px);
    }

    .support-chat.is-open .support-chat__launcher {
        display: none;
    }

    html.support-chat-open,
    html.support-chat-open body {
        overflow: hidden;
    }
}

@media (prefers-reduced-motion: reduce) {
    .support-chat__panel,
    .support-chat .support-chat__launcher {
        transition: none;
    }
}
