/* Chat Widget */
.chat-widget {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 90;
    font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

.chat-toggle {
    position: relative;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
    cursor: pointer;
    box-shadow: 0 16px 40px rgba(79, 70, 229, 0.35);
    display: grid;
    place-items: center;
    transition: transform 0.25s ease, box-shadow 0.25s ease;
}

.chat-toggle:hover {
    transform: translateY(-3px) scale(1.04);
    box-shadow: 0 20px 50px rgba(79, 70, 229, 0.45);
}

.chat-toggle:focus-visible {
    outline: 3px solid rgba(79, 70, 229, 0.6);
    outline-offset: 4px;
}

.chat-toggle-icon {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    transition: transform 0.3s ease, opacity 0.3s ease;
    font-size: 1.6rem;
    pointer-events: none;
}

.chat-icon-close {
    transform: scale(0.4) rotate(-45deg);
    opacity: 0;
}

.chat-widget.is-open .chat-icon-open {
    transform: scale(0.4) rotate(45deg);
    opacity: 0;
}

.chat-widget.is-open .chat-icon-close {
    transform: scale(1) rotate(0);
    opacity: 1;
}

.chat-toggle-pulse {
    display: none;
}

.chat-toggle-hint {
    animation: chatBounce 0.55s ease 2;
}

@keyframes chatBounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-8px);
    }
}

/* Panel */
.chat-panel {
    position: absolute;
    right: 0;
    bottom: 80px;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 560px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border-radius: 22px;
    box-shadow: 0 30px 70px rgba(15, 23, 42, 0.2), 0 0 0 1px rgba(15, 23, 42, 0.05);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transform: translateY(20px) scale(0.95);
    opacity: 0;
    pointer-events: none;
    transition: transform 0.3s cubic-bezier(0.34, 1.4, 0.64, 1), opacity 0.25s ease;
}

.chat-widget.is-open .chat-panel {
    transform: translateY(0) scale(1);
    opacity: 1;
    pointer-events: auto;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 18px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(79, 70, 229, 0.06), rgba(79, 70, 229, 0));
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(79, 70, 229, 0.1), rgba(124, 58, 237, 0.1));
    display: grid;
    place-items: center;
    position: relative;
    flex: none;
}

.chat-avatar img {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.chat-avatar-status {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #10b981;
    border: 2px solid #fff;
}

.chat-meta {
    flex: 1;
    min-width: 0;
}

.chat-meta h3 {
    margin: 0;
    font-size: 0.97rem;
    letter-spacing: -0.01em;
    line-height: 1.2;
    color: var(--text);
}

.chat-online {
    font-size: 0.78rem;
    color: var(--text-muted);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.chat-online::before {
    content: "";
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10b981;
}

.chat-close {
    background: transparent;
    border: none;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    color: var(--text-muted);
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    font-size: 1.1rem;
}

.chat-close:hover {
    background: rgba(15, 23, 42, 0.06);
    color: var(--text);
}

.chat-body {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 20px 18px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: linear-gradient(180deg, #f8fafd 0%, #ffffff 100%);
    scrollbar-width: thin;
    scrollbar-color: rgba(15, 23, 42, 0.18) transparent;
}

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

.chat-body::-webkit-scrollbar-thumb {
    background: rgba(15, 23, 42, 0.18);
    border-radius: 3px;
}

.chat-msg {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 85%;
    animation: chatMsgIn 0.35s ease both;
}

@keyframes chatMsgIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-msg-bot {
    align-self: flex-start;
}

.chat-msg-user {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-bubble {
    padding: 12px 16px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: anywhere;
}

.chat-msg-bot .chat-bubble {
    background: #fff;
    border: 1px solid var(--border);
    border-top-left-radius: 6px;
    color: var(--text);
    box-shadow: var(--shadow-sm);
}

.chat-msg-user .chat-bubble {
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    border-top-right-radius: 6px;
    color: #fff;
    box-shadow: 0 6px 18px rgba(79, 70, 229, 0.28);
}

.chat-time {
    font-size: 0.7rem;
    color: var(--text-muted);
    padding: 0 6px;
}

.chat-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 14px 18px;
}

.chat-typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    opacity: 0.4;
    animation: chatDot 1.4s ease-in-out infinite;
}

.chat-typing span:nth-child(2) {
    animation-delay: 0.15s;
}

.chat-typing span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes chatDot {
    0%, 80%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    40% {
        transform: translateY(-4px);
        opacity: 1;
    }
}

/* Quick replies */
.chat-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
    align-self: flex-start;
    max-width: 100%;
    animation: chatMsgIn 0.4s ease 0.1s both;
}

.chat-quick-btn {
    padding: 8px 14px;
    border-radius: 999px;
    background: #fff;
    border: 1px solid var(--border);
    color: var(--text);
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s, color 0.2s, box-shadow 0.2s, background 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.chat-quick-btn:hover {
    border-color: rgba(79, 70, 229, 0.4);
    color: var(--primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.chat-quick-btn-primary {
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    border-color: transparent;
    color: #fff;
    box-shadow: 0 6px 16px rgba(79, 70, 229, 0.25);
}

.chat-quick-btn-primary:hover {
    color: #fff;
    box-shadow: 0 10px 22px rgba(79, 70, 229, 0.35);
}

.chat-quick-btn [data-lucide],
.chat-quick-btn .lucide {
    font-size: 0.95rem;
}

/* Form */
.chat-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    background: #fff;
}

.chat-input {
    flex: 1;
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 10px 16px;
    font-size: 0.95rem;
    font-family: inherit;
    color: var(--text);
    background: #f8fafd;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
    outline: none;
    min-width: 0;
}

.chat-input::placeholder {
    color: var(--text-muted);
    opacity: 0.7;
}

.chat-input:focus {
    border-color: rgba(79, 70, 229, 0.45);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.12);
}

.chat-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
    box-shadow: 0 8px 18px rgba(79, 70, 229, 0.3);
    flex: none;
    font-size: 1.05rem;
}

.chat-send:hover {
    transform: scale(1.05);
}

.chat-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.chat-footer {
    text-align: center;
    padding: 8px 14px 12px;
    font-size: 0.7rem;
    color: var(--text-muted);
    background: #fff;
}

.chat-footer strong {
    color: var(--primary);
    font-weight: 600;
}

/* Mobile */
@media (max-width: 480px) {
    .chat-widget {
        right: 16px;
        bottom: 16px;
    }
    .chat-toggle {
        width: 56px;
        height: 56px;
    }
    .chat-panel {
        width: calc(100vw - 32px);
        height: calc(100vh - 100px);
        bottom: 76px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .chat-typing span,
    .chat-msg,
    .chat-quick {
        animation: none !important;
    }
    .chat-panel,
    .chat-toggle,
    .chat-toggle-icon {
        transition: none !important;
    }
}
