/*
 * SDA Bible AI Chat — Base Stylesheet  v4.0.0
 * spencervillechurch.org
 *
 * HOW TO SAVE THIS FILE CORRECTLY
 * 1. Copy the full text of this file.
 * 2. Open VS Code or Notepad++ (NOT Windows Notepad).
 * 3. Paste and save as: chat.css
 * 4. Encoding must be UTF-8. In VS Code this shows in the bottom status
 *    bar. In Notepad++ use Encoding > UTF-8.
 * 5. Upload to /wp-content/plugins/sda-bible-ai-chat/assets/chat.css
 *
 * All colours reference CSS custom properties (--sda-*) that are
 * injected by PHP via wp_add_inline_style so both skins share this file.
 */

/* =====================================================================
   LAUNCHER BUTTON
   all:unset resets any theme button styles that would interfere.
   !important on position/z-index/display survives aggressive theme
   overrides (Divi, Avada, Elementor).
===================================================================== */
#sda-chat-launcher {
    all: unset;
    position: fixed !important;
    bottom: 28px;
    right: 28px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--sda-primary);
    cursor: pointer;
    display: flex !important;
    align-items: center;
    justify-content: center;
    z-index: 999999 !important;
    box-shadow: var(--sda-shadow);
    transition: background 0.2s, transform 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}
#sda-chat-launcher:hover {
    background: var(--sda-dark);
    transform: scale(1.08);
}
#sda-chat-launcher svg {
    width: 28px;
    height: 28px;
    fill: white;
    pointer-events: none;
}
#sda-chat-launcher .sda-icon-close {
    display: none;
}

/* =====================================================================
   CHAT WINDOW
   Hidden by default (opacity 0, pointer-events none).
   .sda-open reveals it with a scale + fade transition.
   pointer-events: auto — NOT "all" (invalid on HTML elements).
===================================================================== */
#sda-chat-window {
    position: fixed !important;
    bottom: 100px;
    right: 28px;
    width: 390px;
    max-width: calc(100vw - 32px);
    height: 570px;
    max-height: calc(100vh - 120px);
    background: #ffffff;
    box-shadow: var(--sda-shadow);
    display: flex !important;
    flex-direction: column;
    z-index: 999998 !important;
    overflow: hidden;
    transform: scale(0.93) translateY(18px);
    opacity: 0 !important;
    pointer-events: none;
    transform-origin: bottom right;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.25s;
    border-radius: var(--sda-radius);
    font-family: var(--sda-font);
    box-sizing: border-box;
}
#sda-chat-window.sda-open {
    transform: scale(1) translateY(0);
    opacity: 1 !important;
    pointer-events: auto;
}

/* =====================================================================
   HEADER
===================================================================== */
#sda-chat-header {
    background: var(--sda-primary);
    color: white;
    padding: 15px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.sda-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    overflow: hidden;
}
.sda-avatar-img {
    width: 32px;
    height: 32px;
    object-fit: contain;
    border-radius: 50%;
    display: block;
}
.sda-header-info {
    flex: 1;
    min-width: 0;
}
.sda-header-info h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: white;
}
.sda-header-info p {
    margin: 2px 0 0;
    font-size: 11px;
    opacity: 0.85;
    color: white;
}
#sda-chat-clear {
    all: unset;
    border: 1px solid rgba(255, 255, 255, 0.4);
    color: white;
    border-radius: 6px;
    padding: 5px 11px;
    font-size: 11px;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s, border-color 0.15s;
    font-family: var(--sda-font);
    box-sizing: border-box;
    white-space: nowrap;
}
#sda-chat-clear:hover {
    background: rgba(255, 255, 255, 0.15);
}

/* =====================================================================
   MESSAGES
===================================================================== */
#sda-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    overflow-anchor: none;
    font-family: var(--sda-font);
}
#sda-chat-messages::-webkit-scrollbar { width: 5px; }
#sda-chat-messages::-webkit-scrollbar-thumb {
    background: var(--sda-border);
    border-radius: 4px;
}

.sda-msg {
    display: flex;
    gap: 8px;
    align-items: flex-end;
    animation: sdaFadeIn 0.22s ease;
}
@keyframes sdaFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.sda-msg.sda-user { flex-direction: row-reverse; }

.sda-msg-bubble {
    max-width: 82%;
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.56;
    word-wrap: break-word;
    color: var(--sda-text);
    border-radius: var(--sda-radius);
}
.sda-user .sda-msg-bubble {
    background: var(--sda-primary);
    color: white;
    border-bottom-right-radius: 2px;
}
.sda-bot .sda-msg-bubble {
    background: var(--sda-bubble-bot-bg);
    border-bottom-left-radius: 2px;
}

