/* Apisrom AI Chat Widget — bottom-left, isolated from theme styles */

#aai-root *,
#aai-root *::before,
#aai-root *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ── Bubble ────────────────────────────────────────────────────────────────── */

#aai-bubble {
    position: fixed;
    bottom: 60px;
    right: 150px;
    left: auto;
    z-index: 99998;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: #D3A863;                /* APISROM GOLD */
    border: none;
    cursor: pointer;
    box-shadow: 0 6px 24px rgba(211, 168, 99, 0.4);  /* gold-tinted shadow */
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    color: #1a1a2e;                       /* dark icon for contrast */
}

#aai-bubble:hover {
    transform: scale(1.08);
    box-shadow: 0 8px 32px rgba(211, 168, 99, 0.5);
    background: #e4b974;                  /* lighter gold on hover */
}

#aai-bubble svg {
    width: 28px;
    height: 28px;
}

/* ── Drawer ────────────────────────────────────────────────────────────────── */

#aai-drawer {
    position: fixed;
    bottom: 140px;
    right: 60px;
    left: auto;
    z-index: 99999;
    width: 400px;
    max-width: calc(100vw - 120px);
    height: 75vh;
    max-height: 800px;
    min-height: 500px;
    background: #fff;                     /* WHITE background like site */
    border-radius: 20px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    border: 1px solid rgba(211, 168, 99, 0.3);  /* gold-tinted border */
}

#aai-drawer.aai-open {
    display: flex;
}

/* ── Header ────────────────────────────────────────────────────────────────── */

#aai-header {
    background: #D3A863;                  /* APISROM GOLD header */
    padding: 14px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    flex-shrink: 0;
}

#aai-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

#aai-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #6b7280;
    flex-shrink: 0;
    transition: background 0.3s;
}

#aai-status-dot.online  { background: #22c55e; }
#aai-status-dot.offline { background: #ef4444; }
#aai-status-dot.connecting { background: #f59e0b; }

#aai-agent-name {
    color: #1a1a2e;                       /* dark text on gold */
    font-weight: 600;
    font-size: 14px;
    line-height: 1.2;
}

#aai-status-text {
    color: rgba(26, 26, 46, 0.7);         /* muted dark */
    font-size: 12px;
    line-height: 1.2;
}

#aai-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

#aai-close-btn,
#aai-new-chat-btn {
    background: none;
    border: none;
    color: #1a1a2e;
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
    padding: 0;
    border-radius: 6px;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    min-width: 36px;
    min-height: 36px;
    max-width: 36px;
    max-height: 36px;
    box-sizing: border-box;
    flex-shrink: 0;
    overflow: hidden;
}

#aai-close-btn:hover,
#aai-new-chat-btn:hover {
    background: rgba(0, 0, 0, 0.08);
}

#aai-new-chat-btn svg {
    width: 18px;
    height: 18px;
    display: block;
    flex-shrink: 0;
}

/* ── Messages ──────────────────────────────────────────────────────────────── */

#aai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

#aai-messages::-webkit-scrollbar       { width: 4px; }
#aai-messages::-webkit-scrollbar-track { background: transparent; }
#aai-messages::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 4px; }

/* Empty state */
#aai-empty-state {
    margin: auto;
    text-align: center;
    color: #666;
    font-size: 13px;
    line-height: 1.8;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

#aai-empty-state div:first-child {
    font-size: 32px;
    margin-bottom: 8px;
}

/* Message rows */
.aai-msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.aai-msg-row.aai-user {
    flex-direction: row-reverse;
}

.aai-msg-icon {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: #2d3748;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
}

.aai-bubble {
    max-width: 100%;
    min-width: 48px;
    padding: 12px 16px;                   /* comfortable padding */
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
    overflow-wrap: break-word;
    color: #333;
}

.aai-msg-row.aai-bot  .aai-bubble {
    background: #f5f5f5;                  /* light gray for bot */
    border-bottom-left-radius: 4px;
}

.aai-msg-row.aai-user .aai-bubble {
    background: #D3A863;                  /* APISROM GOLD for user */
    color: #1a1a2e;
    border-bottom-right-radius: 4px;
}

/* System messages */
.aai-sys-msg {
    text-align: center;
    font-size: 11px;
    color: #999;
    padding: 2px 0;
}

/* Typing indicator */
.aai-typing-indicator {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 4px 2px;
}

