/* ===========================
   CHAT-WIDGET.CSS - AI Trip Assistant Chat Widget
   Floating FAB + expandable chat panel
   =========================== */

/* --- Floating Action Button --- */
.chat-fab {
    position: fixed;
    bottom: calc(var(--tab-bar-height, 64px) + 16px + env(safe-area-inset-bottom, 0px));
    right: 16px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--adult-accent);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: var(--shadow-lg);
    z-index: 40;
    transition: transform 0.2s ease, background 0.2s ease;
    font-size: 1.5em;
    line-height: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-fab:hover {
    transform: translateY(-2px);
    background: var(--adult-accent-hover, #628A7C);
}

.chat-fab:active {
    transform: translateY(0);
}

.chat-fab.is-open {
    background: var(--adult-text-light);
    font-size: 1.2em;
}

/* --- Chat Panel --- */
.chat-panel {
    position: fixed;
    bottom: calc(var(--tab-bar-height, 64px) + 80px + env(safe-area-inset-bottom, 0px));
    right: 16px;
    width: 380px;
    max-height: 520px;
    background: var(--adult-card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    z-index: 60;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}

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

/* --- Chat Header --- */
.chat-header {
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--adult-border);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 48px;
}

.chat-header-title {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.95em;
}

.chat-header-title strong {
    color: var(--adult-primary);
}

.chat-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.chat-header-user .user-badge {
    font-size: 0.75em;
    padding: 3px 10px;
    border-radius: var(--radius-pill);
    color: white;
    font-weight: 600;
}

.chat-close-btn {
    display: none;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--adult-surface, #F5F3F0);
    color: var(--adult-text-light);
    font-size: 1em;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease;
}

.chat-close-btn:hover {
    background: var(--adult-border, #E8E4DF);
    color: var(--adult-text);
}

/* --- Messages Area --- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    min-height: 200px;
    max-height: 360px;
}

/* --- Message Bubbles --- */
.chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 0.92em;
    line-height: 1.55;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.chat-msg-user {
    align-self: flex-end;
    background: var(--adult-accent);
    color: white;
    border-bottom-right-radius: 4px;
}

.chat-msg-ai {
    align-self: flex-start;
    background: var(--adult-surface, #F5F3F0);
    color: var(--adult-text);
    border-bottom-left-radius: 4px;
}

/* --- Action Indicators --- */
.chat-action {
    align-self: center;
    font-size: 0.8em;
    color: var(--adult-text-light);
    background: var(--adult-surface, #F5F3F0);
    padding: 4px 12px;
    border-radius: var(--radius-pill);
    font-style: italic;
}

/* --- Typing Indicator --- */
.chat-typing {
    display: flex;
    align-items: center;
    padding: 12px 16px;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dots span {
    width: 8px;
    height: 8px;
    background: var(--adult-text-light);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

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

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

@keyframes typingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* --- Input Area --- */
.chat-input-row {
    display: flex;
    padding: var(--space-sm) var(--space-md);
    border-top: 1px solid var(--adult-border);
    gap: var(--space-xs);
    background: var(--adult-card-bg);
    align-items: center;
}

.chat-input {
    flex: 1;
    border: 1px solid var(--adult-border);
    border-radius: var(--radius-pill);
    padding: 9px 16px;
    font-family: var(--font-adult);
    font-size: 0.92em;
    outline: none;
    background: white;
    transition: border-color 0.15s ease;
}

.chat-input:focus {
    border-color: var(--adult-accent);
    box-shadow: 0 0 0 2px rgba(122, 155, 142, 0.15);
}

.chat-send-btn {
    width: 36px;
    height: 36px;
    min-width: 36px;
    border-radius: 50%;
    background: var(--adult-accent);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85em;
    transition: background 0.15s ease;
}

.chat-send-btn:hover {
    background: var(--adult-accent-hover, #628A7C);
}

.chat-send-btn:disabled {
    background: var(--adult-border);
    cursor: not-allowed;
}

/* --- Error State --- */
.chat-msg-error {
    background: #FDF5F4;
    color: var(--adult-danger);
    border: 1px solid #E6D4D0;
}

/* --- Kids Theme Override --- */
.page-kids .chat-fab {
    background: var(--game-accent, #F59E0B);
}

.page-kids .chat-fab:hover {
    background: #B87A2E;
}

.page-kids .chat-msg-user {
    background: var(--game-accent, #F59E0B);
}

.page-kids .chat-send-btn {
    background: var(--game-accent, #F59E0B);
}

.page-kids .chat-send-btn:hover {
    background: #B87A2E;
}

.page-kids .chat-header-title strong {
    color: var(--game-accent, #F59E0B);
}

.page-kids .chat-input:focus {
    border-color: var(--game-accent, #F59E0B);
    box-shadow: 0 0 0 2px rgba(212, 145, 59, 0.15);
}

/* --- Mobile Responsive: Bottom Drawer --- */
@media (max-width: 600px) {
    .chat-panel {
        bottom: 0;
        right: 0;
        left: 0;
        top: auto;
        width: 100%;
        max-height: 85vh;
        border-radius: 16px 16px 0 0;
        /* Slide up from bottom instead of fade+scale */
        opacity: 1;
        transform: translateY(100%);
        transition: transform 0.3s ease;
    }

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

    /* Drawer handle indicator */
    .chat-panel::before {
        content: '';
        display: block;
        width: 36px;
        height: 4px;
        background: #ccc;
        border-radius: 2px;
        margin: 8px auto 0;
    }

    /* Show close button on mobile */
    .chat-close-btn {
        display: flex;
    }

    /* Hide FAB when drawer is open */
    .chat-fab.is-open {
        opacity: 0;
        pointer-events: none;
    }

    .chat-fab {
        bottom: calc(var(--tab-bar-height, 64px) + 12px + env(safe-area-inset-bottom, 0px));
        right: 12px;
        width: 50px;
        height: 50px;
        font-size: 1.3em;
    }

    .chat-messages {
        max-height: calc(85vh - 140px);
    }

    /* Ensure input stays above mobile keyboard */
    .chat-input-row {
        padding-bottom: env(safe-area-inset-bottom, 8px);
    }
}

/* --- Reduced Motion --- */
@media (prefers-reduced-motion: reduce) {
    .chat-panel {
        transition: none;
    }

    .chat-fab {
        transition: none;
    }

    .typing-dots span {
        animation: none;
        opacity: 0.6;
    }
}
