/* ============================================================
   Apricot AI Chat — Mobile-First Widget Styles
   v2.0 — Full mobile/keyboard/safe-area overhaul
   ============================================================ */

/* ── CSS Variables ───────────────────────────────────────── */
:root {
    --aac-primary:       #ffbb84;   /* apricot orange */
    --aac-primary-dark:  #f0a060;
    --aac-primary-light: #fff4ec;
    --aac-primary-text:  #7a3b00;   /* dark text on light orange bg */
    --aac-bg:            #ffffff;
    --aac-msg-bg:        #f1f1f1;
    --aac-text:          #1a1a1a;
    --aac-text-muted:    #8a8a8a;
    --aac-border:        #e5e5e5;
    --aac-shadow:        0 8px 48px rgba(0,0,0,0.18);
    --aac-radius:        16px;

    /*
     * Safe-area insets — populated by the browser on notched / Dynamic Island
     * devices and Android gesture-navigation devices.
     * Requires  viewport-fit=cover  in the page's <meta name="viewport">.
     * If the theme already sets that we get real values; otherwise these fall
     * back to 0px and nothing breaks.
     */
    --aac-safe-top:    env(safe-area-inset-top,    0px);
    --aac-safe-right:  env(safe-area-inset-right,  0px);
    --aac-safe-bottom: env(safe-area-inset-bottom, 0px);
    --aac-safe-left:   env(safe-area-inset-left,   0px);
}

/* ── Base widget container ───────────────────────────────── */
.aac-widget {
    position: fixed;
    /*
     * Include safe-area-inset-bottom so the toggle button is never hidden
     * behind the iOS home indicator or Android gesture bar.
     */
    bottom: calc(20px + var(--aac-safe-bottom));
    right:  calc(20px + var(--aac-safe-right));
    z-index: 99999;
    font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--aac-text);
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    /*
     * Smooth repositioning when keyboard opens/closes (JS drives the value).
     * Disabled by .aac-keyboard-open while JS is actively adjusting position.
     */
    transition: bottom 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}

.aac-open .aac-toggle {
    display: none;
}

/* ── Toggle button ───────────────────────────────────────── */
.aac-toggle {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--aac-primary);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(255, 187, 132, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.2s ease;
    outline: none;
    flex-shrink: 0;
    position: relative;
    /*
     * touch-action: manipulation removes the 300 ms tap-delay on mobile
     * without disabling pinch-zoom on the rest of the page.
     * -webkit-tap-highlight-color removes the grey flash on Android Chrome.
     */
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    /* Apple HIG / Material Design: interactive targets ≥ 44 × 44 pt */
    min-width:  44px;
    min-height: 44px;
}
.aac-toggle:hover {
    background: var(--aac-primary-dark);
    transform: scale(1.06);
    box-shadow: 0 6px 26px rgba(255, 187, 132, 0.65);
}
.aac-toggle:focus-visible {
    box-shadow: 0 0 0 3px rgba(255, 187, 132, 0.45);
}

/* Tawk-style chat icon inside button */
.aac-toggle-icon {
    font-size: 26px;
    line-height: 1;
    transition: opacity 0.15s, transform 0.2s;
    color: #7a3b00;
}
.aac-toggle .aac-icon-close {
    font-size: 20px;
    font-weight: 700;
}

/* Notification badge */
.aac-toggle::after {
    content: '';
    position: absolute;
    top: 4px;
    right: 4px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #ff4757;
    border: 2px solid #fff;
    display: none;
}
.aac-has-unread .aac-toggle::after { display: block; }

/* ── First-visit greeting tooltip ────────────────────────── */
.aac-greeting-tooltip {
    position: relative;
    background: #fff;
    border: 1px solid rgba(255, 187, 132, 0.55);
    border-radius: 14px;
    padding: 11px 34px 11px 14px;
    margin-bottom: 10px;
    max-width: 240px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12);
    font-size: 13.5px;
    color: var(--aac-text);
    line-height: 1.45;
    animation: aac-tooltip-in 0.32s cubic-bezier(.4,0,.2,1);
    transform-origin: bottom right;
}
.aac-greeting-tooltip[hidden] { display: none; }

