/* ═══════════════════════════════════
   GBPH AI Chat Widget
   可愛雲朵 AI 聊天氣泡
   位置：Chaty 紫色按鈕的正上方
   ═══════════════════════════════════ */

/* ── 觸發按鈕：實心橘紅圓 + 白色愛心 ── */
.gbph-ai-bubble {
    position: fixed;
    bottom: 90px; /* Chaty: bottom 25 + size 54 + gap 11 = 90 */
    right: 27px;  /* 對齊 Chaty 中心：Chaty right 25 + half(56-52)/2 = 27 */
    z-index: 99998;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    -webkit-tap-highlight-color: transparent;
}

.gbph-ai-bubble:hover {
    transform: scale(1.1);
}

.gbph-ai-bubble:active {
    transform: scale(0.93);
}

.gbph-ai-bubble-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, #E8573A, #FF6B35);
    box-shadow: 0 3px 14px rgba(232, 87, 58, 0.35), 0 1px 4px rgba(0, 0, 0, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    position: relative;
}

/* 白色愛心 + 閃跳動畫 */
.gbph-ai-bubble-btn svg.heart-icon {
    width: 24px;
    height: 24px;
    fill: white;
    animation: gbph-heart-bounce 2s ease-in-out infinite;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
}

@keyframes gbph-heart-bounce {
    0%, 100% { transform: scale(1); }
    15% { transform: scale(1.25); }
    30% { transform: scale(0.95); }
    45% { transform: scale(1.12); }
    60% { transform: scale(1); }
}

/* 小標籤 */
.gbph-ai-bubble-label {
    position: absolute;
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-right: 10px;
    background: white;
    color: #E8573A;
    font-size: 12px;
    font-weight: 600;
    font-family: 'PingFang TC', 'Microsoft JhengHei', sans-serif;
    padding: 5px 12px;
    border-radius: 20px;
    white-space: nowrap;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s;
}

.gbph-ai-bubble-label.show {
    opacity: 1;
}

.gbph-ai-bubble-label::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 100%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-left-color: white;
}

.gbph-ai-bubble.chat-open .gbph-ai-bubble-label {
    opacity: 0 !important;
}

/* 小紅點通知 */
.gbph-ai-bubble-dot {
    position: absolute;
    top: 0px;
    right: 0px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: white;
    border: 2.5px solid #E8573A;
    animation: gbph-dot-pulse 2.5s ease-in-out infinite;
}

.gbph-ai-bubble.chat-open .gbph-ai-bubble-dot {
    display: none;
}

@keyframes gbph-dot-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.3); }
}

/* ── 聊天視窗 ── */
.gbph-ai-chatbox {
    position: fixed;
    bottom: 100px;
    right: 40px;
    width: 370px;
    max-height: 520px;
    background: #FFFAF7;
    border-radius: 20px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15), 0 4px 16px rgba(232, 87, 58, 0.1);
    z-index: 99998;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.35s cubic-bezier(0.16, 1, 0.3, 1),
                transform 0.35s cubic-bezier(0.16, 1, 0.3, 1);
    font-family: 'PingFang TC', 'Microsoft JhengHei', sans-serif;
}

.gbph-ai-chatbox.visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ── Header ── */
.gbph-ai-header {
    background: linear-gradient(135deg, #E8573A, #FF6B35);
    color: white;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}

.gbph-ai-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
}

.gbph-ai-header-info h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.3px;
}

.gbph-ai-header-info p {
    margin: 2px 0 0;
    font-size: 11px;
    opacity: 0.85;
}

.gbph-ai-close {
    margin-left: auto;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
}

.gbph-ai-close:hover {
    background: rgba(255, 255, 255, 0.35);
}

/* ── 訊息區 ── */
.gbph-ai-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-height: 200px;
    max-height: 320px;
}

.gbph-ai-messages::-webkit-scrollbar {
    width: 4px;
}

.gbph-ai-messages::-webkit-scrollbar-thumb {
    background: #ddd;
    border-radius: 4px;
}

/* 訊息泡泡 */
.gbph-ai-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.6;
    animation: gbph-msg-in 0.3s ease-out;
}

