/* ============================================================================
   AvA Yachts Chatbot Widget — frontend styles
   Loaded by FrontendWidget class on non-admin pages.
   ============================================================================ */

#chatbox {
    position: fixed;
    bottom: 20px;
    right: 20px;
    /* v3.18.1 — Default widget 360px sabit; çok küçük ekranda (≤375px) ekrana sığsın.
       Eski açılış genişliği (Samsung S25 vb. geniş mobile'da bile 360px → ferah görünür).
       Expanded mode 2. mesaj sonrası daha geniş alana geçer (aşağıda). */
    width: min(360px, calc(100vw - 16px));
    max-height: 640px;
    background: white;
    border: 1px solid #ccc;
    border-radius: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    font-family: Arial, sans-serif;
    z-index: 9999;
    transition: width 280ms ease, max-height 280ms ease, height 280ms ease;
}

/* v3.17.0 — Expanded mode: ziyaretçi 2. mesajını yazınca otomatik aktif.
   Mobile-safe (vw cap) + viewport-aware max-height (vh - margin).
   v3.17.1 — Genişlik %30 artırıldı (540→700px), height de orantılı arttı (820→880px). */
#chatbox.expanded {
    width: min(700px, 92vw);
    max-height: min(880px, calc(100vh - 60px));
}
#chatbox.expanded #messages {
    font-size: 15px;
}

/* v3.18.1 — Mobile uyumluluk (≤600px ekran):
   - Default widget açılışta zaten 360px (min(360, 100vw-16px) ile küçük ekranda fit-to-screen).
     Samsung S25 (~412px) gibi geniş mobile'da bile 360px ferah görünür → eski açılış davranışı.
   - 2. mesaj sonrası EXPANDED mode → mobile'da full width (uzun cevaplar rahat okunsun).
   - Margin'ları daralt + balon padding mobile-friendly. */
@media (max-width: 600px) {
    #chatbox {
        right: 8px;
        bottom: 8px;
        /* width: min(360px, 100vw-16px) zaten default'ta */
    }
    #chatbox.expanded {
        width: calc(100vw - 16px);
        max-height: calc(100vh - 16px);
    }
    #chatbox.expanded #messages {
        font-size: 14px;  /* mobilde küçük ekranda 15px gereksiz büyük */
    }
    /* Header buton padding'i mobilde biraz daha küçük (touch-friendly ama yer kazanır) */
    #chatbox-header { padding: 8px 10px; }
    #chatbox .assistant-title { font-size: 16px; }
    #chatbox .logo { height: 32px; }
    /* Balonlar mobilde biraz daha kompakt — yer az */
    #chatbox #messages .bubble {
        max-width: 92%;          /* mobilde biraz daha geniş — ekran zaten dar */
        padding: 8px 10px;
        font-size: 14px;
    }
    /* Input yüksekliğini azaltma (klavye açıldığında yer kalsın) */
    #chatbox #input input,
    #chatbox #input button {
        padding: 8px !important;
    }
}

#chatbox-header {
    background-color: #004080;
    color: white;
    padding: 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top-left-radius: 10px;
    border-top-right-radius: 10px;
}

#chatbox .header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

#chatbox .logo {
    height: 36px;
}

#chatbox .assistant-title {
    font-size: 18px;
    font-weight: bold;
    color: white;
}

#chatbox .header-right {
    display: flex;
    gap: 4px;
    margin-left: auto;   /* keep buttons at far right even when .header-left is hidden */
    flex: 0 0 auto;      /* don't stretch — content width only */
}

/* Strong override — WordPress themes often style <button> with large padding/min-width.
   !important keeps − and × tight together regardless of theme. */
#chatbox-header button {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    padding: 2px 6px !important;
    margin: 0 !important;
    width: auto !important;
    min-width: 0 !important;
    height: auto !important;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    color: white !important;
    font-size: 20px !important;
    font-weight: normal !important;
    line-height: 1 !important;
    cursor: pointer;
}

/* Minimized: hide only the message list — input stays visible */
#chatbox.minimized #messages { display: none; }

/* Collapsed: only the two buttons remain */
#chatbox.collapsed .header-left,
#chatbox.collapsed #messages,
#chatbox.collapsed #input { display: none; }

/* Thinner bar in collapsed state */
#chatbox.collapsed #chatbox-header { padding: 4px 10px; }

/* When everything below the header is hidden (collapsed only), round all four corners */
#chatbox.collapsed #chatbox-header { border-radius: 10px; }

#chatbox #messages {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    font-size: 14px;
    line-height: 1.4em;
    background: #fafbfc;
}

/* v3.17.0 — Bubble UI: user sağa (mavi), assistant sola (gri). Modern chat UX. */
#chatbox #messages .msg {
    display: flex;
    margin: 0 0 8px 0;
    width: 100%;
}
#chatbox #messages .msg--user {
    justify-content: flex-end;
}
#chatbox #messages .msg--assistant {
    justify-content: flex-start;
}
#chatbox #messages .bubble {
    /* v3.17.1 — Balon max-width 78% → 88% (uzun mesaj/cevaplar daha rahat görünür).
       Expanded mode'da balon da otomatik ile daha geniş alanı kullanır. */
    max-width: 88%;
    padding: 10px 14px;
    border-radius: 14px;
    line-height: 1.45;
    word-wrap: break-word;
    overflow-wrap: anywhere;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.06);
}
#chatbox #messages .bubble--user {
    background: #004080;
    color: #fff;
    border-bottom-right-radius: 4px;
}
#chatbox #messages .bubble--user a {
    color: #cfe1ff;
}
#chatbox #messages .bubble--assistant {
    background: #ffffff;
    color: #1d2327;
    border: 1px solid #e2e4e7;
    border-bottom-left-radius: 4px;
}
#chatbox #messages .bubble--assistant a {
    color: #2271b1;
}

#chatbox #input {
    display: flex;
    border-top: 1px solid #ccc;
    margin: 0 !important;
    padding: 0 !important;
}

#chatbox #input input {
    flex: 1;
    padding: 10px !important;
    margin: 0 !important;
    border: none;
    border-radius: 0 0 0 10px;
    box-sizing: border-box;
}

#chatbox #input button {
    padding: 10px !important;
    margin: 0 !important;
    background: #004080;
    color: white;
    border: none;
    border-radius: 0 0 10px 0;
    cursor: pointer;
    box-sizing: border-box;
}

/* v3.17.0 — typing indicator artık assistant balonu içinde göründüğü için inline-flex */
#chatbox .typing {
    font-style: italic;
    color: gray;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0 4px;
}

#chatbox .typing-dots {
    display: inline-flex;
    margin-left: 4px;
}

#chatbox .typing-dots span {
    width: 5px;
    height: 5px;
    margin: 0 1px;
    background: gray;
    border-radius: 50%;
    display: inline-block;
    animation: ava-chatbot-typing-blink 1.4s infinite both;
}

#chatbox .typing-dots span:nth-child(2) { animation-delay: 0.2s; }
#chatbox .typing-dots span:nth-child(3) { animation-delay: 0.4s; }

@keyframes ava-chatbot-typing-blink {
    0%, 80%, 100% { opacity: 0.2; transform: translateY(0); }
    40%           { opacity: 1;   transform: translateY(-2px); }
}
