:root {
    --support-chat-primary: #e63946;
    --support-chat-primary-dark: #b00020;
    --support-chat-text: #0f172a;
    --support-chat-muted: #64748b;
    --support-chat-border: #e2e8f0;
    --support-chat-surface: #ffffff;
    --support-chat-surface-soft: #f8fafc;
    --support-chat-shadow: 0 24px 50px rgba(15, 23, 42, 0.16);
    --support-chat-shadow-soft: 0 12px 28px rgba(15, 23, 42, 0.12);
}

.support-chat-widget {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 120;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
    font-family: 'Poppins', sans-serif;
}

.support-chat-panel[hidden],
.support-chat-auth[hidden],
.support-chat-thread[hidden],
.support-chat-attachment[hidden] {
    display: none !important;
}

.support-chat-panel-avatar [hidden],
.support-chat-panel-avatar img[hidden],
.support-chat-panel-avatar-fallback[hidden] {
    display: none !important;
}

.support-chat-launcher {
    border: 0;
    background: linear-gradient(135deg, var(--support-chat-primary), var(--support-chat-primary-dark));
    color: #fff;
    min-height: 62px;
    border-radius: 20px;
    padding: 0 18px 0 16px;
    display: inline-flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    box-shadow: var(--support-chat-shadow-soft);
    transition: transform 0.18s ease, box-shadow 0.18s ease, opacity 0.18s ease;
}

.support-chat-launcher:hover {
    transform: translateY(-1px);
    box-shadow: var(--support-chat-shadow);
}

.support-chat-widget.is-open .support-chat-launcher {
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
}

.support-chat-widget.is-auth-only .support-chat-panel {
    width: min(360px, calc(100vw - 24px));
    max-height: min(420px, calc(100vh - 110px));
}

.support-chat-widget.is-auth-only .support-chat-status-chip {
    display: none;
}

.support-chat-launcher-icon {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.18);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    overflow: hidden;
    flex: 0 0 42px;
}