/* border triangle (slightly larger — gives the "border" on the tail) */
.aac-greeting-tooltip::before {
    content: '';
    position: absolute;
    bottom: -10px;
    right: 21px;
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-top: 9px solid rgba(255, 187, 132, 0.55);
}
/* white fill triangle on top of the border triangle */
.aac-greeting-tooltip::after {
    content: '';
    position: absolute;
    bottom: -8px;
    right: 22px;
    border-left: 8px solid transparent;
    border-right: 8px solid transparent;
    border-top: 8px solid #fff;
}

@keyframes aac-tooltip-in {
    from { opacity: 0; transform: translateY(10px) scale(0.94); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

.aac-tooltip-dismiss {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    border: none;
    background: transparent;
    color: var(--aac-text-muted);
    font-size: 13px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    transition: background 0.15s, color 0.15s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.aac-tooltip-dismiss:hover {
    background: var(--aac-msg-bg);
    color: var(--aac-text);
}

/* Hide tooltip while chat is open */
.aac-open .aac-greeting-tooltip { display: none; }

/* ── Chat box ────────────────────────────────────────────── */
.aac-chat-box {
    width: 370px;
    max-width: calc(100vw - 40px);
    /*
     * Height — progressively enhanced viewport units:
     *   520px      → absolute fallback for very old browsers
     *   100vh      → classic viewport (includes mobile browser chrome)
     *   100svh     → small viewport: most conservative, chrome always excluded
     *   100dvh     → dynamic: updates live as browser chrome hides/shows
     * JS overrides with an exact pixel height when the keyboard is open.
     */
    height: 520px;
    max-height: calc(100vh  - 100px);
    max-height: calc(100svh - 100px);
    max-height: calc(100dvh - 100px);
    background: var(--aac-bg);
    border-radius: var(--aac-radius);
    box-shadow: var(--aac-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 14px;
    animation: aac-slide-up 0.25s cubic-bezier(.4,0,.2,1);
    transform-origin: bottom right;
    border: 1px solid rgba(0,0,0,0.08);
    /*
     * Promote to GPU compositing layer for stutter-free height animation
     * when JS resizes the box as the keyboard opens/closes.
     */
    will-change: transform, height;
    transition: height     0.22s cubic-bezier(0.4, 0, 0.2, 1),
                max-height 0.22s cubic-bezier(0.4, 0, 0.2, 1);
}
.aac-chat-box[hidden] { display: none; }

@keyframes aac-slide-up {
    from { opacity: 0; transform: translateY(20px) scale(0.97); }
    to   { opacity: 1; transform: translateY(0)    scale(1);    }
}

/* ── Header ──────────────────────────────────────────────── */
.aac-header {
    background: var(--aac-primary);
    color: #7a3b00;
    padding: 16px 18px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
}
/* Subtle dot pattern overlay */
.aac-header::before {
    content: '';
    position: absolute;
    inset: 0;
    background: url("data:image/svg+xml,%3Csvg width='40' height='40' viewBox='0 0 40 40' xmlns='http://www.w3.org/2000/svg'%3E%3Ccircle cx='20' cy='20' r='1' fill='rgba(255,255,255,0.06)'/%3E%3C/svg%3E") repeat;
    pointer-events: none;
}

.aac-header-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: rgba(255,255,255,0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    flex-shrink: 0;
    border: 2px solid var(--aac-primary);
}
/* Online dot on avatar */
.aac-header-avatar::after {
    content: '';
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #fff3e0;
    border: 2px solid var(--aac-primary);
}

.aac-header-info {
    flex: 1;
    min-width: 0;
}
.aac-title {
    font-weight: 700;
    font-size: 15px;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.01em;
}
.aac-subtitle {
    font-size: 12px;
    opacity: 0.88;
    display: flex;
    align-items: center;
    gap: 5px;
    margin-top: 2px;
}
.aac-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #fff3e0;
    display: inline-block;
    animation: aac-pulse 2s infinite;
}
@keyframes aac-pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.35; }
}

/*
 * Header close button: enlarged padding + negative margin gives a 44×44 pt
 * touch target while keeping the visual icon size small.
 */
.aac-header-close {
    background: transparent;
    border: none;
    color: rgba(122, 59, 0, 0.7);
    font-size: 35px;
    cursor: pointer;
    padding: 11px 13px;
    margin: -9px -11px;
    border-radius: 8px;
    transition: background 0.15s, color 0.15s;
    line-height: 1;
    flex-shrink: 0;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.aac-header-close:hover {
    background: rgba(122, 59, 0, 0.12);
    color: #7a3b00;
}

/* ── Greeting banner (below header) ─────────────────────── */
.aac-greeting {
    background: var(--aac-primary-light);
    padding: 10px 18px;
    font-size: 13px;
    color: var(--aac-primary-text);
    border-bottom: 1px solid rgba(255,187,132,0.25);
    flex-shrink: 0;
}

/* ── Messages area ───────────────────────────────────────── */
.aac-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;          /* prevent horizontal scroll from long URLs */
    padding: 18px 16px 10px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
    background: #f7f7f7;
    /*
     * overscroll-behavior: contain — prevents rubber-band / over-scroll from
     * propagating to the parent page on both iOS and Android.
     */
    overscroll-behavior: contain;
    /* Momentum (inertia) scrolling on iOS — essential for native feel */
    -webkit-overflow-scrolling: touch;
}
.aac-messages::-webkit-scrollbar { width: 4px; }
.aac-messages::-webkit-scrollbar-track { background: transparent; }
.aac-messages::-webkit-scrollbar-thumb { background: #d0d0d0; border-radius: 4px; }

/* Disable smooth-scroll while keyboard is animating to avoid visual conflicts */
.aac-keyboard-open .aac-messages {
    scroll-behavior: auto;
}

/* ── Date/time separator ─────────────────────────────────── */
.aac-date-sep {
    text-align: center;
    font-size: 11px;
    color: var(--aac-text-muted);
    margin: 4px 0;
    position: relative;
}
.aac-date-sep::before, .aac-date-sep::after {
    content: '';
    position: absolute;
    top: 50%;
    width: 28%;
    height: 1px;
    background: var(--aac-border);
}
.aac-date-sep::before { left: 0; }
.aac-date-sep::after  { right: 0; }

/* ── Message bubbles ─────────────────────────────────────── */
.aac-msg {
    display: flex;
    flex-direction: column;
    max-width: 80%;
    animation: aac-msg-in 0.2s ease;
}
@keyframes aac-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.aac-msg--bot  { align-self: flex-start; }
.aac-msg--user { align-self: flex-end;   }

/* Bot message: avatar on the left */
.aac-msg--bot {
    flex-direction: row;
    align-items: flex-end;
    gap: 8px;
    max-width: 86%;
}
.aac-msg--bot .aac-msg-inner {
    display: flex;
    flex-direction: column;
    min-width: 0; /* allow inner content to shrink properly */
}
.aac-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--aac-primary);
    color: #7a3b00;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    margin-bottom: 2px;
}

