/* ═══════════════════════════════════
   iWishs AI Chat Widget
   通用版聊天氣泡 — 所有顏色由 CSS 變數控制
   CSS 變數由 PHP 從後台設定注入
   ═══════════════════════════════════ */

/* ── 觸發按鈕 ── */
.iwishs-ai-bubble {
    position: fixed;
    bottom: 90px;
    right: 27px;
    z-index: 99998;
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    -webkit-tap-highlight-color: transparent;
}

.iwishs-ai-bubble:hover { transform: scale(1.1); }
.iwishs-ai-bubble:active { transform: scale(0.93); }

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

.iwishs-ai-bubble-btn .iwishs-bubble-icon {
    font-size: 24px;
    line-height: 1;
    filter: drop-shadow(0 1px 2px rgba(0,0,0,0.1));
    animation: iwishs-icon-bounce 2s ease-in-out infinite;
}

@keyframes iwishs-icon-bounce {
    0%, 100% { transform: scale(1); }
    15% { transform: scale(1.2); }
    30% { transform: scale(0.95); }
    45% { transform: scale(1.1); }
    60% { transform: scale(1); }
}

/* 小標籤 */
.iwishs-ai-bubble-label {
    position: absolute;
    right: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-right: 10px;
    background: white;
    color: var(--iwishs-dark);
    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;
}

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

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

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

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

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

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

/* ── 聊天視窗 ── */
.iwishs-ai-chatbox {
    position: fixed;
    bottom: 100px;
    right: 40px;
    width: 370px;
    max-height: 520px;
    background: var(--iwishs-bg);
    border-radius: 20px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.15), 0 4px 16px rgba(var(--iwishs-primary-rgb), 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;
}

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

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

.iwishs-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;
}

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

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

.iwishs-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;
}

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

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

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

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

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

.iwishs-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);
}

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

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

.iwishs-ai-product:hover {
    border-color: var(--iwishs-primary);
    box-shadow: 0 2px 8px rgba(var(--iwishs-primary-rgb), 0.15);
}

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

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

.iwishs-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;
}

.iwishs-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;
}

.iwishs-ai-product-price {
    font-size: 13px;
    font-weight: 700;
    color: var(--iwishs-dark);
}

.iwishs-ai-product-cta {
    font-size: 10px;
    background: var(--iwishs-primary);
    color: white;
    padding: 3px 8px;
    border-radius: 10px;
    display: inline-block;
    margin-left: 6px;
    font-weight: 500;
}

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