.support-chat-launcher-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.support-chat-launcher-icon-fallback {
    width: 100%;
    height: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.support-chat-launcher-icon [hidden],
.support-chat-launcher-icon img[hidden],
.support-chat-launcher-icon-fallback[hidden] {
    display: none !important;
}

.support-chat-launcher-copy {
    display: grid;
    text-align: left;
}

.support-chat-launcher-copy strong {
    font-size: 0.97rem;
    line-height: 1.1;
}

.support-chat-launcher-copy small {
    font-size: 0.78rem;
    opacity: 0.88;
}

.support-chat-panel {
    width: min(390px, calc(100vw - 24px));
    max-height: min(680px, calc(100vh - 110px));
    background: var(--support-chat-surface);
    border: 1px solid rgba(226, 232, 240, 0.9);
    border-radius: 24px;
    box-shadow: var(--support-chat-shadow);
    overflow: hidden;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
}

.support-chat-panel-head {
    padding: 18px 18px 16px;
    background: linear-gradient(180deg, rgba(230, 57, 70, 0.08), rgba(255, 255, 255, 0));
    border-bottom: 1px solid var(--support-chat-border);
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
}

.support-chat-panel-brand {
    min-width: 0;
    display: flex;
    align-items: center;
    gap: 12px;
}

.support-chat-panel-avatar {
    width: 46px;
    height: 46px;
    border-radius: 16px;
    overflow: hidden;
    flex: 0 0 46px;
    background: linear-gradient(135deg, rgba(230, 57, 70, 0.12), rgba(176, 0, 32, 0.08));
    border: 1px solid rgba(230, 57, 70, 0.14);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.support-chat-panel-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.support-chat-panel-avatar-fallback {
    color: var(--support-chat-primary-dark);
    font-size: 1.02rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.support-chat-panel-brand-copy {
    min-width: 0;
}

.support-chat-panel-head strong {
    display: block;
    font-size: 1rem;
    color: var(--support-chat-text);
}

.support-chat-panel-head small {
    display: block;
    margin-top: 3px;
    color: var(--support-chat-muted);
}

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

.support-chat-status-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 10px;
    min-height: 30px;
    border-radius: 999px;
    background: rgba(226, 232, 240, 0.7);
    color: #334155;
    font-size: 0.74rem;
    font-weight: 600;
    white-space: nowrap;
}

.support-chat-status-chip.is-danger {
    background: rgba(230, 57, 70, 0.12);
    color: var(--support-chat-primary-dark);
}

.support-chat-status-chip.is-primary {
    background: rgba(29, 78, 216, 0.12);
    color: #1d4ed8;
}

.support-chat-status-chip.is-warning {
    background: rgba(245, 158, 11, 0.14);
    color: #b45309;
}

.support-chat-status-chip.is-success {
    background: rgba(22, 163, 74, 0.12);
    color: #166534;
}

.support-chat-status-chip.is-secondary {
    background: rgba(100, 116, 139, 0.12);
    color: #475569;
}

.support-chat-close {
    width: 34px;
    height: 34px;
    border-radius: 12px;
    border: 1px solid var(--support-chat-border);
    background: #fff;
    color: var(--support-chat-text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.support-chat-auth,
.support-chat-thread {
    min-height: 0;
}

.support-chat-auth {
    padding: 18px;
    display: grid;
    gap: 16px;
}

.support-chat-auth-copy h3 {
    margin: 0 0 8px;
    font-size: 1.06rem;
    color: var(--support-chat-text);
}

.support-chat-auth-copy p {
    margin: 0;
    color: var(--support-chat-muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

.support-chat-auth-form {
    display: grid;
    gap: 12px;
}

.support-chat-auth-form label {
    display: grid;
    gap: 6px;
    font-size: 0.82rem;
    color: var(--support-chat-text);
    font-weight: 600;
}

.support-chat-auth-form input,
.support-chat-compose textarea {
    width: 100%;
    border: 1px solid var(--support-chat-border);
    background: #fff;
    border-radius: 14px;
    padding: 12px 14px;
    font: inherit;
    color: var(--support-chat-text);
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.support-chat-auth-form input:focus,
.support-chat-compose textarea:focus {
    border-color: rgba(230, 57, 70, 0.5);
    box-shadow: 0 0 0 4px rgba(230, 57, 70, 0.08);
}

.support-chat-auth-form button,
.support-chat-send-btn {
    border: 0;
    border-radius: 14px;
    min-height: 46px;
    padding: 0 16px;
    font: inherit;
    font-weight: 600;
    color: #fff;
    background: linear-gradient(135deg, var(--support-chat-primary), var(--support-chat-primary-dark));
    cursor: pointer;
}

.support-chat-thread {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    min-height: 0;
}

.support-chat-thread-meta {
    padding: 14px 18px;
    border-bottom: 1px solid var(--support-chat-border);
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}

.support-chat-thread-meta strong {
    display: block;
    color: var(--support-chat-text);
}

.support-chat-thread-meta small {
    display: block;
    color: var(--support-chat-muted);
}

.support-chat-messages {
    min-height: 220px;
    max-height: 360px;
    overflow: auto;
    padding: 16px 18px;
    background:
        radial-gradient(circle at top left, rgba(230, 57, 70, 0.04), transparent 28%),
        var(--support-chat-surface-soft);
    display: grid;
    align-content: start;
    gap: 10px;
}

.support-chat-empty {
    min-height: 100%;
    display: grid;
    place-items: center;
    text-align: center;
    color: var(--support-chat-muted);
    font-size: 0.9rem;
    padding: 32px 18px;
}

.support-chat-row {
    display: flex;
}

.support-chat-row.is-customer {
    justify-content: flex-end;
}

.support-chat-row.is-admin,
.support-chat-row.is-system {
    justify-content: flex-start;
}

.support-chat-message {
    max-width: min(82%, 292px);
    display: grid;
    gap: 4px;
}

.support-chat-message-name,
.support-chat-message-meta {
    font-size: 0.72rem;
    color: var(--support-chat-muted);
}

.support-chat-row.is-customer .support-chat-message-name,
.support-chat-row.is-customer .support-chat-message-meta {
    text-align: right;
}

.support-chat-bubble,
.support-chat-system-bubble {
    border-radius: 18px;
    padding: 11px 13px;
    background: #fff;
    border: 1px solid rgba(226, 232, 240, 0.92);
    color: var(--support-chat-text);
    box-shadow: 0 8px 16px rgba(15, 23, 42, 0.06);
    overflow: hidden;
}

.support-chat-row.is-customer .support-chat-bubble {
    background: linear-gradient(135deg, var(--support-chat-primary), var(--support-chat-primary-dark));
    color: #fff;
    border-color: transparent;
}

.support-chat-system-bubble {
    background: rgba(15, 23, 42, 0.05);
    box-shadow: none;
    color: #334155;
    font-size: 0.84rem;
}

.support-chat-message-text {
    font-size: 0.88rem;
    line-height: 1.6;
    word-break: break-word;
}

.support-chat-message-attachment {
    margin-top: 10px;
    display: grid;
    gap: 8px;
}

.support-chat-message-attachment img {
    width: 100%;
    max-height: 190px;
    object-fit: cover;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.18);
}

.support-chat-message-attachment audio {
    width: 100%;
}

.support-chat-file-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(15, 23, 42, 0.06);
    color: inherit;
    font-size: 0.82rem;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.support-chat-row.is-customer .support-chat-file-link {
    background: rgba(255, 255, 255, 0.16);
}

.support-chat-attachment {
    padding: 0 18px 12px;
}

.support-chat-attachment-card {
    border: 1px solid var(--support-chat-border);
    background: #fff;
    border-radius: 16px;
    padding: 10px 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.support-chat-attachment-card strong {
    display: block;
    font-size: 0.82rem;
    color: var(--support-chat-text);
    overflow-wrap: anywhere;
}

.support-chat-attachment-card small {
    display: block;
    color: var(--support-chat-muted);
    font-size: 0.74rem;
}

.support-chat-attachment-clear {
    border: 0;
    background: rgba(230, 57, 70, 0.08);
    color: var(--support-chat-primary-dark);
    width: 34px;
    height: 34px;
    border-radius: 12px;
    cursor: pointer;
    flex: 0 0 auto;
}

.support-chat-compose {
    padding: 0 18px 18px;
    display: grid;
    gap: 12px;
}

.support-chat-compose textarea {
    min-height: 90px;
    resize: vertical;
    background: #fff;
}

.support-chat-compose-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.support-chat-file-btn,
.support-chat-audio-btn {
    min-height: 44px;
    padding: 0 14px;
    border-radius: 14px;
    border: 1px solid var(--support-chat-border);
    background: #fff;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--support-chat-text);
    cursor: pointer;
    font-size: 0.84rem;
    font-weight: 600;
}

.support-chat-file-btn input {
    display: none;
}

.support-chat-audio-btn.is-recording {
    border-color: rgba(230, 57, 70, 0.42);
    background: rgba(230, 57, 70, 0.08);
    color: var(--support-chat-primary-dark);
}

.support-chat-send-btn {
    margin-left: auto;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.support-chat-feedback {
    min-height: 22px;
    padding: 0 18px 16px;
    color: var(--support-chat-muted);
    font-size: 0.78rem;
}

.support-chat-feedback.is-error {
    color: #b91c1c;
}

.support-chat-feedback.is-success {
    color: #166534;
}

@media (max-width: 640px) {
    .support-chat-widget {
        left: 12px;
        right: 12px;
        bottom: 12px;
        align-items: stretch;
    }

    .support-chat-launcher {
        width: 100%;
        justify-content: center;
    }

    .support-chat-panel {
        width: 100%;
        max-height: min(78vh, 680px);
        border-radius: 22px;
    }

    .support-chat-widget.is-auth-only .support-chat-panel {
        width: 100%;
        max-height: min(64vh, 420px);
    }

    .support-chat-thread-meta,
    .support-chat-compose-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .support-chat-send-btn {
        margin-left: 0;
        justify-content: center;
    }
}