.aac-bubble {
    padding: 10px 14px;
    border-radius: 18px;
    /*
     * word-break + overflow-wrap ensure long unbreakable strings (URLs,
     * tokens) wrap rather than causing horizontal overflow.
     */
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    font-size: 14px;
    line-height: 1.6;
    /* Hyphenate long words on narrow screens */
    hyphens: auto;
    -webkit-hyphens: auto;
}
.aac-msg--bot .aac-bubble {
    background: #ffffff;
    border: 1px solid #e8e8e8;
    border-bottom-left-radius: 4px;
    color: var(--aac-text);
    box-shadow: 0 1px 3px rgba(0,0,0,0.07);
}
.aac-msg--bot .aac-bubble a {
    color: #c05a00;
    text-decoration: underline;
    word-break: break-all;
}
.aac-msg--bot .aac-bubble a:hover {
    color: #7a3b00;
}
.aac-msg--user .aac-bubble {
    background: var(--aac-primary);
    color: #7a3b00;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(255,187,132,0.40);
}

.aac-msg-time {
    font-size: 10.5px;
    color: var(--aac-text-muted);
    margin-top: 4px;
    padding: 0 4px;
}
.aac-msg--user .aac-msg-time { text-align: right; }

/* read tick for user messages */
.aac-msg--user .aac-msg-time::after {
    content: ' ✓✓';
    color: #f0a060;
    font-size: 10px;
}

