/* ============================================================
   OpenAudible web chat widget
   Panel drops from the nav bar top-right on all pages.
   ============================================================ */

/* Chat trigger button — styled to match nav links */
#oa-chat-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0;
    color: #d4c0f4;   /* french-lilac equivalent */
    font-family: inherit;
    font-size: 1.1rem;
    line-height: 1;
    white-space: nowrap;
    transition: color 0.15s;
    vertical-align: middle;
}

#oa-chat-btn:hover {
    color: #fff;
}

#oa-chat-btn img {
    display: block;
    width: 18px;
    height: 18px;
    object-fit: contain;
    border-radius: 3px;
    opacity: 0.9;
    transition: opacity 0.15s;
}

#oa-chat-btn:hover img {
    opacity: 1;
}

/* Chat panel */
#oa-chat-panel {
    position: fixed;
    top: 68px;   /* just below nav bar; adjust if nav height changes */
    right: 16px;
    width: 360px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 90px);
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    display: flex;
    flex-direction: column;
    z-index: 10000;
    overflow: hidden;
    /* slide-down animation */
    transform-origin: top right;
    animation: oa-chat-in 0.18s ease;
}

@keyframes oa-chat-in {
    from { opacity: 0; transform: scale(0.95) translateY(-8px); }
    to   { opacity: 1; transform: scale(1) translateY(0); }
}

#oa-chat-panel.oa-hidden {
    display: none;
}

/* Panel header */
#oa-chat-header {
    background: linear-gradient(135deg, #513a83, #7b5ea7);
    color: #fff;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

#oa-chat-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.95rem;
}

#oa-chat-close {
    background: none;
    border: none;
    color: rgba(255,255,255,0.8);
    cursor: pointer;
    font-size: 1.2rem;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color 0.1s, background 0.1s;
}

#oa-chat-close:hover {
    color: #fff;
    background: rgba(255,255,255,0.15);
}

/* Welcome / intro form */
#oa-chat-intro {
    padding: 20px 16px;
    flex: 1;
    overflow-y: auto;
}

#oa-chat-intro p {
    margin: 0 0 14px;
    font-size: 0.9rem;
    color: #444;
    line-height: 1.5;
}

#oa-chat-intro label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 4px;
}

#oa-chat-intro input[type=text] {
    width: 100%;
    box-sizing: border-box;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 0.9rem;
    margin-bottom: 12px;
    font-family: inherit;
}

#oa-chat-intro input[type=text]:focus {
    outline: none;
    border-color: #7b5ea7;
    box-shadow: 0 0 0 2px rgba(123,94,167,0.15);
}

.oa-chat-opt-note {
    font-size: 0.78rem;
    color: #888;
    margin: -8px 0 12px;
}

#oa-chat-start-btn {
    width: 100%;
    background: #513a83;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 10px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: background 0.15s;
}

#oa-chat-start-btn:hover { background: #3e2d65; }
#oa-chat-start-btn:disabled { background: #aaa; cursor: not-allowed; }

/* Messages area */
#oa-chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.oa-msg {
    max-width: 84%;
    padding: 8px 12px;
    border-radius: 14px;
    font-size: 0.875rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.oa-msg a {
    color: inherit;
    text-decoration: underline;
}

/* Tighten HTML elements inside bot bubbles */
.oa-msg-bot p { margin: 0 0 6px; }
.oa-msg-bot p:last-child { margin-bottom: 0; }
.oa-msg-bot ul, .oa-msg-bot ol { margin: 4px 0 4px 16px; padding: 0; }
.oa-msg-bot li { margin-bottom: 3px; }

.oa-msg-bot {
    background: #f0ecf8;
    color: #2d1f50;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.oa-msg-user {
    background: #513a83;
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.oa-msg-error {
    background: #fff0f0;
    color: #b00;
    align-self: center;
    font-size: 0.82rem;
    border: 1px solid #f5c6c6;
    max-width: 100%;
    text-align: center;
}

/* Typing indicator */
.oa-typing {
    align-self: flex-start;
    display: flex;
    gap: 4px;
    padding: 10px 14px;
}

.oa-typing span {
    width: 7px;
    height: 7px;
    background: #aaa;
    border-radius: 50%;
    animation: oa-bounce 1.2s infinite;
}

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

@keyframes oa-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40%            { transform: translateY(-5px); opacity: 1; }
}

/* Input bar */
#oa-chat-input-bar {
    display: flex;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid #eee;
    background: #fafafa;
    flex-shrink: 0;
}

#oa-chat-input {
    flex: 1;
    border: 1px solid #ccc;
    border-radius: 20px;
    padding: 8px 14px;
    font-size: 0.875rem;
    font-family: inherit;
    resize: none;
    height: 36px;
    max-height: 100px;
    overflow-y: auto;
}

#oa-chat-input:focus {
    outline: none;
    border-color: #7b5ea7;
    box-shadow: 0 0 0 2px rgba(123,94,167,0.12);
}

#oa-chat-send {
    background: #513a83;
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

#oa-chat-send:hover { background: #3e2d65; }
#oa-chat-send:disabled { background: #ccc; cursor: not-allowed; }

/* Remaining questions bar */
.oa-remaining-bar {
    padding: 5px 14px;
    font-size: 0.78rem;
    flex-shrink: 0;
    border-top: 1px solid transparent;
}

.oa-remaining-low {
    background: #fffbea;
    color: #856404;
    border-color: #ffe69c;
}

.oa-remaining-zero {
    background: #fff3cd;
    color: #664d03;
    border-color: #ffc107;
}

/* Friendly "out of questions" message bubble */
.oa-msg-limit {
    background: #f0f4ff;
    color: #1a2a6c;
    border: 1px solid #c5d0f5;
    border-radius: 12px;
    border-bottom-left-radius: 4px;
    padding: 12px 14px;
    font-size: 0.875rem;
    line-height: 1.6;
    align-self: flex-start;
    max-width: 92%;
}

.oa-msg-limit a {
    color: #3b5bdb;
    text-decoration: underline;
}

/* Error box */
#oa-chat-error {
    padding: 12px 16px;
    font-size: 0.85rem;
    color: #b00;
    background: #fff5f5;
    border-top: 1px solid #fcc;
    display: none;
    flex-shrink: 0;
}

/* License status note */
#oa-chat-lic-note {
    font-size: 0.78rem;
    color: #6a6;
    padding: 6px 14px;
    background: #f0fff0;
    border-bottom: 1px solid #d0ecd0;
    display: none;
    flex-shrink: 0;
}

/* Mobile: full-width panel */
@media (max-width: 480px) {
    #oa-chat-panel {
        right: 0;
        left: 0;
        width: 100%;
        border-radius: 0 0 12px 12px;
        top: 60px;
    }
}
