/* --- WOPA AI ASSISTANT WIDGET STYLES --- */
:root {
    --wopa-ai-primary: #8b5cf6;
    --wopa-ai-primary-hover: #7c3aed;
    --wopa-ai-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #d946ef 100%);
    --wopa-ai-header-bg: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
    --wopa-ai-bg: #0f172a;
    --wopa-ai-card: #1e293b;
    --wopa-ai-border: rgba(255, 255, 255, 0.12);
    --wopa-ai-text: #f8fafc;
    --wopa-ai-muted: #94a3b8;
    --wopa-ai-user-bubble: linear-gradient(135deg, #6366f1, #8b5cf6);
    --wopa-ai-assistant-bubble: #1e293b;
}

/* Floating Launcher Button */
#wopa-ai-launcher,
.wopa-ai-launcher {
    position: fixed !important;
    bottom: 25px !important;
    right: 25px !important;
    width: 60px !important;
    height: 60px !important;
    border-radius: 50% !important;
    background: var(--wopa-ai-gradient) !important;
    color: #ffffff !important;
    border: none !important;
    cursor: pointer !important;
    box-shadow: 0 10px 30px rgba(139, 92, 246, 0.5) !important;
    display: none;
    align-items: center;
    justify-content: center !important;
    font-size: 1.5rem !important;
    z-index: 999999 !important;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275), box-shadow 0.3s !important;
}

#wopa-ai-launcher:hover,
.wopa-ai-launcher:hover {
    transform: scale(1.1) rotate(5deg) !important;
    box-shadow: 0 14px 35px rgba(168, 85, 247, 0.65) !important;
}

.wopa-ai-launcher-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    font-size: 0.72rem;
    font-weight: 800;
}

.wopa-ai-launcher-inner i {
    font-size: 1.3rem;
}

/* Main Chat Container */
#wopa-ai-container,
.wopa-ai-container {
    position: fixed !important;
    bottom: 95px;
    right: 25px;
    left: auto;
    width: 440px;
    min-width: 320px;
    max-width: calc(100vw - 20px);
    height: 600px;
    min-height: 350px;
    max-height: calc(100vh - 40px);
    background: #0f172a !important;
    border: 1px solid rgba(168, 85, 247, 0.4) !important;
    border-radius: 20px !important;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.65), 0 0 40px rgba(168, 85, 247, 0.25) !important;
    display: flex !important;
    flex-direction: column !important;
    z-index: 999999 !important;
    overflow: hidden;
    direction: rtl !important;
    font-family: 'Assistant', 'Segoe UI', Tahoma, sans-serif !important;
    color: var(--wopa-ai-text) !important;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    backdrop-filter: blur(16px);
}

#wopa-ai-container.open,
.wopa-ai-container.open {
    opacity: 1 !important;
    transform: translateY(0) scale(1) !important;
    pointer-events: all !important;
}

/* Resize Handles */
.wopa-ai-resize-handle {
    position: absolute !important;
    z-index: 10000 !important;
    user-select: none !important;
    -webkit-user-select: none !important;
}

.wopa-ai-resize-handle.top {
    top: 0 !important;
    left: 14px !important;
    right: 14px !important;
    height: 10px !important;
    cursor: ns-resize !important;
}

.wopa-ai-resize-handle.bottom {
    bottom: 0 !important;
    left: 14px !important;
    right: 14px !important;
    height: 10px !important;
    cursor: ns-resize !important;
}

.wopa-ai-resize-handle.left {
    left: 0 !important;
    top: 14px !important;
    bottom: 14px !important;
    width: 10px !important;
    cursor: ew-resize !important;
}

.wopa-ai-resize-handle.right {
    right: 0 !important;
    top: 14px !important;
    bottom: 14px !important;
    width: 10px !important;
    cursor: ew-resize !important;
}

.wopa-ai-resize-handle.tl {
    top: 0 !important;
    left: 0 !important;
    width: 18px !important;
    height: 18px !important;
    cursor: nwse-resize !important;
}

.wopa-ai-resize-handle.tr {
    top: 0 !important;
    right: 0 !important;
    width: 18px !important;
    height: 18px !important;
    cursor: nesw-resize !important;
}

.wopa-ai-resize-handle.bl {
    bottom: 0 !important;
    left: 0 !important;
    width: 18px !important;
    height: 18px !important;
    cursor: nesw-resize !important;
}

