/* ═══════════════════════════════════════════════════════════════════
   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) ─────────────────────────── */
.aw-chat-inline-mode .aw-chat-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;
}
.aw-chat-inline-mode .aw-chat-min { display: none; }

/* ─── Floating bubble + slide-up panel ──────────────────────── */
.aw-chat-bubble-mode {
    position: fixed;
    bottom: 20px; right: 20px;
    z-index: 999999;
}
.aw-chat-bubble-mode .aw-chat-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);
}
.aw-chat-bubble-mode.is-open .aw-chat-panel {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* FAB (floating action button) */
.aw-chat-fab {
    width: 68px;
    height: 68px;
    border-radius: 50%;
    border: 0;
    background: linear-gradient(135deg, var(--ai-brand) 0%, var(--ai-brand-dk, #047857) 100%);
    color: #fff;
    box-shadow:
        0 10px 28px color-mix(in srgb, var(--ai-brand) 55%, transparent),
        0 0 0 4px rgba(255, 255, 255, .9);
    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;
    animation: ai-fab-bounce 3.2s ease-in-out infinite;
}
@keyframes ai-fab-bounce {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-6px); }
}
.aw-chat-fab:hover {
    transform: translateY(-8px) scale(1.06);
    box-shadow:
        0 16px 36px color-mix(in srgb, var(--ai-brand) 65%, transparent),
        0 0 0 4px rgba(255, 255, 255, 1);
    animation-play-state: paused;
}
.aw-chat-fab:active { transform: translateY(-2px) scale(.97); }
.aw-chat-fab svg { width: 38px; height: 38px; transition: transform .25s, opacity .15s; }
.aw-chat-fab-icon-close { position: absolute; opacity: 0; transform: rotate(-90deg); width: 24px !important; height: 24px !important; }
.aw-chat-bubble-mode.is-open .aw-chat-fab-icon-chat { opacity: 0; transform: rotate(90deg); }
.aw-chat-bubble-mode.is-open .aw-chat-fab-icon-close { opacity: 1; transform: rotate(0); }
.aw-chat-bubble-mode.is-open .aw-chat-fab { animation: none; }

/* Robot character animations */
.aw-chat-robot-antenna {
    transform-origin: 32px 14px;
    animation: ai-robot-antenna 2.4s ease-in-out infinite;
}
@keyframes ai-robot-antenna {
    0%, 100% { transform: rotate(-6deg); }
    50%      { transform: rotate(6deg); }
}
.aw-chat-robot-arm {
    transform-origin: 48px 46px;
    animation: ai-robot-wave 1.6s ease-in-out infinite;
}
@keyframes ai-robot-wave {
    0%, 100% { transform: rotate(-10deg); }
    50%      { transform: rotate(25deg); }
}
.aw-chat-robot-eye {
    animation: ai-robot-blink 4s ease-in-out infinite;
    transform-origin: center;
    transform-box: fill-box;
}
@keyframes ai-robot-blink {
    0%, 92%, 100% { transform: scaleY(1); }
    95%           { transform: scaleY(0.1); }
}

/* Header robot — slower, more "professional" idle animation */
.aw-chat-header .aw-chat-robot-antenna {
    animation: ai-robot-antenna 4s ease-in-out infinite;
}
.aw-chat-header .aw-chat-robot-eye {
    animation: ai-robot-blink 5s ease-in-out infinite;
}

/* Pulse rings on FAB when chat hasn't been opened yet */
.aw-chat-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;
}
.aw-chat-fab-pulse-2 { animation-delay: 1.1s; }
.aw-chat-bubble-mode.is-open .aw-chat-fab-pulse,
.aw-chat-bubble-mode.has-been-opened .aw-chat-fab-pulse { display: none; }
@keyframes ai-pulse {
    0%   { transform: scale(1);    opacity: .55; }
    100% { transform: scale(1.7);  opacity: 0; }
}

/* ─── Header ─────────────────────────────────────────────────── */
.aw-chat-header {
    background: linear-gradient(135deg, var(--ai-brand) 0%, var(--ai-brand-dk) 100%);
    color: var(--ai-text-on-brand);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}
