/* AI Chat Widget - floating button and chat panel */

/* ── Streaming cursor ──────────────────────────────────────────────────────── */
@keyframes ai-cursor-blink {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0; }
}
.ai-stream-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: currentColor;
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: ai-cursor-blink 0.8s ease-in-out infinite;
}
.ai-chat-msg.ai-streaming {
    opacity: 0.9;
}
/* ─────────────────────────────────────────────────────────────────────────── */
.ai-chat-widget {
    position: fixed;
    bottom: 24px;
    left: 24px;
    z-index: 9999;
    font-family: inherit;
}

/* Hidden until country check: show widget only for Jordan (JO) */
.ai-chat-widget.geo-pending {
    visibility: hidden;
    pointer-events: none;
}

/* Launcher: button first, then label */
.ai-chat-launcher {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-direction: row;
}

/* ── Siri-like animations ─────────────────────────────────────────────────── */
@keyframes siri-border-flow {
    0%   { background-position: 0% 50%; }
    50%  { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}
@keyframes siri-breathe {
    0%, 100% { transform: scale(1); }
    50%       { transform: scale(1.025); }
}
@keyframes siri-toggle-glow {
    0%, 100% { box-shadow: 0 4px 18px rgba(0,122,255,0.38), 0 1px 4px rgba(0,0,0,0.10); }
    30%       { box-shadow: 0 4px 22px rgba(88,86,214,0.42),  0 1px 4px rgba(0,0,0,0.10); }
    60%       { box-shadow: 0 4px 22px rgba(255,149,0,0.38),  0 1px 4px rgba(0,0,0,0.10); }
}
/* ─────────────────────────────────────────────────────────────────────────── */

.ai-chat-launcher-label {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    /* White interior — ::before draws the animated gradient border */
    background: rgba(255,255,255,0.97);
    color: #1a2f50;
    font-size: 13px;
    font-weight: 700;
    padding: 9px 16px 9px 12px;
    border-radius: 24px;
    white-space: nowrap;
    letter-spacing: 0.01em;
    line-height: 1.4;
    visibility: visible;
    opacity: 1;
    /* Breathing */
    animation: siri-breathe 3s ease-in-out infinite;
    /* Stacking context for the gradient border pseudo-element */
    position: relative;
    z-index: 0;
    border: none;
}
/* Animated rainbow border (Siri-style) */
.ai-chat-launcher-label::before {
    content: '';
    position: absolute;
    inset: -2.5px;
    border-radius: 27px;
    background: linear-gradient(
        270deg,
        #007AFF 0%,
        #5856D6 18%,
        #AF52DE 33%,
        #FF2D55 50%,
        #FF9500 68%,
        #34C759 84%,
        #007AFF 100%
    );
    background-size: 300% 300%;
    animation: siri-border-flow 3s linear infinite;
    z-index: -1;
}
/* White fill inside the border */
.ai-chat-launcher-label::after {
    content: '';
    position: absolute;
    inset: 2px;
    background: rgba(255,255,255,0.97);
    border-radius: 21px;
    z-index: -1;
}

.ai-launcher-bot-icon {
    font-size: 15px;
    flex-shrink: 0;
    position: relative;
    z-index: 1;
}
#ai-chat-launcher-label {
    position: relative;
    z-index: 1;
}

/* Toggle button — uses the real Platinum "P" logo */
.ai-chat-toggle {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    border: none;
    background: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    /* Siri-like color-cycling glow */
    animation: siri-toggle-glow 3s ease infinite;
    transition: transform 0.2s;
    flex-shrink: 0;
    position: relative;
    overflow: visible;
    padding: 0;
}
.ai-chat-toggle:hover {
    transform: scale(1.07) translateY(-2px);
    animation: none;
    box-shadow: 0 8px 28px rgba(0,102,200,0.32), 0 2px 6px rgba(0,0,0,0.14);
}
.ai-chat-toggle-logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
    border-radius: 50%;
    display: block;
}
/* Small "AI" badge on the toggle button */
.ai-chat-toggle-badge {
    position: absolute;
    bottom: 2px;
    right: 2px;
    background: linear-gradient(135deg, #008ACF, #005f9e);
    color: #fff;
    font-size: 9px;
    font-weight: 800;
    line-height: 1;
    padding: 2px 5px;
    border-radius: 8px;
    letter-spacing: 0.04em;
    border: 1.5px solid #fff;
    pointer-events: none;
}

/* Unread messages badge — shown when new assistant reply arrives while panel closed or tab not focused */
.ai-chat-unread-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    min-width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #c00;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid #fff;
    pointer-events: none;
    box-sizing: border-box;
}
.ai-chat-unread-badge.hidden {
    display: none !important;
}

