/* ==========================================================================
   Ask AI Assistant Chat Widget Stylesheet
   Scoped to #askai-widget-root
   ========================================================================== */

#askai-widget-root {
    --askai-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --askai-primary-color: var(--askai-primary, #4F46E5);
    --askai-secondary-color: var(--askai-secondary, #7C3AED);
    --askai-primary-hover: #4338CA;
    --askai-primary-light: rgba(79, 70, 229, 0.12);

    --askai-trigger-bg: var(--askai-trigger-bg-custom, var(--askai-primary-color));
    --askai-send-bg: var(--askai-send-bg-custom, var(--askai-primary-color));
    --askai-user-bubble-bg: var(--askai-user-bubble-bg-custom, var(--askai-primary-color));

    /* Light Theme Default Variables */
    --askai-bg: #FFFFFF;
    --askai-card-bg: #F8FAFC;
    --askai-border: #E2E8F0;
    --askai-text: #0F172A;
    --askai-text-muted: #64748B;
    --askai-user-bubble-text: #FFFFFF;
    --askai-bot-bubble-bg: #F1F5F9;
    --askai-bot-bubble-text: #1E293B;
    --askai-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
    --askai-input-bg: #F8FAFC;

    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;
    font-family: var(--askai-font-family);
    box-sizing: border-box;
}

/* Explicit Dark Theme Overrides */
#askai-widget-root[data-theme="dark"] {
    --askai-bg: #0F172A;
    --askai-card-bg: #1E293B;
    --askai-border: #334155;
    --askai-text: #F8FAFC;
    --askai-text-muted: #94A3B8;
    --askai-bot-bubble-bg: #1E293B;
    --askai-bot-bubble-text: #F1F5F9;
    --askai-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --askai-input-bg: #1E293B;
}

/* System Auto Dark Mode Preference */
@media (prefers-color-scheme: dark) {
    #askai-widget-root[data-theme="auto"] {
        --askai-bg: #0F172A;
        --askai-card-bg: #1E293B;
        --askai-border: #334155;
        --askai-text: #F8FAFC;
        --askai-text-muted: #94A3B8;
        --askai-bot-bubble-bg: #1E293B;
        --askai-bot-bubble-text: #F1F5F9;
        --askai-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
        --askai-input-bg: #1E293B;
    }
}

#askai-widget-root *,
#askai-widget-root *::before,
#askai-widget-root *::after {
    box-sizing: border-box;
    margin: 3;
    padding: 3;
}

/* --------------------------------------------------------------------------
   Floating Trigger Bubble
   -------------------------------------------------------------------------- */
.askai-bubble-btn {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--askai-trigger-bg);
    color: #FFFFFF;
    border: none;
    cursor: pointer;
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), filter 0.2s ease, box-shadow 0.2s ease;
    outline: none;
}

.askai-bubble-btn:hover {
    transform: scale(1.08);
    filter: brightness(1.1);
    box-shadow: 0 14px 20px -3px rgba(0, 0, 0, 0.3);
}

.askai-bubble-btn:focus-visible {
    ring: 3px solid rgba(79, 70, 229, 0.5);
    outline: 2px solid #FFFFFF;
}

.askai-bubble-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    object-fit: cover;
}

.askai-svg-icon {
    width: 28px;
    height: 28px;
}

.askai-unread-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    background: #EF4444;
    color: #FFFFFF;
    font-size: 11px;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 2px solid var(--askai-bg);
    animation: askai-pulse 2s infinite;
}

@keyframes askai-pulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.15);
    }
}

/* --------------------------------------------------------------------------
   Chat Drawer / Window Container
   -------------------------------------------------------------------------- */
