/* SOS AI Chat Widget — Science of Spirituality brand theme (Frappe-on-SOS).
   Palette + light/dark per the SOS UI theme standard. Scoped to the widget so
   it never collides with the host sos.org theme. */
@import url('https://fonts.googleapis.com/css2?family=Antic+Didone&family=Inter:wght@400;500;600;700&display=swap');

#sos-chat-widget {
    /* Brand constants (same in both themes) */
    --navy:    #043a5b;
    --navy-2:  #0a4f78;
    --gold:    #e1b93b;
    --gold-2:  #c9a32d;
    --maroon:  #8B4543;
    --cream:   #f7eedf;

    /* Light theme (default) */
    --bg:          #ffffff;
    --surface:     #ffffff;
    --surface-2:   #f8fafc;
    --border:      #e2e8f0;
    --text:        #1c2530;
    --text-muted:  #64748b;
    --text-subtle: #94a3b8;
    --bot-bubble:  var(--cream);
    --bot-border:  #ecdec0;
    --header-bg-1: var(--navy);
    --header-bg-2: var(--navy-2);
    --header-text: #ffffff;
    --shadow:      0 8px 36px rgba(4,58,91,0.18);
    --btn-shadow:  0 4px 18px rgba(4,58,91,0.35);
}

@media (prefers-color-scheme: dark) {
    #sos-chat-widget {
        --bg:          #0f172a;
        --surface:     #1e293b;
        --surface-2:   #16202e;
        --border:      #334155;
        --text:        #e2e8f0;
        --text-muted:  #94a3b8;
        --text-subtle: #64748b;
        --bot-bubble:  #16202e;
        --bot-border:  #334155;
        --header-bg-1: #08263a;
        --header-bg-2: #0a3458;
        --header-text: #f1f5f9;
        --shadow:      0 8px 36px rgba(0,0,0,0.55);
        --btn-shadow:  0 4px 18px rgba(0,0,0,0.5);
    }
}

#sos-chat-widget * {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Floating button — navy with gold ring ── */
#sos-chat-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 58px;
    height: 58px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--navy), var(--navy-2));
    color: #fff;
    border: none;
    cursor: pointer;
    box-shadow: var(--btn-shadow), 0 0 0 2px var(--gold);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99998;
    transition: transform 0.2s, box-shadow 0.2s;
}
#sos-chat-btn:hover { transform: scale(1.08); }
#sos-chat-btn svg { width: 26px; height: 26px; fill: #fff; }
#sos-chat-btn .sos-icon-close { display: none; }
#sos-chat-btn.open .sos-icon-chat  { display: none; }
#sos-chat-btn.open .sos-icon-close { display: block; }

/* ── Panel ── */
#sos-chat-panel {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 370px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 120px);
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    z-index: 99997;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px) scale(0.97);
    pointer-events: none;
    transition: opacity 0.22s ease, transform 0.22s ease;
    border: 1px solid var(--border);
}
#sos-chat-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ── Header — navy gradient + 3px gold bottom border ── */
#sos-chat-header {
    background: linear-gradient(135deg, var(--header-bg-1), var(--header-bg-2));
    color: var(--header-text);
    padding: 12px 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
    border-bottom: 3px solid var(--gold);
}
/* round logo, white pad, gold ring */
#sos-chat-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 0 0 2px var(--gold);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    padding: 2px;
}
#sos-chat-avatar img { width: 100%; height: 100%; border-radius: 50%; object-fit: cover; }
#sos-chat-header-info { flex: 1; }
#sos-chat-header-name {
    font-family: 'Antic Didone', Georgia, serif;
    font-weight: 700;
    font-size: 17px;
    line-height: 1.1;
    color: var(--header-text);
}
#sos-chat-header-status {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.7px;
    font-weight: 600;
    color: var(--gold);
    margin-top: 2px;
}
#sos-chat-clear {
    background: rgba(255,255,255,0.08);
    border: 1px solid rgba(255,255,255,0.18);
    color: var(--header-text);
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 11px;
    cursor: pointer;
    transition: background 0.15s;
}
#sos-chat-clear:hover { background: rgba(255,255,255,0.18); }