/* Chat panel */
.ai-chat-panel {
    position: absolute;
    bottom: 74px;
    left: 0;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 500px;
    max-height: 70vh;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(10px) scale(0.96);
    transition: opacity 0.25s, visibility 0.25s, transform 0.25s;
}
.ai-chat-panel.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}
.ai-chat-panel[aria-hidden="false"] {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

/* Header */
.ai-chat-header {
    padding: 14px 16px;
    background: linear-gradient(135deg, #008ACF 0%, #006699 100%);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}
.ai-chat-header-logo {
    width: 26px;
    height: 26px;
    margin-right: 10px;
    object-fit: contain;
    flex-shrink: 0;
    /* No filter: assistant icon uses brand blue/orange; keep colors visible on blue header */
}
[dir="rtl"] .ai-chat-header-logo {
    margin-right: 0;
    margin-left: 10px;
}
.ai-chat-header-title {
    font-weight: 600;
    font-size: 16px;
    display: flex;
    align-items: center;
    min-height: 1.5em;
    overflow: visible;
}
.ai-chat-header-title span {
    flex: 1;
    min-width: 0;
    overflow: visible;
    white-space: nowrap;
    text-overflow: ellipsis;
}
.ai-chat-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}
.ai-chat-clear,
.ai-chat-close {
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    border: none;
    background: rgba(255,255,255,0.2);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s;
    flex-shrink: 0;
}
.ai-chat-clear:hover,
.ai-chat-close:hover {
    background: rgba(255,255,255,0.35);
}
.ai-chat-clear i,
.ai-chat-close i {
    font-size: 16px;
    pointer-events: none;
}

/* Messages area */
.ai-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    background: #f5f6f8;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.ai-chat-welcome {
    padding: 12px 14px;
    background: #e8eef2;
    border-radius: 12px;
    color: #333;
    font-size: 14px;
    line-height: 1.5;
}
.ai-chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}
.ai-chat-msg.user {
    align-self: flex-end;
    background: #008ACF;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ai-chat-msg.assistant {
    align-self: flex-start;
    background: #fff;
    color: #333;
    border: 1px solid #e0e0e0;
    border-bottom-left-radius: 4px;
}
.ai-chat-msg.error {
    align-self: flex-start;
    background: #ffebee;
    color: #c62828;
    border: 1px solid #ffcdd2;
}
.ai-chat-msg .ai-chat-link {
    color: #008ACF;
    text-decoration: underline;
    word-break: break-all;
}
.ai-chat-msg.user .ai-chat-link {
    color: #fff;
    text-decoration: underline;
}
.ai-chat-msg .ai-chat-link:hover {
    opacity: 0.9;
}

/* Row of product images — صور المنتج في الشات بصف لحال */
.ai-chat-product-images-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin: 10px 0 14px 0;
    align-items: flex-start;
}
.ai-chat-product-images-row .ai-product-card {
    flex-direction: column;
    align-items: center;
    text-align: center;
    width: auto;
    max-width: 110px;
    min-width: 90px;
    padding: 10px 8px;
}
.ai-chat-product-images-row .ai-product-thumb-wrap {
    width: 88px;
    height: 88px;
    border-radius: 10px;
    margin-bottom: 6px;
}
.ai-chat-product-images-row .ai-product-name {
    font-size: 12px;
    -webkit-line-clamp: 2;
    margin-bottom: 2px;
}
.ai-chat-product-images-row .ai-product-meta {
    align-items: center;
    margin-inline-start: 0;
}
.ai-chat-product-images-row .ai-product-card:hover {
    transform: translateY(-2px);
}
[dir="rtl"] .ai-chat-product-images-row .ai-product-card:hover {
    transform: translateY(-2px);
}