@keyframes gbph-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.gbph-ai-msg.bot {
    background: white;
    color: #333;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.gbph-ai-msg.user {
    background: linear-gradient(135deg, #E8573A, #FF6B35);
    color: white;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* 產品卡片 */
.gbph-ai-product {
    display: flex;
    gap: 10px;
    background: white;
    border: 1px solid #f0e0d0;
    border-radius: 12px;
    padding: 10px;
    margin-top: 6px;
    text-decoration: none;
    color: inherit;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.gbph-ai-product:hover {
    border-color: #E8573A;
    box-shadow: 0 2px 8px rgba(232, 87, 58, 0.12);
}

.gbph-ai-product img {
    width: 56px;
    height: 56px;
    border-radius: 8px;
    object-fit: cover;
    flex-shrink: 0;
    background: #f5f5f5;
}

.gbph-ai-product-info {
    flex: 1;
    min-width: 0;
}

.gbph-ai-product-name {
    font-size: 13px;
    font-weight: 600;
    color: #333;
    margin: 0 0 3px;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.gbph-ai-product-desc {
    font-size: 11.5px;
    color: #888;
    margin: 0 0 4px;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.gbph-ai-product-reason {
    font-size: 11.5px;
    color: #E8573A;
    font-weight: 500;
    margin: 0 0 3px;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.gbph-ai-product-price {
    font-size: 13px;
    font-weight: 700;
    color: #E8573A;
}

.gbph-ai-product-cta {
    font-size: 10px;
    background: #E8573A;
    color: white;
    padding: 3px 8px;
    border-radius: 10px;
    display: inline-block;
    margin-left: 6px;
    font-weight: 500;
}

/* 快速問題按鈕 */
.gbph-ai-quick-btns {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
}

.gbph-ai-quick-btn {
    padding: 6px 12px;
    border: 1px solid #FFDDD2;
    border-radius: 20px;
    background: white;
    color: #E8573A;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.gbph-ai-quick-btn:hover {
    background: #E8573A;
    color: white;
    border-color: #E8573A;
}

/* 打字中動畫 */
.gbph-ai-typing {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    align-self: flex-start;
}

.gbph-ai-typing span {
    width: 7px;
    height: 7px;
    background: #ccc;
    border-radius: 50%;
    animation: gbph-typing-dot 1.2s infinite;
}

.gbph-ai-typing span:nth-child(2) { animation-delay: 0.2s; }
.gbph-ai-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes gbph-typing-dot {
    0%, 60%, 100% { transform: translateY(0); background: #ccc; }
    30% { transform: translateY(-6px); background: #E8573A; }
}

/* ── 輸入區 ── */
.gbph-ai-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid #f0e0d0;
    background: white;
    flex-shrink: 0;
}

.gbph-ai-input {
    flex: 1;
    border: 1px solid #e8ddd5;
    border-radius: 20px;
    padding: 9px 16px;
    font-size: 16px; /* 必須 >= 16px 否則 iOS Safari 會自動放大 */
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    background: #FFFAF7;
    -webkit-text-size-adjust: 100%; /* 防止 iOS 自動調整 */
}

.gbph-ai-input:focus {
    border-color: #E8573A;
}

.gbph-ai-input::placeholder {
    color: #bbb;
}

.gbph-ai-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #E8573A, #FF6B35);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, opacity 0.15s;
}

.gbph-ai-send:hover {
    transform: scale(1.05);
}

.gbph-ai-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.gbph-ai-send svg {
    width: 16px;
    height: 16px;
    fill: white;
}

/* ── 免責小字 ── */
.gbph-ai-disclaimer {
    text-align: center;
    font-size: 10px;
    color: #bbb;
    padding: 4px 16px 10px;
    background: white;
}

/* ── 訂單查詢表單（緊湊：四欄位一次顯示） ── */
.gbph-ai-order-form-wrap.gbph-ai-msg {
    padding: 4px 8px;
}

.gbph-ai-order-form {
    background: #FFF8F5;
    border: 1px solid #f0e0d0;
    border-radius: 10px;
    padding: 8px 10px;
}

.gbph-ai-of-row {
    margin-bottom: 3px;
}

.gbph-ai-of-row label {
    display: block;
    font-size: 11px;
    color: #666;
    margin-bottom: 1px;
    font-weight: 500;
}

.gbph-ai-of-row input {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid #e0d5cc;
    border-radius: 6px;
    font-size: 14px;
    line-height: normal;
    font-family: inherit;
    outline: none;
    background: white;
    box-sizing: border-box;
    transition: border-color 0.2s;
}

.gbph-ai-of-row input:focus {
    border-color: #E8573A;
}

.gbph-ai-of-row input::placeholder {
    color: #ccc;
}

.gbph-ai-of-submit {
    width: 100%;
    padding: 7px;
    background: linear-gradient(135deg, #E8573A, #FF6B35);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: transform 0.15s, opacity 0.15s;
}

.gbph-ai-of-submit:hover {
    transform: scale(1.02);
}

.gbph-ai-of-submit:active {
    transform: scale(0.98);
}

/* ── 訂單卡片 ── */
.gbph-ai-order-card {
    background: white;
    border: 1px solid #f0e0d0;
    border-radius: 12px;
    padding: 12px;
    margin-top: 8px;
    font-size: 13px;
    box-sizing: border-box;
    overflow: hidden;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.gbph-ai-oc-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.gbph-ai-oc-id {
    font-weight: 700;
    color: #333;
    font-size: 14px;
}

.gbph-ai-oc-date {
    font-size: 11px;
    color: #999;
}

.gbph-ai-oc-status {
    margin-left: auto;
    font-size: 11px;
    font-weight: 600;
    color: white;
    padding: 2px 10px;
    border-radius: 10px;
}

.gbph-ai-oc-items {
    border-top: 1px solid #f5ece5;
    padding-top: 8px;
}

.gbph-ai-oc-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 0;
    font-size: 12.5px;
}

.gbph-ai-oc-item-name {
    flex: 1;
    color: #444;
    min-width: 0;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.gbph-ai-oc-item-qty {
    color: #999;
    font-size: 11px;
    flex-shrink: 0;
}

.gbph-ai-oc-item-total {
    color: #333;
    font-weight: 500;
    flex-shrink: 0;
}

.gbph-ai-oc-total {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid #f5ece5;
    margin-top: 6px;
    padding-top: 8px;
    font-weight: 700;
    color: #E8573A;
    font-size: 14px;
}

.gbph-ai-oc-meta {
    font-size: 11px;
    color: #999;
    margin-top: 6px;
}

.gbph-ai-oc-tracking {
    background: #F0FFF4;
    border: 1px solid #C6F6D5;
    border-radius: 8px;
    padding: 8px 10px;
    margin-top: 8px;
    font-size: 12px;
    color: #2D6A4F;
}

.gbph-ai-oc-tracking div {
    padding: 2px 0;
}

.gbph-ai-oc-tracking strong {
    font-weight: 600;
    user-select: all;
}

/* ── 手機版 ── */
@media (max-width: 768px) {
    .gbph-ai-chatbox {
        width: calc(100vw - 20px);
        max-width: calc(100vw - 20px);
        right: 10px;
        bottom: 150px;
        max-height: 60vh;
        border-radius: 16px;
    }

    .gbph-ai-bubble {
        right: 26px;
        bottom: 90px;
    }

    .gbph-ai-bubble-btn {
        width: 48px;
        height: 48px;
    }

    .gbph-ai-bubble-btn svg {
        width: 22px;
        height: 22px;
    }

    .gbph-ai-bubble-label {
        display: none;
    }

    .gbph-ai-bubble-dot {
        width: 10px;
        height: 10px;
    }

    .gbph-ai-quick-btn {
        font-size: 14px;
        padding: 7px 14px;
    }
}

/* 訂單卡片防溢出（全裝置） */
.gbph-ai-order-card {
    max-width: 100%;
    box-sizing: border-box;
    overflow: hidden;
}

.gbph-ai-oc-item-name {
    min-width: 0;
}

.gbph-ai-oc-tracking {
    word-break: break-all;
}
