/* admin/menu-buttons/ai-chat/ai-chat.css */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap');

#aiChatModalOverlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    z-index: 999999 !important;
    background: transparent;
    display: none; /* Changed by JS to flex */
    align-items: center;
    justify-content: center;
    overflow: hidden;
    padding: 0 !important;
    box-sizing: border-box !important;
}


.ai-chat-modal {
    display: flex !important;
    flex-direction: column !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
    width: 100vw !important;
    max-width: 100% !important;
    margin: 0 !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    background: #ffffff;
    border-radius: 0 !important;
    overflow: hidden;
    box-shadow: none !important;
    font-family: 'Inter', sans-serif;
    border: none !important;
    box-sizing: border-box !important;
    transform: translateY(100%);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.ai-chat-modal .admin-modal-header {
    flex-shrink: 0;
}

.active-chat-search {
    flex-shrink: 0;
    padding: 8px 16px;
    background: #ffffff;
    border-bottom: 1px solid #e2e8f0;
    box-sizing: border-box;
}
#aiActiveChatSearch {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: 8px 36px;
    outline: none;
    font-size: 13px;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
    transition: border-color 0.2s;
}
#aiActiveChatSearch:focus {
    border-color: #8b5cf6;
}

.admin-modal-overlay.show .ai-chat-modal {
    transform: translateY(0);
}

.ai-chat-modal .admin-modal-header {
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.05);
    z-index: 10;
}

.ai-header-btn {
    background: transparent;
    border: none;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: 0.2s;
    color: #ef4444;
}

.ai-header-btn:hover {
    background: #fee2e2;
}

.ai-chat-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
    background: #f8fafc;
    /* Subtle dot pattern for premium feel */
    background-image: radial-gradient(#cbd5e1 1px, transparent 1px);
    background-size: 20px 20px;
}

/* Custom Scrollbar for chat body */
.ai-chat-body::-webkit-scrollbar {
    width: 6px;
}
.ai-chat-body::-webkit-scrollbar-track {
    background: transparent;
}
.ai-chat-body::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.ai-message {
    display: flex;
    width: 100%;
    animation: messageSlideUp 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
    opacity: 0;
    transform: translateY(20px);
}

.ai-message.system-msg {
    justify-content: flex-start;
}

.ai-message.system-msg .bubble {
    background: #ffffff;
    color: #1e293b;
    border-radius: 20px 20px 20px 4px;
    max-width: 85%;
    padding: 16px 20px;
    font-size: 14.5px;
    line-height: 1.6;
    box-shadow: 0 4px 20px rgba(0,0,0,0.04);
    border: 1px solid rgba(0,0,0,0.02);
}

/* Markdown Rendering Cleanups */
.bubble p {
    margin: 0 0 10px 0;
}
.bubble p:last-child {
    margin: 0;
}
.bubble strong {
    font-weight: 700;
}
.bubble ul, .bubble ol {
    margin: 0 0 10px 0;
    padding-left: 20px;
}
.bubble li {
    margin-bottom: 4px;
}
.bubble hr {
    border: none;
    border-top: 1px solid rgba(0,0,0,0.1);
    margin: 12px 0;
}

/* Markdown Table Styling */
.bubble table {
    width: 100%;
    border-collapse: collapse;
    margin: 12px 0;
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    border-radius: 8px;
    border: 1px solid #e2e8f0;
}
.bubble table::-webkit-scrollbar {
    height: 6px;
}
.bubble table::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}
.bubble table::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 10px;
}
.bubble th, .bubble td {
    padding: 10px 14px;
    border: 1px solid #e2e8f0;
    text-align: left;
    font-size: 13.5px;
}
.bubble th {
    background-color: #f8fafc;
    font-weight: 600;
    color: #334155;
}
.bubble td {
    color: #475569;
}
.bubble tr:nth-child(even) {
    background-color: #f8fafc;
}
.bubble tr:hover {
    background-color: #f1f5f9;
}

.ai-message.user-msg {
    justify-content: flex-end;
}

.ai-message.user-msg .bubble {
    background: #8b5cf6;
    color: white;
    border-radius: 20px 20px 4px 20px;
    max-width: 85%;
    padding: 16px 20px;
    font-size: 14.5px;
    line-height: 1.6;
    word-break: break-word;
}

