/* AI Sidebar Styling - OneNote Style (Right Side) */
.ai-sidebar-container {
    position: fixed;
    top: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    z-index: var(--z-overlay);
    pointer-events: none;
    display: flex;
    justify-content: flex-end;
    /* Keep the container LTR so flex-end stays on the physical right
       even when the document is dir="rtl" (Arabic). Inner panel uses .rtl-mode. */
    direction: ltr;
}

.ai-sidebar {
    width: 400px;
    height: 100%;
    background: var(--bg-surface-solid);
    border-left: 1px solid var(--border-glass);
    box-shadow: var(--shadow-main);
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform var(--tr-smooth), width 0.3s ease;
    pointer-events: auto;
    z-index: var(--z-modal);
    position: relative;
}

.ai-sidebar.expanded {
    width: 600px;
}

.ai-sidebar-container.open .ai-sidebar {
    transform: translateX(0);
}

/* CRITICAL: iOS Safari requires pointer-events: auto on the CONTAINER 
   when open. Touch events don't propagate through pe:none parents on WebKit. */
.ai-sidebar-container.open {
    pointer-events: auto;
}

/* Layout Shift - Connects slide to sidebar */
@media (min-width: 1024px) {
    /* body.main-ai-open .zen-workspace {
        width: calc(100vw - 400px);
        transition: width var(--tr-smooth);
    }

    body.main-ai-open.ai-sidebar-expanded .zen-workspace {
        width: calc(100vw - 600px);
    } */
}

/* Expand Toggle Button - Redesigned as a purple circular "robot" handle */
.ai-expand-toggle {
    position: absolute;
    top: calc(50% - 28px);
    transform: translateY(-50%);
    left: -22px;
    /* Overlaps precisely to look "attached" */
    width: 44px;
    height: 44px;
    background: #6366f1;
    /* Purple accent */
    border: 3px solid var(--bg-surface-solid);
    /* "Joint" look */
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1);
    box-shadow: -4px 0 15px rgba(0, 0, 0, 0.2);
    opacity: 0;
    pointer-events: none;
    z-index: 10;
}

.ai-sidebar-container.open .ai-expand-toggle {
    opacity: 1;
    pointer-events: auto;
}

.ai-expand-toggle:hover {
    transform: translateY(-50%) scale(1.1) rotate(-10deg);
    background: #4f46e5;
    box-shadow: -6px 0 20px rgba(99, 102, 241, 0.4);
}

/* Side Close Button - Positioned exactly below the robot handle */
.ai-side-close-btn {
    position: absolute;
    top: calc(50% + 28px);
    transform: translateY(-50%);
    left: -22px;
    width: 44px;
    height: 44px;
    background: var(--bg-surface-solid);
    border: 2px solid var(--border-glass);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-muted);
    transition: all 0.3s cubic-bezier(0.19, 1, 0.22, 1);
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1);
    opacity: 0;
    pointer-events: none;
    z-index: 10;
}

.ai-sidebar-container.open .ai-side-close-btn {
    opacity: 1;
    pointer-events: auto;
}

.ai-side-close-btn:hover {
    transform: translateY(-50%) scale(1.1);
    background: var(--bg-item-hover);
    color: var(--text-main);
    border-color: var(--text-muted);
}

.ai-expand-toggle i {
    font-size: 1.1rem;
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.ai-sidebar.expanded .ai-expand-toggle {
    left: -22px;
}

.ai-sidebar.expanded .ai-expand-toggle i {
    transform: rotate(360deg);
    /* Robot spins on expansion */
}

/* Backdrop for mobile or focus */
/* Backdrop removed to allow interaction with app */
.ai-backdrop {
    display: none;
}

/* Header */
.ai-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-glass);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-surface);
    backdrop-filter: blur(var(--glass-blur));
    -webkit-backdrop-filter: blur(var(--glass-blur));
}

.ai-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 1rem;
    color: var(--text-main);
    flex-shrink: 0;
}

.ai-sidebar:not(.expanded) .ai-title span {
    display: none;
}

.ai-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    justify-content: flex-end;
    overflow: hidden;
}

.ai-badge {
    font-size: 0.75rem;
    background: rgba(99, 102, 241, 0.1);
    color: #6366f1;
    padding: 4px 8px;
    border-radius: 12px;
    border: 1px solid rgba(99, 102, 241, 0.2);
}

.ai-context-select {
    background: var(--bg-item);
    color: var(--text-main);
    border: 1px solid var(--border-glass);
    border-radius: 8px;
    padding: 4px 6px;
    font-size: 0.75rem;
    font-family: inherit;
    cursor: pointer;
    outline: none;
    transition: all 0.2s;
    max-width: 110px;
    text-overflow: ellipsis;
}

#aiLanguageSelect {
    width: 65px;
}

.ai-context-select:hover {
    background: var(--bg-item-hover);
    border-color: #6366f1;
}

.close-ai-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px;
    border-radius: 50%;
    transition: all 0.2s;
}

.close-ai-btn:hover {
    background: var(--bg-item-hover);
    color: var(--text-main);
}

.new-chat-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.9rem;
    padding: 6px 8px;
    border-radius: 8px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.new-chat-btn:hover {
    background: var(--bg-item-hover);
    color: #6366f1;
    transform: scale(1.05);
}


/* Body (Chat Area) */
.ai-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background: var(--bg-app);
    background-image: radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.05) 0%, transparent 50%);
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    overscroll-behavior: contain;
}

/* AI action chips — touch-friendly sizing & feedback */
.ai-action-chip {
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

@media (pointer: coarse) {
    .ai-action-chip {
        min-height: 44px;
        padding: 12px 8px !important;
        font-size: 0.85rem !important;
    }

    .ai-action-chip:active {
        transform: scale(0.95) !important;
        opacity: 0.85;
    }

    /* Larger touch targets for sidebar buttons */
    .ai-expand-toggle,
    .ai-side-close-btn {
        width: 48px;
        height: 48px;
    }

    .close-ai-btn,
    .new-chat-btn {
        min-width: 44px;
        min-height: 44px;
    }

    #btnSendAi {
        width: 44px;
        height: 44px;
    }
}