.askai-chat-drawer {
    position: absolute;
    bottom: 76px;
    right: 0;
    width: 390px;
    height: 600px;
    max-height: calc(100vh - 120px);
    background: var(--askai-bg);
    border: 1px solid var(--askai-border);
    border-radius: 20px;
    box-shadow: var(--askai-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform-origin: bottom right;
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.2s ease;
    opacity: 1;
    transform: scale(1) translateY(0);
}

.askai-chat-drawer.askai-hidden {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
    pointer-events: none;
}

/* --------------------------------------------------------------------------
   Header Bar
   -------------------------------------------------------------------------- */
.askai-header {
    padding: 16px 20px;
    background: var(--askai-card-bg);
    border-bottom: 1px solid var(--askai-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.askai-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.askai-avatar-wrapper {
    position: relative;
    width: 40px;
    height: 40px;
}

.askai-header-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.askai-header-avatar-placeholder {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--askai-trigger-bg);
    color: #FFFFFF;
    display: flex;
    align-items: center;
    justify-content: center;
}

.askai-status-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 11px;
    height: 11px;
    background: #10B981;
    border: 2px solid var(--askai-bg);
    border-radius: 50%;
}

.askai-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--askai-text);
    line-height: 1.2;
}

.askai-subtitle {
    font-size: 12px;
    color: var(--askai-text-muted);
}

.askai-header-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.askai-icon-btn {
    background: transparent;
    border: none;
    color: var(--askai-text-muted);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s ease, color 0.15s ease;
}

.askai-icon-btn:hover {
    background: var(--askai-border);
    color: var(--askai-text);
}

.askai-svg-sm {
    width: 18px;
    height: 18px;
}

/* Theme toggle icons visibility */
#askai-widget-root[data-theme="dark"] .askai-theme-sun {
    display: block;
}

#askai-widget-root[data-theme="dark"] .askai-theme-moon {
    display: none;
}

#askai-widget-root[data-theme="light"] .askai-theme-sun {
    display: none;
}

#askai-widget-root[data-theme="light"] .askai-theme-moon {
    display: block;
}

#askai-widget-root[data-theme="auto"] .askai-theme-sun {
    display: none;
}

#askai-widget-root[data-theme="auto"] .askai-theme-moon {
    display: block;
}

/* --------------------------------------------------------------------------
   Messages Scroll Body
   -------------------------------------------------------------------------- */
.askai-messages-body {
    flex: 1 1 auto;
    min-height: 0;
    padding: 16px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scroll-behavior: smooth;
}

.askai-messages-body::-webkit-scrollbar {
    width: 5px;
}

.askai-messages-body::-webkit-scrollbar-thumb {
    background: var(--askai-border);
    border-radius: 10px;
}

.askai-welcome-card {
    background: var(--askai-card-bg);
    border: 1px solid var(--askai-border);
    border-radius: 14px;
    padding: 14px 16px;
    font-size: 14px;
    color: var(--askai-text);
    line-height: 1.5;
    margin-bottom: 8px;
}

.askai-suggestions-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 12px;
}

.askai-suggestions-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--askai-text-muted);

}