/* ── Typing indicator ────────────────────────────────────── */
.aac-typing .aac-bubble {
    display: flex;
    gap: 5px;
    align-items: center;
    padding: 12px 16px;
    background: #fff;
    border: 1px solid #e8e8e8;
}
.aac-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #c0c0c0;
    animation: aac-bounce 1.3s infinite ease-in-out;
}
.aac-typing-dot:nth-child(2) { animation-delay: 0.18s; }
.aac-typing-dot:nth-child(3) { animation-delay: 0.36s; }
@keyframes aac-bounce {
    0%, 80%, 100% { transform: translateY(0);   opacity: 0.5; }
    40%            { transform: translateY(-6px); opacity: 1;   }
}

/* ── WhatsApp fallback banner ────────────────────────────── */
.aac-fallback {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    margin: 0 12px 6px;
    background: #fff4ec;
    border: 1px solid #ffd4aa;
    border-radius: 12px;
    font-size: 13px;
    color: #7a3b00;
    animation: aac-msg-in 0.2s ease;
    flex-shrink: 0;
}
.aac-fallback-text { flex: 1; line-height: 1.4; }
.aac-fallback-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: #25d366;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 7px 13px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background 0.2s, transform 0.15s;
    box-shadow: 0 2px 6px rgba(37,211,102,0.35);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    min-height: 44px; /* touch target */
}
.aac-fallback-btn:hover {
    background: #1da851;
    color: #fff;
    transform: translateY(-1px);
}
.aac-fallback-btn svg { flex-shrink: 0; }