.aw-chat-header::after {
    /* subtle glossy highlight overlay */
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 50%;
    background: linear-gradient(180deg, rgba(255,255,255,.12), transparent);
    pointer-events: none;
}
.aw-chat-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .22);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 2px solid rgba(255, 255, 255, .4);
    color: #fff;
    position: relative;
    z-index: 1;
}
.aw-chat-avatar svg { width: 32px; height: 32px; color: #fff; }
.aw-chat-titlewrap { flex: 1; min-width: 0; position: relative; z-index: 1; }
.aw-chat-title {
    font-size: 16px;
    font-weight: 700;
    line-height: 1.2;
    color: #fff;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    letter-spacing: -0.01em;
}
.aw-chat-subtitle {
    font-size: 12px;
    color: rgba(255, 255, 255, .85);
    margin-top: 3px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.aw-chat-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); }
}
.aw-chat-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;
}
.aw-chat-min:hover { background: rgba(255, 255, 255, .25); }
.aw-chat-min svg { width: 16px; height: 16px; }

/* ─── Messages ───────────────────────────────────────────────── */
.aw-chat-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;
}
.aw-chat-messages::-webkit-scrollbar { width: 6px; }
.aw-chat-messages::-webkit-scrollbar-track { background: transparent; }
.aw-chat-messages::-webkit-scrollbar-thumb { background: var(--ai-border); border-radius: 3px; }
.aw-chat-messages::-webkit-scrollbar-thumb:hover { background: var(--ai-text-soft); }

.aw-chat-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); }
}
.aw-chat-msg-bot { align-self: flex-start; }
.aw-chat-msg-user { align-self: flex-end; flex-direction: row-reverse; }

.aw-chat-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);
}
.aw-chat-msg-user .aw-chat-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;
}
.aw-chat-msg-content { font-size: 14px; line-height: 1.5; }
.aw-chat-msg-content > *:first-child { margin-top: 0; }
.aw-chat-msg-content > *:last-child { margin-bottom: 0; }
.aw-chat-msg-content p { margin: 0 0 8px; }
.aw-chat-msg-content p:last-child { margin-bottom: 0; }
.aw-chat-msg-content strong { font-weight: 700; }
.aw-chat-msg-content em { font-style: italic; }
.aw-chat-msg-content ul, .aw-chat-msg-content ol { margin: 6px 0 6px 22px; padding: 0; }
.aw-chat-msg-content li { margin: 3px 0; }
.aw-chat-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;
}
.aw-chat-msg-user .aw-chat-msg-content code {
    background: rgba(255, 255, 255, .2);
    color: #fff;
}
.aw-chat-msg-content pre {
    background: rgba(15, 23, 42, .08);
    padding: 10px 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 6px 0;
    font-size: 12px;
}
.aw-chat-msg-content pre code { background: transparent; padding: 0; }
.aw-chat-msg-content a {
    color: var(--ai-brand);
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-thickness: 1.5px;
    font-weight: 600;
    word-break: break-word;
    transition: color .15s, background .15s;
    padding: 1px 2px;
    border-radius: 3px;
}
.aw-chat-msg-content a:hover {
    color: var(--ai-brand-dk, var(--ai-brand));
    background: color-mix(in srgb, var(--ai-brand) 10%, transparent);
    text-decoration-thickness: 2px;
}
.aw-chat-msg-content a::after {
    /* tiny external-link indicator */
    content: ' ↗';
    font-size: 0.85em;
    opacity: 0.65;
}
.aw-chat-msg-user .aw-chat-msg-content a { color: #fff; }
.aw-chat-msg-user .aw-chat-msg-content a:hover {
    color: #fff;
    background: rgba(255, 255, 255, .18);
}
.aw-chat-msg-content h1, .aw-chat-msg-content h2, .aw-chat-msg-content h3 {
    font-weight: 700;
    margin: 8px 0 4px;
    font-size: 14px;
}

/* Streaming cursor */
.aw-chat-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) */
.aw-chat-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);
}
.aw-chat-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--ai-text-soft);
    border-radius: 50%;
    animation: ai-typing 1.2s ease-in-out infinite;
}
.aw-chat-typing-dot:nth-child(2) { animation-delay: .15s; }
.aw-chat-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) */
.aw-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
    align-self: flex-start;
    max-width: 100%;
}
.aw-chat-chip {
    background: linear-gradient(180deg, var(--ai-bg) 0%, color-mix(in srgb, var(--ai-brand) 4%, var(--ai-bg)) 100%);
    border: 1px solid color-mix(in srgb, var(--ai-brand) 25%, var(--ai-border));
    border-radius: 16px;
    padding: 8px 14px;
    font-size: 12.5px;
    font-weight: 500;
    color: var(--ai-text);
    cursor: pointer;
    transition: all .18s cubic-bezier(.34, 1.56, .64, 1);
    font-family: inherit;
    line-height: 1.3;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .03);
}
.aw-chat-chip:hover {
    background: var(--ai-brand);
    color: var(--ai-text-on-brand);
    border-color: var(--ai-brand);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--ai-brand) 40%, transparent);
}
.aw-chat-chip:active { transform: translateY(0); }
.aw-chat-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 ─────────────────────────────────────────────── */
.aw-chat-form {
    flex-shrink: 0;
    background: var(--ai-bg);
    border-top: 1px solid var(--ai-border);
    padding: 12px 14px 10px;
}
.aw-chat-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;
}
.aw-chat-input-wrap:focus-within {
    border-color: var(--ai-brand);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ai-brand) 18%, transparent);
}
.aw-chat-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;
}
.aw-chat-input::placeholder { color: var(--ai-text-soft); }
.aw-chat-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;
}
.aw-chat-send:hover:not(:disabled) {
    background: var(--ai-brand-dk);
    transform: scale(1.05);
}
.aw-chat-send:active:not(:disabled) { transform: scale(.92); }
.aw-chat-send:disabled { opacity: .4; cursor: not-allowed; }
.aw-chat-send svg { width: 18px; height: 18px; }
.aw-chat-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;
}
.aw-chat-powered { white-space: nowrap; }
.aw-chat-powered a { color: var(--ai-text-soft); text-decoration: none; font-weight: 600; }
.aw-chat-powered a:hover { color: var(--ai-brand); }

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

    .aw-chat-bubble-mode {
        bottom: 16px;
        right: 16px;
    }
    .aw-chat-bubble-mode .aw-chat-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;
    }
    .aw-chat-bubble-mode .aw-chat-header { padding: 14px 16px; padding-top: max(14px, env(safe-area-inset-top, 14px)); }
    .aw-chat-bubble-mode .aw-chat-form { padding-bottom: max(10px, env(safe-area-inset-bottom, 10px)); }

    .aw-chat-fab { width: 56px; height: 56px; }
    .aw-chat-fab svg { width: 24px; height: 24px; }

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

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

