/* ==========================================================================
   Ask AI Sidebar
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Navigation Button (desktop only)
   -------------------------------------------------------------------------- */

.ask-ai-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid #e0e0e0;
    border-radius: 6px;
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    background: transparent;
    color: inherit;
    cursor: pointer;
    transition: border-color 0.2s ease, color 0.2s ease;
}

.ask-ai-btn:hover {
    border-color: var(--primary-color);
    color: var(--primary-color);
}

.ask-ai-btn__icon {
    font-size: 14px;
    line-height: 1;
}

/* --------------------------------------------------------------------------
   2. Floating Action Button (mobile only)
   -------------------------------------------------------------------------- */

.ask-ai-fab {
    display: none;
    position: fixed;
    bottom: calc(24px + env(safe-area-inset-bottom, 0px));
    right: 24px;
    z-index: 99989;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: var(--primary-color, #ff6600);
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(255, 102, 0, 0.35), 0 2px 6px rgba(0, 0, 0, 0.1);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    align-items: center;
    justify-content: center;
}

.ask-ai-fab:active {
    transform: scale(0.92);
}

/* Hide FAB when sidebar is open */
.ask-ai-fab--hidden {
    display: none !important;
}

/* --------------------------------------------------------------------------
   3. Overlay / Backdrop (mobile only)
   -------------------------------------------------------------------------- */

.ask-ai-overlay {
    display: none;
}

/* --------------------------------------------------------------------------
   4. Body Push (desktop only)
   -------------------------------------------------------------------------- */

body {
    transition: margin-right 0.3s ease;
    overflow-x: hidden;
}

@media (min-width: 769px) {
    body.ask-ai-body--pushed {
        margin-right: 420px;
    }

    body.ask-ai-body--pushed.ask-ai-body--expanded {
        margin-right: 100vw;
    }
}

/* --------------------------------------------------------------------------
   5. Sidebar Panel
   -------------------------------------------------------------------------- */

.ask-ai-sidebar {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: 420px;
    z-index: 99991;
    background: #fff;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s ease;
}

/* Offset for WordPress admin bar when logged in */
.admin-bar .ask-ai-sidebar {
    top: 32px;
}

@media screen and (max-width: 782px) {
    .admin-bar .ask-ai-sidebar {
        top: 46px;
    }
}

@media screen and (max-width: 600px) {
    .admin-bar .ask-ai-sidebar {
        top: 0;
    }
}

.ask-ai-sidebar--open {
    transform: translateX(0);
}

/* --------------------------------------------------------------------------
   6. Header
   -------------------------------------------------------------------------- */

.ask-ai-header {
    padding: 16px 20px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    align-items: center;
    gap: 10px;
}

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

.ask-ai-header__title {
    font-weight: 600;
    font-size: 15px;
    flex: 1;
}

.ask-ai-header__actions {
    display: flex;
    gap: 4px;
}

.ask-ai-header__action-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #666;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease;
}

.ask-ai-header__action-btn:hover {
    background: #f5f5f5;
    color: #333;
}

/* --------------------------------------------------------------------------
   7. Disclaimer Banner
   -------------------------------------------------------------------------- */

.ask-ai-disclaimer {
    padding: 10px 20px;
    background: #f9f9f9;
    border-bottom: 1px solid #f0f0f0;
    font-size: 11px;
    color: #888;
    line-height: 1.4;
}

/* --------------------------------------------------------------------------
   8. Messages Area
   -------------------------------------------------------------------------- */

.ask-ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.ask-ai-messages::-webkit-scrollbar {
    width: 4px;
}

.ask-ai-messages::-webkit-scrollbar-track {
    background: transparent;
}

.ask-ai-messages::-webkit-scrollbar-thumb {
    background: #d9d9d9;
    border-radius: 4px;
}

.ask-ai-messages::-webkit-scrollbar-thumb:hover {
    background: #bfbfbf;
}

/* --------------------------------------------------------------------------
   9. Welcome / Empty State
   -------------------------------------------------------------------------- */

.ask-ai-welcome {
    text-align: center;
    padding-top: 60px;
}

.ask-ai-welcome__icon {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #fff3e6;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--primary-color);
    font-size: 22px;
    margin: 0 auto;
}