.iwishs-ai-quick-btn {
    padding: 6px 12px;
    border: 1px solid var(--iwishs-border);
    border-radius: 20px;
    background: white;
    color: var(--iwishs-dark);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.iwishs-ai-quick-btn:hover {
    background: var(--iwishs-primary);
    color: white;
    border-color: var(--iwishs-primary);
}

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

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

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

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

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

.iwishs-ai-input {
    flex: 1;
    border: 1px solid var(--iwishs-border);
    border-radius: 20px;
    padding: 9px 16px;
    font-size: 16px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
    background: var(--iwishs-bg);
    -webkit-text-size-adjust: 100%;
}

.iwishs-ai-input:focus { border-color: var(--iwishs-primary); }
.iwishs-ai-input::placeholder { color: #bbb; }

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

.iwishs-ai-send:hover { transform: scale(1.05); }
.iwishs-ai-send:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.iwishs-ai-send svg { width: 16px; height: 16px; fill: white; }

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

/* ── 手機版 ── */
@media (max-width: 768px) {
    .iwishs-ai-chatbox {
        width: calc(100vw - 20px);
        right: 10px;
        bottom: 150px;
        max-height: 60vh;
        border-radius: 16px;
    }
    .iwishs-ai-bubble { right: 26px; bottom: 90px; }
    .iwishs-ai-bubble-btn { width: 48px; height: 48px; }
    .iwishs-ai-bubble-btn .iwishs-bubble-icon { font-size: 22px; }
    .iwishs-ai-bubble-label { display: none; }
    .iwishs-ai-bubble-dot { width: 10px; height: 10px; }
    .iwishs-ai-quick-btn { font-size: 14px; }
    .iwishs-ai-order-card { max-width: 100%; box-sizing: border-box; }
    .iwishs-ai-oc-item-name { max-width: 140px; }
    .iwishs-ai-oc-tracking { font-size: 12px; }
}

/* ── 訂單查詢表單 ── */
.iwishs-ai-order-form-wrap.iwishs-ai-msg { max-width: 95%; }

.iwishs-ai-order-form {
    padding: 12px;
    border: 1px solid var(--iwishs-border, #ddd);
    border-radius: 10px;
    background: var(--iwishs-bg, #f9f9f9);
}

.iwishs-ai-of-row { margin-bottom: 6px; }

.iwishs-ai-of-row label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: var(--iwishs-dark, #555);
    margin-bottom: 2px;
}

.iwishs-ai-of-row input {
    width: 100%;
    padding: 7px 10px;
    border: 1px solid var(--iwishs-border, #ddd);
    border-radius: 6px;
    font-size: 13px;
    font-family: inherit;
    outline: none;
    background: white;
    box-sizing: border-box;
    transition: border-color 0.2s;
    line-height: normal;
}

.iwishs-ai-of-row input:focus { border-color: var(--iwishs-primary); }
.iwishs-ai-of-row input::placeholder { color: #ccc; }

.iwishs-ai-of-submit {
    width: 100%;
    padding: 9px;
    background: linear-gradient(135deg, var(--iwishs-primary), var(--iwishs-gradient));
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    margin-top: 4px;
}

.iwishs-ai-of-submit:hover { opacity: 0.92; }
.iwishs-ai-of-submit:active { transform: scale(0.98); }

/* ── 訂單卡片 ── */
.iwishs-ai-order-card {
    background: white;
    border: 1px solid var(--iwishs-border, #ddd);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 8px;
    font-size: 13px;
    box-sizing: border-box;
}

.iwishs-ai-order-card:last-child { margin-bottom: 0; }

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

.iwishs-ai-oc-id { font-weight: 700; font-size: 14px; color: var(--iwishs-dark); }
.iwishs-ai-oc-date { font-size: 11px; color: #999; }
.iwishs-ai-oc-status { font-size: 11px; color: white; padding: 2px 8px; border-radius: 10px; font-weight: 600; margin-left: auto; }

.iwishs-ai-oc-items { border-top: 1px solid var(--iwishs-border, #eee); padding-top: 6px; }

.iwishs-ai-oc-item { display: flex; align-items: center; gap: 6px; padding: 3px 0; font-size: 12px; }
.iwishs-ai-oc-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #333; max-width: 160px; }
.iwishs-ai-oc-item-qty { color: #999; font-size: 11px; flex-shrink: 0; }
.iwishs-ai-oc-item-total { font-weight: 600; color: #555; flex-shrink: 0; }

.iwishs-ai-oc-total {
    display: flex;
    justify-content: space-between;
    font-weight: 700;
    border-top: 1px solid var(--iwishs-border, #eee);
    padding-top: 6px;
    margin-top: 4px;
    font-size: 14px;
    color: var(--iwishs-dark);
}

.iwishs-ai-oc-meta { font-size: 11px; color: #888; margin-top: 4px; }

.iwishs-ai-oc-tracking {
    background: var(--iwishs-bg, #f9f9f9);
    border: 1px solid var(--iwishs-border, #ddd);
    border-radius: 8px;
    padding: 8px 10px;
    margin-top: 8px;
    font-size: 12px;
    line-height: 1.6;
}

.iwishs-ai-oc-tracking div { padding: 1px 0; }
.iwishs-ai-oc-tracking strong { color: var(--iwishs-dark); }