/* ── Messages ── */
#sos-chat-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: auto;
    background: var(--bg);
}
#sos-chat-messages::-webkit-scrollbar { width: 5px; }
#sos-chat-messages::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

.sos-msg { display: flex; flex-direction: column; max-width: 86%; animation: sosMsgIn 0.18s ease; }
@keyframes sosMsgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.sos-msg.user { align-self: flex-end;   align-items: flex-end; }
.sos-msg.bot  { align-self: flex-start; align-items: flex-start; }

.sos-msg-bubble {
    padding: 9px 13px;
    border-radius: 12px;
    font-size: 14px;
    line-height: 1.55;
    word-break: break-word;
}
/* User bubble — navy */
.sos-msg.user .sos-msg-bubble {
    background: linear-gradient(135deg, var(--navy), var(--navy-2));
    color: #fff;
    border-bottom-right-radius: 4px;
}
/* Bot bubble — cream (light) / surface-2 (dark) */
.sos-msg.bot .sos-msg-bubble {
    background: var(--bot-bubble);
    color: var(--text);
    border: 1px solid var(--bot-border);
    border-bottom-left-radius: 4px;
}
.sos-msg-bubble a { color: var(--maroon); text-decoration: underline; }
.sos-msg-time { font-size: 10.5px; color: var(--text-subtle); margin-top: 3px; padding: 0 4px; }

/* Source citation chips */
.sos-msg-sources { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 6px; padding: 0 2px; }
.sos-msg-sources a {
    font-size: 11px;
    font-weight: 500;
    background: rgba(225,185,59,0.14);
    color: var(--maroon);
    border: 1px solid rgba(225,185,59,0.45);
    border-radius: 4px;
    padding: 2px 8px;
    text-decoration: none;
    transition: background 0.15s;
}
.sos-msg-sources a:hover { background: rgba(225,185,59,0.28); }
@media (prefers-color-scheme: dark) { .sos-msg-sources a { color: var(--gold); } }

/* ── Typing indicator ── */
#sos-typing {
    display: none;
    align-self: flex-start;
    background: var(--bot-bubble);
    border: 1px solid var(--bot-border);
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    padding: 10px 14px;
    gap: 5px;
    align-items: center;
}
#sos-typing.visible { display: flex; }
#sos-typing span { width: 7px; height: 7px; background: var(--gold); border-radius: 50%; animation: sosDot 1.2s infinite ease-in-out; }
#sos-typing span:nth-child(2) { animation-delay: 0.2s; }
#sos-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes sosDot { 0%,80%,100% { transform: scale(0.7); opacity: 0.5; } 40% { transform: scale(1); opacity: 1; } }

/* ── Input area ── */
#sos-chat-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 14px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    flex-shrink: 0;
}
#sos-chat-input {
    flex: 1;
    resize: none;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 14px;
    line-height: 1.4;
    max-height: 100px;
    outline: none;
    background: var(--surface-2);
    color: var(--text);
    transition: border-color 0.15s, box-shadow 0.15s;
}
#sos-chat-input:focus {
    border-color: var(--navy);
    box-shadow: 0 0 0 3px rgba(4,58,91,0.12);
}
#sos-chat-input::placeholder { color: var(--text-subtle); }

#sos-chat-send {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--gold);
    border: 1px solid var(--gold-2);
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: filter 0.15s, transform 0.1s;
}
#sos-chat-send:hover  { filter: brightness(1.05); }
#sos-chat-send:active { transform: scale(0.92); }
#sos-chat-send svg    { width: 18px; height: 18px; fill: var(--navy); }
#sos-chat-send:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── Footer ── */
#sos-chat-footer {
    text-align: center;
    font-size: 11px;
    color: var(--text-muted);
    padding: 6px 8px 9px;
    background: var(--surface-2);
    border-top: 1px solid var(--border);
}
#sos-chat-footer a { color: var(--navy); text-decoration: none; }
@media (prefers-color-scheme: dark) { #sos-chat-footer a { color: var(--gold); } }

/* ── Mobile ── */
@media (max-width: 420px) {
    #sos-chat-panel { right: 8px; left: 8px; width: auto; bottom: 86px; }
    #sos-chat-btn   { bottom: 16px; right: 16px; }
}