.ask-ai-welcome__heading {
    font-weight: 600;
    font-size: 16px;
    margin-top: 16px;
    margin-bottom: 0;
}

.ask-ai-welcome__subtitle {
    font-size: 13px;
    color: #888;
    margin-top: 8px;
}

/* --------------------------------------------------------------------------
   10. Message Wrapper
   -------------------------------------------------------------------------- */

.ask-ai-message {
    margin-bottom: 20px;
    display: flex;
    gap: 10px;
}

/* --------------------------------------------------------------------------
   11. User Message
   -------------------------------------------------------------------------- */

.ask-ai-message--user {
    justify-content: flex-end;
}

.ask-ai-message--user .ask-ai-message__bubble {
    background: #f3f4f6;
    border-radius: 16px 16px 4px 16px;
    padding: 12px 16px;
    max-width: 85%;
    font-size: 14px;
    line-height: 1.6;
}

/* --------------------------------------------------------------------------
   12. AI Message
   -------------------------------------------------------------------------- */

.ask-ai-message--assistant {
    flex-direction: row;
}

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

.ask-ai-message__body {
    max-width: calc(100% - 40px);
    min-width: 0;
}

.ask-ai-message--assistant .ask-ai-message__content {
    font-size: 14px;
    line-height: 1.7;
}

.ask-ai-message__search-indicator {
    background: #f0f7ff;
    border-left: 3px solid #3b82f6;
    padding: 8px 12px;
    font-size: 12px;
    color: #3b82f6;
    border-radius: 0 6px 6px 0;
    margin-bottom: 8px;
}

/* --------------------------------------------------------------------------
   13. Message Actions (copy, thumbs up/down, regenerate)
   -------------------------------------------------------------------------- */

.ask-ai-message__actions {
    display: flex;
    gap: 2px;
    margin-top: 8px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.ask-ai-message--assistant:hover .ask-ai-message__actions {
    opacity: 1;
}

.ask-ai-action-btn {
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: #999;
    font-size: 13px;
    cursor: pointer;
    padding: 0;
    transition: color 0.15s ease, background 0.15s ease;
}

.ask-ai-action-btn:hover {
    color: #333;
    background: #f5f5f5;
}

.ask-ai-action-btn.active {
    color: var(--primary-color);
}

.ask-ai-action-btn--copy.copied {
    color: #22c55e;
}

/* --------------------------------------------------------------------------
   15. Typing Indicator
   -------------------------------------------------------------------------- */

.ask-ai-typing__inner {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 10px 14px;
    background: #f9fafb;
    border-radius: 12px;
    width: fit-content;
}

.ask-ai-typing__dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--primary-color, #ff6600);
    opacity: 0.4;
    animation: askAiPulse 1.4s infinite;
}

.ask-ai-typing__dot:nth-child(2) {
    animation-delay: 0.2s;
}

.ask-ai-typing__dot:nth-child(3) {
    animation-delay: 0.4s;
}

.ask-ai-typing__text {
    font-size: 13px;
    color: #888;
    margin-left: 6px;
    animation: askAiFadeText 0.3s ease;
}

/* --------------------------------------------------------------------------
   16. Markdown Content Styling
   -------------------------------------------------------------------------- */

.ask-ai-message__content p,
.ask-ai-message__bubble p {
    margin: 0 0 8px;
}

.ask-ai-message__content p:last-child,
.ask-ai-message__bubble p:last-child {
    margin-bottom: 0;
}

