/* ==========================================================================
   SANAD GOLD — HYBRID AI CONCIERGE & UNIFIED WHATSAPP WIDGET
   Luxury Royal Navy (#071b33) + Metallic Gold (#d4af37) Design System
   ========================================================================== */

:root {
    --sg-ai-navy-900: #071b33;
    --sg-ai-navy-800: #0d2849;
    --sg-ai-navy-700: #153761;
    --sg-ai-gold-500: #d4af37;
    --sg-ai-gold-400: #e7c65f;
    --sg-ai-gold-600: #b89024;
    --sg-ai-wa-green: #22c55e;
    --sg-ai-wa-dark: #16a34a;
    --sg-ai-surface: #ffffff;
    --sg-ai-bg: #f6f8fb;
    --sg-ai-border: rgba(7, 27, 51, 0.09);
    --sg-ai-text: #0f172a;
    --sg-ai-muted: #64748b;
}

/* --------------------------------------------------------------------------
   1. FLOATING LAUNCHER BUTTON (Design B: Unified & Design A: Stacked)
   -------------------------------------------------------------------------- */
.sg-ai-launcher {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 1045;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    min-height: 54px;
    padding: 8px 18px 8px 14px;
    border-radius: 999px;
    border: 1.5px solid rgba(212, 175, 55, 0.65);
    background: linear-gradient(135deg, var(--sg-ai-navy-900) 0%, var(--sg-ai-navy-800) 100%);
    color: #ffffff !important;
    box-shadow: 0 14px 34px rgba(7, 27, 51, 0.34), 0 0 0 4px rgba(212, 175, 55, 0.14);
    cursor: pointer;
    font-family: inherit;
    font-size: 14px;
    font-weight: 800;
    line-height: 1.2;
    text-decoration: none !important;
    transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.24s ease, border-color 0.24s ease;
    -webkit-tap-highlight-color: transparent;
}

html[dir="ltr"] .sg-ai-launcher {
    padding: 8px 14px 8px 18px;
}

.sg-ai-launcher:hover,
.sg-ai-launcher:focus {
    transform: translateY(-3px);
    border-color: var(--sg-ai-gold-400);
    box-shadow: 0 18px 40px rgba(7, 27, 51, 0.42), 0 0 0 6px rgba(212, 175, 55, 0.22);
    outline: none;
}

/* Design A (Stacked above separate WhatsApp button) */
.sg-ai-launcher.is-stacked {
    bottom: 88px;
}

/* Respect Saudi Business Center badge if ever positioned bottom-right */
body.sg-sbc-bottom-right .sg-ai-launcher.is-unified {
    bottom: 92px;
}
body.sg-sbc-bottom-right .sg-ai-launcher.is-stacked {
    bottom: 156px;
}

.sg-ai-launcher-icon-wrap {
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--sg-ai-gold-400) 0%, var(--sg-ai-gold-600) 100%);
    color: var(--sg-ai-navy-900);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(212, 175, 55, 0.38);
}

/* Unified WhatsApp micro-badge on launcher icon */
.sg-ai-launcher-wa-dot {
    position: absolute;
    bottom: -2px;
    left: -2px;
    width: 17px;
    height: 17px;
    border-radius: 50%;
    background: var(--sg-ai-wa-dark);
    color: #ffffff;
    border: 2px solid var(--sg-ai-navy-900);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
}

.sg-ai-launcher-online-dot {
    position: absolute;
    top: -1px;
    right: -1px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--sg-ai-wa-green);
    border: 2px solid var(--sg-ai-navy-900);
}

.sg-ai-launcher-copy {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    text-align: start;
}

.sg-ai-launcher-title {
    color: #ffffff;
    font-size: 13.5px;
    font-weight: 800;
    letter-spacing: 0;
    white-space: nowrap;
}

.sg-ai-launcher-sub {
    color: var(--sg-ai-gold-400);
    font-size: 10.5px;
    font-weight: 600;
    white-space: nowrap;
}

