/* Floating chat widget — messenger UI */

.site-chat-widget {
    --site-chat-offset: 0px;
    --site-chat-primary: var(--ui-primary, #4334A1);
    --site-chat-primary-light: var(--ui-primary-light, #5B46D9);
    --site-chat-primary-soft: rgba(67, 52, 161, 0.1);
    --site-chat-border: var(--ui-border, #e8e8ec);
    --site-chat-bg: var(--ui-bg, #fff);
    --site-chat-bg-soft: var(--ui-bg-soft, #f8f7fc);
    --site-chat-text: var(--ui-text, #1a1a2e);
    --site-chat-text-body: var(--ui-text-body, #444);
    --site-chat-muted: var(--ui-text-muted, #666);
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 900;
    pointer-events: none;
}

.site-chat-widget__launcher,
.site-chat-widget__panel {
    pointer-events: auto;
}

/* ── Launcher ── */

.site-chat-widget__launcher {
    position: fixed;
    right: 24px;
    bottom: calc(24px + var(--site-chat-offset));
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 54px;
    padding: 0 18px;
    border: none;
    border-radius: 28px;
    background: linear-gradient(135deg, var(--site-chat-primary) 0%, var(--site-chat-primary-light) 100%);
    color: #fff;
    font-size: 15px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(67, 52, 161, 0.28);
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease;
}

.site-chat-widget__launcher:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(67, 52, 161, 0.34);
}

.site-chat-widget__launcher:focus-visible {
    outline: 2px solid var(--site-chat-primary-light);
    outline-offset: 3px;
}

.site-chat-widget__launcher-icon {
    display: inline-flex;
    flex-shrink: 0;
}

.site-chat-widget__launcher-icon--close {
    display: none;
}

.site-chat-widget.is-open .site-chat-widget__launcher-icon--chat {
    display: none;
}

.site-chat-widget.is-open .site-chat-widget__launcher-icon--close {
    display: inline-flex;
}

.site-chat-widget__launcher-dot {
    position: absolute;
    top: 10px;
    right: 14px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #22c55e;
    border: 2px solid #fff;
}

.site-chat-widget.is-open .site-chat-widget__launcher-dot {
    display: none;
}

/* ── Panel ── */

.site-chat-widget__panel {
    position: fixed;
    right: 24px;
    bottom: calc(92px + var(--site-chat-offset));
    width: 400px;
    height: 580px;
    max-height: calc(100vh - 120px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--site-chat-bg);
    border: 1px solid var(--site-chat-border);
    border-radius: 20px;
    box-shadow:
        0 24px 56px rgba(26, 26, 46, 0.14),
        0 10px 24px rgba(67, 52, 161, 0.1);
    opacity: 0;
    transform: translateY(10px) scale(0.98);
    visibility: hidden;
    transition:
        opacity 0.2s ease,
        transform 0.2s ease,
        visibility 0.2s ease;
}

.site-chat-widget.is-open .site-chat-widget__panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    visibility: visible;
}

.site-chat-widget__panel[hidden] {
    display: flex;
}

/* ── Header ── */

.site-chat-widget__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 76px;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--site-chat-primary) 0%, var(--site-chat-primary-light) 100%);
    color: #fff;
    flex-shrink: 0;
}

.site-chat-widget__header-main {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.site-chat-widget__avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    border: 1px solid rgba(255, 255, 255, 0.22);
    flex-shrink: 0;
}

.site-chat-widget__avatar img {
    display: block;
    width: 24px;
    height: auto;
    filter: brightness(0) invert(1);
}

.site-chat-widget__brand {
    font-family: var(--ui-font-display, 'Loos Normal', sans-serif);
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
}

.site-chat-widget__role {
    margin-top: 2px;
    font-size: 13px;
    line-height: 1.3;
    opacity: 0.92;
}

.site-chat-widget__status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    font-size: 12px;
    line-height: 1.2;
    opacity: 0.88;
}

.site-chat-widget__status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.18);
}

.site-chat-widget__header-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.site-chat-widget__header-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.14);
    color: #fff;
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.18s ease;
}

.site-chat-widget__header-btn:hover {
    background: rgba(255, 255, 255, 0.24);
}