/* ── Input area ───────────────────────────��──────────────── */
.aac-input-area {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--aac-border);
    background: #fff;
    flex-shrink: 0;
}
.aac-input {
    flex: 1;
    resize: none;
    border: 1px solid #ddd;
    border-radius: 22px;
    padding: 9px 16px;
    font-family: inherit;
    /*
     * IMPORTANT: font-size must be ≥ 16px on iOS Safari.
     * Anything smaller causes the browser to auto-zoom the entire viewport
     * when the textarea receives focus — a major UX problem.
     */
    font-size: 16px;
    line-height: 1.45;
    max-height: 110px;
    overflow-y: auto;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    background: #f7f7f7;
    color: var(--aac-text);
    /* Remove system default styling on iOS (rounded corners, inner shadow) */
    -webkit-appearance: none;
    appearance: none;
}
.aac-input::placeholder { color: #b0b0b0; }
.aac-input:focus {
    border-color: var(--aac-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(255,187,132,0.28);
}

.aac-send {
    /* 44 × 44 minimum touch target (Apple HIG / Material Design guideline) */
    width:  44px;
    height: 44px;
    border-radius: 50%;
    background: var(--aac-primary);
    border: none;
    cursor: pointer;
    color: #7a3b00;
    font-size: 17px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s, opacity 0.15s, background 0.2s;
    outline: none;
    box-shadow: 0 2px 8px rgba(255,187,132,0.50);
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.aac-send:hover    { background: var(--aac-primary-dark); transform: scale(1.08); }
.aac-send:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }

/* Powered-by footer */
.aac-powered {
    text-align: center;
    font-size: 10.5px;
    color: #bbb;
    padding: 5px 0 7px;
    background: #fff;
    letter-spacing: 0.02em;
    flex-shrink: 0;
    border-top: 1px solid #f0f0f0;
}
.aac-powered a {
    color: var(--aac-primary-dark);
    text-decoration: none;
}

/* ── Tab content wrapper ──────────────────────��──────────── */
/*
 * flex:1 + min-height:0 allow nested flex children to scroll correctly.
 * Without min-height:0 the child refuses to shrink below its intrinsic
 * content height, which breaks the messages overflow-y:auto scrolling.
 */
.aac-tab-content {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Panel base ──────────────────────────────────────────── */
.aac-panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.aac-panel[hidden] { display: none !important; }

/* ── Footer tab bar ──────────────────────────────────────── */
.aac-footer-tabs {
    display: flex;
    flex-shrink: 0;
    border-top: 1px solid var(--aac-border);
    background: #fff;
}

.aac-tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 10px 4px 8px;
    border: none;
    border-top: 2.5px solid transparent;
    background: transparent;
    color: var(--aac-text-muted);
    font-family: inherit;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    letter-spacing: 0.02em;
    line-height: 1.3;
    min-height: 54px;
    outline: none;
    transition: color 0.18s, background 0.18s, border-color 0.18s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.aac-tab-btn:hover {
    background: var(--aac-primary-light);
    color: var(--aac-primary-text);
}
.aac-tab-btn:focus-visible {
    background: var(--aac-primary-light);
    outline: 2px solid var(--aac-primary);
    outline-offset: -2px;
}
.aac-tab-btn.aac-tab-active {
    color: var(--aac-primary-text);
    /*border-top-color: var(--aac-primary);*/
    background: rgba(255, 187, 132, 0.09);
    font-weight: 700;
}
.aac-tab-btn svg { flex-shrink: 0; }

/* ── Export panel ────────────────────────────────────────── */
.aac-export-panel {
    background: #f7f7f7;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
}
.aac-export-inner {
    padding: 32px 24px 28px;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 12px;
}
.aac-export-icon {
    width: 62px;
    height: 62px;
    border-radius: 50%;
    background: var(--aac-primary-light);
    border: 2px solid rgba(255, 187, 132, 0.50);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--aac-primary-text);
    flex-shrink: 0;
    margin-bottom: 4px;
}
.aac-export-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--aac-text);
    margin: 0;
    line-height: 1.3;
}
.aac-export-desc {
    font-size: 13px;
    color: var(--aac-text-muted);
    line-height: 1.55;
    margin: 0;
    max-width: 270px;
}
.aac-export-form {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 8px;
    text-align: left;
}
.aac-export-field {
    display: flex;
    flex-direction: column;
    gap: 5px;
}
.aac-export-label {
    font-size: 12.5px;
    font-weight: 600;
    color: var(--aac-text);
    letter-spacing: 0.01em;
}
.aac-export-email-input {
    width: 100%;
    border: 1px solid #ddd;
    border-radius: 10px;
    padding: 11px 14px;
    font-family: inherit;
    font-size: 16px; /* ≥16px prevents iOS Safari auto-zoom */
    color: var(--aac-text);
    background: #fff;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
    box-sizing: border-box;
    -webkit-appearance: none;
    appearance: none;
}
.aac-export-email-input::placeholder { color: #b5b5b5; }
.aac-export-email-input:focus {
    border-color: var(--aac-primary);
    box-shadow: 0 0 0 3px rgba(255, 187, 132, 0.28);
}
.aac-export-submit {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 13px 16px;
    background: var(--aac-primary);
    color: var(--aac-primary-text);
    border: none;
    border-radius: 10px;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 0.01em;
    min-height: 46px;
    outline: none;
    box-shadow: 0 2px 8px rgba(255, 187, 132, 0.40);
    transition: background 0.2s, transform 0.15s, box-shadow 0.2s;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}
.aac-export-submit:hover:not(:disabled) {
    background: var(--aac-primary-dark);
    transform: translateY(-1px);
    box-shadow: 0 4px 14px rgba(255, 187, 132, 0.50);
}
.aac-export-submit:focus-visible {
    box-shadow: 0 0 0 3px rgba(255, 187, 132, 0.45);
}
.aac-export-submit:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}
.aac-export-status {
    width: 100%;
    padding: 11px 14px;
    border-radius: 10px;
    font-size: 13px;
    text-align: center;
    line-height: 1.45;
    animation: aac-msg-in 0.2s ease;
}
.aac-export-status[hidden] { display: none !important; }
.aac-export-status--success {
    background: #e8f5e9;
    color: #256029;
    border: 1px solid #a5d6a7;
}
.aac-export-status--error {
    background: #fdecea;
    color: #b71c1c;
    border: 1px solid #ef9a9a;
}

