/* ============================================================
   AI Live Support Widget — YZ Restaurant
   Tema-agnostic: --br-* design token'larını kullanır.
   tokens.css yüklendikten sonra include edilmelidir.
============================================================ */

/* ─── Widget scope'unda local CSS variable override ───────────
   Toon Pop teması (sıcak, ışık, marka uyumlu):
   - Panel zemini: krem (#fef3e8) — markanın signature ışık rengi
   - Bot mesaj: beyaz (kart-içi-kart efekti)
   - Yazılar: wine (#A03252) — yüksek kontrast, marka karakteri
   - User mesaj: gold gradient (header ile süreklilik)
─────────────────────────────────────────────────────────── */
.ase-chat-root {
    --br-bg-2: #fef3e8;                              /* Panel zemini — krem */
    --br-bg-3: #ffffff;                              /* Bot mesaj — beyaz */
    --br-cream: #A03252;                             /* Ana yazı — wine (yüksek kontrast) */
    --br-cream-soft: rgba(160, 50, 82, 0.85);        /* Subtitle */
    --br-cream-muted: rgba(160, 50, 82, 0.55);       /* Placeholder */
    --br-cream-dim: rgba(160, 50, 82, 0.35);         /* Disabled */
    --br-cream-faint: rgba(160, 50, 82, 0.15);       /* Border */
    --br-gold: #D9883C;                              /* Accent — gold (link, vurgu) */
    --br-gold-light: #B85C2A;                        /* Hover — koyu gold (krem zeminde okunur) */
    --br-grad-sunset: linear-gradient(135deg, #D9883C 0%, #A03252 100%);
    --br-radius-lg: 16px;
}

/* ─── Root container ──────────────────────────────────────
   ÖNEMLİ: Container layout almıyor — sadece DOM yapısı için.
   Toggle button ve panel kendi `position: fixed` ile yerleşir.
   Bu sayede container görünmez overlay yapmaz, kapalıyken sayfa
   tıklamalarını engellemez (özellikle mobile'da kritik).
─────────────────────────────────────────────────────────── */
.ase-chat-root,
.ase-chat-root *,
.ase-chat-root *::before,
.ase-chat-root *::after {
    box-sizing: border-box;
}

/* ─── CSS Leak Protection ─────────────────────────────────
   Tema'nın global kuralları (örn: `body.theme-dark a { color: ... }`)
   widget içine sızmasın diye widget'ın kendi link/heading
   stillerini explicit olarak set ediyoruz.
─────────────────────────────────────────────────────────── */
.ase-chat-root a {
    color: inherit;
    text-decoration: none;
}
.ase-chat-root h1,
.ase-chat-root h2,
.ase-chat-root h3,
.ase-chat-root h4,
.ase-chat-root h5,
.ase-chat-root h6,
.ase-chat-root p {
    color: inherit;
    margin: 0;
}

/* ─── Toggle Button (sağ alt FAB) ──────────────────────────── */
.ase-chat-toggle {
    position: fixed;
    right: 24px;
    bottom: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: var(--br-grad-sunset, linear-gradient(135deg, #D9883C 0%, #A03252 100%));
    color: #fff;
    box-shadow: 0 8px 24px rgba(160, 50, 82, 0.45), 0 2px 6px rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.3s ease;
    z-index: 9001;
}
.ase-chat-toggle:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 32px rgba(160, 50, 82, 0.55), 0 4px 8px rgba(0,0,0,0.35);
}
.ase-chat-toggle:active {
    transform: scale(0.95);
}
.ase-chat-toggle-icon {
    width: 28px;
    height: 28px;
    transition: opacity 0.2s ease, transform 0.2s ease;
    position: absolute;
}
.ase-chat-toggle-icon--close { opacity: 0; transform: rotate(-45deg); }
.ase-chat-root[data-state="open"] .ase-chat-toggle-icon--chat  { opacity: 0; transform: rotate(45deg); }
.ase-chat-root[data-state="open"] .ase-chat-toggle-icon--close { opacity: 1; transform: rotate(0); }

/* Pulse anim — yeni mesaj geldiğinde dikkat çekmek için */
@keyframes ase-pulse {
    0%, 100% { box-shadow: 0 8px 24px rgba(160, 50, 82, 0.45), 0 0 0 0 rgba(217, 136, 60, 0.5); }
    50%      { box-shadow: 0 8px 24px rgba(160, 50, 82, 0.45), 0 0 0 12px rgba(217, 136, 60, 0); }
}
.ase-chat-toggle.is-pulsing {
    animation: ase-pulse 2s ease-out infinite;
}

/* ─── Panel ─────────────────────────────────────────────── */
.ase-chat-panel {
    position: fixed;
    z-index: 9999;             /* ★ HOTFIX-002: br-header (~1500) ve .speed-dial (8000) üstünde */
    right: 24px;
    bottom: 100px;            /* Toggle button'ın üstünde */
    width: 380px;
    max-width: calc(100vw - 48px);
    height: 580px;
    max-height: calc(100vh - 140px);
    background: var(--br-bg-2, #15091a);
    border: 1px solid var(--br-cream-faint, rgba(254, 243, 232, 0.18));
    border-radius: var(--br-radius-lg, 16px);
    box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 8px 16px rgba(0,0,0,0.3);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
}
.ase-chat-root[data-state="open"] .ase-chat-panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ─── Header ───────────────────────────────────────────── */
.ase-chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--br-grad-sunset, linear-gradient(135deg, #D9883C 0%, #A03252 100%));
    color: #fff;
    flex-shrink: 0;
}
.ase-chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--br-font-display, 'Cormorant Garamond', serif);
    font-size: 22px;
    font-weight: 600;
    color: #fff;
    flex-shrink: 0;
    overflow: hidden;          /* ★ HOTFIX-002: img taşmasın */
}
/* ★ HOTFIX-002: avatar img için stil (logo iconuyla doldurma) */
.ase-chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: inherit;
}
.ase-chat-headinfo {
    flex: 1;
    min-width: 0;
}
.ase-chat-title {
    font-family: var(--br-font-display, 'Cormorant Garamond', serif);
    font-size: 18px;
    font-weight: 600;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.ase-chat-status {
    font-size: 11px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}
.ase-chat-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 6px rgba(74, 222, 128, 0.8);
    flex-shrink: 0;
}
.ase-chat-close-btn {
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.ase-chat-close-btn:hover { background: rgba(255, 255, 255, 0.15); }
.ase-chat-close-btn svg { width: 20px; height: 20px; }

/* ─── Messages alanı ───────────────────────────────────── */
.ase-chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--br-bg-1, #1a0e1a);
    scroll-behavior: smooth;
}
.ase-chat-messages::-webkit-scrollbar { width: 6px; }
.ase-chat-messages::-webkit-scrollbar-track { background: transparent; }
.ase-chat-messages::-webkit-scrollbar-thumb {
    background: var(--br-cream-faint, rgba(254, 243, 232, 0.18));
    border-radius: 3px;
}

