/* Support Chat Widget */

.support-chat-toggle {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9990;
    width: 3.25rem;
    height: 3.25rem;
    border-radius: 50%;
    border: 1px solid var(--gray-200);
    background: white;
    color: var(--srw-charcoal);
    cursor: pointer;
    box-shadow: var(--shadow-md);
    display: flex;
    align-items: center;
    justify-content: center;
    transition:
        background var(--transition-fast),
        color var(--transition-fast),
        transform var(--transition-fast),
        box-shadow var(--transition-fast);
}
.support-chat-toggle:hover {
    background: var(--srw-charcoal);
    color: white;
    border-color: var(--srw-charcoal);
    transform: scale(1.05);
    box-shadow: var(--shadow-lg);
}
.support-chat-toggle svg {
    width: 1.375rem;
    height: 1.375rem;
}
.support-chat-icon-close {
    display: none;
}
.support-chat-toggle.active .support-chat-icon-open {
    display: none;
}
.support-chat-toggle.active .support-chat-icon-close {
    display: block;
}

/* Panel */
.support-chat-panel {
    position: fixed;
    bottom: 5.5rem;
    right: 1.5rem;
    z-index: 9989;
    width: 420px;
    max-height: min(640px, calc(100vh - 8rem));
    background: white;
    border-radius: 1rem;
    border: 1px solid var(--gray-200);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(12px) scale(0.96);
    transition:
        opacity var(--transition-normal),
        visibility var(--transition-normal),
        transform var(--transition-normal);
}
.support-chat-panel.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}
@starting-style {
    .support-chat-panel.active {
        opacity: 0;
        transform: translateY(12px) scale(0.96);
    }
}

/* Header */
.support-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
    flex-shrink: 0;
}
.support-chat-header-title {
    font-weight: 700;
    font-size: 0.9375rem;
    color: var(--srw-charcoal);
    letter-spacing: -0.02em;
}
.support-chat-header-status {
    display: block;
    font-size: 0.75rem;
    color: var(--gray-400);
    margin-top: 0.125rem;
}
.support-chat-close {
    width: 2rem;
    height: 2rem;
    border-radius: 0.375rem;
    border: none;
    background: transparent;
    color: var(--gray-400);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background var(--transition-fast), color var(--transition-fast);
}
.support-chat-close:hover {
    background: var(--gray-100);
    color: var(--srw-charcoal);
}
.support-chat-close svg {
    width: 1.125rem;
    height: 1.125rem;
}

/* Messages */
.support-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.support-chat-messages::-webkit-scrollbar {
    width: 4px;
}
.support-chat-messages::-webkit-scrollbar-track {
    background: transparent;
}
.support-chat-messages::-webkit-scrollbar-thumb {
    background: var(--gray-200);
    border-radius: 2px;
}

/* Message bubbles */
.support-chat-message {
    display: flex;
    max-width: 88%;
}
.support-chat-message-user {
    align-self: flex-end;
}
.support-chat-message-assistant {
    align-self: flex-start;
}
.support-chat-bubble {
    padding: 0.625rem 0.875rem;
    border-radius: 0.875rem;
    font-size: 0.875rem;
    line-height: 1.4;
    word-break: break-word;
}
.support-chat-message-user .support-chat-bubble {
    background: var(--srw-charcoal);
    color: white;
    border-bottom-right-radius: 0.25rem;
}
.support-chat-message-assistant .support-chat-bubble {
    background: var(--gray-100);
    color: var(--srw-charcoal);
    border-bottom-left-radius: 0.25rem;
}

/* Links in bubbles */
.support-chat-bubble a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    overflow-wrap: anywhere;
}
.support-chat-message-user .support-chat-bubble a {
    color: white;
}

/* Formatted content in assistant bubbles */
.support-chat-message-assistant .support-chat-bubble ul,
.support-chat-message-assistant .support-chat-bubble ol {
    margin: 0.375rem 0;
    padding-left: 1.25rem;
}
.support-chat-message-assistant .support-chat-bubble ul {
    list-style: disc;
}
.support-chat-message-assistant .support-chat-bubble ol {
    list-style: decimal;
}
.support-chat-message-assistant .support-chat-bubble li {
    margin: 0.1875rem 0;
}
.support-chat-message-assistant .support-chat-bubble li:last-child {
    margin-bottom: 0;
}
.support-chat-message-assistant .support-chat-bubble strong {
    font-weight: 600;
}

/* Typing indicator */
.support-chat-typing {
    display: inline-flex;
    padding: 0.625rem 0.875rem;
    align-items: center;
}
.support-chat-typing svg {
    width: 1.125rem;
    height: 1.125rem;
    color: var(--gray-400);
    animation: supportChatWrite 1s ease-in-out infinite;
}
@keyframes supportChatWrite {
    0%, 100% { transform: translateX(0) rotate(0deg); opacity: 0.5; }
    50% { transform: translateX(2px) rotate(-4deg); opacity: 1; }
}

/* Input bar */
.support-chat-form {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--gray-200);
    flex-shrink: 0;
}
.support-chat-form input {
    flex: 1;
    min-width: 0;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-200);
    border-radius: 0.625rem;
    font-size: 1rem;
    font-family: inherit;
    background: var(--gray-50);
    color: var(--srw-charcoal);
    transition: border-color var(--transition-fast);
}
.support-chat-form input::placeholder {
    color: var(--gray-400);
}
.support-chat-form input:focus {
    outline: none;
    border-color: var(--srw-charcoal);
    background: white;
}
.support-chat-form button[type="submit"] {
    width: 2.25rem;
    height: 2.25rem;
    border-radius: 0.625rem;
    border: none;
    background: var(--srw-charcoal);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity var(--transition-fast);
}
.support-chat-form button[type="submit"]:disabled {
    opacity: 0.35;
    cursor: default;
}
.support-chat-form button[type="submit"]:not(:disabled):hover {
    opacity: 0.85;
}
.support-chat-form button[type="submit"] svg {
    width: 1.125rem;
    height: 1.125rem;
}

/* Escalation notice */
.support-chat-escalation {
    padding: 0.75rem 1rem;
    background: var(--gray-50);
    border-top: 1px solid var(--gray-200);
    text-align: center;
    font-size: 0.8125rem;
    color: var(--gray-500);
    flex-shrink: 0;
}
.support-chat-escalation a {
    color: var(--srw-charcoal);
    font-weight: 600;
    text-decoration: underline;
    text-underline-offset: 2px;
}

/* Mobile: full screen */
@media (max-width: 640px) {
    .support-chat-panel {
        inset: 0;
        width: 100%;
        max-height: 100%;
        border-radius: 0;
        border: none;
        bottom: 0;
        right: 0;
        transform: translateY(100%);
    }
    .support-chat-panel.active {
        transform: translateY(0);
    }
    @starting-style {
        .support-chat-panel.active {
            transform: translateY(100%);
        }
    }
    .support-chat-header {
        padding-top: max(1rem, env(safe-area-inset-top));
    }
    .support-chat-form {
        padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    }
    .support-chat-form input {
        padding: 0.625rem 0.75rem;
    }
    .support-chat-form button[type="submit"] {
        width: 2.5rem;
        height: 2.5rem;
    }
    .support-chat-toggle.active {
        display: none;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    .support-chat-panel,
    .support-chat-toggle {
        transition: none !important;
    }
    .support-chat-typing svg {
        animation: none !important;
        opacity: 0.5;
    }
}