.askai-chips-wrapper {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.askai-chip {
    background: var(--askai-card-bg);
    border: 1px solid var(--askai-border);
    border-radius: 18px;
    padding: 6px 12px;
    font-size: 13px;
    color: var(--askai-text);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s ease;
    text-align: left;
}

.askai-chip:hover {
    border-color: var(--askai-primary-color);
    background: var(--askai-primary-light);
    color: var(--askai-primary-color);
}

/* Message Bubbles */
.askai-msg-row {
    display: flex;
    flex-direction: column;
    max-width: 85%;
    animation: askai-fade-in 0.2s ease;
}

@keyframes askai-fade-in {
    from {
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.askai-msg-row.askai-msg-user {
    align-self: flex-end;
}

.askai-msg-row.askai-msg-bot {
    align-self: flex-start;
}

.askai-msg-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

.askai-msg-user .askai-msg-bubble {
    background: var(--askai-user-bubble-bg);
    color: var(--askai-user-bubble-text);
    border-bottom-right-radius: 4px;
    padding: 12px 18px;
}

.askai-msg-bot .askai-msg-bubble {
    background: var(--askai-bot-bubble-bg);
    color: var(--askai-bot-bubble-text);
    border-bottom-left-radius: 4px;
    border: 1px solid var(--askai-border);
}

.askai-msg-bubble p {
    margin: 0 0 8px 0;
}

.askai-msg-bubble p:last-child {
    margin-bottom: 0;
}

.askai-msg-bubble a {
    color: var(--askai-primary-color);
    text-decoration: underline;
}

.askai-msg-bubble ul,
.askai-msg-bubble ol {
    margin: 4px 0 8px 18px;
    padding: 0;
}

.askai-msg-bubble img {
    max-width: 100%;
    border-radius: 8px;
}

.askai-msg-time {
    font-size: 10px;
    color: var(--askai-text-muted);
    margin-top: 4px;
    align-self: flex-end;
}

.askai-msg-bot .askai-msg-time {
    align-self: flex-start;
}

/* --------------------------------------------------------------------------
   Typing Indicator
   -------------------------------------------------------------------------- */
.askai-typing-bar {
    padding: 8px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--askai-bg);
    border-top: 1px solid var(--askai-border);
}

.askai-typing-bar.askai-hidden {
    display: none;
}

.askai-typing-dots {
    display: flex;
    gap: 4px;
}

.askai-typing-dots span {
    width: 6px;
    height: 6px;
    background: var(--askai-text-muted);
    border-radius: 50%;
    animation: askai-dot-bounce 1.4s infinite ease-in-out both;
}

.askai-typing-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.askai-typing-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes askai-dot-bounce {

    0%,
    80%,
    100% {
        transform: scale(0);
    }

    40% {
        transform: scale(1);
    }
}

.askai-typing-text {
    font-size: 12px;
    color: var(--askai-text-muted);
}

/* --------------------------------------------------------------------------
   Footer & Input Form
   -------------------------------------------------------------------------- */
.askai-footer {
    padding: 12px 16px;
    background: var(--askai-card-bg);
    border-top: 1px solid var(--askai-border);
    flex-shrink: 0;
}

.askai-input-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--askai-input-bg);
    border: 1px solid var(--askai-border);
    border-radius: 12px;
    padding: 6px 8px 6px 12px;
    transition: border-color 0.15s ease;
}

.askai-input-form:focus-within {
    border-color: var(--askai-primary-color);
}

.askai-input-textarea {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--askai-text);
    font-family: inherit;
    font-size: 14px;
    resize: none;
    max-height: 100px;
    line-height: 1.4;
}

.askai-input-textarea::placeholder {
    color: var(--askai-text-muted);
}

.askai-send-button {
    background: var(--askai-send-bg);
    color: #FFFFFF;
    border: none;
    width: 34px;
    height: 34px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: filter 0.15s ease, transform 0.1s ease;
    flex-shrink: 0;
}

.askai-send-button:hover {
    filter: brightness(1.1);
    transform: scale(1.04);
}

.askai-send-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.askai-svg-send {
    width: 16px;
    height: 16px;
}

.askai-branding-footer {
    text-align: center;
    font-size: 10px;
    color: var(--askai-text-muted);
    margin-top: 6px;
}

/* --------------------------------------------------------------------------
   Mobile Responsive Rules (768px and below)
   -------------------------------------------------------------------------- */
@media (max-width: 768px) {
    #askai-widget-root {
        bottom: 12px;
        right: 12px;
    }

    .askai-chat-drawer {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
        display: flex;
        flex-direction: column;
        z-index: 999999;
    }

    .askai-input-textarea {
        font-size: 16px;
        /* Prevents auto-zoom on iOS Safari when tapping input */
    }

    .askai-footer {
        padding: 10px 12px;
        padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
        flex-shrink: 0;
    }
}