.ai-message.user-msg .bubble img {
    max-width: 100%;
    max-height: 250px;
    object-fit: cover;
    border-radius: 12px;
    margin-bottom: 10px;
    display: block;
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    cursor: pointer;
}

/* ---- Image Preview Modal ---- */
.ai-image-fullscreen-preview {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.92);
    z-index: 100100;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: imgFade 0.2s ease;
}

@keyframes imgFade {
    from { opacity: 0; }
    to { opacity: 1; }
}

.ai-image-fullscreen-preview img {
    max-width: 95%;
    max-height: 90%;
    object-fit: contain;
    border-radius: 4px;
}

/* Chat Input Area */
.ai-chat-input-area {
    padding: 16px 24px 24px 24px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-shrink: 0;
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.05);
    z-index: 20;
}

.ai-image-preview-container {
    position: relative;
    width: max-content;
    padding-bottom: 8px;
    animation: slideUp 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

.ai-image-preview-container img {
    max-height: 120px;
    border-radius: 12px;
    border: 2px solid #e2e8f0;
    box-shadow: 0 8px 20px rgba(0,0,0,0.08);
}

.remove-image-btn {
    position: absolute;
    top: -10px;
    right: -10px;
    background: #ff4d4d;
    color: white;
    border: 2px solid white;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(255, 77, 77, 0.4);
    transition: transform 0.2s;
}

.remove-image-btn:hover {
    background: #ef4444;
}

.ai-input-row {
    display: flex;
    align-items: flex-end;
    gap: 14px;
}

.ai-attach-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    background: #f1f5f9;
    color: #475569;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s ease;
    flex-shrink: 0;
    margin-bottom: 2px;
}

.ai-attach-btn:hover {
    background: #e0e7ff;
    color: #8b5cf6;
    box-shadow: 0 4px 12px rgba(27, 38, 59, 0.15);
}

.ai-attach-btn svg {
    width: 22px;
    height: 22px;
}

.ai-text-field {
    flex: 1;
    min-height: 52px;
    max-height: 40vh;
    border: 2px solid transparent;
    border-radius: 26px;
    padding: 15px 16px;
    font-size: 15px;
    font-family: 'Inter', sans-serif;
    outline: none;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    background: #f1f5f9;
    color: #1e293b;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.03);
    resize: none;
    line-height: 1.4;
    overflow-y: auto;
}

.ai-text-field::-webkit-scrollbar { width: 4px; }
.ai-text-field::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

.ai-text-field:focus {
    background: #ffffff;
    border-color: #8b5cf6;
    box-shadow: 0 0 0 4px rgba(27, 38, 59, 0.15), inset 0 2px 5px rgba(0,0,0,0.01);
}

.ai-mic-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    background: #f1f5f9;
    color: #475569;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    flex-shrink: 0;
}

.ai-mic-btn:hover {
    background: #e2e8f0;
    color: #8b5cf6;
}

.ai-mic-btn.listening {
    background: #fee2e2;
    color: #ef4444;
    animation: micPulse 1.5s infinite;
}

@keyframes micPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }
    70% {
        box-shadow: 0 0 0 15px rgba(239, 68, 68, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

.ai-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    background: #8b5cf6;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    flex-shrink: 0;
}

.ai-send-btn:not(:disabled):hover {
    transform: scale(1.05);
}

.ai-send-btn:active {
    transform: scale(0.95);
}

.ai-send-btn svg {
    width: 22px;
    height: 22px;
    transform: translateX(-1px) translateY(1px);
}

.ai-send-btn:disabled {
    background: #cbd5e1;
    box-shadow: none;
    cursor: not-allowed;
    transform: scale(1);
}

/* Premium Review Card Styling */
.ai-review-card {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255,255,255,0.5);
    border-radius: 16px;
    overflow: hidden;
    width: 100%;
    max-width: 340px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.08), 0 0 0 1px rgba(0,0,0,0.02);
    margin-top: 10px;
}

