/**
 * Chat Widget Styles — T2W Intelligence Layer Phase 2
 *
 * FAB + bottom sheet chat interface.
 * Uses existing design tokens from variables.css.
 *
 * @since 45.2.0
 */

/* ─── Hero Chat CTA ───────────────────────── */
.t2w-hero-dark__chat-cta {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 8px auto 4px;
    padding: 8px 16px;
    border: 1px solid rgba(255, 255, 255, 0.25);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.85);
    font-size: 13px;
    cursor: pointer;
    transition: background 0.2s, color 0.2s;
    -webkit-backdrop-filter: blur(4px);
    backdrop-filter: blur(4px);
}

.t2w-hero-dark__chat-cta:hover {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}

.t2w-hero-dark__chat-cta .material-symbols-outlined {
    font-size: 16px;
}

/* ─── FAB ─────────────────────────────────── */
.t2w-chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9000;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--hp-primary, #2563eb);
    color: #fff;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.t2w-chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3);
}

.t2w-chat-fab:active {
    transform: scale(0.95);
}

.t2w-chat-fab .material-symbols-outlined {
    font-size: 24px;
}

.t2w-chat-fab--hidden {
    opacity: 0;
    pointer-events: none;
    transform: scale(0.8);
}

/* ─── Overlay ─────────────────────────────── */
.t2w-chat-overlay {
    position: fixed;
    inset: 0;
    z-index: 9998;
    background: rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
}

.t2w-chat-overlay--open {
    opacity: 1;
    pointer-events: auto;
}