.site-chat-widget__header-btn:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* ── Messages ── */

.site-chat-widget__messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 18px 16px 12px;
    background: var(--site-chat-bg-soft);
    scrollbar-width: thin;
    scrollbar-color: rgba(67, 52, 161, 0.22) transparent;
}

.site-chat-widget__messages::-webkit-scrollbar {
    width: 6px;
}

.site-chat-widget__messages::-webkit-scrollbar-thumb {
    background: rgba(67, 52, 161, 0.22);
    border-radius: 999px;
}

.site-chat-widget__msg {
    display: flex;
    margin-bottom: 10px;
}

.site-chat-widget__msg--bot {
    justify-content: flex-start;
}

.site-chat-widget__msg--user {
    justify-content: flex-end;
}

.site-chat-widget__msg--system {
    justify-content: center;
}

.site-chat-widget__msg-bubble {
    max-width: 84%;
    padding: 11px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

.site-chat-widget__msg--bot .site-chat-widget__msg-bubble {
    background: #fff;
    color: var(--site-chat-text-body);
    border: 1px solid rgba(67, 52, 161, 0.08);
    border-bottom-left-radius: 6px;
}

.site-chat-widget__msg--user .site-chat-widget__msg-bubble {
    background: linear-gradient(135deg, var(--site-chat-primary) 0%, var(--site-chat-primary-light) 100%);
    color: #fff;
    border-bottom-right-radius: 6px;
}

.site-chat-widget__msg-system {
    max-width: 92%;
    padding: 8px 12px;
    border-radius: 10px;
    background: rgba(67, 52, 161, 0.08);
    color: var(--site-chat-muted);
    font-size: 12px;
    line-height: 1.45;
    text-align: center;
}

/* ── Quick reply chips ── */

.site-chat-widget__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
    margin-bottom: 6px;
}

.site-chat-widget__chip {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    border: 1px solid rgba(67, 52, 161, 0.18);
    border-radius: 999px;
    background: #fff;
    color: var(--site-chat-primary);
    font-size: 13px;
    font-weight: 600;
    line-height: 1.25;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.18s ease, border-color 0.18s ease, transform 0.18s ease;
}

.site-chat-widget__chip:hover {
    background: var(--site-chat-primary-soft);
    border-color: rgba(67, 52, 161, 0.3);
    transform: translateY(-1px);
}

.site-chat-widget__chip:focus-visible {
    outline: 2px solid var(--site-chat-primary-light);
    outline-offset: 2px;
}

/* ── System panel (no backend) ── */

.site-chat-widget__system {
    flex-shrink: 0;
    padding: 12px 16px;
    border-top: 1px solid var(--site-chat-border);
    background: #fff;
}

.site-chat-widget__system[hidden] {
    display: none;
}

.site-chat-widget__system-text {
    margin: 0;
    font-size: 13px;
    line-height: 1.45;
    color: var(--site-chat-text-body);
}

.site-chat-widget__system-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.site-chat-widget__system-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 14px;
    border-radius: 10px;
    border: 1px solid var(--site-chat-border);
    background: #fff;
    color: var(--site-chat-text-body);
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.18s ease, border-color 0.18s ease;
}

.site-chat-widget__system-btn--primary {
    color: #fff;
    border-color: transparent;
    background: linear-gradient(135deg, var(--site-chat-primary) 0%, var(--site-chat-primary-light) 100%);
}

.site-chat-widget__system-btn--primary:hover {
    filter: brightness(1.03);
}

.site-chat-widget__system-btn--tg {
    color: #229ed9;
    border-color: rgba(34, 158, 217, 0.2);
    background: rgba(34, 158, 217, 0.06);
}

.site-chat-widget__system-btn--wa {
    color: #25d366;
    border-color: rgba(37, 211, 102, 0.2);
    background: rgba(37, 211, 102, 0.06);
}

.site-chat-widget__system-btn:focus-visible {
    outline: 2px solid var(--site-chat-primary-light);
    outline-offset: 2px;
}

/* ── Composer ── */

.site-chat-widget__composer {
    flex-shrink: 0;
    padding: 12px 14px;
    border-top: 1px solid var(--site-chat-border);
    background: #fff;
}