.ai-review-card-header {
    background: linear-gradient(to right, #f8fafc, #f1f5f9);
    padding: 16px 20px;
    font-weight: 700;
    color: #1e293b;
    border-bottom: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 14px;
}

.ai-review-card-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.ai-review-row {
    display: flex;
    justify-content: space-between;
    font-size: 14px;
    align-items: center;
}

.ai-review-label {
    color: #64748b;
    font-weight: 500;
}

.ai-review-value {
    color: #0f172a;
    font-weight: 700;
}

.ai-review-value input {
    width: 90px;
    text-align: right;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 14px;
    font-family: 'Inter', sans-serif;
    font-weight: 600;
    color: #0f172a;
    outline: none;
    transition: all 0.2s;
    background: #f8fafc;
}

.ai-review-value input:focus {
    border-color: #8b5cf6;
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(27, 38, 59, 0.1);
}

.ai-review-card-actions {
    padding: 16px 20px;
    background: #f8fafc;
    border-top: 1px solid #e2e8f0;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.ai-btn-confirm {
    background: linear-gradient(135deg, #10b981, #059669);
    color: white;
    border: none;
    border-radius: 10px;
    padding: 14px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 15px rgba(16, 185, 129, 0.2);
}

.ai-btn-confirm:hover:not(:disabled) {
    box-shadow: 0 8px 20px rgba(16, 185, 129, 0.3);
}

.ai-btn-confirm:disabled {
    background: #10b981;
    opacity: 0.8;
    transform: none;
    box-shadow: none;
}

.ai-btn-edit {
    background: transparent;
    color: #8b5cf6;
    border: 2px solid #bfdbfe;
    border-radius: 10px;
    padding: 12px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.ai-btn-edit:hover {
    background: #f0f9ff;
    border-color: #93c5fd;
}

/* Typing Indicator (Updated for richness) */
.ai-typing-indicator {
    display: flex;
    gap: 6px;
    padding: 16px 20px;
    background: #ffffff;
    border-radius: 20px 20px 20px 4px;
    width: fit-content;
    box-shadow: 0 4px 20px rgba(0,0,0,0.04);
    border: 1px solid rgba(0,0,0,0.02);
}

.ai-typing-dot {
    width: 8px;
    height: 8px;
    background: #8b5cf6;
    border-radius: 50%;
    animation: typingPulse 1.4s infinite ease-in-out both;
}

.ai-typing-dot:nth-child(1) { animation-delay: -0.32s; }
.ai-typing-dot:nth-child(2) { animation-delay: -0.16s; }

@keyframes typingPulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1.2); opacity: 1; }
}

@keyframes messageSlideUp {
    0% { opacity: 0; transform: translateY(20px) scale(0.95); }
    100% { opacity: 1; transform: translateY(0) scale(1); }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Cropper Overlay Styling */
.ai-cropper-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.95);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    z-index: 100;
    display: flex;
    flex-direction: column;
    padding: 24px;
    animation: fadeIn 0.3s ease;
}

.ai-cropper-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    height: 100%;
}

.ai-cropper-image-wrapper {
    flex: 1;
    min-height: 0; /* needed for flex children to scroll/contain correctly */
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.5);
    border-radius: 16px;
    overflow: hidden;
    position: relative;
}