/* Messages */
.ai-message {
    display: flex;
    gap: 12px;
    max-width: 90%;
    animation: slideIn 0.3s ease-out;
}

.ai-message.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.ai-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.system .ai-avatar {
    background: linear-gradient(135deg, #6366f1, #a855f7);
    color: white;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.user .ai-avatar {
    background: var(--bg-item);
    color: var(--text-muted);
}

.ai-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.5;
    background: var(--bg-surface-solid);
    border: 1px solid var(--border-glass);
    color: var(--text-main);
    box-shadow: var(--shadow-glass);
    /* Prevent horizontal scrolling */
    white-space: pre-wrap;
    /* Preserve newlines but wrap text */
    word-wrap: break-word;
    /* Break long words */
    overflow-wrap: break-word;
    /* Standard property */
    max-width: 100%;
    /* Ensure it doesn't exceed container */
    user-select: text !important;
    -webkit-user-select: text !important;
}

.system .ai-bubble {
    border-top-left-radius: 4px;
}

.user .ai-bubble {
    background: linear-gradient(135deg, #eef2ff, #e0e7ff);
    color: #1e293b;
    border: 1px solid #c7d2fe;
    border-top-right-radius: 4px;
}

/* Markdown Styling inside AI bubbles */
.ai-bubble p {
    margin-bottom: 8px;
}

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

.ai-bubble code {
    background: rgba(0, 0, 0, 0.2);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 0.9em;
}

.ai-bubble pre {
    background: #1e1e1e;
    padding: 10px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.ai-bubble pre code {
    background: transparent;
    padding: 0;
    color: #efefef;
}

/* Message Actions (Copy / Add) */
.ai-msg-actions {
    display: flex;
    gap: 8px;
    margin-top: 6px;
    margin-left: 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.ai-message:hover .ai-msg-actions {
    opacity: 1;
}

.ai-action-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s;
}

.ai-action-btn:hover {
    background: var(--bg-item-hover);
    color: var(--text-main);
}

.ai-action-btn i {
    font-size: 0.8rem;
}

.ai-footer {
    padding: 16px 20px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-glass);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ai-input-container {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    background: var(--bg-item);
    padding: 8px 12px;
    border-radius: 24px;
    border: 1px solid var(--border-glass);
    transition: border-color 0.2s;
}

.ai-input-container:focus-within {
    border-color: #6366f1;
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.1);
}

#aiInput {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-main);
    font-family: inherit;
    font-size: 0.95rem;
    padding: 8px 0;
    resize: none;
    max-height: 100px;
    outline: none;
}

#btnSendAi {
    background: #6366f1;
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

#btnSendAi:hover:not(:disabled) {
    background: #4f46e5;
    transform: scale(1.05);
}

#btnSendAi:disabled {
    background: var(--bg-item-hover);
    color: var(--text-muted);
    cursor: not-allowed;
}

