/* ─── ACF AI Chatbot — Search Bar Widget ───────────────────────────────
 * Version: 2.8.3
 * Author: Dan Lee
 *
 * Uses the same --aaipc-* CSS custom properties as the main chatbot widget.
 * ──────────────────────────────────────────────────────────────────────── */

/* ── Wrapper ────────────────────────────────────────────────────────────── */
.aaipc-searchbar-wrap {
    max-width: 800px;
    width: 100%;
    margin: 0 auto;
    position: relative;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
}

/* ── Search Bar ─────────────────────────────────────────────────────────── */
.aaipc-sb-bar {
    display: flex;
    align-items: center;
    background: var(--aaipc-bg, #ffffff);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 52px;
    overflow: visible;
    transition: border-radius 0.3s ease, box-shadow 0.3s ease;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.10), 0 2px 8px rgba(0, 0, 0, 0.06);
}
.aaipc-sb-bar:focus-within {
    box-shadow: 0 8px 36px rgba(0, 0, 0, 0.14), 0 2px 8px rgba(0, 0, 0, 0.08);
}
.aaipc-sb-bar.aaipc-sb-expanded {
    border-radius: 24px 24px 0 0;
}

/* Search icon (decorative) */
.aaipc-sb-icon {
    padding: 0 6px 0 18px;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}
