/**
 * ShopAgent AI — Frontend Widget Styles.
 *
 * Dark-themed, modern chat widget. Uses CSS custom properties
 * from CSS custom properties.
 * with local overrides for full admin customisation.
 *
 * @since 2.4.0
 */

/* ── Variables ──────────────────────────────────────────────────── */

:root {
    --sai-chat-primary:   var(--sai-primary, #ff00ff);
    --sai-chat-secondary: var(--sai-secondary, #00e5ff);
    --sai-chat-accent:    var(--sai-accent, #ffea00);
    --sai-chat-dark:      #0f0326;
    --sai-chat-panel-bg:  #ffffff;
    --sai-chat-radius:    16px;
    --sai-chat-font:      var(--sai-font, 'Poppins', sans-serif);
    --sai-chat-shadow:    0 8px 40px rgba(0, 0, 0, 0.25);
    --sai-chat-btn-size:  60px;
}

/* ── Widget Container ───────────────────────────────────────────── */

.sai-chat-widget {
    position: fixed;
    z-index: 999992;
    font-family: var(--sai-chat-font);
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    /* Offset for sticky bars (Ravers Co Cart sticky ATC bar, etc.)
       Default 0px — JS sets --sai-sticky-offset when a bar is detected. */
    --sai-sticky-offset: 0px;
    transition: bottom 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sai-chat--right {
    bottom: calc(20px + var(--sai-sticky-offset));
    right: 20px;
}

.sai-chat--left {
    bottom: calc(20px + var(--sai-sticky-offset));
    left: 20px;
}

/* When the panel is open the sticky-footer offset is irrelevant —
   the FAB is already hidden.  Reset so the chat window sits at its
   natural height and the close (×) button stays visible. */
body.sai-chat-open .sai-chat--right,
body.sai-chat-open .sai-chat--left {
    bottom: 20px;
}

/* ── Floating Toggle Button ─────────────────────────────────────── */

.sai-chat-toggle {
    width: var(--sai-chat-btn-size);
    height: var(--sai-chat-btn-size);
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ff00ff;
    color: #fff;
    box-shadow: 0 4px 20px rgba(255, 0, 255, 0.35);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.3s ease;
    position: relative;
    animation: sai-toggle-rainbow 6s linear infinite;
}

@keyframes sai-toggle-rainbow {
    0%   { background: #ff00ff; box-shadow: 0 4px 20px rgba(255, 0, 255, 0.4); }
    16%  { background: #7c3aed; box-shadow: 0 4px 20px rgba(124, 58, 237, 0.4); }
    33%  { background: #00e5ff; box-shadow: 0 4px 20px rgba(0, 229, 255, 0.4); }
    50%  { background: #06b6d4; box-shadow: 0 4px 20px rgba(6, 182, 212, 0.4); }
    66%  { background: #ffea00; box-shadow: 0 4px 20px rgba(255, 234, 0, 0.4); }
    83%  { background: #ec4899; box-shadow: 0 4px 20px rgba(236, 72, 153, 0.4); }
    100% { background: #ff00ff; box-shadow: 0 4px 20px rgba(255, 0, 255, 0.4); }
}

.sai-chat-toggle:hover {
    transform: scale(1.08);
    animation-play-state: running;
}

.sai-chat-toggle:active {
    transform: scale(0.95);
}

/* Pulse animation on idle */
.sai-chat-toggle::after {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    background: inherit;
    opacity: 0;
    z-index: -1;
    animation: sai-chat-pulse 3s ease-in-out infinite;
}

@keyframes sai-chat-pulse {
    0%, 100% { transform: scale(1); opacity: 0; }
    50%      { transform: scale(1.2); opacity: 0.2; }
}

.sai-chat-toggle-icon {
    display: flex;
    align-items: center;
    justify-content: center;
}

.sai-chat-toggle-icon svg {
    width: 24px;
    height: 24px;
}

/* Unread badge */
.sai-chat-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    background: #ec4899;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    line-height: 1;
    box-shadow: 0 2px 6px rgba(236, 72, 153, 0.4);
}

/* ── Chat Panel ─────────────────────────────────────────────────── */

.sai-chat-panel {
    position: absolute;
    bottom: calc(var(--sai-chat-btn-size) + 16px);
    width: 380px;
    height: 520px;
    max-height: calc(100vh - var(--sai-chat-btn-size) - 40px);
    background: var(--sai-chat-panel-bg);
    border-radius: var(--sai-chat-radius);
    box-shadow: var(--sai-chat-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-sizing: border-box;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    /* Animated rainbow border — uses border-image (works with overflow:hidden) */
    border: 2px solid transparent;
    background-clip: padding-box;
    outline: 2px solid transparent;
    outline-offset: 0px;
    animation: sai-chat-border-hue 6s linear infinite;
}

@keyframes sai-chat-border-hue {
    0%   { outline-color: #ff00ff; border-color: #ff00ff; }
    16%  { outline-color: #7c3aed; border-color: #7c3aed; }
    33%  { outline-color: #00e5ff; border-color: #00e5ff; }
    50%  { outline-color: #06b6d4; border-color: #06b6d4; }
    66%  { outline-color: #ffea00; border-color: #ffea00; }
    83%  { outline-color: #ec4899; border-color: #ec4899; }
    100% { outline-color: #ff00ff; border-color: #ff00ff; }
}

.sai-chat--right .sai-chat-panel {
    right: 0;
}

.sai-chat--left .sai-chat-panel {
    left: 0;
}

.sai-chat-panel[aria-hidden="false"] {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* ── Header ─────────────────────────────────────────────────────── */

.sai-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, var(--sai-chat-dark), #1a0a3e);
    color: #fff;
    flex-shrink: 0;
}

.sai-chat-header-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.sai-chat-header-avatar {
    font-size: 24px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 50%;
}

.sai-chat-header-title {
    font-weight: 700;
    font-size: 15px;
    letter-spacing: 0.01em;
    animation: sai-chat-border-hue 6s linear infinite;
    /* Animate the text colour through the rainbow */
}

/* Override: apply colour to the text itself */
.sai-chat-header-title {
    color: #ff00ff;
    animation-name: sai-text-rainbow;
}

@keyframes sai-text-rainbow {
    0%   { color: #ff00ff; }
    16%  { color: #7c3aed; }
    33%  { color: #00e5ff; }
    50%  { color: #06b6d4; }
    66%  { color: #ffea00; }
    83%  { color: #ec4899; }
    100% { color: #ff00ff; }
}

.sai-chat-header-subtitle {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 1px;
}

.sai-chat-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    opacity: 0.7;
    transition: opacity 0.2s;
    padding: 4px 8px;
    line-height: 1;
}

.sai-chat-close:hover {
    opacity: 1;
}

/* ── Pre-chat Form ──────────────────────────────────────────────── */

.sai-chat-prechat {
    position: absolute;
    inset: 0;
    top: 60px; /* below header */
    z-index: 10;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sai-chat-prechat-inner {
    padding: 24px;
    text-align: center;
    width: 100%;
}

.sai-chat-prechat-inner h3 {
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 16px;
    color: var(--sai-chat-dark);
}

.sai-chat-input {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid #e5e7eb;
    border-radius: 10px;
    font-size: 14px;
    font-family: var(--sai-chat-font);
    margin-bottom: 10px;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

.sai-chat-input:focus {
    border-color: var(--sai-chat-primary);
}

.sai-chat-gdpr {
    font-size: 11px;
    color: #9ca3af;
    margin: 8px 0;
}

.sai-chat-btn-primary {
    width: 100%;
    padding: 12px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--sai-chat-primary), #7c3aed);
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    font-family: var(--sai-chat-font);
    cursor: pointer;
    transition: opacity 0.2s;
    margin-top: 4px;
}

.sai-chat-btn-primary:hover {
    opacity: 0.9;
}

/* ── Messages Area ──────────────────────────────────────────────── */

.sai-chat-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 14px 0;
    scroll-behavior: smooth;
}

.sai-chat-messages-area {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding-bottom: 8px;
}

/* Message bubbles */
.sai-chat-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.5;
    word-break: break-word;
    position: relative;
    animation: sai-msg-in 0.3s ease;
}

@keyframes sai-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.sai-chat-msg--customer {
    align-self: flex-end;
    background: linear-gradient(135deg, #7c3aed, var(--sai-chat-primary));
    color: #fff;
    border-bottom-right-radius: 4px;
}

.sai-chat-msg--ai {
    align-self: flex-start;
    background: #f3f4f6;
    color: #1f2937;
    border-bottom-left-radius: 4px;
}

.sai-chat-msg--admin {
    align-self: flex-start;
    background: #ecfdf5;
    color: #065f46;
    border-bottom-left-radius: 4px;
}

.sai-chat-msg--system {
    align-self: center;
    background: transparent;
    color: #9ca3af;
    font-size: 12px;
    text-align: center;
    max-width: 100%;
    padding: 4px 12px;
}

.sai-chat-msg-sender {
    font-size: 11px;
    font-weight: 600;
    opacity: 0.7;
    margin-bottom: 2px;
}

.sai-chat-msg-time {
    font-size: 10px;
    opacity: 0.5;
    margin-top: 4px;
    text-align: right;
}

/* Clickable links in chat messages */
.sai-chat-msg a.sai-chat-link,
.sai-chat-msg--ai a.sai-chat-link {
    color: #7c3aed;
    text-decoration: underline;
    text-underline-offset: 2px;
    word-break: break-all;
    cursor: pointer;
    pointer-events: auto !important;
    position: relative;
    z-index: 1;
    display: inline;
}
.sai-chat-msg a.sai-chat-link:hover {
    color: #ec4899;
    text-decoration-style: solid;
}
.sai-chat-msg--customer a.sai-chat-link {
    color: #e0d4ff;
}
.sai-chat-msg--customer a.sai-chat-link:hover {
    color: #fff;
}

/* Order card */
.sai-chat-order-card {
    background: #fff;
    border: 1.5px solid #e5e7eb;
    border-radius: 12px;
    padding: 12px;
    margin: 4px 0;
    max-width: 85%;
    align-self: flex-start;
    animation: sai-msg-in 0.3s ease;
}

.sai-chat-order-card h4 {
    margin: 0 0 6px;
    font-size: 13px;
    font-weight: 700;
    color: var(--sai-chat-dark);
}

.sai-chat-order-card p {
    margin: 2px 0;
    font-size: 12px;
    color: #6b7280;
}

.sai-chat-order-card .sai-chat-order-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    background: #dbeafe;
    color: #1e40af;
}

/* ── Cart Action Buttons ────────────────────────────────────────── */

.sai-chat-cart-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.sai-chat-cart-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 5px 12px;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
    text-decoration: none;
    background: rgba(139, 92, 246, 0.1);
    color: #7c3aed;
    transition: background 0.2s, transform 0.15s;
    cursor: pointer;
}

.sai-chat-cart-btn:hover {
    background: rgba(139, 92, 246, 0.2);
    transform: translateY(-1px);
    text-decoration: none;
    color: #6d28d9;
}

.sai-chat-cart-btn--checkout {
    background: #7c3aed;
    color: #fff;
}

.sai-chat-cart-btn--checkout:hover {
    background: #6d28d9;
    color: #fff;
}

/* ── Coupon Actions ─────────────────────────────────────────────── */

.sai-chat-coupon-actions {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.sai-chat-coupon-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    border: none;
    border-radius: 16px;
    font-size: 12px;
    font-weight: 600;
    background: linear-gradient(135deg, #10b981, #059669);
    color: #fff;
    cursor: pointer;
    transition: background 0.2s, transform 0.15s;
}

.sai-chat-coupon-btn:hover {
    background: linear-gradient(135deg, #059669, #047857);
    transform: translateY(-1px);
}

.sai-chat-coupon-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.sai-chat-coupon-btn--done {
    background: #10b981;
}

/* ── Login Button ───────────────────────────────────────────────── */

.sai-chat-login-link {
    display: inline-block;
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    color: #fff;
    text-decoration: none;
    padding: 10px 20px;
    border-radius: 100px;
    font-weight: 700;
    font-size: 13px;
    margin-top: 8px;
    transition: opacity 0.2s, transform 0.15s;
}

.sai-chat-login-link:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    color: #fff;
    text-decoration: none;
}

.sai-chat-auth-buttons {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.sai-chat-forgot-pw-link {
    background: transparent;
    border: 1px solid rgba(124, 58, 237, 0.4);
    color: #7c3aed;
    font-size: 12px;
    padding: 8px 16px;
}

.sai-chat-forgot-pw-link:hover {
    color: #7c3aed;
    border-color: #7c3aed;
}

/* ── Product Cards in Chat ──────────────────────────────────────── */

.sai-chat-product-grid {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 8px 0 4px;
    max-width: 85%;
}

.sai-chat-product-card {
    background: #fff;
    border-radius: 12px;
    border: 1px solid rgba(124, 58, 237, 0.12);
    overflow: hidden;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.sai-chat-product-card:hover {
    border-color: rgba(124, 58, 237, 0.3);
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.1);
}

.sai-chat-product-card-inner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
}

.sai-chat-product-thumb {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    border-radius: 8px;
    overflow: hidden;
    background: #f9fafb;
}

.sai-chat-product-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.sai-chat-product-info {
    flex: 1;
    min-width: 0;
}

.sai-chat-product-name {
    font-size: 12px;
    font-weight: 700;
    color: #1a1a2e;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sai-chat-product-price {
    font-size: 11px;
    color: #6b7280;
    margin-top: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.sai-chat-product-stock {
    font-size: 10px;
    font-weight: 600;
}

.sai-chat-product-stock--in {
    color: #059669;
}

.sai-chat-product-stock--out {
    color: #d97706;
}

.sai-chat-product-actions {
    flex-shrink: 0;
}

.sai-chat-product-atc,
.sai-chat-product-options {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
    text-decoration: none;
    border: none;
    white-space: nowrap;
}

.sai-chat-product-atc {
    background: linear-gradient(135deg, #7c3aed, #ec4899);
    color: #fff;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.25);
}

.sai-chat-product-atc:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(124, 58, 237, 0.35);
}

.sai-chat-product-atc:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.sai-chat-product-atc--done {
    background: #059669;
    box-shadow: 0 2px 8px rgba(5, 150, 105, 0.25);
}

.sai-chat-product-options {
    background: rgba(124, 58, 237, 0.1);
    color: #7c3aed;
}

.sai-chat-product-options:hover {
    background: rgba(124, 58, 237, 0.2);
    transform: translateY(-1px);
    color: #6d28d9;
    text-decoration: none;
}

/* ── Typing Indicator ───────────────────────────────────────────── */

.sai-chat-typing {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    align-self: flex-start;
    background: #f3f4f6;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    margin: 4px 0 8px;
}

.sai-chat-typing span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #9ca3af;
    animation: sai-typing-dot 1.2s ease-in-out infinite;
}

.sai-chat-typing span:nth-child(2) { animation-delay: 0.2s; }
.sai-chat-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes sai-typing-dot {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30%           { transform: translateY(-4px); opacity: 1; }
}

/* ── Quick Action Chips ─────────────────────────────────────────── */

.sai-chat-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 8px 14px 10px;
    border-top: 1px solid #f3f4f6;
    flex-shrink: 0;
}

.sai-chat-quick-btn {
    padding: 6px 12px;
    border: 1.5px solid #e5e7eb;
    border-radius: 100px;
    background: #fff;
    color: #374151;
    font-size: 12px;
    font-family: var(--sai-chat-font);
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.sai-chat-quick-btn:hover {
    border-color: var(--sai-chat-primary);
    color: var(--sai-chat-primary);
    background: rgba(124, 58, 237, 0.05);
}

.sai-chat-quick-btn--human {
    border-color: #ec4899;
    color: #ec4899;
}

.sai-chat-quick-btn--human:hover {
    background: rgba(236, 72, 153, 0.05);
    border-color: #ec4899;
    color: #ec4899;
}

/* ── Input Footer ───────────────────────────────────────────────── */

.sai-chat-footer {
    border-top: 1px solid #f3f4f6;
    padding: 10px 14px 12px;
    flex-shrink: 0;
    background: #fff;
}

.sai-chat-input-wrap {
    display: flex;
    align-items: flex-end;
    gap: 8px;
}

.sai-chat-textarea {
    flex: 1;
    resize: none;
    border: 1.5px solid #e5e7eb;
    border-radius: 12px;
    padding: 8px 12px;
    font-size: 13.5px;
    font-family: var(--sai-chat-font);
    line-height: 1.4;
    outline: none;
    max-height: 100px;
    transition: border-color 0.2s;
}

.sai-chat-textarea:focus {
    border-color: var(--sai-chat-primary);
}

.sai-chat-send {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--sai-chat-primary), #7c3aed);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: opacity 0.2s, transform 0.2s;
}

.sai-chat-send:hover {
    opacity: 0.9;
    transform: scale(1.05);
}

.sai-chat-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
}

.sai-chat-footer-actions {
    display: flex;
    justify-content: center;
    margin-top: 6px;
}

.sai-chat-footer-btn {
    background: none;
    border: none;
    color: #9ca3af;
    font-size: 11px;
    font-family: var(--sai-chat-font);
    cursor: pointer;
    padding: 2px 8px;
    transition: color 0.2s;
}

.sai-chat-footer-btn:hover {
    color: #6b7280;
}

/* ── Rating Overlay ─────────────────────────────────────────────── */

.sai-chat-rating {
    position: absolute;
    inset: 0;
    top: 60px;
    z-index: 10;
    background: rgba(255, 255, 255, 0.98);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.sai-chat-rating h3 {
    font-size: 18px;
    font-weight: 700;
    color: var(--sai-chat-dark);
    margin: 0;
}

.sai-chat-stars {
    display: flex;
    gap: 8px;
}

.sai-chat-stars button {
    font-size: 28px;
    background: none;
    border: none;
    cursor: pointer;
    transition: transform 0.2s;
    padding: 4px;
    filter: grayscale(1);
}

.sai-chat-stars button:hover,
.sai-chat-stars button.sai-chat-star--active {
    transform: scale(1.2);
    filter: grayscale(0);
}

.sai-chat-rating-feedback {
    width: 80%;
    max-width: 260px;
    border: 1px solid #e5e7eb;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 13px;
    resize: none;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s;
}

.sai-chat-rating-feedback:focus {
    border-color: var(--sai-chat-primary, #7c3aed);
}

.sai-chat-admin-typing-label {
    font-size: 11px;
    color: #6b7280;
    font-style: italic;
    margin-right: 2px;
}

/* ── Status indicators ──────────────────────────────────────────── */

.sai-chat-status-waiting {
    background: #fef3c7;
    color: #92400e;
    padding: 8px 14px;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
}

/* ── Mobile Responsive ──────────────────────────────────────────── */

@media (max-width: 768px) {
    .sai-chat-panel {
        position: fixed;
        inset: 0;
        width: 100% !important;
        height: 100vh !important;
        height: 100dvh !important; /* Dynamic viewport height — accounts for mobile browser chrome */
        border-radius: 0;
        bottom: 0;
        max-height: 100vh;
        max-height: 100dvh;
        /* Prevent outline / border overflow on mobile */
        outline: none !important;
        border: none !important;
        /* Safe areas for notched phones */
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
        /* Prevent double-tap zoom */
        touch-action: manipulation;
    }

    /* Ensure header & footer respect safe areas */
    .sai-chat-header {
        padding-top: max(14px, env(safe-area-inset-top, 14px));
    }

    .sai-chat-footer {
        padding-bottom: max(12px, env(safe-area-inset-bottom, 12px));
    }

    /* Prevent iOS auto-zoom on input focus (requires >= 16px) */
    .sai-chat-textarea {
        font-size: 16px;
    }

    .sai-chat-input {
        font-size: 16px;
    }

    /* Hide the FAB toggle when chat panel is open — the header × button is sufficient.
       CSS fallback for the JS-based hide (belt & braces). */
    .sai-chat-panel[aria-hidden="false"] ~ .sai-chat-toggle {
        display: none !important;
    }

    .sai-chat-toggle {
        bottom: 0;
        right: 0;
        --sai-chat-btn-size: 54px;
    }

    .sai-chat--right .sai-chat-toggle,
    .sai-chat--left .sai-chat-toggle {
        position: fixed;
        bottom: calc(16px + var(--sai-sticky-offset, 0px));
        right: 16px;
    }

    .sai-chat-widget {
        bottom: var(--sai-sticky-offset, 0px) !important;
        right: 0 !important;
        left: auto !important;
    }

    body.sai-chat-open .sai-chat-widget {
        bottom: 0 !important;
    }
}

/* ── Greeting Popup ──────────────────────────────────────────────── */

.sai-chat-greeting {
    position: absolute;
    bottom: calc(var(--sai-chat-btn-size) + 16px);
    width: 310px;
    box-sizing: border-box;
    background: rgba(15, 3, 38, 0.82);
    backdrop-filter: blur(18px) saturate(1.4);
    -webkit-backdrop-filter: blur(18px) saturate(1.4);
    border: 2px solid transparent;
    border-radius: var(--sai-chat-radius);
    padding: 16px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.45),
                inset 0 1px 0 rgba(255, 255, 255, 0.08);
    color: #fff;
    font-family: var(--sai-chat-font);
    font-size: 13.5px;
    line-height: 1.5;
    z-index: 2;
    animation: sai-greeting-in 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) forwards,
               sai-greeting-rainbow 4s linear 0.45s infinite;
    transform-origin: bottom right;
    /* Rainbow glow behind the popup */
    outline: 2px solid transparent;
    outline-offset: 0px;
}

/* Animated rainbow border on the greeting popup */
@keyframes sai-greeting-rainbow {
    0%   { border-color: #ff00ff; outline-color: #ff00ff; box-shadow: 0 12px 48px rgba(0,0,0,0.45), 0 0 18px rgba(255,0,255,0.25); }
    14%  { border-color: #ff3333; outline-color: #ff3333; box-shadow: 0 12px 48px rgba(0,0,0,0.45), 0 0 18px rgba(255,51,51,0.25); }
    28%  { border-color: #ffea00; outline-color: #ffea00; box-shadow: 0 12px 48px rgba(0,0,0,0.45), 0 0 18px rgba(255,234,0,0.25); }
    42%  { border-color: #00e5ff; outline-color: #00e5ff; box-shadow: 0 12px 48px rgba(0,0,0,0.45), 0 0 18px rgba(0,229,255,0.25); }
    57%  { border-color: #06b6d4; outline-color: #06b6d4; box-shadow: 0 12px 48px rgba(0,0,0,0.45), 0 0 18px rgba(6,182,212,0.25); }
    71%  { border-color: #7c3aed; outline-color: #7c3aed; box-shadow: 0 12px 48px rgba(0,0,0,0.45), 0 0 18px rgba(124,58,237,0.25); }
    85%  { border-color: #ec4899; outline-color: #ec4899; box-shadow: 0 12px 48px rgba(0,0,0,0.45), 0 0 18px rgba(236,72,153,0.25); }
    100% { border-color: #ff00ff; outline-color: #ff00ff; box-shadow: 0 12px 48px rgba(0,0,0,0.45), 0 0 18px rgba(255,0,255,0.25); }
}

/* Position: right-aligned default. */
.sai-chat--right .sai-chat-greeting {
    right: 0;
}

.sai-chat--left .sai-chat-greeting {
    left: 0;
    transform-origin: bottom left;
}

/* Entry animation. */
@keyframes sai-greeting-in {
    from {
        opacity: 0;
        transform: translateY(12px) scale(0.92);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

/* Exit animation (added via JS). */
.sai-chat-greeting--out {
    animation: sai-greeting-out 0.25s ease forwards;
}

@keyframes sai-greeting-out {
    to {
        opacity: 0;
        transform: translateY(8px) scale(0.95);
    }
}

/* Close button. */
.sai-chat-greeting-close {
    position: absolute;
    top: 6px;
    right: 8px;
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.5);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 50%;
    transition: color 0.2s, background 0.2s;
}

.sai-chat-greeting-close:hover {
    color: #fff;
    background: rgba(255, 255, 255, 0.1);
}

/* Body: avatar + text. */
.sai-chat-greeting-body {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin-bottom: 12px;
}

.sai-chat-greeting-avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--sai-chat-primary), #7c3aed);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    box-shadow: 0 2px 8px rgba(124, 58, 237, 0.35);
}

.sai-chat-greeting-text {
    margin: 0;
    color: rgba(255, 255, 255, 0.92);
    font-size: 13px;
    line-height: 1.55;
}

/* Suggestion chips. */
.sai-chat-greeting-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.sai-chat-greeting-chip {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 100px;
    padding: 5px 12px;
    font-size: 12px;
    font-family: var(--sai-chat-font);
    color: rgba(255, 255, 255, 0.88);
    cursor: pointer;
    transition: background 0.2s, border-color 0.2s, transform 0.15s;
    white-space: nowrap;
}

.sai-chat-greeting-chip:hover {
    background: rgba(255, 0, 255, 0.15);
    border-color: var(--sai-chat-primary);
    color: #fff;
    transform: translateY(-1px);
}

.sai-chat-greeting-chip:active {
    transform: scale(0.97);
}

/* Nub / pointer arrow pointing toward FAB. */
.sai-chat-greeting::after {
    content: '';
    position: absolute;
    bottom: -7px;
    width: 14px;
    height: 14px;
    background: rgba(15, 3, 38, 0.82);
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(45deg);
    animation: sai-nub-rainbow 4s linear infinite;
}

@keyframes sai-nub-rainbow {
    0%   { border-color: #ff00ff; }
    14%  { border-color: #ff3333; }
    28%  { border-color: #ffea00; }
    42%  { border-color: #00e5ff; }
    57%  { border-color: #06b6d4; }
    71%  { border-color: #7c3aed; }
    85%  { border-color: #ec4899; }
    100% { border-color: #ff00ff; }
}

.sai-chat--right .sai-chat-greeting::after {
    right: 22px;
}

.sai-chat--left .sai-chat-greeting::after {
    left: 22px;
}

/* ── Print — hide widget ────────────────────────────────────────── */

@media print {
    .sai-chat-widget {
        display: none !important;
    }
}

/* ── Reduced motion ─────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
    .sai-chat-toggle::after,
    .sai-chat-msg,
    .sai-chat-typing span,
    .sai-chat-greeting,
    .sai-chat-greeting::after {
        animation: none !important;
    }

    .sai-chat-panel {
        transition: opacity 0.15s ease !important;
        transform: none !important;
    }
}

/* Mobile: wider greeting — suppress glow that causes horizontal overflow. */
@media (max-width: 480px) {
    .sai-chat-greeting {
        width: calc(100vw - 40px);
        right: 0 !important;
        left: auto !important;
        /* Override animation glow that bleeds past viewport edge */
        box-shadow: 0 12px 48px rgba(0, 0, 0, 0.45) !important;
        outline: none !important;
    }

    .sai-chat--left .sai-chat-greeting {
        left: 0 !important;
        right: auto !important;
    }
}

/* ═══════════════════════════════════════════════════════════════
   RAINBOW OPT-OUT — Controlled via widget CSS classes.
   When sai-no-rainbow-* classes are present, disable the
   matching animations and fall back to static colours.
   ═══════════════════════════════════════════════════════════════ */

/* Toggle button: no rainbow. */
.sai-no-rainbow-toggle .sai-chat-toggle {
    animation: none !important;
    background: var(--sai-chat-primary) !important;
    box-shadow: 0 4px 20px rgba(124, 58, 237, 0.35) !important;
}

.sai-no-rainbow-toggle .sai-chat-toggle::after {
    animation: none !important;
}

/* Chat panel + greeting: no rainbow border. */
.sai-no-rainbow-border .sai-chat-panel {
    animation: none !important;
    border-color: var(--sai-chat-secondary) !important;
}

.sai-no-rainbow-border .sai-chat-greeting {
    animation: none !important;
    border-color: var(--sai-chat-secondary) !important;
}

.sai-no-rainbow-border .sai-chat-greeting::after {
    animation: none !important;
    border-top-color: var(--sai-chat-secondary) !important;
}

/* Header title text: no rainbow. */
.sai-no-rainbow-title .sai-chat-header-title {
    animation: none !important;
    color: #ffffff !important;
}

/* ═══════════════════════════════════════════════════════════════
   RAINBOW MESSAGE BUBBLES — Opt-in via .sai-rainbow-messages
   Adds animated rainbow border to AI/admin message bubbles.
   ═══════════════════════════════════════════════════════════════ */

@keyframes sai-msg-border-rainbow {
    0%   { border-color: rgba(255, 0, 255, 0.35); }
    16%  { border-color: rgba(124, 58, 237, 0.35); }
    33%  { border-color: rgba(0, 229, 255, 0.35); }
    50%  { border-color: rgba(6, 182, 212, 0.35); }
    66%  { border-color: rgba(255, 234, 0, 0.35); }
    83%  { border-color: rgba(236, 72, 153, 0.35); }
    100% { border-color: rgba(255, 0, 255, 0.35); }
}

.sai-rainbow-messages .sai-chat-msg--ai,
.sai-rainbow-messages .sai-chat-msg--admin {
    border: 1.5px solid rgba(255, 0, 255, 0.25);
    animation: sai-msg-in 0.3s ease, sai-msg-border-rainbow 6s linear 0.3s infinite;
}

.sai-rainbow-messages .sai-chat-msg--customer {
    border: 1.5px solid rgba(255, 255, 255, 0.15);
    animation: sai-msg-in 0.3s ease, sai-msg-border-rainbow 6s linear 0.3s infinite;
}

/* ═══════════════════════════════════════════════════════════════
   CROSS-PLUGIN: Hide sibling floating widgets while chat is open.
   Body class .sai-chat-open is toggled by JS on open/close.
   ═══════════════════════════════════════════════════════════════ */

.sai-chat-open .rcrr-toggle,
.sai-chat-open .rcrr-widget {
    display: none !important;
}
