/* ============================================
   AI Chat Widget Styles
   ============================================ */

/* CSS Variables */
:root {
    --chat-primary: #FF2B54;
    --chat-primary-light: #FF2B54;
    --chat-bg: #FFFFFF;
    --chat-border: #E5E7EB;
    --chat-text: #1F2937;
    --chat-text-secondary: #6B7280;
    --chat-header-text: #111827; /* Darker blue/black for header */
    --chat-message-bg: #F9FAFB; /* Lighter grey */
    --chat-user-bg: #FF2B54;
    --chat-shadow: 0 20px 40px -8px rgba(0, 0, 0, 0.15); /* Softer shadow */
    --chat-radius: 32px; /* More rounded */
    --chat-radius-sm: 20px;
    --chat-transition: 0.3s cubic-bezier(0.2, 0.8, 0.2, 1); /* Smoother */
}

/* Prevent zoom on mobile input focus */
@supports (-webkit-touch-callout: none) {
    .ai-chat__input {
        font-size: 16px !important;
    }
}

/* ============================================
   Toggle Button (FAB) with Hover Label
   ============================================ */
.ai-chat-toggle-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9998;
    display: flex;
    align-items: center;
    gap: 0;
}

.ai-chat-toggle__label {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    padding-right: 36px;
    margin-right: -28px;
    background: #FFFFFF;
    border-radius: 100px;
    font-size: 15px;
    font-weight: 500;
    color: var(--chat-text);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
    opacity: 0;
    transform: translateX(20px);
    pointer-events: none;
    transition: opacity var(--chat-transition), transform var(--chat-transition);
    white-space: nowrap;
}

.ai-chat-toggle-container:hover .ai-chat-toggle__label,
.ai-chat-toggle-container:focus-within .ai-chat-toggle__label {
    opacity: 1;
    transform: translateX(0);
}

.ai-chat-toggle-container.is-active .ai-chat-toggle__label {
    opacity: 0 !important;
    transform: translateX(20px) !important;
}

.ai-chat-toggle {
    position: relative;
    width: 64px; /* Larger FAB like Figma */
    height: 64px;
    border-radius: 50%;
    background: var(--chat-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 24px rgba(255, 43, 84, 0.3);
    transition: transform var(--chat-transition), box-shadow var(--chat-transition), background var(--chat-transition);
    flex-shrink: 0;
}

.ai-chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 32px rgba(255, 43, 84, 0.4);
}

.ai-chat-toggle.is-active {
    background: #FF2B54; /* Keep red for close state */
}

.ai-chat-toggle__icon {
    width: 32px; /* Larger icon */
    height: 32px;
    transition: opacity var(--chat-transition), transform var(--chat-transition);
}

.ai-chat-toggle__icon--close {
    position: absolute;
    opacity: 0;
    transform: rotate(-90deg);
}

.ai-chat-toggle.is-active .ai-chat-toggle__icon--chat {
    opacity: 0;
    transform: rotate(90deg);
}

.ai-chat-toggle.is-active .ai-chat-toggle__icon--close {
    opacity: 1;
    transform: rotate(0);
}

/* Close icon size tweak */
.ai-chat-toggle__icon--close {
    width: 28px;
    height: 28px;
}

/* ============================================
   Chat Container
   ============================================ */
.ai-chat {
    position: fixed;
    bottom: 100px; /* More space from bottom */
    right: 24px;
    width: 400px; /* Slightly narrower */
    max-width: calc(100vw - 48px);
    height: 765px;
    max-height: calc(100vh - 140px);
    background: var(--chat-bg);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    overflow-x: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.98); /* Less scale movement */
    transition: opacity var(--chat-transition), 
                visibility var(--chat-transition), 
                transform var(--chat-transition);
}

.ai-chat.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* ============================================
   Chat Header
   ============================================ */
.ai-chat__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 24px 28px; /* More padding */
    border-bottom: 1px solid rgba(229, 231, 235, 0.5); /* Lighter border */
    flex-shrink: 0;
}