.aai-typing-dot {
    width: 7px;
    height: 7px;
    background: #94a3b8;
    border-radius: 50%;
    animation: aai-bounce 1.2s infinite ease-in-out;
}

.aai-typing-dot:nth-child(1) { animation-delay: 0s; }
.aai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.aai-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes aai-bounce {
    0%, 80%, 100% { transform: scale(0.8); opacity: 0.5; }
    40%           { transform: scale(1.2); opacity: 1; }
}

/* ── Input row with vertical action buttons ───────────────────────────────── */

#aai-input-row {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    padding: 12px 14px;
    border-top: 1px solid rgba(211, 168, 99, 0.2);
    background: #fafafa;
    flex-shrink: 0;
}

#aai-input {
    flex: 1;
    background: #fff;
    border: 1px solid rgba(211, 168, 99, 0.3);
    border-radius: 20px;
    padding: 10px 14px;
    color: #333;
    font-size: 13px;
    resize: none;
    outline: none;
    line-height: 1.5;
    max-height: 100px;
    overflow-y: auto;
    transition: border-color 0.2s;
}

#aai-input::placeholder { color: #999; }
#aai-input:focus { border-color: #D3A863; }
#aai-input:disabled { opacity: 0.5; cursor: not-allowed; }

/* Vertical stack for mic + send buttons */
#aai-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Mic button — completely circular */
#aai-mic-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #f0f0f0;
    border: 1px solid rgba(211, 168, 99, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, border-color 0.2s;
    color: #555;
    padding: 0;
}

#aai-mic-btn:hover:not(:disabled) {
    background: #e8e8e8;
    border-color: #D3A863;
    color: #1a1a2e;
}

#aai-mic-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#aai-mic-btn.aai-recording {
    background: #fee2e2;
    border-color: #ef4444;
    color: #ef4444;
    animation: aai-mic-pulse 1.2s infinite ease-in-out;
}

#aai-mic-btn svg {
    width: 18px;
    height: 18px;
}

#aai-mic-loading {
    animation: aai-spin 1s linear infinite;
}

@keyframes aai-mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50%       { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
}

/* Send button — completely circular */
#aai-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #D3A863;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.15s;
    color: #1a1a2e;
    padding: 0;
}

#aai-send:hover:not(:disabled) {
    background: #e4b974;
    transform: scale(1.05);
}

#aai-send:disabled {
    background: #ddd;
    cursor: not-allowed;
}

#aai-send svg {
    width: 18px;
    height: 18px;
}

/* ── Message wrapper with play button ─────────────────────────────────────── */

.aai-bubble-wrapper {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 85%;
}

.aai-msg-row.aai-user .aai-bubble-wrapper {
    flex-direction: row-reverse;
}

/* Play button on bot messages — completely circular, fixed size */
.aai-play-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    border-radius: 50%;
    background: #f0f0f0;
    border: 1px solid rgba(211, 168, 99, 0.3);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, border-color 0.2s, color 0.2s;
    color: #888;
    padding: 0;
    box-sizing: border-box;
}

.aai-play-btn:hover {
    background: #e8e8e8;
    border-color: #D3A863;
    color: #D3A863;
}

.aai-play-btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.aai-play-btn:disabled {
    cursor: not-allowed;
    opacity: 0.7;
}

.aai-play-btn .aai-loading-icon {
    animation: aai-spin 1s linear infinite;
}

@keyframes aai-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ── Mobile ────────────────────────────────────────────────────────────────── */

@media (max-width: 480px) {
    #aai-drawer {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        top: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        max-height: 100%;
        min-height: unset;
        border-radius: 0;
        border: none;
        box-shadow: none;
        /* Account for notch / home indicator */
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    #aai-bubble {
        right: 16px;
        left: auto;
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        width: 56px;
        height: 56px;
    }

    #aai-input-row {
        padding: 10px 10px;
        gap: 8px;
        /* Stay above the virtual keyboard */
        position: sticky;
        bottom: 0;
        background: #fafafa;
    }

    #aai-input {
        font-size: 16px; /* prevents iOS auto-zoom */
        max-height: 80px;
    }

    #aai-send,
    #aai-mic-btn {
        width: 44px;
        height: 44px;
        flex-shrink: 0;
    }

    #aai-messages {
        padding: 12px;
        gap: 10px;
    }

    .aai-bubble-wrapper {
        max-width: 92%;
    }

    #aai-header {
        padding: 12px 14px;
        /* Account for status bar on phones */
        padding-top: calc(12px + env(safe-area-inset-top, 0px));
    }
}
