/* ============================================================
   CHAT-WIDGET.CSS — Conversational Chat Widget
   ============================================================
   Guest: floating avatar trigger → conversational bubble
   Auth:  floating trigger → embedded mini-chat panel
   ============================================================ */

/* ── Animations ── */
@keyframes cw-fade-in {
    from { opacity: 0; transform: translateY(12px) scale(0.95); }
    to   { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes cw-fade-out {
    to { opacity: 0; transform: translateY(8px) scale(0.97); }
}
@keyframes cw-trigger-pop {
    0%   { transform: scale(0); opacity: 0; }
    70%  { transform: scale(1.1); }
    100% { transform: scale(1); opacity: 1; }
}
@keyframes cw-pulse {
    0%, 100% { opacity: 0.6; transform: scale(1); }
    50%      { opacity: 0; transform: scale(1.8); }
}
@keyframes cw-dot-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30%           { transform: translateY(-4px); }
}

/* ══════════════════════════════════════════════════════════
 *  SHARED: Floating Trigger Button
 * ══════════════════════════════════════════════════════════ */
.cw-trigger {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--glass-bg-strong, rgba(17, 14, 26, 0.92));
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    box-shadow:
        0 4px 24px rgba(0, 0, 0, 0.4),
        0 0 0 1px rgba(167, 139, 250, 0.12),
        0 0 20px rgba(167, 139, 250, 0.08);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: box-shadow 0.3s, transform 0.2s;
    transform: scale(0);
    opacity: 0;
}

.cw-trigger--visible {
    animation: cw-trigger-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.cw-trigger--hidden {
    transform: scale(0) !important;
    opacity: 0 !important;
    pointer-events: none;
    transition: transform 0.2s, opacity 0.2s;
}

.cw-trigger:hover {
    box-shadow:
        0 6px 32px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(167, 139, 250, 0.2),
        0 0 30px rgba(167, 139, 250, 0.15);
    transform: scale(1.05);
}

.cw-trigger:active {
    transform: scale(0.95);
}

.cw-trigger__avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
}

.cw-trigger--auth .cw-trigger__avatar {
    width: 40px;
    height: 40px;
}

.cw-trigger__pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--color-primary, #A78BFA);
    animation: cw-pulse 2s ease-out infinite;
    pointer-events: none;
}