.wopa-ai-resize-handle.br {
    bottom: 0 !important;
    right: 0 !important;
    width: 24px !important;
    height: 24px !important;
    cursor: nwse-resize !important;
    background: linear-gradient(135deg, transparent 50%, #a855f7 50%) !important;
    border-bottom-right-radius: 12px !important;
    opacity: 0.9 !important;
    transition: transform 0.2s, opacity 0.2s !important;
}

.wopa-ai-resize-handle.br:hover {
    opacity: 1 !important;
    transform: scale(1.15) !important;
}

/* Header */
.wopa-ai-header {
    background: var(--wopa-ai-header-bg);
    padding: 14px 18px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: #ffffff;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}

.wopa-ai-header:active {
    cursor: grabbing;
}

.wopa-ai-header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.95rem;
    font-weight: 700;
}

.wopa-ai-header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.wopa-ai-header-controls button {
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.18);
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    transition: all 0.2s ease;
}

.wopa-ai-header-controls button:hover {
    background: rgba(168, 85, 247, 0.4);
    border-color: #a855f7;
    transform: scale(1.1);
}

/* History Drawer Panel */
.wopa-ai-history-drawer {
    position: absolute;
    top: 60px;
    right: 0;
    left: 0;
    bottom: 0;
    background: #0f172a;
    z-index: 200;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-10px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.wopa-ai-history-drawer.open {
    opacity: 1;
    pointer-events: all;
    transform: translateY(0);
}

.wopa-ai-history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    padding-bottom: 10px;
}

.wopa-ai-history-header h4 {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 800;
}

.wopa-ai-history-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.wopa-ai-history-item {
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 12px 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    transition: background 0.2s, border-color 0.2s;
}

.wopa-ai-history-item:hover, .wopa-ai-history-item.active {
    background: rgba(168, 85, 247, 0.2);
    border-color: #a855f7;
}

.wopa-ai-history-item-info h5 {
    margin: 0 0 3px;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--wopa-ai-text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 250px;
}

.wopa-ai-history-item-info span {
    font-size: 0.75rem;
    color: var(--wopa-ai-muted);
}

.wopa-ai-history-del-btn {
    background: transparent;
    border: none;
    color: var(--wopa-ai-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: color 0.2s;
}

.wopa-ai-history-del-btn:hover {
    color: #ff7675;
}

/* Messages Area */
.wopa-ai-messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: #0f172a;
}

.wopa-ai-msg {
    display: flex;
    flex-direction: column;
    max-width: 88%;
}

.wopa-ai-msg.user {
    align-self: flex-start;
}

.wopa-ai-msg.assistant {
    align-self: flex-end;
}

.wopa-ai-msg-bubble {
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 0.95rem;
    line-height: 1.5;
    word-break: break-word;
}

.wopa-ai-msg.user .wopa-ai-msg-bubble {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #ffffff;
    border-top-right-radius: 4px;
    box-shadow: 0 4px 14px rgba(99, 102, 241, 0.3);
}

.wopa-ai-msg.assistant .wopa-ai-msg-bubble {
    background: #1e293b;
    color: #f8fafc;
    border-top-left-radius: 4px;
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

.wopa-ai-msg-actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
    font-size: 0.75rem;
}

.wopa-ai-copy-btn {
    background: transparent;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
}

.wopa-ai-copy-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

/* Action Cards */
.wopa-ai-action-card {
    background: rgba(168, 85, 247, 0.18);
    border: 1px solid rgba(168, 85, 247, 0.45);
    border-radius: 12px;
    padding: 12px 14px;
    margin: 10px 0;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.wopa-ai-action-label {
    font-size: 0.88rem;
    color: #f1f5f9;
    line-height: 1.4;
}

.wopa-ai-apply-btn {
    background: linear-gradient(135deg, #a855f7, #6c5ce7);
    color: white;
    border: none;
    padding: 8px 18px;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s ease;
    box-shadow: 0 4px 14px rgba(168, 85, 247, 0.4);
    align-self: flex-start;
}

.wopa-ai-apply-btn:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 6px 20px rgba(168, 85, 247, 0.6);
    background: linear-gradient(135deg, #b866ff, #7d6df8);
}

/* Input Area */
.wopa-ai-input-area {
    padding: 12px 14px;
    background: #1e293b;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    gap: 10px;
}

.wopa-ai-input-area textarea {
    flex: 1;
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 10px 14px;
    color: #f8fafc;
    font-family: inherit;
    font-size: 0.92rem;
    resize: none;
    height: 42px;
    max-height: 120px;
    outline: none;
    direction: rtl;
}

.wopa-ai-input-area textarea:focus {
    border-color: #a855f7;
    box-shadow: 0 0 0 3px rgba(168, 85, 247, 0.25);
}

.wopa-ai-send-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--wopa-ai-gradient);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: all 0.2s ease;
}