.sg-ai-launcher.is-open .sg-ai-launcher-icon-wrap i.sg-ai-open-ico {
    display: none;
}
.sg-ai-launcher:not(.is-open) .sg-ai-launcher-icon-wrap i.sg-ai-close-ico {
    display: none;
}

/* Hide separate floating WhatsApp button when Unified Mode is active */
body.sg-ai-unified-active .sg-whatsapp-float {
    display: none !important;
}

/* --------------------------------------------------------------------------
   2. CHAT PANEL WINDOW
   -------------------------------------------------------------------------- */
.sg-ai-panel {
    position: fixed;
    right: 22px;
    bottom: 88px;
    z-index: 1055;
    width: 392px;
    max-width: calc(100vw - 28px);
    height: 585px;
    max-height: calc(100vh - 115px);
    display: flex;
    flex-direction: column;
    border-radius: 22px;
    background: var(--sg-ai-surface);
    border: 1px solid rgba(212, 175, 55, 0.35);
    box-shadow: 0 24px 64px rgba(7, 27, 51, 0.28), 0 4px 16px rgba(7, 27, 51, 0.12);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(18px) scale(0.97);
    transform-origin: bottom right;
    transition: opacity 0.24s ease, transform 0.26s cubic-bezier(0.22, 1, 0.36, 1), visibility 0.24s ease;
}

.sg-ai-panel.is-stacked {
    bottom: 152px;
    max-height: calc(100vh - 175px);
}

.sg-ai-panel.is-open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

/* Header */
.sg-ai-header {
    padding: 15px 16px 13px;
    background: linear-gradient(135deg, var(--sg-ai-navy-900) 0%, var(--sg-ai-navy-800) 60%, var(--sg-ai-navy-700) 100%);
    border-bottom: 1px solid rgba(212, 175, 55, 0.28);
    color: #ffffff;
    flex-shrink: 0;
}

.sg-ai-header-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.sg-ai-brand {
    display: flex;
    align-items: center;
    gap: 11px;
    min-width: 0;
}

.sg-ai-avatar {
    position: relative;
    width: 42px;
    height: 42px;
    border-radius: 13px;
    background: linear-gradient(135deg, rgba(212, 175, 55, 0.24) 0%, rgba(212, 175, 55, 0.08) 100%);
    border: 1px solid rgba(212, 175, 55, 0.55);
    color: var(--sg-ai-gold-400);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 19px;
    flex-shrink: 0;
}

.sg-ai-avatar-status {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: var(--sg-ai-wa-green);
    border: 2px solid var(--sg-ai-navy-900);
}

.sg-ai-brand-text {
    min-width: 0;
}