.ai-disclaimer {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-align: center;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

/* Typing Indicator */
.typing-dots {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

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

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

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

@keyframes bounce {

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

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

/* RTL Support for Arabic */
.ai-sidebar.rtl-mode {
    direction: rtl;
    font-family: 'Cairo', 'Tajawal', sans-serif;
}

.ai-sidebar.rtl-mode .ai-title {
    flex-direction: row-reverse;
}

.ai-sidebar.rtl-mode .ai-message {
    flex-direction: row;
    /* Standard row for RTL means avatar on right if gap is used correctly */
}

.ai-sidebar.rtl-mode .ai-message.user {
    align-self: flex-start;
    /* Opposite of LTR align-self: flex-end */
}

.ai-sidebar.rtl-mode .ai-message.system {
    align-self: flex-end;
}

.ai-sidebar.rtl-mode .ai-bubble {
    text-align: right;
}

.ai-sidebar.rtl-mode .ai-msg-actions {
    margin-right: 4px;
    margin-left: 0;
    justify-content: flex-start;
}

.ai-sidebar.rtl-mode .ai-input-container {
    flex-direction: row-reverse;
}

.ai-sidebar.rtl-mode #aiInput {
    text-align: right;
}

/* ═══════════════════════════════════════════════════════
   AI Floating Toolbar — Appears on canvas after selection
   ═══════════════════════════════════════════════════════ */

.ai-floating-toolbar {
    position: fixed;
    z-index: 99999;
    transform: translate(-50%, 0) scale(0.85);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s cubic-bezier(0.19, 1, 0.22, 1),
                transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    filter: drop-shadow(0 8px 32px rgba(0, 0, 0, 0.18));
}

.ai-floating-toolbar.visible {
    opacity: 1;
    transform: translate(-50%, 0) scale(1);
    pointer-events: auto;
}

/* Buttons Container */
.ai-float-btns {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    max-width: min(92vw, 820px);
    gap: 6px;
    padding: 8px 10px;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.12),
                0 1px 3px rgba(0, 0, 0, 0.06),
                inset 0 1px 0 rgba(255, 255, 255, 0.8);
}

/* Upward arrow pointer */
.ai-float-btns::before {
    content: '';
    position: absolute;
    top: -7px;
    left: 50%;
    transform: translateX(-50%) rotate(45deg);
    width: 14px;
    height: 14px;
    background: rgba(255, 255, 255, 0.92);
    border-left: 1px solid rgba(255, 255, 255, 0.6);
    border-top: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 3px 0 0 0;
}

/* Individual button */
.ai-float-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px 12px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    background: transparent;
    color: var(--btn-color, #475569);
    font-size: 0.72rem;
    font-weight: 600;
    font-family: 'Inter', 'Outfit', system-ui, sans-serif;
    transition: all 0.2s cubic-bezier(0.19, 1, 0.22, 1);
    position: relative;
    min-width: 56px;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
}

.ai-float-btn i {
    font-size: 1rem;
    transition: transform 0.2s ease;
}

.ai-float-btn span {
    white-space: nowrap;
    letter-spacing: 0.01em;
}

.ai-float-btn:hover {
    background: var(--btn-gradient, linear-gradient(135deg, #6366f1, #4f46e5));
    color: #fff;
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.15);
}

.ai-float-btn:hover i {
    transform: scale(1.15);
}

.ai-float-btn:active {
    transform: translateY(-1px) scale(0.97);
}

/* Cancel button special style */
.ai-float-btn[data-action="undo"] {
    color: #94a3b8;
}
.ai-float-btn[data-action="undo"]:hover {
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
}

/* Loading overlay — AI loader (orb + rotating status + indeterminate bar), soft pastel palette. Markup: AiSelectionFx.loaderHtml */
.ai-float-loading {
    position: relative;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 230px;
    max-width: min(92vw, 420px);
    padding: 12px 20px 14px 12px;
    background: rgba(255, 255, 255, 0.985);
    backdrop-filter: blur(20px) saturate(160%);
    -webkit-backdrop-filter: blur(20px) saturate(160%);
    border: 1px solid rgba(165, 180, 252, 0.35);
    border-radius: 18px;
    box-shadow: 0 10px 30px rgba(99, 102, 241, 0.10), 0 1px 3px rgba(15, 23, 42, 0.05);
    font-size: 0.9rem;
    font-weight: 600;
    color: #6366f1;
    font-family: 'Inter', 'Outfit', system-ui, sans-serif;
    overflow: hidden;
}
.aisx-orb {
    position: relative; flex: none; width: 36px; height: 36px; border-radius: 50%;
    display: grid; place-items: center; color: #6366f1; font-size: 0.95rem;
    background: conic-gradient(from var(--aisx-a, 0deg), #c7d2fe, #ddd6fe, #fbcfe8, #bae6fd, #c7d2fe);
    animation: aisx-spin 1.8s linear infinite;
    box-shadow: 0 4px 14px rgba(165, 180, 252, 0.45);
}
.aisx-orb::before { content: ''; position: absolute; inset: 3px; border-radius: 50%; background: #eef2ff; }
.aisx-orb i { position: relative; animation: aisx-twinkle 1.8s ease-in-out infinite; }
.aisx-orb.err { background: #fecaca; animation: none; box-shadow: 0 4px 14px rgba(252, 165, 165, 0.45); color: #dc2626; }
.aisx-orb.err::before { background: #fef2f2; }
.aisx-orb.err i { animation: none; }
.aisx-load-text {
    min-width: 0; flex: 1; line-height: 1.3;
    background: linear-gradient(90deg, #6366f1 0%, #8b5cf6 40%, #c084fc 50%, #8b5cf6 60%, #6366f1 100%);
    background-size: 220% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
    animation: aisx-text-shimmer 2.6s linear infinite;
}
.aisx-orb.err + .aisx-load-text { background: none; color: #c24b4b; animation: none; }
.aisx-load-text.swap { animation: aisx-text-shimmer 2.6s linear infinite, aisx-text-in 0.35s ease; }
.aisx-load-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(199, 210, 254, 0.25); overflow: hidden; }
.aisx-load-bar i { position: absolute; top: 0; bottom: 0; width: 40%; border-radius: 3px; background: linear-gradient(90deg, transparent, #c7d2fe, #ddd6fe, #fbcfe8, transparent); animation: aisx-bar 1.6s cubic-bezier(0.45, 0, 0.25, 1) infinite; }
@keyframes aisx-bar { from { transform: translateX(-100%); } to { transform: translateX(260%); } }
@keyframes aisx-text-shimmer { from { background-position: 110% 0; } to { background-position: -110% 0; } }
@keyframes aisx-text-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@keyframes aisx-twinkle { 0%, 100% { transform: scale(1) rotate(0); } 50% { transform: scale(1.15) rotate(-10deg); } }

/* ─── Dark Mode Support ─── */
@media (prefers-color-scheme: dark) {
    .ai-float-btns {
        background: rgba(30, 41, 59, 0.92);
        border-color: rgba(51, 65, 85, 0.6);
        box-shadow: 0 4px 24px rgba(0, 0, 0, 0.3),
                    inset 0 1px 0 rgba(255, 255, 255, 0.06);
    }

    .ai-float-btns::before {
        background: rgba(30, 41, 59, 0.92);
        border-color: rgba(51, 65, 85, 0.6);
    }

    .ai-float-loading {
        background: rgba(30, 41, 59, 0.985);
        border-color: rgba(165, 180, 252, 0.18);
        color: #c7d2fe;
    }
    .aisx-orb::before { background: #1e293b; }
    .aisx-orb { color: #c7d2fe; }
    .aisx-load-text { background-image: linear-gradient(90deg, #c7d2fe 0%, #ddd6fe 40%, #f5d0fe 50%, #ddd6fe 60%, #c7d2fe 100%); }
    .aisx-orb.err + .aisx-load-text { color: #fca5a5; }
}

/* ─── Touch Devices ─── */
@media (pointer: coarse) {
    .ai-float-btn {
        min-width: 60px;
        padding: 10px 14px;
        min-height: 52px;
        font-size: 0.75rem;
    }

    .ai-float-btn i {
        font-size: 1.1rem;
    }

    .ai-float-btn:active {
        transform: scale(0.93) !important;
        opacity: 0.85;
    }

    .ai-floating-toolbar {
        filter: drop-shadow(0 6px 20px rgba(0, 0, 0, 0.2));
    }
}

/* ════════════════════════════════════════════════════════
   AI SEARCH SIDEBAR (sliding panel — best photo + AI insight + web)
   ════════════════════════════════════════════════════════ */
.ai-search-sidebar-container {
    position: fixed;
    top: 0;
    right: 0;
    width: 100vw;
    height: 100vh;
    z-index: 100000;
    pointer-events: none;
    display: flex;
    justify-content: flex-end;
    direction: ltr; /* keep panel on physical right even in RTL docs */
    font-family: 'Inter', 'Outfit', system-ui, sans-serif;
}
.ai-search-sidebar-container.open { pointer-events: auto; }

.ai-search-sidebar {
    width: 400px;
    max-width: 100vw;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border-left: 1px solid rgba(148, 163, 184, 0.25);
    box-shadow: -12px 0 40px rgba(15, 23, 42, 0.18);
    transform: translateX(100%);
    transition: transform 0.4s cubic-bezier(0.19, 1, 0.22, 1);
    pointer-events: auto;
}
.ai-search-sidebar-container.open .ai-search-sidebar { transform: translateX(0); }
.ai-search-sidebar-container.rtl-mode .ai-search-sidebar { direction: rtl; }

@media (max-width: 480px) {
    .ai-search-sidebar { width: 100vw; }
}

.ai-search-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    color: #fff;
    flex-shrink: 0;
}
.ai-search-title { display: flex; align-items: center; gap: 14px; }
.ai-search-icon {
    width: 42px; height: 42px;
    display: flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, 0.18);
    border-radius: 12px;
    font-size: 1.2rem;
}
.ai-search-title-main { font-size: 1.05rem; font-weight: 700; }
.ai-search-title-sub { font-size: 0.78rem; opacity: 0.9; margin-top: 2px; }
.ai-search-close {
    width: 34px; height: 34px;
    border: none; cursor: pointer;
    background: rgba(255, 255, 255, 0.15);
    color: #fff; border-radius: 10px;
    font-size: 1rem;
    transition: background 0.2s ease;
}
.ai-search-close:hover { background: rgba(255, 255, 255, 0.3); }

.ai-search-querybar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    margin: 14px 16px 4px;
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    flex-shrink: 0;
}
.ai-search-querybar > i { color: #94a3b8; }
.ai-search-querybar input {
    flex: 1;
    min-width: 0;
    border: none;
    outline: none;
    font-size: 0.92rem;
    color: #0f172a;
    background: transparent;
    font-family: inherit;
}
.ai-search-go {
    flex-shrink: 0;
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    border: none;
    cursor: pointer;
    border-radius: 9px;
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    color: #fff;
    font-size: 0.85rem;
    transition: filter 0.2s ease, transform 0.2s ease;
}
.ai-search-go:hover { filter: brightness(1.08); transform: scale(1.06); }

.ai-search-body {
    flex: 1;
    padding: 14px 16px 22px;
    overflow-y: auto;
    overflow-x: hidden;
}

.ai-search-loading,
.ai-search-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 44px 20px;
    color: #64748b;
    text-align: center;
}
.ai-search-loading i, .ai-search-empty i { font-size: 1.8rem; color: #0ea5e9; }
.ai-search-empty .fa-exclamation-triangle { color: #ef4444; }

/* Section headers */
.ai-search-section-head {
    display: flex; align-items: center; gap: 8px;
    font-weight: 700; font-size: 0.78rem;
    color: #475569;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 4px 0 10px;
}
.ai-search-section-head i { color: #0ea5e9; }

/* Best photo (hero) */
.ai-search-hero {
    position: relative;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid #e2e8f0;
    background: #f8fafc repeating-conic-gradient(#eef2f7 0% 25%, #ffffff 0% 50%) 50% / 18px 18px;
    margin-bottom: 12px;
}
.ai-search-hero img {
    display: block;
    width: 100%;
    max-height: 260px;
    object-fit: contain;
    background: #fff;
}
.ai-search-add-btn {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    display: inline-flex; align-items: center; gap: 7px;
    border: none; cursor: pointer;
    padding: 9px 18px;
    border-radius: 999px;
    background: rgba(2, 132, 199, 0.95);
    color: #fff;
    font-size: 0.82rem; font-weight: 600;
    font-family: inherit;
    box-shadow: 0 6px 18px rgba(2, 132, 199, 0.35);
    backdrop-filter: blur(4px);
    transition: filter 0.2s ease, transform 0.2s ease;
}
.ai-search-add-btn:hover:not(:disabled) { filter: brightness(1.1); transform: translateX(-50%) translateY(-2px); }
.ai-search-add-btn:disabled { opacity: 0.85; cursor: default; }

/* Alternate thumbnails */
.ai-search-thumbs {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    margin-bottom: 18px;
}
.ai-search-thumb {
    aspect-ratio: 1;
    padding: 0;
    border: 2px solid transparent;
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    background: #f1f5f9;
    transition: border-color 0.2s ease, transform 0.2s ease;
}
.ai-search-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ai-search-thumb:hover { transform: translateY(-2px); }
.ai-search-thumb.active { border-color: #0ea5e9; }

/* AI insight block */
.ai-search-comment {
    border: 1px solid #bae6fd;
    background: linear-gradient(135deg, #f0f9ff, #e0f2fe);
    border-radius: 14px;
    padding: 14px 16px;
    margin-bottom: 18px;
}
.ai-search-comment-head {
    display: flex; align-items: center; gap: 8px;
    font-weight: 700; font-size: 0.85rem;
    color: #0369a1;
    margin-bottom: 8px;
}
.ai-search-comment-body { font-size: 0.9rem; line-height: 1.6; color: #0f172a; }
.ai-search-comment-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    flex-wrap: wrap;
}
.ai-search-cmt-btn {
    display: inline-flex; align-items: center; gap: 6px;
    border: 1px solid rgba(2, 132, 199, 0.3);
    background: rgba(255, 255, 255, 0.7);
    color: #0369a1;
    cursor: pointer;
    padding: 7px 12px;
    border-radius: 9px;
    font-size: 0.78rem; font-weight: 600;
    font-family: inherit;
    transition: background 0.2s ease, transform 0.2s ease;
}
.ai-search-cmt-btn:hover { background: #fff; transform: translateY(-1px); }
.ai-search-cmt-btn.primary {
    background: linear-gradient(135deg, #0ea5e9, #0284c7);
    border-color: transparent;
    color: #fff;
    box-shadow: 0 4px 12px rgba(2, 132, 199, 0.28);
}
.ai-search-cmt-btn.primary:hover { background: linear-gradient(135deg, #0ea5e9, #0284c7); filter: brightness(1.08); }

.ai-search-results { display: flex; flex-direction: column; gap: 10px; }

.ai-search-result {
    display: block;
    text-decoration: none;
    padding: 12px 14px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}
.ai-search-result:hover {
    border-color: #7dd3fc;
    box-shadow: 0 6px 18px rgba(14, 165, 233, 0.12);
    transform: translateY(-2px);
}
.ai-search-result-title { display: block; font-weight: 600; color: #0369a1; font-size: 0.92rem; }
.ai-search-result-url { display: block; font-size: 0.72rem; color: #16a34a; margin: 3px 0 5px; word-break: break-all; }
.ai-search-result-snippet { margin: 0; font-size: 0.82rem; line-height: 1.5; color: #475569;
    display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* RTL */
.ai-search-sidebar-container.rtl-mode .ai-search-result-snippet,
.ai-search-sidebar-container.rtl-mode .ai-search-comment-body { text-align: right; }

/* Dark mode */
@media (prefers-color-scheme: dark) {
    .ai-search-sidebar { background: #1e293b; border-left-color: #334155; }
    .ai-search-querybar { background: #0f172a; border-color: #334155; }
    .ai-search-querybar input { color: #f1f5f9; }
    .ai-search-hero { border-color: #334155; }
    .ai-search-thumb { background: #0f172a; }
    .ai-search-comment { background: rgba(14, 165, 233, 0.1); border-color: rgba(14, 165, 233, 0.3); }
    .ai-search-comment-body { color: #e2e8f0; }
    .ai-search-cmt-btn { background: rgba(15, 23, 42, 0.5); color: #7dd3fc; border-color: rgba(14, 165, 233, 0.4); }
    .ai-search-cmt-btn:hover { background: rgba(15, 23, 42, 0.8); }
    .ai-search-result { border-color: #334155; }
    .ai-search-result-snippet { color: #94a3b8; }
    .ai-search-result-title { color: #38bdf8; }
}

/* ─── AI Sidebar Scrollbar ─── */
.ai-body::-webkit-scrollbar {
    width: 8px;
}

.ai-body::-webkit-scrollbar-track {
    background: rgba(128, 128, 128, 0.06);
    border-radius: 4px;
}

.ai-body::-webkit-scrollbar-thumb {
    background: rgba(128, 128, 128, 0.3);
    border-radius: 4px;
    border: 2px solid transparent;
    background-clip: padding-box;
    min-height: 40px;
}

.ai-body::-webkit-scrollbar-thumb:hover {
    background: rgba(128, 128, 128, 0.5);
    border: 2px solid transparent;
    background-clip: padding-box;
}

/* ─── Small screens: compact layout ─── */
@media (max-width: 600px) {
    .ai-float-btns {
        gap: 4px;
        padding: 6px 8px;
        border-radius: 12px;
        flex-wrap: wrap;
        max-width: 320px;
        justify-content: center;
    }

    .ai-float-btn {
        min-width: 48px;
        padding: 6px 8px;
        font-size: 0.65rem;
    }

    .ai-float-btn i {
        font-size: 0.9rem;
    }

    .ai-float-btn span {
        font-size: 0.6rem;
    }
}

/* ═══════════════════════════════════════════════════════
   AI Undo Result Button — Appears after AI adds content
   ═══════════════════════════════════════════════════════ */

.ai-undo-result-btn {
    position: fixed;
    z-index: 99998;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 20px;
    cursor: pointer;
    background: linear-gradient(135deg, #ef4444, #dc2626);
    color: #fff;
    font-size: 0.8rem;
    font-weight: 700;
    font-family: 'Inter', 'Outfit', system-ui, sans-serif;
    box-shadow: 0 4px 16px rgba(239, 68, 68, 0.35),
                0 1px 3px rgba(0, 0, 0, 0.1);
    transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
    opacity: 0;
    transform: scale(0.8) translateY(6px);
    pointer-events: none;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    -webkit-user-select: none;
    letter-spacing: 0.02em;
}

.ai-undo-result-btn.visible {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

.ai-undo-result-btn:hover {
    background: linear-gradient(135deg, #dc2626, #b91c1c);
    transform: scale(1.06) translateY(-2px);
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.45);
}

.ai-undo-result-btn:active {
    transform: scale(0.95) translateY(0);
}

.ai-undo-result-btn i {
    font-size: 0.85rem;
}

/* Touch devices */
@media (pointer: coarse) {
    .ai-undo-result-btn {
        padding: 10px 20px;
        font-size: 0.85rem;
        min-height: 44px;
    }

    .ai-undo-result-btn:active {
        transform: scale(0.92) !important;
        opacity: 0.85;
    }
}
/* ─── Instant activity setup panel (AI selection → Sketch Solve / Aura Quiz) ─── */
.ai-instant-panel {
    width: min(92vw, 380px);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(15, 23, 42, 0.08);
    border-radius: 18px;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.18), 0 1px 3px rgba(15, 23, 42, 0.08);
    font-family: 'Inter', 'Outfit', system-ui, sans-serif;
    color: #0f172a;
    text-align: start;
}
.ai-instant-panel .aii-head { display: flex; align-items: center; gap: 12px; }
.ai-instant-panel .aii-head b { display: block; font-size: 1rem; font-weight: 800; }
.ai-instant-panel .aii-head small { display: block; font-size: 0.74rem; color: #64748b; margin-top: 2px; }
.ai-instant-panel .aii-ic { flex: none; width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; color: #fff; font-size: 1.1rem; background: linear-gradient(135deg, #8b7bff, #5b4dff); }
.ai-instant-panel .aii-ic.quiz { background: linear-gradient(135deg, #fbbf24, #d97706); }
.ai-instant-panel .aii-ic.match { background: linear-gradient(135deg, #22d3ee, #0891b2); }
.ai-instant-panel .aii-ic.poll { background: linear-gradient(135deg, #818cf8, #6366f1); }
.ai-instant-panel .aii-f { display: flex; flex-direction: column; gap: 6px; }
.ai-instant-panel .aii-f > span { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.05em; text-transform: uppercase; color: #64748b; }
.ai-instant-panel .aii-subject {
    height: 46px; padding: 0 14px; border-radius: 12px; border: 1.5px solid #e2e8f0; background: #f8fafc;
    font: inherit; font-size: 0.95rem; color: #0f172a; outline: none; width: 100%; box-sizing: border-box;
}
.ai-instant-panel .aii-subject:focus { border-color: #6d5efc; background: #fff; box-shadow: 0 0 0 3px rgba(109, 94, 252, 0.15); }
.ai-instant-panel .aii-seg { display: flex; gap: 3px; padding: 3px; border-radius: 12px; background: #f1f5f9; }
.ai-instant-panel .aii-seg button { flex: 1; min-height: 40px; border: 0; border-radius: 9px; background: transparent; font: inherit; font-size: 0.88rem; font-weight: 700; color: #475569; cursor: pointer; }
.ai-instant-panel .aii-seg button.on { background: #fff; color: #5b4dff; box-shadow: 0 1px 4px rgba(15, 23, 42, 0.16); }
.ai-instant-panel .aii-actions { display: flex; gap: 8px; margin-top: 2px; }
.ai-instant-panel .aii-btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 48px; padding: 0 16px; border: 0; border-radius: 13px; font: inherit; font-size: 0.92rem; font-weight: 800; cursor: pointer; }
.ai-instant-panel .aii-btn.ghost { background: #eef1f6; color: #334155; }
.ai-instant-panel .aii-btn.primary { flex: 1; color: #fff; background: linear-gradient(135deg, #8b7bff, #5b4dff); box-shadow: 0 8px 20px rgba(91, 77, 255, 0.35); }
.ai-instant-panel .aii-btn.primary.quiz { background: linear-gradient(135deg, #fbbf24, #d97706); box-shadow: 0 8px 20px rgba(217, 119, 6, 0.35); }
.ai-instant-panel .aii-btn.primary.match { background: linear-gradient(135deg, #22d3ee, #0891b2); box-shadow: 0 8px 20px rgba(8, 145, 178, 0.35); }
.ai-instant-panel .aii-btn.primary.poll { background: linear-gradient(135deg, #818cf8, #6366f1); box-shadow: 0 8px 20px rgba(99, 102, 241, 0.35); }
.ai-instant-panel .aii-btn:active { transform: scale(0.97); }
.ai-instant-panel .aii-head > div { flex: 1; min-width: 0; }
.ai-instant-panel .aii-ic.set { background: linear-gradient(135deg, #94a3b8, #64748b); }
.ai-instant-panel .aii-gear { flex: none; width: 40px; height: 40px; border: 0; border-radius: 12px; background: #eef1f6; color: #475569; font-size: 1rem; cursor: pointer; }
.ai-instant-panel .aii-gear:active { transform: scale(0.94); }
.ai-instant-panel .aii-opts { display: flex; flex-direction: column; gap: 6px; }
.ai-instant-panel .aii-opts button { display: grid; grid-template-columns: 30px 1fr; column-gap: 10px; align-items: center; text-align: start; padding: 10px 12px; min-height: 56px; border: 2px solid #e2e8f0; border-radius: 12px; background: #f8fafc; font: inherit; color: #334155; cursor: pointer; }
.ai-instant-panel .aii-opts button i { grid-row: 1 / 3; font-size: 1.15rem; color: #94a3b8; text-align: center; }
.ai-instant-panel .aii-opts button b { font-size: 0.88rem; font-weight: 800; }
.ai-instant-panel .aii-opts button small { font-size: 0.72rem; color: #64748b; }
.ai-instant-panel .aii-opts button.on { border-color: #6d5efc; background: #fff; box-shadow: 0 0 0 3px rgba(109, 94, 252, 0.14); }
.ai-instant-panel .aii-opts button.on i { color: #5b4dff; }
@media (prefers-color-scheme: dark) {
    .ai-instant-panel { background: rgba(30, 41, 59, 0.97); border-color: rgba(51, 65, 85, 0.7); color: #e2e8f0; }
    .ai-instant-panel .aii-head small, .ai-instant-panel .aii-f > span { color: #94a3b8; }
    .ai-instant-panel .aii-subject { background: #0f172a; border-color: #334155; color: #e2e8f0; }
    .ai-instant-panel .aii-seg { background: #0f172a; }
    .ai-instant-panel .aii-seg button { color: #cbd5e1; }
    .ai-instant-panel .aii-seg button.on { background: #334155; color: #c4b5fd; }
    .ai-instant-panel .aii-btn.ghost, .ai-instant-panel .aii-gear { background: #334155; color: #e2e8f0; }
    .ai-instant-panel .aii-opts button { background: #0f172a; border-color: #334155; color: #e2e8f0; }
    .ai-instant-panel .aii-opts button small { color: #94a3b8; }
    .ai-instant-panel .aii-opts button.on { background: #1e293b; border-color: #8b7bff; }
}

/* Grouped AI toolbar buttons (Solve It / Practice / Explore / Live Activity) open a sub-menu — show a small ▾ */
.ai-float-btn .ai-float-caret {
    position: absolute; top: 7px; right: 7px; width: 0; height: 0;
    border-left: 4px solid transparent; border-right: 4px solid transparent; border-top: 5px solid currentColor; opacity: 0.55;
}
[dir="rtl"] .ai-float-btn .ai-float-caret { right: auto; left: 7px; }

/* ═══════════════════════════════════════════════════════════════════════
   AI SELECTION FX — the selection box drawn over the board (AiSelectionFx.js)
   Soft pastel palette (low contrast, calm on a projector). States: drawing → locked → thinking → done / error.
   Pointer-events none: it never blocks the board.
   ═══════════════════════════════════════════════════════════════════════ */
@property --aisx-a { syntax: '<angle>'; inherits: true; initial-value: 0deg; }

.aisx {
    --aisx-r: 14px;
    --aisx-bw: 2px;
    --aisx-grad: conic-gradient(from var(--aisx-a), #a5b4fc, #c4b5fd, #f0abfc, #a5d8fd, #a5b4fc);
    position: fixed; left: 0; top: 0; width: 0; height: 0; z-index: 99990;
    pointer-events: none; box-sizing: border-box; will-change: transform;
    animation: aisx-in 0.18s ease-out;
}
.aisx *, .aisx *::before, .aisx *::after { box-sizing: border-box; }
@keyframes aisx-in { from { opacity: 0; } to { opacity: 1; } }
.aisx.aisx-out { opacity: 0; transition: opacity 0.26s ease; }

/* gradient border: a conic gradient masked to a ring */
.aisx-frame {
    position: absolute; inset: 0; border-radius: var(--aisx-r); padding: var(--aisx-bw);
    background: var(--aisx-grad);
    -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
    -webkit-mask-composite: xor; mask-composite: exclude;
}
.aisx-glow { position: absolute; inset: -3px; border-radius: calc(var(--aisx-r) + 3px); opacity: 0; background: var(--aisx-grad); filter: blur(14px); transition: opacity 0.3s ease; }
.aisx-fill { position: absolute; inset: var(--aisx-bw); border-radius: calc(var(--aisx-r) - 2px); overflow: hidden; background: rgba(199, 210, 254, 0.12); transition: background 0.3s ease; }
.aisx-grid {
    position: absolute; inset: 0; opacity: 0; transition: opacity 0.4s ease;
    background-image: radial-gradient(rgba(165, 180, 252, 0.45) 1px, transparent 1.4px); background-size: 14px 14px;
    -webkit-mask: radial-gradient(ellipse at center, #000 30%, transparent 78%); mask: radial-gradient(ellipse at center, #000 30%, transparent 78%);
}
.aisx-scan {
    position: absolute; left: 0; right: 0; top: 0; height: 38%; opacity: 0;
    background: linear-gradient(180deg, transparent 0%, rgba(196, 181, 253, 0.08) 60%, rgba(196, 181, 253, 0.22) 96%, rgba(255, 255, 255, 0.75) 100%);
}

/* corner brackets */
.aisx-c { position: absolute; width: 16px; height: 16px; border: 3px solid #fff; filter: drop-shadow(0 1px 2px rgba(99, 102, 241, 0.25)); transition: transform 0.25s ease; }
.aisx-c.tl { left: -5px; top: -5px; border-right: 0; border-bottom: 0; border-top-left-radius: 8px; }
.aisx-c.tr { right: -5px; top: -5px; border-left: 0; border-bottom: 0; border-top-right-radius: 8px; }
.aisx-c.bl { left: -5px; bottom: -5px; border-right: 0; border-top: 0; border-bottom-left-radius: 8px; }
.aisx-c.br { right: -5px; bottom: -5px; border-left: 0; border-top: 0; border-bottom-right-radius: 8px; }
.aisx-c::after { content: ''; position: absolute; inset: -3px; border: inherit; border-color: #a5b4fc; border-width: 1.5px; border-radius: inherit; opacity: 0.9; }

/* status chip (top-left, outside the box) */
.aisx-chip {
    position: absolute; left: 0; bottom: calc(100% + 8px); display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 11px 5px 9px; border-radius: 999px; white-space: nowrap;
    background: linear-gradient(135deg, #a5b4fc, #c4b5fd); color: #312e81; font: 700 12px/1 'Inter', 'Outfit', system-ui, sans-serif;
    box-shadow: 0 6px 16px rgba(165, 180, 252, 0.35); transition: opacity 0.2s ease, transform 0.2s ease;
}
.aisx-chip[dir="rtl"] { left: auto; right: 0; }
.aisx-spark { display: inline-block; font-size: 11px; }
.aisx-dots { display: none; gap: 3px; }
.aisx-dots b { width: 4px; height: 4px; border-radius: 50%; background: #4338ca; animation: aisx-dot 1s ease-in-out infinite; }
.aisx-dots b:nth-child(2) { animation-delay: 0.15s; } .aisx-dots b:nth-child(3) { animation-delay: 0.3s; }
@keyframes aisx-dot { 0%, 80%, 100% { opacity: 0.35; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-3px); } }
.aisx.aisx-small .aisx-chip { font-size: 11px; padding: 4px 9px 4px 7px; }

/* ── states ── */
.aisx[data-state="drawing"] .aisx-frame { animation: aisx-spin 4s linear infinite; }
.aisx[data-state="drawing"] .aisx-chip { opacity: 0.95; }

.aisx[data-state="locked"] .aisx-frame { animation: aisx-spin 6s linear infinite; }
.aisx[data-state="locked"] .aisx-glow { opacity: 0.3; }
.aisx[data-state="locked"] .aisx-chip { opacity: 0; transform: translateY(4px); }

.aisx[data-state="thinking"] { --aisx-bw: 2.5px; }
.aisx[data-state="thinking"] .aisx-frame { animation: aisx-spin 1.6s linear infinite; }
.aisx[data-state="thinking"] .aisx-glow { opacity: 0.55; animation: aisx-spin 1.6s linear infinite, aisx-breathe 2s ease-in-out infinite; }
.aisx[data-state="thinking"] .aisx-fill { background: rgba(199, 210, 254, 0.18); }
.aisx[data-state="thinking"] .aisx-grid { opacity: 1; animation: aisx-grid 2.4s ease-in-out infinite; }
.aisx[data-state="thinking"] .aisx-scan { opacity: 1; animation: aisx-scan 2.1s cubic-bezier(0.5, 0, 0.3, 1) infinite; }
.aisx[data-state="thinking"] .aisx-c { animation: aisx-bracket 1.8s ease-in-out infinite; }
.aisx[data-state="thinking"] .aisx-dots { display: inline-flex; }
.aisx[data-state="thinking"] .aisx-spark { animation: aisx-twinkle 1.4s ease-in-out infinite; }

.aisx[data-state="done"] { --aisx-grad: linear-gradient(135deg, #86efac, #a7f3d0); }
.aisx[data-state="done"] .aisx-glow { opacity: 0.5; }
.aisx[data-state="done"] .aisx-c::after { border-color: #86efac; }
.aisx[data-state="done"] .aisx-chip { background: linear-gradient(135deg, #86efac, #a7f3d0); color: #065f46; animation: aisx-pop 0.35s ease; }
.aisx[data-state="done"] .aisx-spark { font-size: 0; } .aisx[data-state="done"] .aisx-spark::before { content: '✓'; font-size: 12px; }

.aisx[data-state="error"] { --aisx-grad: linear-gradient(135deg, #fca5a5, #fecaca); animation: aisx-shake 0.4s ease; }
.aisx[data-state="error"] .aisx-c::after { border-color: #fca5a5; }
.aisx[data-state="error"] .aisx-chip { background: linear-gradient(135deg, #fca5a5, #fecaca); color: #7f1d1d; }

@keyframes aisx-spin { to { --aisx-a: 360deg; } }
@keyframes aisx-breathe { 0%, 100% { filter: blur(12px); } 50% { filter: blur(18px); } }
@keyframes aisx-scan { 0% { transform: translateY(-100%); } 100% { transform: translateY(270%); } }
@keyframes aisx-grid { 0%, 100% { opacity: 0.55; } 50% { opacity: 1; } }
@keyframes aisx-bracket { 0%, 100% { transform: translate(0, 0); } 50% { transform: var(--aisx-bt, translate(0, 0)); } }
.aisx-c.tl { --aisx-bt: translate(-3px, -3px); } .aisx-c.tr { --aisx-bt: translate(3px, -3px); }
.aisx-c.bl { --aisx-bt: translate(-3px, 3px); } .aisx-c.br { --aisx-bt: translate(3px, 3px); }
@keyframes aisx-pop { 0% { transform: scale(0.85); } 60% { transform: scale(1.08); } 100% { transform: scale(1); } }
@keyframes aisx-shake { 0%, 100% { margin-left: 0; } 25% { margin-left: -6px; } 50% { margin-left: 5px; } 75% { margin-left: -3px; } }

/* selection-mode hint pill */
.aisx-hint {
    position: fixed; left: 50%; top: calc(16px + env(safe-area-inset-top, 0px)); z-index: 99995;
    display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 8px; border-radius: 999px;
    background: rgba(17, 24, 39, 0.88); color: #fff; font: 600 14px/1.2 'Inter', 'Outfit', system-ui, sans-serif;
    -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); box-shadow: 0 12px 34px rgba(15, 23, 42, 0.3);
    pointer-events: none; opacity: 0; transform: translate(-50%, -10px); transition: opacity 0.22s ease, transform 0.22s ease;
    max-width: calc(100vw - 24px);
}
.aisx-hint.show { opacity: 1; transform: translate(-50%, 0); }
.aisx-hint-ic { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; background: conic-gradient(from var(--aisx-a), #a5b4fc, #c4b5fd, #f0abfc, #a5d8fd, #a5b4fc); color: #312e81; animation: aisx-spin 3s linear infinite; }
.aisx-hint kbd { flex: none; padding: 4px 8px; border-radius: 8px; background: rgba(255, 255, 255, 0.14); font: 600 11.5px/1 'Inter', system-ui, sans-serif; color: rgba(255, 255, 255, 0.85); }
@media (pointer: coarse) { .aisx-hint kbd { display: none; } }

@media (prefers-reduced-motion: reduce) {
    .aisx *, .aisx, .aisx-hint *, .aisx-orb, .aisx-orb i, .aisx-load-text, .aisx-load-bar i { animation: none !important; }
    .aisx[data-state="thinking"] .aisx-glow { opacity: 0.5; }
}

/* ── One-tap quick actions above the input (Oct 2026) ── */
.ai-quick-bar {
    display: flex;
    gap: 6px;
    padding: 8px 12px 2px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.ai-quick-bar::-webkit-scrollbar { display: none; }
.ai-quick {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid rgba(99, 102, 241, .28);
    background: rgba(99, 102, 241, .07);
    color: #4f46e5;
    font: 700 .76rem/1 'Outfit', 'Cairo', system-ui, sans-serif;
    white-space: nowrap;
    cursor: pointer;
    transition: background .15s ease, transform .1s ease;
}
.ai-quick:hover { background: rgba(99, 102, 241, .15); }
.ai-quick:active { transform: scale(.95); }
.ai-quick-4ir { border-color: rgba(2, 132, 199, .35); background: rgba(2, 132, 199, .08); color: #0369a1; }
body.touch-device .ai-quick { min-height: 40px; padding: 0 14px; }
.ai-sidebar.rtl-mode .ai-quick-bar { direction: rtl; }

/* "Add to Board" is the main action on an AI reply */
.ai-action-btn.ai-action-primary {
    background: linear-gradient(135deg, #6366f1, #8b5cf6) !important;
    color: #fff !important;
    border-color: transparent !important;
    font-weight: 700;
}
body.touch-device .ai-msg-actions .ai-action-btn { min-height: 40px; }
.ai-quick-bar[hidden] { display: none !important; }

/* ── Image style picker: readable chips on the light sidebar (the inline styles were for a dark panel) ── */
#aiStylePicker { border-top: 0 !important; padding: 8px 12px 2px !important; scrollbar-width: none !important; }
#aiStylePicker::-webkit-scrollbar { display: none; }
#aiStylePicker::before {
    content: 'Art style';
    display: block;
    margin: 0 0 6px 2px;
    font: 800 .66rem/1 'Outfit', system-ui, sans-serif;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-muted, #64748b);
}
#aiStylePicker .ai-style-btn {
    min-height: 34px;
    padding: 0 12px !important;
    border: 1px solid rgba(100, 116, 139, .3) !important;
    border-radius: 999px !important;
    background: transparent !important;
    color: var(--text-main, #1e293b) !important;
    font: 700 .76rem/1 'Outfit', 'Cairo', system-ui, sans-serif !important;
}
#aiStylePicker .ai-style-btn:hover { border-color: #6366f1 !important; }
#aiStylePicker .ai-style-btn.active { background: #6366f1 !important; border-color: #6366f1 !important; color: #fff !important; }
body.touch-device #aiStylePicker .ai-style-btn { min-height: 40px; }
/* the mode menu: wide enough to read "Generate Image (From Canvas)" */
#aiContextSelect { min-width: 0; max-width: 190px; }
.ai-sidebar:not(.expanded) #aiContextSelect { flex: 1 1 150px; }

/* ── graphs / charts / tables inside AI replies (RichVisual, same as STEAM Bridge) ── */
.ai-bubble .ai-vis { white-space: normal; margin: 10px 0 8px; }
.ai-bubble .ai-vis .rv-figure { margin: 0 0 6px !important; }
.ai-bubble .ai-vis canvas { border: 1px solid rgba(100, 116, 139, .22); border-radius: 10px; background: #fff; }
.ai-bubble .ai-vis figcaption { color: inherit !important; }
.ai-bubble .ai-vis .rv-table { font-size: .85rem; color: #0f172a; background: #fff; border-radius: 8px; overflow: hidden; }
.ai-bubble .ai-vis .ai-vis-add { margin-top: 2px; }