.cw-trigger__badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--color-primary, #A78BFA);
    color: var(--color-text-inverse, #0A0810);
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* ══════════════════════════════════════════════════════════
 *  GUEST: Conversational Bubble
 * ══════════════════════════════════════════════════════════ */
.cw-bubble {
    position: fixed;
    bottom: 90px;
    right: 24px;
    z-index: 1001;
    width: 340px;
    max-width: calc(100vw - 48px);
    background: var(--glass-bg-strong, rgba(17, 14, 26, 0.95));
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(167, 139, 250, 0.1);
    border-radius: 16px;
    box-shadow:
        0 12px 40px rgba(0, 0, 0, 0.5),
        0 0 0 1px rgba(167, 139, 250, 0.06);
    padding: 0;
    overflow: hidden;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

.cw-bubble--visible {
    animation: cw-fade-in 0.35s ease-out both;
}

.cw-bubble--hiding {
    animation: cw-fade-out 0.2s ease-in forwards;
}

.cw-bubble__close {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 2;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--color-text-muted, #6B6681);
    font-size: 18px;
    cursor: pointer;
    border-radius: 50%;
    transition: color 0.2s, background 0.2s;
    line-height: 1;
    padding: 0;
}
.cw-bubble__close:hover {
    color: var(--color-text-secondary, #A09CB2);
    background: rgba(167, 139, 250, 0.1);
}

/* Message row — looks like a real chat message */
.cw-bubble__conversation {
    padding: 16px 16px 8px;
}

.cw-bubble__msg-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.cw-bubble__avatar {
    flex-shrink: 0;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    overflow: hidden;
}

.cw-bubble__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cw-bubble__msg {
    flex: 1;
    min-width: 0;
    padding-right: 20px;
}

.cw-bubble__name {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--color-primary, #A78BFA);
    margin-bottom: 4px;
    letter-spacing: 0.02em;
}

.cw-bubble__text {
    font-size: 14px;
    line-height: 1.5;
    color: var(--color-text, #EDEBF4);
    margin: 0;
}

/* Quick-reply chips — feel like replies the user can tap */
.cw-bubble__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px 16px 16px;
}

.cw-bubble__chip {
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
    background: rgba(167, 139, 250, 0.08);
    border: 1px solid rgba(167, 139, 250, 0.15);
    border-radius: 20px;
    color: var(--color-primary, #A78BFA);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, transform 0.15s;
    line-height: 1.3;
}

.cw-bubble__chip:hover {
    background: rgba(167, 139, 250, 0.15);
    border-color: rgba(167, 139, 250, 0.25);
    color: var(--color-primary-hover, #C4B5FD);
    text-decoration: none;
    transform: translateY(-1px);
}

.cw-bubble__chip:active {
    transform: translateY(0);
}

/* ══════════════════════════════════════════════════════════
 *  AUTH: Mini-Chat Panel
 * ══════════════════════════════════════════════════════════ */
.cw-panel {
    position: fixed;
    bottom: 90px;
    right: 24px;
    z-index: 1001;
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 480px;
    max-height: calc(100vh - 160px);
    background: var(--color-bg, #0A0810);
    border: 1px solid rgba(167, 139, 250, 0.1);
    border-radius: 16px;
    box-shadow:
        0 16px 48px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(167, 139, 250, 0.06);
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
}

.cw-panel[hidden] {
    display: none !important;
}

.cw-panel--visible {
    display: flex;
    animation: cw-fade-in 0.3s ease-out both;
}

.cw-panel--hiding {
    animation: cw-fade-out 0.2s ease-in forwards;
}

/* Panel header */
.cw-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: var(--glass-bg-strong, rgba(17, 14, 26, 0.92));
    border-bottom: 1px solid rgba(167, 139, 250, 0.08);
    flex-shrink: 0;
}

.cw-panel__header-left {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.cw-panel__avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.cw-panel__avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cw-panel__header-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.cw-panel__name {
    font-size: 13px;
    font-weight: 600;
    color: var(--color-text, #EDEBF4);
    line-height: 1.2;
}

.cw-panel__status {
    display: flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--color-text-muted, #6B6681);
    line-height: 1.2;
}

.cw-panel__status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
    flex-shrink: 0;
}

.cw-panel__status--thinking .cw-panel__status-dot {
    background: var(--color-primary, #A78BFA);
    animation: cw-pulse 1.5s ease-out infinite;
}

.cw-panel__header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.cw-panel__expand,
.cw-panel__minimize {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--color-text-muted, #6B6681);
    cursor: pointer;
    border-radius: 8px;
    transition: color 0.2s, background 0.2s;
    text-decoration: none;
    position: relative;
    z-index: 10;
}

.cw-panel__expand svg,
.cw-panel__minimize svg {
    pointer-events: none;
}

.cw-panel__expand:hover,
.cw-panel__minimize:hover {
    color: var(--color-text-secondary, #A09CB2);
    background: rgba(167, 139, 250, 0.08);
    text-decoration: none;
}

/* Messages area */
.cw-panel__messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scrollbar-width: thin;
    scrollbar-color: rgba(167, 139, 250, 0.15) transparent;
}

.cw-panel__messages::-webkit-scrollbar {
    width: 4px;
}
.cw-panel__messages::-webkit-scrollbar-track {
    background: transparent;
}
.cw-panel__messages::-webkit-scrollbar-thumb {
    background: rgba(167, 139, 250, 0.15);
    border-radius: 2px;
}

/* Message rows */
.cw-panel__msg {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    animation: cw-fade-in 0.25s ease-out;
}

.cw-panel__msg--user {
    flex-direction: row-reverse;
}

.cw-panel__msg-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
}

.cw-panel__msg-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.cw-panel__msg-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
}

.cw-panel__msg--ai .cw-panel__msg-bubble {
    background: var(--color-bg-elevated, #221E34);
    color: var(--color-text, #EDEBF4);
    border-bottom-left-radius: 4px;
}

.cw-panel__msg--user .cw-panel__msg-bubble {
    background: linear-gradient(135deg, var(--color-primary, #A78BFA), #8B6FD4);
    color: var(--color-text-inverse, #0A0810);
    border-bottom-right-radius: 4px;
}

.cw-panel__msg-bubble--error {
    background: rgba(239, 68, 68, 0.15) !important;
    color: #fca5a5 !important;
    border: 1px solid rgba(239, 68, 68, 0.2);
}

/* System messages */
.cw-panel__system {
    text-align: center;
    padding: 4px 0;
    animation: cw-fade-in 0.3s ease-out;
}

.cw-panel__system-link {
    font-size: 12px;
    color: var(--color-primary, #A78BFA);
    text-decoration: none;
    font-weight: 500;
    transition: color 0.2s;
}

.cw-panel__system-link:hover {
    color: var(--color-primary-hover, #C4B5FD);
    text-decoration: none;
}

/* Typing indicator */
.cw-panel__typing {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.cw-panel__typing-dots {
    display: flex;
    gap: 3px;
    padding: 12px 14px;
    background: var(--color-bg-elevated, #221E34);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}

.cw-panel__typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-text-muted, #6B6681);
}

.cw-panel__typing-dots span:nth-child(1) { animation: cw-dot-bounce 1.2s ease-in-out infinite 0s; }
.cw-panel__typing-dots span:nth-child(2) { animation: cw-dot-bounce 1.2s ease-in-out infinite 0.15s; }
.cw-panel__typing-dots span:nth-child(3) { animation: cw-dot-bounce 1.2s ease-in-out infinite 0.3s; }

.cw-panel__typing[hidden] {
    display: none !important;
}

/* Suggestion chips */
.cw-panel__chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 14px 8px;
    flex-shrink: 0;
}

.cw-panel__chip {
    display: inline-flex;
    align-items: center;
    padding: 6px 12px;
    background: rgba(167, 139, 250, 0.06);
    border: 1px solid rgba(167, 139, 250, 0.12);
    border-radius: 16px;
    color: var(--color-primary, #A78BFA);
    font-size: 12px;
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s;
    line-height: 1.3;
}

.cw-panel__chip:hover {
    background: rgba(167, 139, 250, 0.12);
    border-color: rgba(167, 139, 250, 0.2);
    color: var(--color-primary-hover, #C4B5FD);
    text-decoration: none;
}

.cw-panel__chips[hidden] {
    display: none !important;
}

/* Inline dynamic chips inside messages area */
.cw-panel__inline-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0;
    animation: cw-fade-in 0.25s ease-out;
}

/* Input area */
.cw-panel__input-area {
    flex-shrink: 0;
    border-top: 1px solid rgba(167, 139, 250, 0.08);
    background: var(--glass-bg-strong, rgba(17, 14, 26, 0.92));
}

.cw-panel__composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 14px 6px;
}

.cw-panel__input {
    flex: 1;
    background: rgba(167, 139, 250, 0.05);
    border: 1px solid rgba(167, 139, 250, 0.1);
    border-radius: 12px;
    padding: 8px 12px;
    color: var(--color-text, #EDEBF4);
    font-size: 13px;
    font-family: inherit;
    line-height: 1.4;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
    min-height: 36px;
    max-height: 80px;
}

.cw-panel__input::placeholder {
    color: var(--color-text-muted, #6B6681);
}

.cw-panel__input:focus {
    border-color: rgba(167, 139, 250, 0.25);
}

.cw-panel__send {
    width: 36px;
    height: 36px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--color-primary, #A78BFA);
    border: none;
    border-radius: 50%;
    color: var(--color-text-inverse, #0A0810);
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s, transform 0.15s;
}

.cw-panel__send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.cw-panel__send:not(:disabled):hover {
    background: var(--color-primary-hover, #C4B5FD);
    transform: scale(1.05);
}

.cw-panel__send:not(:disabled):active {
    transform: scale(0.95);
}

.cw-panel__footer {
    display: flex;
    justify-content: center;
    padding: 4px 14px 10px;
}

.cw-panel__footer-link {
    font-size: 11px;
    color: var(--color-text-muted, #6B6681);
    text-decoration: none;
    transition: color 0.2s;
}

.cw-panel__footer-link:hover {
    color: var(--color-primary, #A78BFA);
    text-decoration: none;
}

/* ── Hint tooltip ── */
.cw-hint {
    position: fixed;
    bottom: 32px;
    right: 90px;
    z-index: 1000;
    opacity: 0;
    transform: translateX(8px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    cursor: pointer;
    pointer-events: none;
}

.cw-hint--visible {
    opacity: 1;
    transform: translateX(0);
    pointer-events: auto;
}

.cw-hint--hiding {
    opacity: 0;
    transform: translateX(8px);
    pointer-events: none;
}

.cw-hint__text {
    display: inline-block;
    padding: 8px 14px;
    background: var(--glass-bg-strong, rgba(17, 14, 26, 0.95));
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid rgba(167, 139, 250, 0.15);
    border-radius: 12px;
    color: var(--color-text, #EDEBF4);
    font-size: 13px;
    font-weight: 500;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    white-space: nowrap;
    box-shadow:
        0 4px 16px rgba(0, 0, 0, 0.3),
        0 0 0 1px rgba(167, 139, 250, 0.06);
}

/* ══════════════════════════════════════════════════════════
 *  Mobile Responsive
 * ══════════════════════════════════════════════════════════ */
@media (max-width: 767px) {
    /* Trigger above mobile nav */
    .layout-app .cw-trigger {
        bottom: 80px;
        right: 16px;
    }

    .layout-marketing .cw-trigger {
        bottom: 16px;
        right: 16px;
    }

    /* Guest bubble */
    .cw-bubble {
        bottom: auto;
        top: auto;
        right: 12px;
        left: 12px;
        bottom: 80px;
        width: auto;
        max-width: none;
    }

    .layout-marketing .cw-bubble {
        bottom: 80px;
    }

    /* Auth panel — bottom sheet style */
    .cw-panel {
        bottom: 64px;
        right: 8px;
        left: 8px;
        width: auto;
        max-width: none;
        height: 420px;
        max-height: calc(100vh - 140px);
        border-radius: 16px 16px 12px 12px;
    }

    .layout-app .cw-panel {
        bottom: 72px;
    }

    .cw-hint {
        bottom: 88px;
        right: 72px;
    }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
    .cw-trigger--visible,
    .cw-bubble--visible,
    .cw-bubble--hiding,
    .cw-panel--visible,
    .cw-panel--hiding,
    .cw-panel__msg,
    .cw-panel__system {
        animation-duration: 0.01ms !important;
    }
    .cw-trigger__pulse {
        animation: none;
    }
}
