/* ═══════════════════════════════════════════════════════════════════
   Auto Inbox — Modern chat UI
   Light + dark auto-theme, smooth animations, mobile-friendly
   ═══════════════════════════════════════════════════════════════════ */

.auto-inbox {
    /* Brand color is overridden inline per-instance via --ai-brand */
    --ai-brand: #1e40af;
    --ai-brand-dk: color-mix(in srgb, var(--ai-brand) 80%, #000);
    --ai-brand-lt: color-mix(in srgb, var(--ai-brand) 88%, #fff);

    /* Light theme (default) */
    --ai-bg:       #ffffff;
    --ai-bg-soft:  #f8fafc;
    --ai-bg-msg-bot: #f1f5f9;
    --ai-bg-msg-user: var(--ai-brand);
    --ai-text:     #0f172a;
    --ai-text-soft: #64748b;
    --ai-text-on-brand: #ffffff;
    --ai-border:   #e2e8f0;
    --ai-shadow:   0 10px 40px rgba(15, 23, 42, .14);
    --ai-shadow-lg: 0 24px 60px rgba(15, 23, 42, .22);
    --ai-input-bg: #ffffff;
    --ai-radius:   14px;
    --ai-radius-sm: 10px;
    --ai-radius-bubble: 18px;

    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--ai-text);
    -webkit-font-smoothing: antialiased;
}

/* Auto dark mode */
@media (prefers-color-scheme: dark) {
    .auto-inbox {
        --ai-bg:       #0f172a;
        --ai-bg-soft:  #1e293b;
        --ai-bg-msg-bot: #1e293b;
        --ai-text:     #f1f5f9;
        --ai-text-soft: #94a3b8;
        --ai-border:   #334155;
        --ai-shadow:   0 10px 40px rgba(0, 0, 0, .5);
        --ai-shadow-lg: 0 24px 60px rgba(0, 0, 0, .6);
        --ai-input-bg: #1e293b;
    }
}

.auto-inbox *, .auto-inbox *::before, .auto-inbox *::after { box-sizing: border-box; }
.auto-inbox button { font-family: inherit; }
.auto-inbox kbd {
    background: var(--ai-bg-soft);
    padding: 1px 5px;
    border-radius: 4px;
    font-size: 11px;
    border: 1px solid var(--ai-border);
    font-family: -apple-system, monospace;
}

/* ─── Inline panel (always visible) ─────────────────────────── */
.auto-inbox-inline-mode .auto-inbox-panel {
    width: 100%;
    max-width: 600px;
    height: 600px;
    margin: 0 auto;
    background: var(--ai-bg);
    border: 1px solid var(--ai-border);
    border-radius: var(--ai-radius);
    box-shadow: var(--ai-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.auto-inbox-inline-mode .auto-inbox-min { display: none; }

/* ─── Floating bubble + slide-up panel ──────────────────────── */
.auto-inbox-bubble-mode {
    position: fixed;
    bottom: 20px; right: 20px;
    z-index: 999999;
}
.auto-inbox-bubble-mode .auto-inbox-panel {
    position: fixed;
    bottom: 90px;
    right: 20px;
    width: 560px;
    max-width: calc(100vw - 40px);
    height: 640px;
    max-height: calc(100vh - 110px);
    background: var(--ai-bg);
    border: 1px solid var(--ai-border);
    border-radius: var(--ai-radius);
    box-shadow: var(--ai-shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(.96);
    transform-origin: bottom right;
    pointer-events: none;
    transition: opacity .22s ease-out, transform .22s cubic-bezier(.34, 1.56, .64, 1);
}
.auto-inbox-bubble-mode.is-open .auto-inbox-panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* FAB (floating action button) */
.auto-inbox-fab {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: 0;
    background: var(--ai-brand);
    color: #fff;
    box-shadow: 0 8px 24px color-mix(in srgb, var(--ai-brand) 50%, transparent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s cubic-bezier(.34, 1.56, .64, 1), box-shadow .2s;
    position: relative;
}
.auto-inbox-fab:hover {
    transform: scale(1.06);
    box-shadow: 0 12px 32px color-mix(in srgb, var(--ai-brand) 60%, transparent);
}
.auto-inbox-fab:active { transform: scale(.96); }
.auto-inbox-fab svg { width: 26px; height: 26px; transition: transform .25s, opacity .15s; }
.auto-inbox-fab-icon-close { position: absolute; opacity: 0; transform: rotate(-90deg); }
.auto-inbox-bubble-mode.is-open .auto-inbox-fab-icon-chat { opacity: 0; transform: rotate(90deg); }
.auto-inbox-bubble-mode.is-open .auto-inbox-fab-icon-close { opacity: 1; transform: rotate(0); }

/* Pulse ring on FAB when chat hasn't been opened yet */
.auto-inbox-fab-pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--ai-brand);
    animation: ai-pulse 2.2s ease-out infinite;
    pointer-events: none;
}
.auto-inbox-bubble-mode.is-open .auto-inbox-fab-pulse,
.auto-inbox-bubble-mode.has-been-opened .auto-inbox-fab-pulse { display: none; }
@keyframes ai-pulse {
    0%   { transform: scale(1);    opacity: .7; }
    100% { transform: scale(1.6);  opacity: 0; }
}

/* ─── Header ─────────────────────────────────────────────────── */
.auto-inbox-header {
    background: linear-gradient(135deg, var(--ai-brand) 0%, var(--ai-brand-dk) 100%);
    color: var(--ai-text-on-brand);
    padding: 16px 18px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
}
.auto-inbox-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .2);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, .3);
}
.auto-inbox-avatar svg { width: 22px; height: 22px; color: #fff; }
.auto-inbox-titlewrap { flex: 1; min-width: 0; }
.auto-inbox-title {
    font-size: 15px;
    font-weight: 700;
    line-height: 1.2;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.auto-inbox-subtitle {
    font-size: 12px;
    color: rgba(255, 255, 255, .85);
    margin-top: 3px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.auto-inbox-online-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 0 rgba(74, 222, 128, .6);
    animation: ai-online-pulse 2s ease-in-out infinite;
}
@keyframes ai-online-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(74, 222, 128, .6); }
    50%      { box-shadow: 0 0 0 6px rgba(74, 222, 128, 0); }
}
.auto-inbox-min {
    background: rgba(255, 255, 255, .15);
    border: 0;
    color: #fff;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .15s;
    flex-shrink: 0;
}
.auto-inbox-min:hover { background: rgba(255, 255, 255, .25); }
.auto-inbox-min svg { width: 16px; height: 16px; }