/* Rich text rendering inside bubbles */
.sda-msg-bubble p          { margin: 0 0 7px; }
.sda-msg-bubble p:last-child { margin-bottom: 0; }
.sda-msg-bubble strong     { font-weight: 700; }
.sda-msg-bubble em         { font-style: italic; }
.sda-msg-bubble ul,
.sda-msg-bubble ol         { margin: 6px 0 6px 18px; padding: 0; }
.sda-msg-bubble li         { margin-bottom: 3px; }
.sda-msg-bubble blockquote {
    border-left: 3px solid var(--sda-primary);
    margin: 0.6em 0;
    padding: 0 10px;
    background: rgba(0, 0, 0, 0.04);
    border-radius: 0 4px 4px 0;
    font-size: 1em;
}
/* Inner <p> wraps the blockquote text — padding here keeps the
   border/background on the outer element while letting the text
   breathe independently, and avoids ::before injection issues */
.sda-msg-bubble blockquote p {
    margin: 0;
    padding: 0.6em 0;
    font-style: italic;
}
.sda-user .sda-msg-bubble blockquote {
    border-left-color: rgba(255, 255, 255, 0.5);
    background: rgba(255, 255, 255, 0.1);
}
/* Reset ::before and ::after — neutralises theme stylesheets (e.g. Divi)
   that inject decorative quotation marks or other content into blockquotes */
.sda-msg-bubble blockquote::before,
.sda-msg-bubble blockquote::after,
.sda-msg-bubble blockquote p::before,
.sda-msg-bubble blockquote p::after {
    content: none;
    display: none;
}

.sda-bot-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #ffffff;
    color: var(--sda-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

/* =====================================================================
   TYPING INDICATOR
===================================================================== */
.sda-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 10px 14px;
    background: var(--sda-bubble-bot-bg);
    border-radius: var(--sda-radius) var(--sda-radius) var(--sda-radius) 2px;
    width: fit-content;
}
.sda-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--sda-border);
    animation: sdaDot 1.2s infinite;
}
.sda-typing span:nth-child(2) { animation-delay: 0.2s; }
.sda-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes sdaDot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
    30%            { transform: translateY(-5px); opacity: 1; }
}

/* =====================================================================
   SUGGESTION CHIPS
===================================================================== */
#sda-suggestions {
    padding: 0 16px 6px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex-shrink: 0;
}
.sda-suggestion {
    all: unset;
    background: var(--sda-light);
    border: 1px solid var(--sda-border);
    border-radius: 20px;
    padding: 5px 12px;
    cursor: pointer;
    color: var(--sda-text);
    white-space: nowrap;
    font-family: var(--sda-font);
    font-size: 12px;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    box-sizing: border-box;
}
.sda-suggestion:hover {
    background: var(--sda-primary);
    border-color: var(--sda-primary);
    color: white;
}

/* =====================================================================
   INPUT AREA
===================================================================== */
#sda-input-area {
    padding: 12px 16px;
    border-top: 1px solid var(--sda-border);
    display: flex;
    gap: 8px;
    align-items: flex-end;
    flex-shrink: 0;
    background: #ffffff;
}
#sda-chat-input {
    flex: 1;
    border: 1px solid var(--sda-border);
    border-radius: var(--sda-btn-radius);
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.4;
    resize: none;
    outline: none;
    font-family: var(--sda-font);
    color: var(--sda-text);
    background: var(--sda-light);
    max-height: 120px;
    transition: border-color 0.2s, background 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
}
#sda-chat-input:focus {
    border-color: var(--sda-primary);
    background: white;
}
#sda-chat-input::placeholder { color: #b0b8c4; }

#sda-chat-send {
    all: unset;
    width: 40px;
    height: 40px;
    background: var(--sda-primary);
    border-radius: var(--sda-btn-radius);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.1s;
    box-sizing: border-box;
}
#sda-chat-send:hover    { background: var(--sda-dark); }
#sda-chat-send:active   { transform: scale(0.93); }
#sda-chat-send:disabled { opacity: 0.45; cursor: not-allowed; }
#sda-chat-send svg {
    width: 18px;
    height: 18px;
    fill: white;
    pointer-events: none;
}

/* =====================================================================
   FOOTER
===================================================================== */
#sda-chat-footer {
    text-align: center;
    font-size: 10px;
    color: #b0b8c4;
    padding: 0 16px 10px;
    flex-shrink: 0;
    font-family: var(--sda-font);
}

/* =====================================================================
   RESPONSIVE
===================================================================== */
@media (max-width: 430px) {
    #sda-chat-window {
        right: 10px !important;
        width: calc(100vw - 20px);
        bottom: 88px;
    }
    #sda-chat-launcher {
        right: 14px !important;
        bottom: 18px;
    }
}