/* Chat History Modal Overlay */
.ai-history-modal-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}
.ai-history-modal {
    width: 90%;
    max-width: 400px;
    max-height: 80%;
    background: white;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.ai-history-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
}
.ai-history-modal-header h3 {
    margin: 0; font-size: 16px; font-weight: 700; color: #1e293b;
}
.ai-sidebar-new-btn {
    background: #f0f4f8; border: none; border-radius: 8px; width: 36px; height: 36px;
    display: flex; align-items: center; justify-content: center; cursor: pointer; color: #8b5cf6;
    transition: 0.2s;
}
.ai-sidebar-new-btn:hover { background: #e0e7ff; }
.ai-history-close-btn {
    background: transparent; border: none; font-size: 24px; cursor: pointer; color: #64748b; line-height: 1;
}
.sidebar-search {
    padding: 12px;
    border-bottom: 1px solid #e2e8f0;
    position: relative;
}
.sidebar-search input {
    width: 100%; border: 1px solid #cbd5e1; border-radius: 8px; padding: 8px 12px; outline: none; font-family: 'Inter', sans-serif;
    box-sizing: border-box;
}
.sidebar-thread-list {
    flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px;
}
.thread-item {
    background: white; border: 1px solid #e2e8f0; padding: 12px; border-radius: 10px; cursor: pointer; transition: 0.2s; position: relative;
}
.thread-item:hover {
    border-color: #8b5cf6; box-shadow: 0 2px 8px rgba(27,38,59,0.1);
}
.thread-item.active {
    background: #f0f4f8; border-color: #8b5cf6;
}
.thread-item-title {
    font-size: 14px; font-weight: 600; color: #1e293b; margin-bottom: 4px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 90px; outline: none;
}
.thread-item-date {
    font-size: 11px; color: #64748b;
}
.thread-actions {
    position: absolute; right: 12px; top: 50%; transform: translateY(-50%); display: flex; gap: 4px;
}
.thread-action-btn {
    background: transparent; border: none; cursor: pointer; color: #94a3b8; width: 32px; height: 32px; border-radius: 6px; display: flex; align-items: center; justify-content: center;
    transition: 0.2s;
}
.thread-action-btn svg {
    width: 16px; height: 16px;
}.thread-action-btn:hover { background: #f1f5f9; color: #1e293b; }
.thread-action-btn.del-btn:hover { background: #fee2e2; color: #ef4444; }
.thread-item.pinned { border-left: 3px solid #f59e0b; }
.thread-item.pinned .thread-item-title { color: #78350f; }

.pinned-msg-markdown {
    font-size: 13px; color: #334155; margin-top: 2px;
}
.pinned-msg-markdown p {
    margin: 0; padding: 0;
}
.pinned-msg-markdown strong, .pinned-msg-markdown b {
    font-weight: 700;
}
.pinned-msg-markdown em, .pinned-msg-markdown i {
    font-style: italic;
}
.pinned-msg-markdown code {
    background: rgba(0,0,0,0.05); padding: 2px 4px; border-radius: 4px; font-family: monospace; font-size: 11px;
}

.ai-main-area {
    flex: 1; display: flex; flex-direction: column; position: relative; z-index: 10;
    overflow: hidden; min-height: 0;
}

/* Edit message inline */
.user-msg-container, .sys-msg-container {
    display: flex;
    flex-direction: column;
    width: 100%;
}

.user-msg-container {
    align-items: flex-end;
}

.sys-msg-container {
    align-items: flex-start;
}

.user-msg-actions, .sys-msg-actions {
    display: flex;
    gap: 14px;
    margin-top: 6px;
    opacity: 0.6;
    transition: opacity 0.2s;
}

.user-msg-actions { margin-right: 4px; }
.sys-msg-actions { margin-left: 4px; }

.user-msg-container:hover .user-msg-actions,
.sys-msg-container:hover .sys-msg-actions {
    opacity: 1;
}

.user-action-btn, .sys-action-btn {
    background: transparent;
    border: none;
    color: #64748b;
    font-size: 13.5px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
    transition: color 0.2s, transform 0.2s;
    font-family: inherit;
    padding: 2px 4px;
}

.user-action-btn:hover, .sys-action-btn:hover {
    color: #8b5cf6;
    transform: scale(1.05);
}

.user-action-btn.pinned, .sys-action-btn.pinned {
    color: #f59e0b;
}

.ai-message.user-msg { position: relative; }

.inline-edit-area {
    width: 100%; display: flex; flex-direction: column; gap: 12px; background: rgba(255, 255, 255, 0.95); border-radius: 16px; padding: 16px; box-shadow: 0 8px 30px rgba(0,0,0,0.12); margin-top: 10px; border: 1px solid rgba(0,0,0,0.05); backdrop-filter: blur(10px);
}
.inline-edit-area textarea {
    width: 100%; border: 2px solid transparent; border-radius: 12px; padding: 12px 16px; resize: vertical; min-height: 80px; outline: none; font-family: 'Inter', sans-serif; font-size: 14.5px;
    box-sizing: border-box; background: #f1f5f9; color: #1e293b; transition: all 0.3s ease;
}
.inline-edit-area textarea:focus {
    background: #ffffff; border-color: #8b5cf6; box-shadow: 0 0 0 4px rgba(27, 38, 59, 0.15);
}
.inline-edit-actions {
    display: flex; gap: 10px; justify-content: flex-end;
}
.inline-edit-actions button {
    padding: 10px 18px; border: none; border-radius: 10px; cursor: pointer; font-size: 13.5px; font-weight: 700; transition: all 0.2s; font-family: inherit;
}
.inline-edit-save { background: #8b5cf6; color: white; box-shadow: 0 4px 12px rgba(27, 38, 59, 0.25); }
.inline-edit-save:hover { box-shadow: 0 6px 16px rgba(27, 38, 59, 0.35); transform: translateY(-1px); }
.inline-edit-cancel { background: transparent; color: #64748b; border: 1px solid #cbd5e1; }
.inline-edit-cancel:hover { background: #f8fafc; color: #1e293b; }

.ai-cropper-image-wrapper img {
    max-width: 100%;
    max-height: 100%;
    display: block;
}

.ai-cropper-actions {
    display: flex;
    gap: 8px;
    padding-bottom: 10px;
    flex-wrap: wrap;
    justify-content: center;
}

/* SVG Icon Image Editor Buttons */
.crop-action-btn {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 4px;
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    color: white;
    border-radius: 10px;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    transition: 0.2s;
    min-width: 58px;
}
.crop-action-btn:hover {
    background: rgba(255,255,255,0.2);
}
.crop-action-btn.cancel-btn {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.4);
    color: #fca5a5;
}
.crop-action-btn.cancel-btn:hover {
    background: rgba(239, 68, 68, 0.35);
}
.crop-action-btn.confirm-btn {
    background: rgba(16, 185, 129, 0.25);
    border-color: rgba(16, 185, 129, 0.5);
    color: #6ee7b7;
}
.crop-action-btn.confirm-btn:hover {
    background: rgba(16, 185, 129, 0.4);
}

.crop-action-btn:disabled,
.crop-action-btn[disabled] {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

/* No Results Empty State - In Chat */
.ai-chat-no-results {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
    animation: fadeIn 0.3s ease;
}

/* No Results Empty State - Sidebar */
.ai-sidebar-no-results {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    animation: fadeIn 0.3s ease;
}

/* Thread Item Snippet (search preview) */
.thread-item-snippet {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    font-size: 12px;
    color: #64748b;
    margin-top: 4px;
    margin-right: 90px;
    padding: 4px 8px;
    background: #f0f9ff;
    border-radius: 6px;
    border-left: 2px solid #8b5cf6;
    line-height: 1.4;
    overflow: hidden;
    max-height: 40px;
}

.thread-item-snippet span {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* Search highlight pulse */
.ai-search-highlight {
    background: #cce4ff;
    border-radius: 2px;
    cursor: pointer;
    animation: searchPulse 1.5s ease-in-out 1;
}

@keyframes searchPulse {
    0%, 100% { background: #cce4ff; }
    50% { background: #93c5fd; }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@media (max-width: 600px) {
    .ai-chat-modal {
        max-height: 100dvh;
        height: 100dvh;
        overflow: hidden !important;
    }
    .ai-chat-body {
        padding: 16px 12px;
        gap: 16px;
    }
    .ai-message.system-msg .bubble,
    .ai-message.user-msg .bubble {
        max-width: 90%;
        padding: 12px 16px;
        font-size: 14px;
    }
    .ai-chat-input-area {
        padding: 12px 16px 16px 16px;
        gap: 10px;
        max-height: auto;
    }
    .ai-input-row {
        gap: 10px;
    }
    .ai-attach-btn {
        width: 44px;
        height: 44px;
    }
    .ai-attach-btn svg {
        width: 20px;
        height: 20px;
    }
    .ai-send-btn {
        width: 46px;
        height: 46px;
    }
    .ai-send-btn svg {
        width: 18px;
        height: 18px;
    }
    .ai-text-field {
        min-height: 46px;
        font-size: 14px;
        padding: 13px 12px;
    }
    .ai-image-preview-container img {
        max-height: 100px;
        max-width: calc(100vw - 32px);
        object-fit: contain;
    }
}

/* =====================================================================
   DARK MODE SUPPORT
   ===================================================================== */
[data-theme="dark"] .ai-chat-modal {
    background: var(--bg-primary);
}
[data-theme="dark"] .ai-chat-modal .admin-modal-header {
    background: rgba(15, 23, 42, 0.85);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}
[data-theme="dark"] .admin-modal-title {
    color: var(--text-primary);
}
[data-theme="dark"] .active-chat-search {
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-primary);
}
[data-theme="dark"] #aiActiveChatSearch {
    background: var(--bg-surface);
    border-color: var(--border-primary);
    color: var(--text-primary);
}
[data-theme="dark"] .ai-chat-body {
    background: var(--bg-primary);
    background-image: radial-gradient(var(--border-primary) 1px, transparent 1px);
}
[data-theme="dark"] .ai-message.system-msg .bubble {
    background: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid rgba(255,255,255,0.05);
}
[data-theme="dark"] .ai-chat-input-area {
    background: rgba(15, 23, 42, 0.85);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
}
[data-theme="dark"] .ai-attach-btn {
    background: var(--bg-surface);
    color: var(--text-secondary);
}
[data-theme="dark"] .ai-attach-btn:hover {
    background: rgba(27, 38, 59, 0.2);
}
[data-theme="dark"] .ai-text-field {
    background: var(--bg-surface);
    color: var(--text-primary);
    box-shadow: none;
}
[data-theme="dark"] .ai-text-field:focus {
    background: var(--bg-primary);
    border-color: #8b5cf6;
}
[data-theme="dark"] #aiAttachMenu {
    background: var(--bg-surface);
    border: 1px solid var(--border-primary);
}
[data-theme="dark"] #aiAttachMenu label {
    color: var(--text-primary);
}
[data-theme="dark"] #aiAttachMenu label:hover {
    background: var(--bg-primary);
}
[data-theme="dark"] .ai-history-modal {
    background: var(--bg-primary);
}
[data-theme="dark"] .ai-history-modal-header {
    border-bottom: 1px solid var(--border-primary);
}
[data-theme="dark"] .ai-history-modal-header h3 {
    color: var(--text-primary);
}
[data-theme="dark"] .sidebar-search {
    border-bottom: 1px solid var(--border-primary);
}
[data-theme="dark"] .sidebar-search input {
    background: var(--bg-surface);
    border-color: var(--border-primary);
    color: var(--text-primary);
}
[data-theme="dark"] .thread-item {
    background: var(--bg-surface);
    border-color: var(--border-primary);
}
[data-theme="dark"] .thread-item:hover {
    border-color: #8b5cf6;
}
[data-theme="dark"] .thread-item.active {
    background: rgba(27, 38, 59, 0.15);
    border-color: #8b5cf6;
}
[data-theme="dark"] .thread-item-title {
    color: var(--text-primary);
}
[data-theme="dark"] .inline-edit-area {
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid rgba(255,255,255,0.05);
}
[data-theme="dark"] .inline-edit-area textarea {
    background: var(--bg-surface);
    color: var(--text-primary);
}
[data-theme="dark"] .ai-review-card {
    background: rgba(30, 41, 59, 0.95);
    border: 1px solid rgba(255,255,255,0.1);
}
[data-theme="dark"] .ai-product-link {
    color: #31415A;
    background: rgba(74, 170, 255, 0.15);
}
[data-theme="dark"] .ai-product-link:hover {
    background: rgba(74, 170, 255, 0.25);
}
[data-theme="dark"] .ai-review-card-header {
    background: var(--bg-surface);
    color: var(--text-primary);
    border-bottom: 1px solid var(--border-primary);
}
[data-theme="dark"] .ai-review-label {
    color: var(--text-secondary);
}
[data-theme="dark"] .ai-review-value {
    color: var(--text-primary);
}
[data-theme="dark"] .ai-review-value input {
    background: var(--bg-primary);
    border-color: var(--border-primary);
    color: var(--text-primary);
}
[data-theme="dark"] .ai-review-card-actions {
    background: var(--bg-surface);
    border-top: 1px solid var(--border-primary);
}
[data-theme="dark"] .ai-typing-indicator {
    background: var(--bg-surface);
    border: 1px solid rgba(255,255,255,0.05);
}

/* =====================================================================
   FALLBACK ADMIN MODAL CLASSES (For User Side Overlays)
   ===================================================================== */
.admin-modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100dvh;
    height: 100dvh;
    background: rgba(15, 23, 42, 0.5);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    z-index: 200000;
    display: none; 
    align-items: center;
    justify-content: center;
    padding: 16px;
    box-sizing: border-box;
}
.admin-modal-overlay.show {
    display: flex;
}
.admin-modal-content {
    background: white;
    width: 100%;
    max-width: 400px;
    border-radius: 16px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.admin-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #e2e8f0;
}
.admin-modal-header h2, .admin-modal-header h3 {
    margin: 0; font-size: 16px; font-weight: 700; color: #1e293b;
    display: flex; align-items: center; gap: 8px;
}
.admin-modal-close {
    background: transparent; border: none; font-size: 24px; cursor: pointer; color: #64748b; line-height: 1;
}
.admin-modal-body {
    padding: 20px;
    box-sizing: border-box;
    width: 100%;
}
.admin-modern-btn {
    padding: 12px;
    border: none;
    border-radius: 12px;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    background: #f1f5f9;
    color: #475569;
}
.admin-modern-btn.primary {
    background: #8b5cf6;
    color: white;
}
.admin-modern-btn.danger {
    background: #ef4444;
    color: white;
}

[data-theme="dark"] .admin-modal-content {
    background: var(--bg-primary);
    border: 1px solid rgba(255,255,255,0.05);
}
[data-theme="dark"] .admin-modal-header {
    border-bottom: 1px solid var(--border-primary);
}
[data-theme="dark"] .admin-modal-header h2, 
[data-theme="dark"] .admin-modal-header h3 {
    color: var(--text-primary);
}
[data-theme="dark"] .admin-modal-body h3, 
[data-theme="dark"] .admin-modal-body p {
    color: var(--text-primary) !important;
}
[data-theme="dark"] .ai-chat-modal .admin-modal-header h2 {
    color: var(--text-primary) !important;
}
[data-theme="dark"] .ai-chat-modal .admin-modal-close,
[data-theme="dark"] .ai-chat-modal #aiToggleHistoryBtn {
    color: var(--text-secondary) !important;
}
[data-theme="dark"] .admin-modern-btn {
    background: var(--bg-surface);
    color: var(--text-primary);
}
[data-theme="dark"] .admin-modern-btn.primary {
    background: #8b5cf6;
    color: white;
}
[data-theme="dark"] .admin-modern-btn.danger {
    background: #ef4444;
    color: white;
}
[data-theme="dark"] #aiRenameInput {
    background: var(--bg-surface) !important;
    border: 1px solid var(--border-primary) !important;
    color: var(--text-primary) !important;
}
[data-theme="dark"] .ai-history-close-btn {
    color: var(--text-primary);
}

.ai-product-link {
    color: #8b5cf6;
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
    padding: 2px 6px;
    background: rgba(27, 38, 59, 0.1);
    border-radius: 4px;
    transition: all 0.2s;
    display: inline-block;
    margin: 2px 0;
}
.ai-product-link:hover {
    background: rgba(27, 38, 59, 0.2);
    text-decoration: underline;
}

[data-theme="dark"] .ai-sidebar-new-btn {
    background: rgba(74, 170, 255, 0.15);
    color: #31415A;
}
[data-theme="dark"] .ai-sidebar-new-btn:hover {
    background: rgba(74, 170, 255, 0.25);
}

.ai-suggested-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.ai-suggested-title {
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 4px;
}
.ai-suggested-btn {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    padding: 10px 14px;
    border-radius: 8px;
    text-align: left;
    cursor: pointer;
    color: #334155;
    font-size: 0.9rem;
    transition: 0.2s;
}
.ai-suggested-btn:hover {
    background: #e2e8f0;
}
[data-theme="dark"] .ai-suggested-title {
    color: var(--text-primary);
}
[data-theme="dark"] .ai-suggested-btn {
    background: var(--bg-surface);
    border: 1px solid var(--border-primary);
    color: var(--text-primary);
}
[data-theme="dark"] .ai-suggested-btn:hover {
    background: var(--bg-surface-hover);
}


.ai-chat-modal .admin-modal-title { font-size: 1.1rem !important; font-weight: 700 !important; display: flex; align-items: center; gap: 8px; }