/* ─── Messages ───────────────────────────────────────────────── */
.auto-inbox-messages {
    flex: 1;
    overflow-y: auto;
    padding: 18px 18px 8px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: var(--ai-bg-soft);
    scroll-behavior: smooth;
}
.auto-inbox-messages::-webkit-scrollbar { width: 6px; }
.auto-inbox-messages::-webkit-scrollbar-track { background: transparent; }
.auto-inbox-messages::-webkit-scrollbar-thumb { background: var(--ai-border); border-radius: 3px; }
.auto-inbox-messages::-webkit-scrollbar-thumb:hover { background: var(--ai-text-soft); }

.auto-inbox-msg {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 85%;
    animation: ai-msg-in .3s cubic-bezier(.2, .8, .2, 1);
}
@keyframes ai-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.auto-inbox-msg-bot { align-self: flex-start; }
.auto-inbox-msg-user { align-self: flex-end; flex-direction: row-reverse; }

.auto-inbox-msg-bubble {
    padding: 10px 14px;
    background: var(--ai-bg-msg-bot);
    color: var(--ai-text);
    border-radius: var(--ai-radius-bubble);
    border-bottom-left-radius: 4px;
    word-wrap: break-word;
    overflow-wrap: break-word;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.auto-inbox-msg-user .auto-inbox-msg-bubble {
    background: var(--ai-bg-msg-user);
    color: var(--ai-text-on-brand);
    border-bottom-left-radius: var(--ai-radius-bubble);
    border-bottom-right-radius: 4px;
}
.auto-inbox-msg-content { font-size: 14px; line-height: 1.5; }
.auto-inbox-msg-content > *:first-child { margin-top: 0; }
.auto-inbox-msg-content > *:last-child { margin-bottom: 0; }
.auto-inbox-msg-content p { margin: 0 0 8px; }
.auto-inbox-msg-content p:last-child { margin-bottom: 0; }
.auto-inbox-msg-content strong { font-weight: 700; }
.auto-inbox-msg-content em { font-style: italic; }
.auto-inbox-msg-content ul, .auto-inbox-msg-content ol { margin: 6px 0 6px 22px; padding: 0; }
.auto-inbox-msg-content li { margin: 3px 0; }
.auto-inbox-msg-content code {
    background: rgba(15, 23, 42, .08);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 12px;
}
.auto-inbox-msg-user .auto-inbox-msg-content code {
    background: rgba(255, 255, 255, .2);
    color: #fff;
}
.auto-inbox-msg-content pre {
    background: rgba(15, 23, 42, .08);
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 6px 0;
    font-size: 12px;
}
.auto-inbox-msg-content pre code { background: transparent; padding: 0; }
.auto-inbox-msg-content a {
    color: var(--ai-brand);
    text-decoration: underline;
    text-underline-offset: 2px;
}
.auto-inbox-msg-user .auto-inbox-msg-content a { color: #fff; }
.auto-inbox-msg-content h1, .auto-inbox-msg-content h2, .auto-inbox-msg-content h3 {
    font-weight: 700;
    margin: 8px 0 4px;
    font-size: 14px;
}

/* Streaming cursor */
.auto-inbox-cursor {
    display: inline-block;
    width: 7px;
    height: 14px;
    background: currentColor;
    margin-left: 2px;
    vertical-align: text-bottom;
    animation: ai-blink 0.9s steps(2) infinite;
}
@keyframes ai-blink { 50% { opacity: 0; } }

/* Typing indicator (3 dots) */
.auto-inbox-typing {
    align-self: flex-start;
    background: var(--ai-bg-msg-bot);
    padding: 14px 16px;
    border-radius: var(--ai-radius-bubble);
    border-bottom-left-radius: 4px;
    display: inline-flex;
    gap: 4px;
    animation: ai-msg-in .25s ease-out;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .04);
}
.auto-inbox-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--ai-text-soft);
    border-radius: 50%;
    animation: ai-typing 1.2s ease-in-out infinite;
}
.auto-inbox-typing-dot:nth-child(2) { animation-delay: .15s; }
.auto-inbox-typing-dot:nth-child(3) { animation-delay: .3s; }
@keyframes ai-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: .4; }
    30%           { transform: translateY(-5px); opacity: 1; }
}