.sg-ai-brand-text h3 {
    margin: 0;
    color: #ffffff !important;
    font-size: 15.5px;
    font-weight: 800;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sg-ai-brand-text p {
    margin: 2px 0 0;
    color: rgba(255, 255, 255, 0.78);
    font-size: 11.5px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sg-ai-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.sg-ai-icon-btn {
    width: 32px;
    height: 32px;
    border-radius: 9px;
    border: 1px solid rgba(255, 255, 255, 0.14);
    background: rgba(255, 255, 255, 0.07);
    color: rgba(255, 255, 255, 0.9);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    cursor: pointer;
    transition: background 0.18s ease, color 0.18s ease;
}

.sg-ai-icon-btn:hover {
    background: rgba(255, 255, 255, 0.18);
    color: #ffffff;
}

/* Direct WhatsApp Quick Bar inside Header */
.sg-ai-wa-bar {
    margin-top: 11px;
    padding-top: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.sg-ai-wa-hint {
    color: rgba(255, 255, 255, 0.82);
    font-size: 11.5px;
    font-weight: 600;
}

.sg-ai-wa-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px;
    border-radius: 999px;
    background: linear-gradient(135deg, #25d366 0%, #16a34a 100%);
    color: #ffffff !important;
    font-size: 11.5px;
    font-weight: 800;
    text-decoration: none !important;
    box-shadow: 0 4px 12px rgba(22, 163, 74, 0.32);
    transition: transform 0.18s ease, filter 0.18s ease;
    white-space: nowrap;
}

.sg-ai-wa-btn:hover {
    transform: translateY(-1px);
    filter: brightness(1.06);
    color: #ffffff !important;
}

/* Messages Stream */
.sg-ai-messages {
    flex: 1 1 auto;
    padding: 15px 14px;
    background: var(--sg-ai-bg);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.sg-ai-msg {
    display: flex;
    flex-direction: column;
    max-width: 89%;
    animation: sgAiFadeUp 0.22s ease forwards;
}

@keyframes sgAiFadeUp {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.sg-ai-msg.is-bot {
    align-self: flex-start;
}

.sg-ai-msg.is-user {
    align-self: flex-end;
}

.sg-ai-bubble {
    padding: 11px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.72;
    word-wrap: break-word;
}

.sg-ai-msg.is-bot .sg-ai-bubble {
    background: #ffffff;
    color: var(--sg-ai-text);
    border: 1px solid var(--sg-ai-border);
    border-top-right-radius: 5px;
    box-shadow: 0 3px 10px rgba(7, 27, 51, 0.04);
}

html[dir="ltr"] .sg-ai-msg.is-bot .sg-ai-bubble {
    border-top-right-radius: 16px;
    border-top-left-radius: 5px;
}

.sg-ai-msg.is-user .sg-ai-bubble {
    background: linear-gradient(135deg, var(--sg-ai-navy-900) 0%, var(--sg-ai-navy-700) 100%);
    color: #ffffff;
    border-top-left-radius: 5px;
    box-shadow: 0 4px 12px rgba(7, 27, 51, 0.16);
}

html[dir="ltr"] .sg-ai-msg.is-user .sg-ai-bubble {
    border-top-left-radius: 16px;
    border-top-right-radius: 5px;
}

.sg-ai-bubble strong {
    font-weight: 800;
    color: var(--sg-ai-navy-900);
}
.sg-ai-msg.is-user .sg-ai-bubble strong {
    color: var(--sg-ai-gold-400);
}

.sg-ai-bubble code {
    padding: 1px 6px;
    border-radius: 5px;
    background: #f1f5f9;
    color: var(--sg-ai-navy-800);
    font-size: 12.5px;
    direction: ltr;
    display: inline-block;
}

/* Rich Matched Store Cards inside Chat */
.sg-ai-stores-list {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.sg-ai-store-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 9px 12px;
    border-radius: 12px;
    background: #ffffff;
    border: 1px solid rgba(212, 175, 55, 0.36);
    text-decoration: none !important;
    transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.sg-ai-store-card:hover {
    transform: translateY(-1px);
    border-color: var(--sg-ai-gold-500);
    box-shadow: 0 6px 15px rgba(7, 27, 51, 0.08);
}

.sg-ai-store-info {
    min-width: 0;
    flex: 1 1 auto;
}

.sg-ai-store-name {
    display: block;
    color: var(--sg-ai-navy-900);
    font-size: 13px;
    font-weight: 800;
    line-height: 1.35;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sg-ai-store-meta {
    display: block;
    margin-top: 2px;
    color: var(--sg-ai-muted);
    font-size: 11.5px;
}

.sg-ai-store-badge {
    padding: 4px 9px;
    border-radius: 8px;
    background: rgba(212, 175, 55, 0.16);
    color: #8a6914;
    font-size: 11.5px;
    font-weight: 800;
    white-space: nowrap;
    flex-shrink: 0;
}

/* Action CTA Button under Bot Reply */
.sg-ai-cta-btn {
    margin-top: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 14px;
    border-radius: 11px;
    background: linear-gradient(135deg, var(--sg-ai-gold-500) 0%, var(--sg-ai-gold-600) 100%);
    color: var(--sg-ai-navy-900) !important;
    font-size: 12.5px;
    font-weight: 800;
    text-decoration: none !important;
    align-self: flex-start;
    box-shadow: 0 5px 14px rgba(212, 175, 55, 0.28);
    transition: filter 0.18s ease, transform 0.18s ease;
}

.sg-ai-cta-btn:hover {
    filter: brightness(1.05);
    transform: translateY(-1px);
    color: var(--sg-ai-navy-900) !important;
}

/* Typing Dots */
.sg-ai-typing {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 12px 15px;
    border-radius: 16px;
    border-top-right-radius: 5px;
    background: #ffffff;
    border: 1px solid var(--sg-ai-border);
    align-self: flex-start;
}

.sg-ai-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--sg-ai-gold-500);
    animation: sgAiBounce 1.2s infinite ease-in-out both;
}

.sg-ai-typing span:nth-child(1) { animation-delay: -0.28s; }
.sg-ai-typing span:nth-child(2) { animation-delay: -0.14s; }

@keyframes sgAiBounce {
    0%, 80%, 100% { transform: scale(0.55); opacity: 0.45; }
    40%           { transform: scale(1); opacity: 1; }
}

/* Quick Chips Strip */
.sg-ai-chips {
    padding: 8px 12px;
    background: #ffffff;
    border-top: 1px solid var(--sg-ai-border);
    display: flex;
    align-items: center;
    gap: 6px;
    overflow-x: auto;
    flex-shrink: 0;
    scrollbar-width: none;
}
.sg-ai-chips::-webkit-scrollbar {
    display: none;
}

.sg-ai-chip {
    padding: 5px 11px;
    border-radius: 999px;
    border: 1px solid rgba(7, 27, 51, 0.13);
    background: #f8fafc;
    color: var(--sg-ai-navy-800);
    font-family: inherit;
    font-size: 11.5px;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
    transition: background 0.16s ease, border-color 0.16s ease, color 0.16s ease;
}

.sg-ai-chip:hover {
    background: rgba(212, 175, 55, 0.14);
    border-color: var(--sg-ai-gold-500);
    color: var(--sg-ai-navy-900);
}

/* Input Composer */
.sg-ai-composer {
    padding: 10px 12px 12px;
    background: #ffffff;
    border-top: 1px solid var(--sg-ai-border);
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.sg-ai-input {
    flex: 1 1 auto;
    height: 42px;
    padding: 0 14px;
    border-radius: 12px;
    border: 1px solid rgba(7, 27, 51, 0.15);
    background: #f8fafc;
    color: var(--sg-ai-text);
    font-family: inherit;
    font-size: 13.5px;
    outline: none;
    transition: border-color 0.18s ease, background 0.18s ease;
}

.sg-ai-input:focus {
    background: #ffffff;
    border-color: var(--sg-ai-gold-500);
}

.sg-ai-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: 0;
    background: linear-gradient(135deg, var(--sg-ai-navy-900) 0%, var(--sg-ai-navy-700) 100%);
    color: var(--sg-ai-gold-400);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.18s ease, opacity 0.18s ease;
}

.sg-ai-send-btn:hover:not(:disabled) {
    transform: scale(1.04);
}

.sg-ai-send-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* --------------------------------------------------------------------------
   3. MOBILE RESPONSIVENESS (<= 767px) — Zero Overlap with Bottom Nav & Seal
   -------------------------------------------------------------------------- */
@media (max-width: 767px) {
    .sg-ai-launcher {
        right: 15px;
        bottom: 82px;
        width: 54px;
        height: 54px;
        min-height: 54px;
        padding: 0;
        border-radius: 50%;
        justify-content: center;
    }

    .sg-ai-launcher.is-stacked {
        bottom: 142px;
    }

    body.sg-sbc-bottom-right .sg-ai-launcher.is-unified {
        bottom: 148px;
    }
    body.sg-sbc-bottom-right .sg-ai-launcher.is-stacked {
        bottom: 208px;
    }

    .sg-ai-launcher-copy {
        display: none;
    }

    .sg-ai-launcher-icon-wrap {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    .sg-ai-panel,
    .sg-ai-panel.is-stacked {
        right: 10px;
        left: 10px;
        bottom: 76px;
        width: auto;
        max-width: none;
        height: calc(100vh - 96px);
        height: calc(100dvh - 96px);
        max-height: 590px;
        border-radius: 20px;
    }

    /* Prevent iOS Safari zoom on input focus */
    .sg-ai-input {
        font-size: 16px;
    }
}
