/* ===========================================
   DUEL Chat Widget - Modern Redesign
   Consistent with DUEL Design System
   =========================================== */

/* ===== CSS Variables (inherited from site) ===== */
:root {
    --chat-primary: var(--color-accent, #e50914);
    --chat-primary-glow: var(--color-accent-glow, rgba(229, 9, 20, 0.4));
    --chat-bg: var(--color-bg-secondary, #141414);
    --chat-surface: var(--color-surface, #1a1a1a);
    --chat-text: var(--color-text-primary, #ffffff);
    --chat-text-muted: var(--color-text-muted, rgba(255, 255, 255, 0.5));
    --chat-border: rgba(255, 255, 255, 0.08);
    --chat-glass: rgba(20, 20, 20, 0.85);
}

/* ===== Floating Action Button ===== */
.chat-widget-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    background: linear-gradient(135deg, var(--chat-primary) 0%, #b81d24 100%);
    border-radius: 50%;
    box-shadow:
        0 4px 20px var(--chat-primary-glow),
        0 0 0 0 var(--chat-primary-glow);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    z-index: 9999;
    border: none;
    transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    animation: pulse-glow 3s ease-in-out infinite;
}

@keyframes pulse-glow {

    0%,
    100% {
        box-shadow: 0 4px 20px var(--chat-primary-glow), 0 0 0 0 var(--chat-primary-glow);
    }

    50% {
        box-shadow: 0 4px 30px var(--chat-primary-glow), 0 0 0 8px rgba(229, 9, 20, 0);
    }
}

.chat-widget-btn:hover {
    transform: scale(1.1) translateY(-2px);
    box-shadow: 0 8px 40px var(--chat-primary-glow);
    animation: none;
}

.chat-widget-btn:active {
    transform: scale(0.95);
}

.chat-widget-btn svg {
    width: 28px;
    height: 28px;
    fill: white;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chat-widget-btn.is-open svg {
    transform: rotate(180deg);
}

/* ===== Chat Window ===== */
.chat-window {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 400px;
    height: 580px;
    max-height: calc(100vh - 140px);
    max-height: calc(100dvh - 140px);
    background: var(--chat-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--chat-border);
    border-radius: 24px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow:
        0 24px 80px rgba(0, 0, 0, 0.6),
        0 0 100px rgba(229, 9, 20, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.05);
    z-index: 9998;

    /* Hidden state */
    visibility: hidden;
    opacity: 0;
    transform: translateY(24px) scale(0.92);
    pointer-events: none;
    transition:
        visibility 0s 0.3s,
        opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1),
        transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chat-window.is-visible {
    visibility: visible;
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
    transition:
        visibility 0s,
        opacity 0.3s cubic-bezier(0.16, 1, 0.3, 1),
        transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ===== Header ===== */
.chat-header {
    padding: 16px 20px;
    background: linear-gradient(180deg, rgba(229, 9, 20, 0.15) 0%, transparent 100%);
    border-bottom: 1px solid var(--chat-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 14px;
    flex: 1;
    min-width: 0;
}

.chat-avatar {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--chat-surface);
    border: 2px solid var(--chat-primary);
    box-shadow: 0 0 20px var(--chat-primary-glow);
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

/* Online pulse indicator - positioned outside overflow */
.chat-avatar::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: #22c55e;
    border-radius: 50%;
    border: 2px solid var(--chat-bg);
    z-index: 10;
    animation: online-pulse 2s ease-in-out infinite;
}

@keyframes online-pulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.5);
    }

    50% {
        box-shadow: 0 0 0 6px rgba(34, 197, 94, 0);
    }
}

.chat-title {
    min-width: 0;
}

.chat-title h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 700;
    font-family: var(--font-body, 'Inter', sans-serif);
    color: var(--chat-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-title p {
    margin: 2px 0 0;
    font-size: 12px;
    color: var(--chat-text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-online {
    color: #22c55e;
    font-weight: 600;
}

/* Close Button */
.chat-close-btn {
    display: none;
    width: 36px;
    height: 36px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--chat-border);
    border-radius: 50%;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.chat-close-btn:hover {
    background: rgba(255, 255, 255, 0.12);
    transform: rotate(90deg);
}

.chat-close-btn svg {
    width: 18px;
    height: 18px;
    fill: var(--chat-text);
}

/* ===== Messages Area ===== */
.chat-messages {
    flex: 1;
    padding: 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;

    /* Custom scrollbar */
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.15) transparent;
}

.chat-messages::-webkit-scrollbar {
    width: 5px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.15);
    border-radius: 10px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.25);
}

/* ===== Message Bubbles ===== */
.message {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: 20px;
    font-size: 14px;
    line-height: 1.55;
    word-wrap: break-word;
    animation: message-in 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
    opacity: 0;
    transform: translateY(12px) scale(0.95);
}

@keyframes message-in {
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Bot messages */
.message.bot {
    align-self: flex-start;
    background: var(--chat-surface);
    color: var(--chat-text);
    border-bottom-left-radius: 6px;
    border: 1px solid var(--chat-border);
}

/* User messages */
.message.user {
    align-self: flex-end;
    background: linear-gradient(135deg, var(--chat-primary) 0%, #b81d24 100%);
    color: white;
    border-bottom-right-radius: 6px;
    box-shadow: 0 4px 16px var(--chat-primary-glow);
}

/* ===== Rich Message Formatting ===== */
.message.bot strong {
    color: #ff6b6b;
    font-weight: 600;
}

.message.bot em {
    color: #ffd93d;
    font-style: italic;
}

/* Headers in messages */
.message .chat-header {
    padding: 0;
    background: none;
    border: none;
    margin: 10px 0 6px 0;
    font-weight: 700;
    display: block;
}

.message .chat-header:first-child {
    margin-top: 0;
}

.message .chat-header--h2 {
    color: #ff6b6b;
    font-size: 14px;
    padding-bottom: 4px;
    border-bottom: 1px solid rgba(255, 107, 107, 0.2);
}

.message .chat-header--h3 {
    color: #ffd93d;
    font-size: 13px;
}

/* Highlighted blocks */
.chat-highlight {
    background: linear-gradient(90deg, rgba(229, 9, 20, 0.15) 0%, transparent 100%);
    padding: 8px 12px;
    border-left: 3px solid var(--chat-primary);
    margin: 8px 0;
    border-radius: 0 12px 12px 0;
    font-weight: 500;
}

/* VS separator */
.chat-vs {
    text-align: center;
    font-weight: 700;
    color: #ff6b6b;
    padding: 6px 0;
    font-size: 13px;
    letter-spacing: 1px;
}

/* List items */
.chat-list-item {
    padding: 4px 0 4px 18px;
    position: relative;
}

.chat-list-item::before {
    content: '';
    position: absolute;
    left: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 5px;
    height: 5px;
    background: var(--chat-primary);
    border-radius: 50%;
}

/* Separators */
.chat-separator {
    border: none;
    border-top: 1px solid var(--chat-border);
    margin: 10px 0;
}

/* Clickable Links */
.chat-link {
    color: #ff6b6b;
    text-decoration: none;
    font-weight: 500;
    border-bottom: 1px solid rgba(255, 107, 107, 0.3);
    transition: all 0.2s ease;
    padding-bottom: 1px;
}

.chat-link:hover {
    color: #ff8a8a;
    border-bottom-color: #ff8a8a;
}

/* ===== Input Area ===== */
.chat-input-area {
    padding: 16px 20px;
    background: linear-gradient(180deg, transparent 0%, rgba(0, 0, 0, 0.3) 100%);
    border-top: 1px solid var(--chat-border);
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-input {
    flex: 1;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--chat-border);
    border-radius: 24px;
    padding: 12px 18px;
    color: var(--chat-text);
    font-family: var(--font-body, 'Inter', sans-serif);
    font-size: 14px;
    outline: none;
    transition: all 0.25s ease;
}

.chat-input::placeholder {
    color: var(--chat-text-muted);
}

.chat-input:focus {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(229, 9, 20, 0.5);
    box-shadow: 0 0 0 3px rgba(229, 9, 20, 0.1);
}

/* Send Button */
.chat-send-btn {
    width: 46px;
    height: 46px;
    background: linear-gradient(135deg, var(--chat-primary) 0%, #b81d24 100%);
    border: none;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    flex-shrink: 0;
    box-shadow: 0 4px 16px var(--chat-primary-glow);
}

.chat-send-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 24px var(--chat-primary-glow);
}

.chat-send-btn:active {
    transform: scale(0.95);
}

.chat-send-btn svg {
    width: 20px;
    height: 20px;
    fill: white;
    margin-left: 2px;
    transition: transform 0.2s ease;
}

.chat-send-btn:hover svg {
    transform: translateX(2px);
}

.chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

/* ===== Typing Indicator ===== */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 8px 16px !important;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 50%;
    animation: typing-bounce 1.4s ease-in-out infinite both;
}

.typing-dot:nth-child(1) {
    animation-delay: 0s;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing-bounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* ===== Mobile Responsive ===== */
@media (max-width: 480px) {
    .chat-widget-btn {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }

    .chat-widget-btn svg {
        width: 24px;
        height: 24px;
    }

    .chat-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 100%;
        max-height: none;
        border-radius: 0;
        z-index: 10000;
        /* Prevent iOS bounce scroll */
        overscroll-behavior: contain;
    }

    /* Ensure header stays at top */
    .chat-window .chat-header {
        flex-shrink: 0;
        position: sticky;
        top: 0;
        z-index: 10;
    }

    /* Messages area fills remaining space */
    .chat-window .chat-messages {
        flex: 1;
        min-height: 0;
        /* Important for flex shrinking */
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Input area stays at bottom */
    .chat-window .chat-input-area {
        flex-shrink: 0;
        position: sticky;
        bottom: 0;
        z-index: 10;
        background: var(--chat-bg);
    }

    .chat-header {
        padding: 14px 16px;
        padding-top: max(14px, env(safe-area-inset-top));
    }

    .chat-close-btn {
        display: flex;
    }

    .chat-messages {
        padding: 16px;
    }

    .chat-input-area {
        padding: 14px 16px;
        padding-bottom: max(14px, env(safe-area-inset-bottom));
    }

    .message {
        max-width: 90%;
    }
}

/* ===== Tablet Adjustments ===== */
@media (min-width: 481px) and (max-width: 768px) {
    .chat-window {
        width: 380px;
        right: 20px;
        bottom: 90px;
    }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {

    .chat-widget-btn,
    .chat-window,
    .message,
    .typing-dot {
        animation: none;
        transition: opacity 0.2s ease;
    }

    .chat-widget-btn:hover {
        transform: none;
    }
}

/* ===== High Contrast Mode ===== */
@media (prefers-contrast: high) {
    .chat-window {
        border: 2px solid var(--chat-text);
    }

    .message.bot {
        border: 1px solid var(--chat-text);
    }

    .chat-input {
        border: 2px solid var(--chat-text);
    }
}