/* ─── Mesaj baloncukları ────────────────────────────────── */
.ase-chat-msg {
    max-width: 78%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    animation: ase-msg-in 0.25s ease;
}
@keyframes ase-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ase-chat-msg--bot {
    align-self: flex-start;
    background: var(--br-bg-3, #2a1622);
    color: var(--br-cream, #fef3e8);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--br-cream-faint, rgba(254, 243, 232, 0.18));
}
.ase-chat-msg--user {
    align-self: flex-end;
    background: var(--br-grad-sunset, linear-gradient(135deg, #D9883C 0%, #A03252 100%));
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Typing indicator (3 nokta animasyonu) */
.ase-chat-msg--typing {
    align-self: flex-start;
    background: var(--br-bg-3, #2a1622);
    border: 1px solid var(--br-cream-faint, rgba(254, 243, 232, 0.18));
    border-bottom-left-radius: 4px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 4px;
}
.ase-chat-msg--typing .dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--br-cream-muted, rgba(254, 243, 232, 0.6));
    animation: ase-typing 1.4s ease infinite;
}
.ase-chat-msg--typing .dot:nth-child(2) { animation-delay: 0.2s; }
.ase-chat-msg--typing .dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes ase-typing {
    0%, 60%, 100% { opacity: 0.4; transform: translateY(0); }
    30%           { opacity: 1;   transform: translateY(-4px); }
}

/* ─── Input alanı ──────────────────────────────────────── */
.ase-chat-input-area {
    padding: 12px;
    background: var(--br-bg-2, #15091a);
    border-top: 1px solid var(--br-cream-faint, rgba(254, 243, 232, 0.18));
    flex-shrink: 0;
}
.ase-chat-form {
    display: flex;
    gap: 8px;
    align-items: center;
}
.ase-chat-input {
    flex: 1;
    height: 44px;
    padding: 0 16px;
    border-radius: 22px;
    border: 1px solid var(--br-cream-faint, rgba(254, 243, 232, 0.18));
    background: var(--br-bg-3, #2a1622);
    color: var(--br-cream, #fef3e8);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.ase-chat-input::placeholder {
    color: var(--br-cream-muted, rgba(254, 243, 232, 0.6));
}
.ase-chat-input:focus {
    border-color: var(--br-gold, #D9883C);
    box-shadow: 0 0 0 3px var(--br-gold-soft, rgba(217, 136, 60, 0.15));
}

.ase-chat-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--br-grad-sunset, linear-gradient(135deg, #D9883C 0%, #A03252 100%));
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s ease, opacity 0.15s ease;
    flex-shrink: 0;
}
.ase-chat-send-btn svg { width: 18px; height: 18px; }
.ase-chat-send-btn:not(:disabled):hover { transform: scale(1.05); }
.ase-chat-send-btn:not(:disabled):active { transform: scale(0.95); }
.ase-chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    background: var(--br-bg-3, #2a1622);
}

/* ─── Footer ───────────────────────────────────────────── */
.ase-chat-footer {
    padding: 8px 12px;
    background: var(--br-bg-2, #15091a);
    border-top: 1px solid var(--br-cream-faint, rgba(254, 243, 232, 0.18));
    text-align: center;
    flex-shrink: 0;
}
.ase-chat-footer a.ase-chat-powered,
.ase-chat-powered {
    display: inline-block;
    font-size: 10px;
    color: var(--br-cream-dim, rgba(254, 243, 232, 0.4));
    letter-spacing: 0.5px;
    text-decoration: none !important;
    border-bottom: none !important;
    transition: color 0.15s ease;
}
.ase-chat-footer a.ase-chat-powered:hover,
.ase-chat-powered:hover {
    color: var(--br-gold-light, #E5A05F);
    text-decoration: none !important;
    border-bottom: none !important;
}

/* ─── Chat link (mesaj içi URL'ler — bare URL fallback) ─── */
.ase-chat-msg .ase-chat-link {
    color: var(--br-gold-light, #E5A05F);
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
    font-weight: 500;
    word-break: break-all;
}
.ase-chat-msg .ase-chat-link:hover {
    color: var(--br-gold, #D9883C);
    text-decoration-thickness: 2px;
}
.ase-chat-msg--user .ase-chat-link {
    color: #fff;
    text-decoration-color: rgba(255, 255, 255, 0.8);
}
.ase-chat-msg--user .ase-chat-link:hover {
    text-decoration-color: #fff;
}

/* ─── Chat CTA (markdown link / "→ /url" pattern → buton) ─ */
.ase-chat-msg .ase-chat-cta {
    display: inline-block;
    padding: 5px 12px;
    margin: 6px 0;
    background: var(--br-gold-soft, rgba(217, 136, 60, 0.10));
    border: 1px solid var(--br-gold-line, rgba(217, 136, 60, 0.28));
    color: var(--br-gold, #D9883C);
    border-radius: 14px;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    line-height: 1.4;
    transition: all 0.15s ease;
    white-space: nowrap;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
}
.ase-chat-msg .ase-chat-cta:hover {
    background: var(--br-gold, #D9883C);
    color: #fff;
    border-color: var(--br-gold, #D9883C);
    transform: translateX(2px);
}
.ase-chat-msg--user .ase-chat-cta {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.4);
    color: #fff;
}
.ase-chat-msg--user .ase-chat-cta:hover {
    background: #fff;
    color: var(--br-gold, #D9883C);
}

/* ─── Mobile: tam ekran ────────────────────────────────── */
@media (max-width: 640px) {
    .ase-chat-panel {
        right: 0;
        bottom: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
    }
    .ase-chat-toggle {
        right: 16px;
        bottom: 16px;
        width: 56px;
        height: 56px;
    }
    .ase-chat-root[data-state="open"] .ase-chat-toggle {
        display: none;       /* Mobile'da panel açıkken toggle gizlenir, kapatma X'i header'da */
    }
}

/* ─── RTL desteği (ar-SA için) ─────────────────────────── */
[dir="rtl"] .ase-chat-toggle  { right: auto; left: 24px; }
[dir="rtl"] .ase-chat-panel   { right: auto; left: 24px; transform-origin: bottom left; }
[dir="rtl"] .ase-chat-msg--bot  { align-self: flex-end;   border-bottom-left-radius: 16px; border-bottom-right-radius: 4px; }
[dir="rtl"] .ase-chat-msg--user { align-self: flex-start; border-bottom-right-radius: 16px; border-bottom-left-radius: 4px; }
[dir="rtl"] .ase-chat-msg--typing { align-self: flex-end; }
@media (max-width: 640px) {
    [dir="rtl"] .ase-chat-toggle { left: 16px; right: auto; }
}

/* ─── Reduced motion ───────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
    .ase-chat-panel,
    .ase-chat-toggle,
    .ase-chat-toggle-icon,
    .ase-chat-msg,
    .ase-chat-send-btn { transition: none !important; animation: none !important; }
    .ase-chat-msg--typing .dot { animation: none !important; opacity: 0.6; }
}