.aaipc-sb-icon svg {
    width: 18px;
    height: 18px;
    stroke: #aaa;
    fill: none;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Text input — !important overrides theme defaults (e.g. Flatsome) */
.aaipc-sb-input {
    flex: 1;
    border: none !important;
    outline: none !important;
    font-size: 15px;
    padding: 14px 8px !important;
    background: transparent !important;
    background-color: transparent !important;
    color: var(--aaipc-bot-text, #1a1a2e) !important;
    min-width: 0;
    font-family: inherit;
    box-shadow: none !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    height: auto !important;
}
.aaipc-sb-input:focus {
    border: none !important;
    outline: none !important;
    box-shadow: none !important;
    background: transparent !important;
    background-color: transparent !important;
}
.aaipc-sb-input::placeholder {
    color: #aaa;
}

/* Follow-up input — same theme overrides */
.aaipc-sb-follow-input {
    flex: 1;
    border: 1px solid #ddd !important;
    border-radius: 20px !important;
    padding: 9px 14px !important;
    font-size: 13px;
    outline: none !important;
    background: var(--aaipc-bg, #ffffff) !important;
    background-color: var(--aaipc-bg, #ffffff) !important;
    color: var(--aaipc-bot-text, #1a1a2e) !important;
    font-family: inherit;
    box-shadow: none !important;
    -webkit-appearance: none !important;
    appearance: none !important;
    height: auto !important;
    margin: 0 !important;
    transition: border-color 0.2s;
}
.aaipc-sb-follow-input:focus {
    border-color: var(--aaipc-header-bg, #1e3a5f) !important;
    outline: none !important;
    box-shadow: none !important;
}

/* Mic button */
.aaipc-sb-mic {
    background: transparent;
    border: none;
    padding: 0 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    transition: opacity 0.2s;
}
.aaipc-sb-mic:hover {
    opacity: 0.7;
}
.aaipc-sb-mic svg {
    width: 18px;
    height: 18px;
    stroke: #bbb;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    transition: stroke 0.2s;
}
.aaipc-sb-mic-active svg {
    stroke: #e74c3c;
}
.aaipc-sb-mic-active {
    animation: aaipc-mic-pulse 1.2s ease-in-out infinite;
}
@keyframes aaipc-mic-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Submit button — inset pill */
.aaipc-sb-submit {
    background: var(--aaipc-header-bg, #1e3a5f);
    border: none;
    padding: 10px 22px;
    margin: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    flex-shrink: 0;
    transition: opacity 0.2s;
    border-radius: 50px;
    position: relative;
}
.aaipc-sb-submit::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 1px;
    height: 28px;
    background: #e0e0e0;
}
.aaipc-sb-submit:hover {
    opacity: 0.85;
}
.aaipc-sb-submit svg {
    width: 18px;
    height: 18px;
    stroke: var(--aaipc-header-text, #ffffff);
    fill: none;
    stroke-width: 2.5;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* ── Mini Chat Panel ────────────────────────────────────────────────────── */
.aaipc-sb-panel {
    max-width: 100%;
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-top: none;
    border-radius: 0 0 18px 18px;
    background: var(--aaipc-bg, #ffffff);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.10);
    display: flex;
    flex-direction: column;
    overflow: hidden;

    /* Collapsed by default */
    max-height: 0;
    opacity: 0;
    visibility: hidden;
    transition: max-height 0.35s ease, opacity 0.3s ease, visibility 0s 0.35s;
}
.aaipc-sb-panel.aaipc-sb-open {
    max-height: 500px;
    opacity: 1;
    visibility: visible;
    transition: max-height 0.35s ease, opacity 0.3s ease, visibility 0s;
}

/* Overlay mode — floats above page content */
.aaipc-sb-panel.aaipc-sb-overlay {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 9999;
    margin-top: -2px; /* overlap border */
}

/* Messages area */
.aaipc-sb-messages {
    max-height: 300px;
    overflow-y: auto;
    padding: 14px 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    text-align: left !important;
}
.aaipc-sb-messages::-webkit-scrollbar {
    width: 5px;
}
.aaipc-sb-messages::-webkit-scrollbar-track {
    background: transparent;
}
.aaipc-sb-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 5px;
}

/* Chat bubbles */
.aaipc-sb-bubble {
    padding: 10px 14px;
    font-size: 13px;
    line-height: 1.6;
    max-width: 85%;
    word-wrap: break-word;
    overflow-wrap: break-word;
    text-align: left !important;
}
.aaipc-sb-bubble.user {
    align-self: flex-end;
    background: var(--aaipc-user-bubble, #1e3a5f);
    color: var(--aaipc-user-text, #ffffff);
    border-radius: 14px 14px 4px 14px;
}
.aaipc-sb-bubble.bot {
    align-self: flex-start;
    background: var(--aaipc-bot-bubble, #f0f4f9);
    color: var(--aaipc-bot-text, #1a1a2e);
    border-radius: 14px 14px 14px 4px;
}
.aaipc-sb-bubble p { margin: 0 0 8px 0; text-align: left !important; }
.aaipc-sb-bubble p:last-child { margin-bottom: 0; }
.aaipc-sb-bubble ul { margin: 4px 0; padding-left: 18px; text-align: left !important; }
.aaipc-sb-bubble li { margin-bottom: 3px; text-align: left !important; }
.aaipc-sb-bubble a { color: inherit; text-decoration: underline; }
.aaipc-sb-bubble h2,
.aaipc-sb-bubble h3 { font-size: 14px; font-weight: 600; margin: 8px 0 4px; text-align: left !important; }

/* Typing indicator */
.aaipc-sb-typing {
    align-self: flex-start;
    background: var(--aaipc-bot-bubble, #f0f4f9);
    border-radius: 14px 14px 14px 4px;
    padding: 12px 18px;
    display: flex;
    gap: 4px;
    align-items: center;
}
.aaipc-sb-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--aaipc-header-bg, #1e3a5f);
    opacity: 0.3;
    animation: aaipc-sb-dot 1.4s infinite;
}
.aaipc-sb-typing span:nth-child(2) { animation-delay: 0.2s; }
.aaipc-sb-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes aaipc-sb-dot {
    0%, 60%, 100% { opacity: 0.3; transform: scale(1); }
    30% { opacity: 0.9; transform: scale(1.15); }
}

/* Source links */
.aaipc-sb-sources {
    padding: 6px 0;
    text-align: left !important;
}
.aaipc-sb-sources-label {
    font-size: 11px;
    font-weight: 600;
    color: #666;
    margin-bottom: 4px;
}
.aaipc-sb-source-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px 10px;
}
.aaipc-sb-source-link {
    font-size: 12px;
    color: var(--aaipc-header-bg, #1e3a5f);
    text-decoration: underline;
}
a.aaipc-sb-source-link:hover {
    opacity: 0.7;
}

/* ── Follow-up input area ───────────────────────────────────────────────── */
.aaipc-sb-follow-area {
    padding: 10px 12px;
    border-top: 1px solid #eee;
    display: flex;
    gap: 8px;
    align-items: center;
}
.aaipc-sb-follow-input::placeholder {
    color: #aaa;
}
.aaipc-sb-follow-send {
    background: var(--aaipc-send-btn, #1e3a5f);
    border: none;
    border-radius: 50%;
    width: 34px;
    height: 34px;
    color: var(--aaipc-header-text, #ffffff);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
    transition: opacity 0.2s;
}
.aaipc-sb-follow-send:hover {
    opacity: 0.85;
}

/* ── Footer / Close ─────────────────────────────────────────────────────── */
.aaipc-sb-footer {
    text-align: center;
    padding: 6px 12px 10px;
    font-size: 11px;
    color: #999;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
}
.aaipc-sb-close {
    background: transparent;
    border: 1px solid #ddd;
    color: #777;
    cursor: pointer;
    font-size: 11px;
    padding: 3px 14px;
    border-radius: 12px;
    transition: background 0.2s, color 0.2s;
}
.aaipc-sb-close:hover {
    background: #f0f0f0;
    color: #333;
}

/* ── Responsive ─────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .aaipc-searchbar-wrap {
        max-width: 100%;
    }
    .aaipc-sb-input {
        font-size: 14px;
        padding: 12px 6px;
    }
    .aaipc-sb-submit {
        padding: 12px 16px;
    }
    .aaipc-sb-messages {
        max-height: 250px;
        padding: 10px 12px;
    }
    .aaipc-sb-bubble {
        max-width: 90%;
        font-size: 13px;
    }
}