.ai-chat__header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.ai-chat__header-icon {
    width: 24px; /* Smaller icon */
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-chat__header-title {
    font-size: 17px;
    font-weight: 600;
    color: var(--chat-primary); /* Keep red as requested, or switch to --chat-header-text for blue */
    margin: 0;
    line-height: 1;
}

.ai-chat__header-toggle {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background var(--chat-transition);
}

.ai-chat__header-toggle svg {
    width: 18px; /* Thinner/smaller chevron */
    height: 18px;
    color: #9CA3AF; /* Lighter grey */
}

.ai-chat.is-minimized .ai-chat__header-toggle svg {
    transform: rotate(180deg);
}

/* ============================================
   Chat Messages
   ============================================ */
.ai-chat__messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}

.ai-chat__message {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 85%;
    animation: messageSlideIn 0.3s ease;
}

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

.ai-chat__message--assistant {
    align-self: flex-start;
}

.ai-chat__message--user {
    align-self: flex-end;
}

.ai-chat__message-sender {
    font-size: 13px;
    font-weight: 500;
    color: var(--chat-text-secondary);
    padding-left: 4px;
}

.ai-chat__message--user .ai-chat__message-sender {
    text-align: right;
    padding-right: 4px;
    padding-left: 0;
}

.ai-chat__message-bubble {
    padding: 14px 18px;
    border-radius: var(--chat-radius-sm);
    font-size: 14px;
    line-height: 1.5;
    color: var(--chat-text);
    overflow-wrap: anywhere;
    word-break: break-word;
    display: inline-block;
    width: fit-content;
    max-width: 100%;
}

.ai-chat__message-bubble a {
    color: var(--chat-primary);
    text-decoration: underline;
    word-break: break-all;
}

.ai-chat__message--assistant .ai-chat__message-bubble {
    background: var(--chat-message-bg);
    border-bottom-left-radius: 4px;
}

.ai-chat__message--user .ai-chat__message-bubble {
    background: var(--chat-user-bg);
    color: #FFFFFF;
    border-bottom-right-radius: 4px;
}

.ai-chat__message-bubble ul {
    margin: 12px 0 0 0;
    padding-left: 20px;
    list-style: disc;
}

.ai-chat__message-bubble li {
    margin-bottom: 8px;
}

.ai-chat__message-bubble li:last-child {
    margin-bottom: 0;
}

/* ============================================
   Quick Actions / Suggestions
   ============================================ */
.ai-chat__suggestions {
    padding: 0 0 20px;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px; /* Slightly more gap */
}

.ai-chat__suggestions-label {
    font-size: 14px;
    color: var(--chat-text-secondary);
    margin-bottom: 6px;
    text-align: right;
    align-self: flex-end;
}

.ai-chat__suggestion-btn {
    padding: 8px 16px;
    background: var(--chat-message-bg);
    border: 1px solid rgba(117, 117, 117, 0.04);
    border-radius: 16px;
    font-size: 14px;
    color: var(--chat-text);
    cursor: pointer;
    text-align: left;
    display: inline-flex;
    align-self: flex-end;
    width: fit-content;
    white-space: normal;
    transition: all var(--chat-transition);
    box-shadow: none;
    max-width: 90%;
}

.ai-chat__suggestion-btn:hover {
    background: #F9FAFB;
    color: var(--chat-primary);
    transform: translateY(-1px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.ai-chat__suggestion-btn--active {
    background: var(--chat-primary);
    color: #FFFFFF;
    border-color: var(--chat-primary);
}

/* ============================================
   Chat Input
   ============================================ */
.ai-chat__input-wrapper {
    padding: 16px 24px 24px;
    border-top: 1px solid var(--chat-border);
    flex-shrink: 0;
}

.ai-chat__input-container {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--chat-message-bg);
    border-radius: 16px;
    border: 1px solid transparent;
    transition: border-color var(--chat-transition), box-shadow var(--chat-transition);
    overflow: hidden;
}

.ai-chat__input-container:focus-within {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(255, 43, 84, 0.1);
}

.ai-chat__input {
    flex: 1;
    border: none;
    background: transparent;
    font-size: 16px;
    color: var(--chat-text);
    outline: none;
    min-width: 0;
}

.ai-chat__input::placeholder {
    color: var(--chat-text-secondary);
}

.ai-chat__send-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--chat-primary);
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform var(--chat-transition), opacity var(--chat-transition);
}