.ask-ai-message__content code,
.ask-ai-message__bubble code {
    background: #f3f4f6;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 12px;
    font-family: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

.ask-ai-message__content pre,
.ask-ai-message__bubble pre {
    margin: 8px 0;
    border-radius: 8px;
    overflow: hidden;
}

.ask-ai-message__content pre > code,
.ask-ai-message__bubble pre > code {
    display: block;
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    font-size: 12px;
    line-height: 1.5;
}

.ask-ai-message__content ul,
.ask-ai-message__content ol,
.ask-ai-message__bubble ul,
.ask-ai-message__bubble ol {
    padding-left: 20px;
    margin: 4px 0 8px;
}

.ask-ai-message__content li,
.ask-ai-message__bubble li {
    margin-bottom: 4px;
}

.ask-ai-message__content blockquote,
.ask-ai-message__bubble blockquote {
    border-left: 3px solid #e0e0e0;
    padding-left: 12px;
    color: #666;
    margin: 8px 0;
}

.ask-ai-message__content a,
.ask-ai-message__bubble a {
    color: var(--primary-color);
    text-decoration: underline;
}

.ask-ai-message__content a:hover,
.ask-ai-message__bubble a:hover {
    opacity: 0.8;
}

/* --------------------------------------------------------------------------
   17. Input Area
   -------------------------------------------------------------------------- */

.ask-ai-input-area {
    padding: 16px 20px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid #f0f0f0;
    flex-shrink: 0;
}

.ask-ai-input-form {
    display: flex;
    align-items: center;
    gap: 8px;
}

.ask-ai-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    resize: none;
    max-height: 120px;
    transition: border-color 0.2s ease;
}

.ask-ai-input:focus {
    border-color: var(--primary-color);
}

.ask-ai-input::placeholder {
    color: #aaa;
}

.ask-ai-send-btn {
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.15s ease;
}

.ask-ai-send-btn:hover {
    opacity: 0.9;
}

.ask-ai-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ask-ai-send-btn__icon {
    font-size: 16px;
    line-height: 1;
}

/* --------------------------------------------------------------------------
   18. Expanded / Full-Screen Mode
   -------------------------------------------------------------------------- */

.ask-ai-sidebar--expanded {
    width: 100vw;
}

/* --------------------------------------------------------------------------
   19. Responsive — Mobile (max-width: 768px)
   -------------------------------------------------------------------------- */

@media (max-width: 768px) {

    /* Hide nav button on mobile */
    .ask-ai-btn {
        display: none !important;
    }

    /* Show floating button on mobile */
    .ask-ai-fab {
        display: flex;
    }

    /* Full-screen sidebar on mobile */
    .ask-ai-sidebar {
        width: 100vw;
        width: 100dvw;
        border-radius: 0;
        box-shadow: none;
    }

    /* Overlay active on mobile */
    .ask-ai-overlay {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 99990;
        background: rgba(0, 0, 0, 0.4);
        opacity: 0;
        visibility: hidden;
        transition: opacity 0.3s ease, visibility 0.3s ease;
    }

    .ask-ai-overlay--active {
        display: block;
        opacity: 1;
        visibility: visible;
    }

    /* Lock body scroll when sidebar is open on mobile */
    body.ask-ai-body--pushed {
        overflow: hidden;
        margin-right: 0;
    }

    /* Mobile header — slightly more padding, bigger close target */
    .ask-ai-header {
        padding: 14px 16px;
        padding-top: max(14px, env(safe-area-inset-top));
    }

    .ask-ai-header__action-btn {
        width: 36px;
        height: 36px;
    }

    /* Hide expand button on mobile (already full screen) */
    #askAiExpand {
        display: none;
    }

    /* Messages — more room on small screens */
    .ask-ai-messages {
        padding: 16px;
    }

    .ask-ai-message--user .ask-ai-message__bubble {
        max-width: 90%;
    }

    .ask-ai-message__body {
        max-width: calc(100% - 36px);
    }

    /* Always show action buttons on mobile (no hover) */
    .ask-ai-message__actions {
        opacity: 1;
    }

    /* Welcome state — less top padding */
    .ask-ai-welcome {
        padding-top: 40px;
    }

    /* Input area — safe area for bottom notch */
    .ask-ai-input-area {
        padding: 12px 16px;
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .ask-ai-input {
        font-size: 16px; /* prevent iOS zoom on focus */
    }
}

/* --------------------------------------------------------------------------
   20. Keyframe Animations
   -------------------------------------------------------------------------- */

@keyframes askAiPulse {
    0%,
    80%,
    100% {
        opacity: 0.4;
        transform: scale(1);
    }
    40% {
        opacity: 1;
        transform: scale(1.2);
    }
}

@keyframes askAiFadeText {
    0% {
        opacity: 0;
        transform: translateY(4px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}