/* ════════════════════════════════════════════════════════════
   MOBILE BREAKPOINTS  (max-width queries)
   ════════════════════════════════════════════════════════════ */

/* ── Primary mobile  ≤ 480 px ───────────────────────────── */
@media (max-width: 480px) {
    .aac-widget {
        bottom: calc(14px + var(--aac-safe-bottom));
        right:  calc(14px + var(--aac-safe-right));
    }

    .aac-chat-box {
        width: calc(100vw - 28px);
        /*
         * Progressive height stack (same pattern as above).
         * Subtract 90 px for the toggle button + margin gap.
         * JS will set an exact pixel height when the keyboard is open.
         */
        height:     calc(100vh  - 90px);
        height:     calc(100svh - 90px);
        height:     calc(100dvh - 90px);
        max-height: calc(100dvh - 90px);
        border-radius: 14px;
    }

    .aac-toggle {
        width: 56px;
        height: 56px;
    }

    .aac-messages { padding: 14px 12px 8px; }

    /* Allow messages to use more width on narrow screens */
    .aac-msg--bot  { max-width: 92%; }
    .aac-msg--user { max-width: 88%; }

    /* Stack WhatsApp fallback vertically */
    .aac-fallback {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    .aac-fallback-btn {
        align-self: stretch;
        justify-content: center;
    }
}

/* ── Extra-small: iPhone SE / 320 px ────────────────────── */
@media (max-width: 360px) {
    .aac-chat-box   { width: calc(100vw - 20px); }
    .aac-messages   { padding: 12px 10px 6px; gap: 10px; }
    .aac-bubble     { padding: 8px 12px; font-size: 13px; }
    .aac-greeting   { padding: 8px 14px; font-size: 12px; }
    .aac-input-area { padding: 8px 10px; gap: 6px; }
}

/* ── Landscape on phones ─────────────────────────────────── */
@media (max-width: 896px) and (orientation: landscape) {
    .aac-widget {
        right: calc(14px + var(--aac-safe-right));
    }
    .aac-chat-box {
        height:     calc(100dvh - 80px);
        max-height: calc(100dvh - 80px);
    }
    /* Hide greeting in landscape to preserve vertical space */
    .aac-greeting { display: none; }
    .aac-greeting-tooltip { display: none; }
}

/* ═══════════════════════════════════════════════════════���════
   KEYBOARD-OPEN STATE  (.aac-keyboard-open added by JS)

   When the virtual keyboard is visible, JS:
     1. Adds .aac-keyboard-open to .aac-widget
     2. Writes an exact pixel height onto chatBox via inline style
     3. On iOS only: overrides widget.style.bottom to push above keyboard

   CSS here handles cosmetic tweaks for that state and disables
   transitions to prevent fighting the native keyboard animation.
   ════════════════════════════════════════════════════════════ */
.aac-keyboard-open .aac-chat-box {
    border-radius: 12px;
    /* Let JS control height without transition lag */
    transition: none !important;
}
.aac-keyboard-open.aac-widget {
    /* Disable bottom transition while JS is repositioning */
    transition: none !important;
}

/* ════════════════════════════════════════════════════════════
   REDUCED MOTION  — respect the OS accessibility preference
   ════════════════════════════════════════════════════════════ */
@media (prefers-reduced-motion: reduce) {
    .aac-chat-box,
    .aac-widget       { transition: none !important; animation: none !important; }
    .aac-msg          { animation: none; }
    .aac-fallback     { animation: none; }
    .aac-status-dot   { animation: none; opacity: 1; }
    .aac-typing-dot   { animation: none; opacity: 0.7; }
    .aac-send,
    .aac-toggle,
    .aac-fallback-btn { transition: none; }
}