/* Product card — rendered for list-style product suggestions */
.ai-product-card {
    display: flex;
    align-items: center;
    gap: 8px;
    background: linear-gradient(135deg, #f0f9ff 0%, #e4f3fb 100%);
    border: 1px solid #b8ddf2;
    border-left: 3px solid #008ACF;
    border-radius: 10px;
    padding: 9px 12px;
    margin: 5px 0;
    text-decoration: none;
    color: #1a1a1a !important;
    font-size: 13px;
    transition: background 0.15s, border-color 0.15s, transform 0.12s;
    width: 100%;
    box-sizing: border-box;
}
.ai-product-card:hover {
    background: linear-gradient(135deg, #daf0ff 0%, #c8e6f8 100%);
    border-left-color: #005580;
    transform: translateX(3px);
    color: #000;
}
[dir="rtl"] .ai-product-card {
    border-left: 1px solid #b8ddf2;
    border-right: 3px solid #008ACF;
}
[dir="rtl"] .ai-product-card:hover {
    transform: translateX(-3px);
}
.ai-product-icon {
    font-size: 15px;
    flex-shrink: 0;
    line-height: 1;
}
.ai-product-thumb-wrap {
    width: 26px;
    height: 26px;
    border-radius: 6px;
    background: #e9f4fb;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    flex-shrink: 0;
}
.ai-product-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}
.ai-product-thumb-wrap.has-image .ai-product-thumb {
    display: block;
}
.ai-product-thumb-wrap.has-image .ai-product-icon {
    display: none;
}
.ai-product-name {
    font-weight: 600;
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-transform: capitalize;
    color: #1a1a1a !important;
    line-height: 1.25;
    max-height: 2.5em;
}
/* Ensure product card text is always dark (overrides any parent/theme) */
.ai-chat-msg .ai-product-card,
.ai-chat-msg .ai-product-card .ai-product-name {
    color: #1a1a1a !important;
}
.ai-product-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
    margin-inline-start: auto;
    flex-shrink: 0;
}
[dir="rtl"] .ai-product-meta {
    align-items: flex-start;
}
.ai-product-price {
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    background: #008ACF;
    padding: 3px 9px;
    border-radius: 12px;
    white-space: nowrap;
    flex-shrink: 0;
}
.ai-product-see {
    font-size: 11px;
    font-weight: 600;
    color: #006699;
    background: rgba(0, 138, 207, 0.12);
    border: 1px solid rgba(0, 138, 207, 0.35);
    padding: 2px 8px;
    border-radius: 10px;
    line-height: 1.2;
}