/* Suggestions (chips) */
.auto-inbox-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 4px;
    align-self: flex-start;
    max-width: 100%;
}
.auto-inbox-chip {
    background: var(--ai-bg);
    border: 1px solid var(--ai-border);
    border-radius: 14px;
    padding: 6px 12px;
    font-size: 12px;
    color: var(--ai-text);
    cursor: pointer;
    transition: all .15s;
    font-family: inherit;
    line-height: 1.3;
}
.auto-inbox-chip:hover {
    background: var(--ai-brand);
    color: var(--ai-text-on-brand);
    border-color: var(--ai-brand);
    transform: translateY(-1px);
}
.auto-inbox-suggestions.is-fading { animation: ai-fade-out .25s ease forwards; }
@keyframes ai-fade-out { to { opacity: 0; height: 0; margin: 0; pointer-events: none; } }

/* ─── Input form ─────────────────────────────────────────────── */
.auto-inbox-form {
    flex-shrink: 0;
    background: var(--ai-bg);
    border-top: 1px solid var(--ai-border);
    padding: 12px 14px 10px;
}
.auto-inbox-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--ai-input-bg);
    border: 1.5px solid var(--ai-border);
    border-radius: 22px;
    padding: 4px 4px 4px 14px;
    transition: border-color .15s, box-shadow .15s;
}
.auto-inbox-input-wrap:focus-within {
    border-color: var(--ai-brand);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ai-brand) 18%, transparent);
}
.auto-inbox-input {
    flex: 1;
    background: transparent;
    border: 0;
    color: var(--ai-text);
    font-family: inherit;
    font-size: 14px;
    line-height: 1.45;
    padding: 8px 0;
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: 22px;
}
.auto-inbox-input::placeholder { color: var(--ai-text-soft); }
.auto-inbox-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 0;
    background: var(--ai-brand);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .15s, background .15s, opacity .15s;
    flex-shrink: 0;
}
.auto-inbox-send:hover:not(:disabled) {
    background: var(--ai-brand-dk);
    transform: scale(1.05);
}
.auto-inbox-send:active:not(:disabled) { transform: scale(.92); }
.auto-inbox-send:disabled { opacity: .4; cursor: not-allowed; }
.auto-inbox-send svg { width: 18px; height: 18px; }
.auto-inbox-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 6px;
    font-size: 11px;
    color: var(--ai-text-soft);
    padding: 0 4px;
    gap: 8px;
}
.auto-inbox-powered { white-space: nowrap; }
.auto-inbox-powered a { color: var(--ai-text-soft); text-decoration: none; font-weight: 600; }
.auto-inbox-powered a:hover { color: var(--ai-brand); }

/* ─── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 600px) {
    .auto-inbox-inline-mode .auto-inbox-panel {
        height: min(600px, 80vh);
        border-radius: var(--ai-radius);
    }

    .auto-inbox-bubble-mode {
        bottom: 16px;
        right: 16px;
    }
    .auto-inbox-bubble-mode .auto-inbox-panel {
        position: fixed;
        bottom: 0; right: 0; left: 0; top: 0;
        width: 100%;
        max-width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        border: 0;
        transform-origin: bottom center;
    }
    .auto-inbox-bubble-mode .auto-inbox-header { padding: 14px 16px; padding-top: max(14px, env(safe-area-inset-top, 14px)); }
    .auto-inbox-bubble-mode .auto-inbox-form { padding-bottom: max(10px, env(safe-area-inset-bottom, 10px)); }

    .auto-inbox-fab { width: 56px; height: 56px; }
    .auto-inbox-fab svg { width: 24px; height: 24px; }

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

@media (max-width: 380px) {
    .auto-inbox-hint { display: none; }
}