.ai-chat__send-btn:hover {
    transform: scale(1.05);
}

.ai-chat__send-btn:active {
    transform: scale(0.95);
}

.ai-chat__send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ai-chat__send-btn svg {
    width: 18px;
    height: 18px;
    color: #FFFFFF;
}

/* Retry button for errors */
.ai-chat__message-bubble--error {
    background: transparent !important;
    padding: 0 !important;
}

.ai-chat__retry-btn {
    display: inline;
    background: none;
    border: none;
    padding: 0;
    font-size: inherit;
    font-weight: 600;
    color: var(--chat-primary);
    cursor: pointer;
    transition: opacity var(--chat-transition);
}

.ai-chat__retry-btn:hover {
    opacity: 0.8;
}

.ai-chat__retry-icon {
    display: inline-block;
    margin-left: 2px;
    transition: transform 0.3s ease;
}

.ai-chat__retry-btn:hover .ai-chat__retry-icon {
    transform: rotate(180deg);
}

/* Typing indicator */
.ai-chat__typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 14px 18px;
    background: var(--chat-message-bg);
    border-radius: var(--chat-radius-sm);
    border-bottom-left-radius: 4px;
    width: fit-content;
}

.ai-chat__typing-dot {
    width: 8px;
    height: 8px;
    background: var(--chat-text-secondary);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out both;
}

.ai-chat__typing-dot:nth-child(1) {
    animation-delay: -0.32s;
}

.ai-chat__typing-dot:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes typingBounce {
    0%, 80%, 100% {
        transform: scale(0.6);
        opacity: 0.5;
    }
    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ============================================
   Mobile Styles
   ============================================ */
@media (max-width: 480px) {
    .ai-chat-toggle-container {
        bottom: 16px;
        right: 16px;
    }

    .ai-chat-toggle__label {
        display: none;
    }

    .ai-chat-toggle {
        width: 52px;
        height: 52px;
    }

    .ai-chat {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        border-radius: 0;
        transform: translateY(100%);
        overscroll-behavior: contain;
    }

    .ai-chat.is-open {
        transform: translateY(0);
    }

    .ai-chat__header {
        padding: 16px 20px;
        /* Safe area for notch */
        padding-top: max(16px, env(safe-area-inset-top));
    }

    .ai-chat__messages {
        padding: 16px 20px;
    }

    .ai-chat__suggestions {
        padding: 0 20px 12px;
    }

    .ai-chat__input-wrapper {
        padding: 12px 20px;
        /* Safe area for home indicator */
        padding-bottom: max(20px, env(safe-area-inset-bottom));
    }

    /* Hide toggle when chat is open on mobile */
    .ai-chat.is-open ~ .ai-chat-toggle-container {
        opacity: 0;
        visibility: hidden;
        pointer-events: none;
    }
}

/* Lock background scroll when chat is open on mobile */
html.ai-chat-body-locked,
body.ai-chat-body-locked {
    overflow: hidden;
}

/* ============================================
   Scrollbar Styling
   ============================================ */
.ai-chat__messages::-webkit-scrollbar {
    width: 6px;
}

.ai-chat__messages::-webkit-scrollbar-track {
    background: transparent;
}

.ai-chat__messages::-webkit-scrollbar-thumb {
    background: var(--chat-border);
    border-radius: 3px;
}

.ai-chat__messages::-webkit-scrollbar-thumb:hover {
    background: var(--chat-text-secondary);
}