.wopa-ai-send-btn:hover:not(:disabled) {
    transform: scale(1.08);
    box-shadow: 0 4px 14px rgba(168, 85, 247, 0.5);
}

/* Typing Indicator Loader */
.wopa-ai-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 8px 12px;
}

.wopa-ai-dot {
    width: 6px;
    height: 6px;
    background: var(--wopa-ai-muted);
    border-radius: 50%;
    animation: wopaAiBlink 1.4s infinite ease-in-out both;
}

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

@keyframes wopaAiBlink {
    0%, 80%, 100% { transform: scale(0); }
    40% { transform: scale(1); }
}


/* Enhanced Action Cards & Full Rewrite */
.wopa-ai-action-card.featured {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.15), rgba(168, 85, 247, 0.2));
    border: 2px solid rgba(245, 158, 11, 0.6);
    box-shadow: 0 8px 25px rgba(245, 158, 11, 0.25);
    padding: 16px;
}

.wopa-ai-apply-btn.primary {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #0f172a;
    font-weight: 800;
    padding: 10px 22px;
    font-size: 0.95rem;
    box-shadow: 0 4px 15px rgba(245, 158, 11, 0.4);
}

.wopa-ai-apply-btn.primary:hover {
    transform: translateY(-2px) scale(1.04);
    box-shadow: 0 8px 25px rgba(245, 158, 11, 0.6);
    background: linear-gradient(135deg, #fbbf24, #f59e0b);
}

/* Quick AI Action buttons in editor */
.editor-ai-quick-btn {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    color: #ffffff;
    border: none;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 700;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease;
    box-shadow: 0 2px 6px rgba(99, 102, 241, 0.3);
}

.editor-ai-quick-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.5);
    background: linear-gradient(135deg, #a855f7, #7c3aed);
}

.editor-ai-menu-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    background: #1e293b;
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.4);
    z-index: 1000;
    min-width: 180px;
    display: none;
    flex-direction: column;
    overflow: hidden;
    margin-top: 4px;
}

.editor-ai-menu-dropdown.show {
    display: flex;
}

.editor-ai-menu-item {
    padding: 8px 12px;
    font-size: 0.82rem;
    color: #f1f5f9;
    background: transparent;
    border: none;
    text-align: right;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background 0.15s ease;
    width: 100%;
}

.editor-ai-menu-item:hover {
    background: rgba(168, 85, 247, 0.25);
    color: #ffffff;
}


/* Vision Reference Attachments & Image Paste */
.wopa-ai-attach-btn {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #cbd5e1;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.05rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.wopa-ai-attach-btn:hover {
    background: rgba(168, 85, 247, 0.3);
    color: #ffffff;
    border-color: #a855f7;
    transform: scale(1.05);
}

.wopa-ai-image-preview-container {
    background: #0f172a;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding: 8px 14px;
    display: flex;
    gap: 10px;
    overflow-x: auto;
    align-items: center;
    border-left: 3px solid #a855f7;
}

.wopa-ai-image-preview-item {
    position: relative;
    width: 58px;
    height: 58px;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #a855f7;
    flex-shrink: 0;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.4);
    background: #000;
}

.wopa-ai-image-preview-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.wopa-ai-image-preview-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    background: rgba(239, 68, 68, 0.9);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 11px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s;
    line-height: 1;
}

.wopa-ai-image-preview-remove:hover {
    transform: scale(1.2);
}

.wopa-ai-image-preview-badge {
    position: absolute;
    bottom: 2px;
    left: 2px;
    right: 2px;
    background: rgba(15, 23, 42, 0.85);
    color: #38bdf8;
    font-size: 8px;
    text-align: center;
    font-weight: 700;
    border-radius: 3px;
    padding: 1px 0;
}

.wopa-ai-msg-images-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.wopa-ai-msg-attached-img {
    max-width: 180px;
    max-height: 140px;
    border-radius: 10px;
    border: 2px solid rgba(255, 255, 255, 0.4);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    object-fit: cover;
}

.wopa-ai-msg-attached-img:hover {
    transform: scale(1.04);
    box-shadow: 0 6px 20px rgba(168, 85, 247, 0.6);
}

.wopa-ai-container.wopa-ai-drag-over {
}


/* Responsive adjustments for mobile */
@media (max-width: 600px) {
    #wopa-ai-launcher,
    .wopa-ai-launcher {
    }
    #wopa-ai-container,
    .wopa-ai-container {
    }
}

#wopa-ai-launcher.visible,
.wopa-ai-launcher.visible {
}
