/* Fruitables storefront chat — page + floating widget */

:root {
    --chat-primary: #81c408;
    --chat-primary-dark: #5a9a00;
    --chat-user-bg: #81c408;
    --chat-user-fg: #fff;
    --chat-assistant-bg: #f1f5f9;
    --chat-assistant-fg: #334155;
    --chat-border: #e2e8f0;
    --chat-shadow: 0 12px 40px rgba(15, 23, 42, 0.18);
    --chat-radius: 16px;
    --chat-z: 1080;
}

/* ---------- Shared shell ---------- */
.chat-page-card,
.chat-widget-panel {
    display: flex;
    flex-direction: column;
    background: #fff;
    border: 1px solid var(--chat-border);
    border-radius: var(--chat-radius);
    box-shadow: var(--chat-shadow);
    overflow: hidden;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-dark) 100%);
    color: #fff;
}

.chat-header-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.35);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-header-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #fff;
}

.chat-header-sub {
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.88);
}

.chat-messages {
    flex: 1 1 auto;
    min-height: 220px;
    max-height: 52vh;
    overflow-y: auto;
    padding: 16px;
    background: #fafbfc;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
}

.chat-bubble {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 0.92rem;
    line-height: 1.5;
    text-align: left;
    word-break: normal;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}

.chat-bubble-user {
    align-self: flex-end;
    background: var(--chat-user-bg);
    color: var(--chat-user-fg);
    border-bottom-right-radius: 4px;
}

.chat-bubble-assistant {
    align-self: flex-start;
    background: var(--chat-assistant-bg);
    color: var(--chat-assistant-fg);
    border-bottom-left-radius: 4px;
}

.chat-bubble-assistant a {
    color: var(--chat-primary-dark);
    font-weight: 600;
    text-decoration: underline;
}

/* Lời chào: căn trái, ôm theo nội dung, xuống dòng gọn */
.chat-welcome {
    opacity: 0.95;
    width: fit-content;
    max-width: min(92%, 280px);
    align-self: flex-start;
    text-align: left;
    white-space: normal;
    line-height: 1.45;
    letter-spacing: 0;
}

.chat-welcome .chat-welcome-line {
    display: block;
}

.chat-welcome .chat-welcome-line + .chat-welcome-line {
    margin-top: 2px;
}

.chat-bubble-typing {
    align-self: flex-start;
    background: var(--chat-assistant-bg);
    color: #64748b;
    font-style: italic;
    font-size: 0.85rem;
}

/* Đang stream token từ AI */
.chat-bubble-streaming {
    align-self: flex-start;
}

.chat-stream-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    margin-left: 2px;
    vertical-align: text-bottom;
    background: var(--chat-primary, #81c408);
    animation: chat-cursor-blink 0.9s steps(1) infinite;
}

@keyframes chat-cursor-blink {
    0%,
    50% {
        opacity: 1;
    }
    51%,
    100% {
        opacity: 0;
    }
}

.chat-refused-note {
    display: block;
    margin-top: 8px;
    font-size: 0.85rem;
}

.chat-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 14px 4px;
    background: #fff;
    border-top: 1px solid var(--chat-border);
}

.chat-chip {
    border: 1px solid var(--chat-primary);
    background: #fff;
    color: var(--chat-primary-dark);
    border-radius: 999px;
    padding: 6px 12px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.chat-chip:hover:not(:disabled) {
    background: var(--chat-primary);
    color: #fff;
}

.chat-chip:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

.chat-error {
    margin: 0 14px;
    padding: 8px 12px;
    border-radius: 8px;
    background: #fef2f2;
    color: #b91c1c;
    font-size: 0.85rem;
    border: 1px solid #fecaca;
}

.chat-input-row {
    display: flex;
    gap: 8px;
    padding: 12px 14px 14px;
    background: #fff;
    border-top: 1px solid var(--chat-border);
    margin: 0;
}

.chat-input {
    flex: 1 1 auto;
    border: 1px solid var(--chat-border);
    border-radius: 999px;
    padding: 10px 16px;
    font-size: 0.92rem;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
    min-width: 0;
}

.chat-input:focus {
    border-color: var(--chat-primary);
    box-shadow: 0 0 0 3px rgba(129, 196, 8, 0.2);
}

.chat-send-btn {
    flex: 0 0 auto;
    border: none;
    border-radius: 999px;
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-dark) 100%);
    color: #fff;
    padding: 10px 16px;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
    box-shadow: 0 4px 12px rgba(129, 196, 8, 0.3);
}

.chat-send-btn:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(129, 196, 8, 0.4);
}

.chat-send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* ---------- Full page ---------- */
.chat-page-section {
    background: #f8fafc;
}

.chat-page-card {
    min-height: 560px;
    max-height: calc(100vh - 220px);
}

.chat-page-card .chat-messages {
    max-height: none;
    flex: 1 1 auto;
}

.chat-page-card .chat-header {
    padding: 18px 20px;
}

.chat-page-card .chat-header-title {
    font-size: 1.2rem;
}

/* ---------- Floating widget ---------- */
.chat-widget {
    position: fixed;
    right: 20px;
    bottom: 24px;
    z-index: var(--chat-z);
    font-family: inherit;
}

.chat-widget-fab {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, var(--chat-primary) 0%, var(--chat-primary-dark) 100%);
    color: #fff;
    font-size: 1.35rem;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(129, 196, 8, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    position: relative;
    z-index: 2;
}

.chat-widget-fab:hover {
    transform: scale(1.06);
    box-shadow: 0 10px 28px rgba(129, 196, 8, 0.55);
}

.chat-widget-fab .chat-fab-icon-close {
    display: none;
}

.chat-widget.is-open .chat-widget-fab .chat-fab-icon-open {
    display: none;
}

.chat-widget.is-open .chat-widget-fab .chat-fab-icon-close {
    display: inline;
}

.chat-widget-panel {
    position: absolute;
    right: 0;
    bottom: 70px;
    width: 360px;
    max-width: calc(100vw - 32px);
    height: min(520px, 70vh);
    max-height: 70vh;
    z-index: 1;
    animation: chatPanelIn 0.22s ease;
}

.chat-widget-panel[hidden] {
    display: none !important;
}

.chat-widget-header {
    padding: 12px 14px;
}

.chat-widget-header-text {
    flex: 1 1 auto;
    min-width: 0;
}

.chat-expand-link {
    color: #fff;
    font-size: 0.78rem;
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    opacity: 0.95;
    margin-left: auto;
}

.chat-expand-link:hover {
    color: #fff;
    text-decoration: underline;
    opacity: 1;
}

.chat-widget-panel .chat-messages {
    min-height: 0;
    max-height: none;
    flex: 1 1 auto;
}

.chat-widget-panel .chat-send-btn {
    padding: 10px 14px;
}

.chat-widget-panel .chat-send-label {
    display: none;
}

@keyframes chatPanelIn {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Avoid clashing with back-to-top on small screens */
@media (max-width: 576px) {
    .chat-widget {
        right: 12px;
        bottom: 16px;
    }

    .chat-widget-panel {
        width: calc(100vw - 24px);
        right: 0;
        bottom: 66px;
        height: min(70vh, 480px);
    }

    .chat-page-card {
        min-height: 480px;
        max-height: none;
    }

    .chat-bubble {
        max-width: 92%;
    }

    .chat-send-label {
        display: none;
    }
}

/* Keep space above site back-to-top (often bottom-left/right) */
@media (min-width: 992px) {
    .chat-widget {
        bottom: 28px;
        right: 28px;
    }
}