/* WhatsApp order handoff card */
.ai-order-card {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 6px 0;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid #b9e8c5;
    background: linear-gradient(135deg, #ecfff2 0%, #dff8ea 100%);
    text-decoration: none;
    color: #136f3a !important;
}
.ai-order-icon {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}
.ai-order-title {
    font-size: 12px;
    font-weight: 700;
    color: #136f3a;
    flex: 1;
}
.ai-order-cta {
    font-size: 11px;
    font-weight: 700;
    color: #fff;
    background: #25d366;
    border-radius: 10px;
    padding: 3px 8px;
    white-space: nowrap;
}
/* Spec rows — title on one line, value on the next; icon per row; RTL-friendly */
.ai-spec-row {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    background: #f4f7fb;
    margin: 5px 0;
    font-size: 13px;
    line-height: 1.5;
    border-inline-start: 4px solid #e0e8f5;
    direction: inherit;
}
.ai-spec-row:nth-child(even) {
    background: #eef2f9;
}
.ai-spec-icon {
    font-size: 18px;
    flex-shrink: 0;
    width: 26px;
    text-align: center;
    line-height: 1.3;
}
.ai-spec-block {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    text-align: start;
}
.ai-spec-title {
    font-weight: 700;
    color: #1a2940;
    font-size: 12px;
    line-height: 1.4;
}
.ai-spec-value {
    color: #3a4a5c;
    font-size: 13px;
    word-break: break-word;
    line-height: 1.45;
}
/* RTL: keep accent on the start side; block content aligns right */
[dir="rtl"] .ai-spec-row,
.ai-chat-msg[dir="rtl"] .ai-spec-row {
    border-inline-start: 4px solid #e0e8f5;
}
[dir="rtl"] .ai-spec-block,
.ai-chat-msg[dir="rtl"] .ai-spec-block {
    text-align: right;
}

/* ── Contact buttons (Maps, Contact page, Facebook, WhatsApp) ─────────────── */
.ai-contact-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 16px;
    border-radius: 22px;
    text-decoration: none !important;
    font-size: 13px;
    font-weight: 700;
    color: #fff !important;
    white-space: nowrap;
    vertical-align: middle;
    margin: 4px 3px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    transition: opacity 0.15s, transform 0.1s;
}
.ai-contact-btn:hover {
    opacity: 0.88;
    transform: translateY(-1px);
    text-decoration: none !important;
}
.ai-contact-icon {
    font-size: 16px;
    line-height: 1;
}
.ai-contact-maps    { background: linear-gradient(135deg,#34a853,#2d8f48); }
.ai-contact-page    { background: linear-gradient(135deg,#1a6fbd,#1558a0); }
.ai-contact-facebook{ background: linear-gradient(135deg,#1877f2,#1060cc); }
.ai-contact-appstore { background: linear-gradient(135deg,#1a1a1a,#444); }
.ai-contact-playstore{ background: linear-gradient(135deg,#00875a,#34a853); }

/* WhatsApp contact pill — for general contact/info mentions */
.ai-wa-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 8px 16px;
    border-radius: 22px;
    background: linear-gradient(135deg,#25d366,#1aaf55);
    color: #fff !important;
    font-size: 13px;
    font-weight: 700;
    text-decoration: none !important;
    white-space: nowrap;
    vertical-align: middle;
    margin: 4px 3px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.15);
    transition: opacity 0.15s, transform 0.1s;
}
.ai-wa-btn:hover {
    opacity: 0.88;
    transform: translateY(-1px);
}
.ai-wa-btn-icon {
    font-size: 16px;
    line-height: 1;
}

.ai-chat-typing {
    align-self: flex-start;
    padding: 12px 18px;
    background: #fff;
    border: 1px solid #e0e0e0;
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}
.ai-chat-typing span {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #008ACF;
    margin: 0 2px;
    animation: ai-chat-bounce 0.6s ease-in-out infinite;
}
.ai-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.ai-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ai-chat-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}

/* Input area */
.ai-chat-input-area {
    padding: 12px;
    background: #fff;
    border-top: 1px solid #e0e0e0;
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
}
.ai-chat-input {
    flex: 1;
    min-height: 44px;
    max-height: 120px;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 22px;
    font-size: 14px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color 0.2s;
}
.ai-chat-input:focus {
    border-color: #008ACF;
}
.ai-chat-send {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: #008ACF;
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}
.ai-chat-send:hover {
    background: #006699;
}
.ai-chat-send:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* RTL: panel still anchors to the left edge of the launcher */
[dir="rtl"] .ai-chat-panel {
    left: 0;
    right: auto;
}

/* Keep launcher label visible on mobile; only hide on very narrow screens to avoid overlap */
@media (max-width: 280px) {
    .ai-chat-launcher-label {
        display: none;
    }
}
[dir="rtl"] .ai-chat-msg.user {
    border-bottom-right-radius: 14px;
    border-bottom-left-radius: 4px;
}
[dir="rtl"] .ai-chat-msg.assistant {
    border-bottom-left-radius: 14px;
    border-bottom-right-radius: 4px;
}
[dir="rtl"] .ai-chat-icon-header {
    margin-right: 0;
    margin-left: 10px;
}

/* Mobile: make panel feel native; ensure header and launcher title visible */
@media (max-width: 600px) {
    .ai-chat-widget {
        left: 16px;
        right: auto;
        bottom: calc(16px + env(safe-area-inset-bottom));
    }

    .ai-chat-panel {
        width: min(420px, calc(100vw - 32px));
        height: min(70vh, 540px);
        max-height: calc(100vh - 140px);
    }

    .ai-chat-header-title {
        visibility: visible;
        opacity: 1;
    }
    .ai-chat-header-title span {
        visibility: visible;
        opacity: 1;
    }

    .ai-chat-launcher-label {
        display: inline-flex;
        visibility: visible;
        opacity: 1;
    }

    .ai-chat-clear,
    .ai-chat-close {
        width: 44px;
        height: 44px;
        min-width: 44px;
        min-height: 44px;
    }
    .ai-chat-header-actions {
        gap: 6px;
    }
    .ai-chat-clear i,
    .ai-chat-close i {
        font-size: 18px;
    }
}

@media (max-width: 420px) {
    .ai-chat-panel {
        width: calc(100vw - 24px);
        height: min(78vh, 560px);
        border-radius: 14px;
    }

    .ai-chat-messages {
        padding: 12px;
    }

    .ai-chat-header {
        padding: 10px 12px;
    }
    .ai-chat-header-title {
        font-size: 15px;
    }
    .ai-chat-clear,
    .ai-chat-close {
        width: 42px;
        height: 42px;
        min-width: 42px;
        min-height: 42px;
    }
    .ai-chat-header-actions {
        gap: 4px;
    }
}

/* ── Product page: glow + label "Ask about this product with AI" ─────────────────────────── */
.ai-chat-widget--on-product-page .ai-chat-launcher {
    animation: product-page-glow-pulse 2.5s ease-in-out infinite;
}
@keyframes product-page-glow-pulse {
    0%, 100% {
        filter: drop-shadow(0 0 8px rgba(0, 136, 204, 0.4)) drop-shadow(0 0 16px rgba(0, 136, 204, 0.2));
    }
    50% {
        filter: drop-shadow(0 0 14px rgba(0, 136, 204, 0.6)) drop-shadow(0 0 24px rgba(0, 136, 204, 0.35));
    }
}
.ai-chat-widget--on-product-page .ai-chat-toggle {
    animation: product-page-toggle-glow 2.5s ease-in-out infinite;
}
@keyframes product-page-toggle-glow {
    0%, 100% { box-shadow: 0 4px 18px rgba(0, 136, 204, 0.45), 0 1px 4px rgba(0,0,0,0.10); }
    50%      { box-shadow: 0 6px 24px rgba(0, 136, 204, 0.6), 0 2px 8px rgba(0,0,0,0.12); }
}
.ai-chat-widget--on-product-page .ai-chat-launcher-label.ai-chat-product-page-label {
    animation: product-page-label-pulse 2.2s ease-in-out infinite;
}
@keyframes product-page-label-pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.95; transform: scale(1.02); }
}