/* ─── CTA Buttons (links promoted below message bubble) ───────────── */
.aw-chat-cta-stack {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
    align-items: flex-start;
    width: 100%;
}
.aw-chat-cta-btn {
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    background: linear-gradient(135deg, var(--ai-brand) 0%, var(--ai-brand-dk, #047857) 100%);
    color: #fff !important;
    text-decoration: none !important;
    padding: 11px 16px;
    border-radius: 12px;
    font-size: 13.5px;
    font-weight: 600;
    letter-spacing: -0.005em;
    box-shadow: 0 4px 14px color-mix(in srgb, var(--ai-brand) 35%, transparent);
    transition: transform .18s cubic-bezier(.34, 1.56, .64, 1), box-shadow .18s, background .18s;
    cursor: pointer;
    max-width: 100%;
    min-height: 42px;
    line-height: 1.3;
    /* Override the generic .aw-chat-msg-content a styles */
    text-underline-offset: 0;
    text-decoration-thickness: 0;
    border-radius: 12px;
}
.aw-chat-cta-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 22px color-mix(in srgb, var(--ai-brand) 50%, transparent);
    color: #fff !important;
    background: linear-gradient(135deg, var(--ai-brand-dk, #047857) 0%, var(--ai-brand) 100%);
}
.aw-chat-cta-btn:active {
    transform: translateY(0);
}
.aw-chat-cta-btn::after {
    /* Remove the inherited ↗ from the generic link rule */
    content: none !important;
}
.aw-chat-cta-label {
    flex: 1;
    word-break: normal;
    overflow-wrap: anywhere;
}
.aw-chat-cta-arrow {
    font-size: 18px;
    line-height: 1;
    opacity: .9;
    transition: transform .2s;
    flex-shrink: 0;
}
.aw-chat-cta-btn:hover .aw-chat-cta-arrow {
    transform: translateX(3px);
}

/* The original inline link inside the bubble: dim it (still visible
 * for copy-paste but the CTA button is now the primary action) */
.aw-chat-msg-content a.aw-chat-link-inline {
    color: var(--ai-text-soft, #64748b) !important;
    font-weight: 500;
    font-size: 0.92em;
    background: transparent !important;
    word-break: break-all;
}
.aw-chat-msg-content a.aw-chat-link-inline:hover {
    color: var(--ai-text) !important;
    background: transparent !important;
}
.aw-chat-msg-content a.aw-chat-link-inline::after {
    content: none !important;
}

/* Mobile: full-width buttons */
@media (max-width: 480px) {
    .aw-chat-cta-stack { width: 100%; }
    .aw-chat-cta-btn { width: 100%; }
}