.site-chat-widget__composer-label {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.site-chat-widget__composer-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}

.site-chat-widget__input {
    flex: 1 1 auto;
    min-height: 42px;
    max-height: 96px;
    resize: none;
    padding: 10px 14px;
    border: 1px solid var(--site-chat-border);
    border-radius: 14px;
    background: var(--site-chat-bg-soft);
    color: var(--site-chat-text);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.45;
    transition: border-color 0.18s ease, background-color 0.18s ease;
}

.site-chat-widget__input:focus {
    outline: none;
    border-color: rgba(67, 52, 161, 0.35);
    background: #fff;
}

.site-chat-widget__input::placeholder {
    color: var(--site-chat-muted);
}

.site-chat-widget__send {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--site-chat-primary) 0%, var(--site-chat-primary-light) 100%);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(67, 52, 161, 0.24);
    transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.site-chat-widget__send:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(67, 52, 161, 0.28);
}

.site-chat-widget__send:focus-visible {
    outline: 2px solid var(--site-chat-primary-light);
    outline-offset: 2px;
}

.site-chat-widget__send:disabled,
.site-chat-widget.is-sending .site-chat-widget__send {
    opacity: 0.65;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.site-chat-widget__hp {
    position: absolute;
    left: -9999px;
    width: 1px;
    height: 1px;
    overflow: hidden;
}

.site-chat-widget__composer-error {
    margin: 0 0 8px;
    padding: 8px 10px;
    border-radius: 10px;
    background: rgba(220, 53, 69, 0.08);
    color: #b42318;
    font-size: 12px;
    line-height: 1.45;
}

.site-chat-widget__composer-error[hidden] {
    display: none;
}

/* ── Footer messengers ── */

.site-chat-widget__footer {
    flex-shrink: 0;
    padding: 10px 14px 14px;
    border-top: 1px solid var(--site-chat-border);
    background: #fff;
}

.site-chat-widget__footer-label {
    font-size: 12px;
    line-height: 1.4;
    color: var(--site-chat-muted);
}

.site-chat-widget__footer-links {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.site-chat-widget__footer-link {
    flex: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
    border-radius: 10px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none;
    transition: background-color 0.18s ease;
}

.site-chat-widget__footer-link--tg {
    color: #229ed9;
    background: rgba(34, 158, 217, 0.08);
    border: 1px solid rgba(34, 158, 217, 0.16);
}

.site-chat-widget__footer-link--wa {
    color: #25d366;
    background: rgba(37, 211, 102, 0.08);
    border: 1px solid rgba(37, 211, 102, 0.16);
}

.site-chat-widget__footer-link:focus-visible {
    outline: 2px solid var(--site-chat-primary-light);
    outline-offset: 2px;
}

/* ── Mobile ── */

@media (max-width: 640px) {
    .site-chat-widget {
        right: 16px;
        bottom: 16px;
    }

    .site-chat-widget__launcher {
        right: 16px;
        bottom: calc(80px + var(--site-chat-offset));
        min-height: 52px;
        width: 52px;
        padding: 0;
        border-radius: 50%;
    }

    .site-chat-widget__launcher-text {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .site-chat-widget__launcher-dot {
        top: 8px;
        right: 8px;
    }

    .site-chat-widget__panel {
        left: 8px;
        right: 8px;
        bottom: calc(72px + var(--site-chat-offset));
        width: auto;
        height: min(620px, calc(100vh - 90px));
        border-radius: 18px;
    }

    .site-chat-widget__header {
        min-height: 68px;
        padding: 12px 14px;
    }

    .site-chat-widget__chips,
    .site-chat-widget__system-actions,
    .site-chat-widget__footer-links {
        flex-direction: column;
    }

    .site-chat-widget__chip,
    .site-chat-widget__system-btn,
    .site-chat-widget__footer-link {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .site-chat-widget__panel,
    .site-chat-widget__launcher,
    .site-chat-widget__chip,
    .site-chat-widget__send {
        transition: none;
    }

    .site-chat-widget__panel {
        transform: none;
    }

    .site-chat-widget.is-open .site-chat-widget__panel {
        transform: none;
    }
}