/* ─── Bottom Sheet ────────────────────────── */
.t2w-chat-sheet {
    position: fixed;
    bottom: 0;
    right: 0;
    z-index: 9999;
    width: 100%;
    max-width: 420px;
    height: 70vh;
    max-height: 600px;
    background: var(--hp-surface, #fff);
    border-radius: 20px 20px 0 0;
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    transform: translateY(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    opacity: 0;
    pointer-events: none;
}

.t2w-chat-sheet--open {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

/* ─── Header ──────────────────────────────── */
.t2w-chat-sheet__header {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid var(--color-border-light, #e5e7eb);
    flex-shrink: 0;
}

.t2w-chat-sheet__handle {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 36px;
    height: 4px;
    background: var(--color-border-medium, #d1d5db);
    border-radius: 2px;
}

.t2w-chat-sheet__title {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
}

.t2w-chat-sheet__title h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: var(--hp-text-primary, #111);
}

.t2w-chat-sheet__icon {
    color: var(--hp-primary, #2563eb);
    font-size: 20px;
}

.t2w-chat-sheet__close {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--hp-text-secondary, #6b7280);
    border-radius: 8px;
    transition: background 0.15s;
}

.t2w-chat-sheet__close:hover {
    background: rgba(0, 0, 0, 0.05);
}

/* ─── Messages area ───────────────────────── */
.t2w-chat-sheet__messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    -webkit-overflow-scrolling: touch;
}

/* ─── Chat bubbles ────────────────────────── */
.t2w-chat-bubble {
    display: flex;
    max-width: 85%;
}

.t2w-chat-bubble--user {
    align-self: flex-end;
}

.t2w-chat-bubble--assistant {
    align-self: flex-start;
}

.t2w-chat-bubble__content {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

.t2w-chat-bubble--user .t2w-chat-bubble__content {
    background: var(--hp-primary, #2563eb);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.t2w-chat-bubble--assistant .t2w-chat-bubble__content {
    background: var(--color-border-light, #f3f4f6);
    color: var(--hp-text-primary, #111);
    border-bottom-left-radius: 4px;
}

/* ─── Markdown rendering ──────────────────── */
.t2w-chat-bubble__content .t2w-chat-h2 {
    display: block;
    font-size: 15px;
    margin: 8px 0 4px;
}

.t2w-chat-bubble__content .t2w-chat-h3 {
    display: block;
    font-size: 14px;
    margin: 6px 0 2px;
}

.t2w-chat-bubble__content .t2w-chat-list {
    margin: 4px 0;
    padding-left: 18px;
}

.t2w-chat-bubble__content .t2w-chat-list li {
    margin-bottom: 4px;
    font-size: 13px;
    line-height: 1.5;
}

.t2w-chat-bubble__content em {
    font-style: italic;
    opacity: 0.85;
}

/* ─── Answer fade-in animation ────────────── */
.t2w-chat-bubble--animate {
    animation: t2w-bubble-in 0.4s ease-out;
}

@keyframes t2w-bubble-in {
    0% {
        opacity: 0;
        transform: translateY(8px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ─── Typing indicator ────────────────────── */
.t2w-chat-bubble--typing {
    display: flex;
    gap: 4px;
    padding: 12px 18px;
}

.t2w-chat-bubble--typing span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--hp-text-secondary, #9ca3af);
    animation: t2w-typing 1.4s infinite ease-in-out;
}

.t2w-chat-bubble--typing span:nth-child(2) { animation-delay: 0.2s; }
.t2w-chat-bubble--typing span:nth-child(3) { animation-delay: 0.4s; }

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

/* ─── Source citations ────────────────────── */
.t2w-chat-sources {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.t2w-chat-source {
    font-size: 11px;
    padding: 3px 8px;
    background: rgba(37, 99, 235, 0.08);
    color: var(--hp-primary, #2563eb);
    border-radius: 10px;
    border: none;
    cursor: default;
}

/* ─── Suggestion chips ────────────────────── */
.t2w-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 0;
}

.t2w-chat-chip {
    font-size: 13px;
    padding: 6px 12px;
    border-radius: 16px;
    border: 1px solid var(--color-border-light, #e5e7eb);
    background: var(--hp-surface, #fff);
    color: var(--hp-text-primary, #374151);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
}

.t2w-chat-chip:hover {
    background: var(--color-border-light, #f3f4f6);
    border-color: var(--hp-primary, #2563eb);
}

/* ─── Input area ──────────────────────────── */
.t2w-chat-sheet__input {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--color-border-light, #e5e7eb);
    flex-shrink: 0;
    background: var(--hp-surface, #fff);
}

.t2w-chat-sheet__input-field {
    flex: 1;
    padding: 10px 14px;
    border: 1px solid var(--color-border-light, #e5e7eb);
    border-radius: 20px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
    background: var(--hp-surface, #fff);
    color: var(--hp-text-primary, #111);
}

.t2w-chat-sheet__input-field:focus {
    border-color: var(--hp-primary, #2563eb);
}

.t2w-chat-sheet__image-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--hp-text-secondary, #6b7280);
    transition: color 0.15s, background 0.15s;
    flex-shrink: 0;
}

.t2w-chat-sheet__image-btn:hover {
    color: var(--hp-primary, #2563eb);
    background: rgba(37, 99, 235, 0.08);
}

.t2w-chat-sheet__image-btn .material-symbols-outlined {
    font-size: 22px;
}

.t2w-chat-sheet__send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--hp-primary, #2563eb);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    flex-shrink: 0;
}

.t2w-chat-sheet__send:hover {
    background: var(--hp-primary-hover, #1d4ed8);
}

.t2w-chat-sheet__send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.t2w-chat-sheet__send .material-symbols-outlined {
    font-size: 20px;
}

/* ─── Planner CTA button ──────────────────── */
.t2w-chat-planner-cta {
    display: flex;
    justify-content: center;
    margin: 8px 0;
}

.t2w-chat-planner-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: var(--hp-primary, #2563eb);
    color: #fff;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.15s;
}

.t2w-chat-planner-btn:hover {
    background: var(--hp-primary-hover, #1d4ed8);
    color: #fff;
}

.t2w-chat-planner-btn .material-symbols-outlined {
    font-size: 16px;
}

/* ─── Mobile (full width) ─────────────────── */
@media (max-width: 480px) {
    .t2w-chat-sheet {
        max-width: 100%;
        height: calc(100vh - 68px); /* Full height minus bottom nav */
        max-height: none;
        bottom: 68px; /* Sit above bottom nav */
        border-radius: 16px 16px 0 0;
    }

    .t2w-chat-fab {
        bottom: 88px; /* Above mobile bottom nav (68px + 20px gap) */
        right: 16px;
    }
}

@media (max-width: 768px) {
    .t2w-chat-fab {
        bottom: 88px;
    }

    .t2w-chat-sheet {
        bottom: 68px;
        height: calc(100vh - 68px);
        max-height: none;
    }
}

/* ─── Desktop (positioned right) ──────────── */
@media (min-width: 768px) {
    .t2w-chat-sheet {
        bottom: 16px;
        right: 16px;
        border-radius: 20px;
        height: 560px;
    }

    .t2w-chat-sheet__handle {
        display: none;
    }
}
