/* Fixed sidebar on the right side of WordPress admin */
.peligent-ai-fixed-sidebar {
    position: fixed !important;
    top: 32px !important;
    right: 0 !important;
    min-width: 480px !important;
    max-width: 45vw !important;
    height: calc(100vh - 32px) !important;
    background: #ffffff !important;
    display: flex !important;
    flex-direction: column !important;
    overflow: hidden !important;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.1) !important;
    z-index: 159999 !important;
    border-left: 1px solid #e5e7eb !important;
    visibility: visible !important;
    opacity: 1 !important;
    transition: width 0.2s ease, right 0.2s ease !important;
}
body:not(.peligent-ai-sidebar-hidden):not(.peligent-ai-fullscreen) .media-modal {
    right: 520px !important;
}
/* Fullscreen mode */
.peligent-ai-fixed-sidebar.peligent-ai-fullscreen {
    width: 100% !important;
    max-width: 100% !important;
    right: 0 !important;
    left: 0 !important;
}
/* Hide PHP sidebar header in fullscreen mode (React header takes over inside iframe) */
.peligent-ai-fixed-sidebar.peligent-ai-fullscreen .peligent-ai-sidebar-header {
    display: none !important;
}

/* Floating fullscreen exit bar — hidden by default, shown in fullscreen */
.peligent-ai-fullscreen-bar {
    display: none !important;
}

.peligent-ai-fixed-sidebar.peligent-ai-fullscreen .peligent-ai-fullscreen-bar {
    display: flex !important;
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 200000;
    gap: 8px;
    align-items: center;
}

.peligent-ai-fullscreen-bar-btn {
    display: flex !important;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: background 0.15s, box-shadow 0.15s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12), 0 1px 2px rgba(0, 0, 0, 0.08);
}

.peligent-ai-fullscreen-minimize {
    background: #ffffff !important;
    color: #374151 !important;
}

.peligent-ai-fullscreen-minimize:hover {
    background: #f3f4f6 !important;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15) !important;
}

.peligent-ai-fullscreen-close {
    background: #ffffff !important;
    color: #6b7280 !important;
    padding: 6px !important;
}

.peligent-ai-fullscreen-close:hover {
    background: #fee2e2 !important;
    color: #dc2626 !important;
}

/* Loading background for iframe container in fullscreen */
.peligent-ai-fixed-sidebar.peligent-ai-fullscreen .peligent-ai-iframe-container {
    background: #f8fafc !important;
}
.peligent-ai-fixed-sidebar.peligent-ai-fullscreen .peligent-ai-resize-handle {
    display: none !important;
}
/* Hidden state */
.peligent-ai-fixed-sidebar.peligent-ai-hidden {
    display: none !important;
}
/* Resize handle */
.peligent-ai-resize-handle {
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    bottom: 0 !important;
    width: 4px !important;
    cursor: col-resize !important;
    background: transparent !important;
    z-index: 160000 !important;
}
.peligent-ai-resize-handle:hover {
    background: rgba(37, 99, 235, 0.2) !important;
}
.peligent-ai-resize-handle:active {
    background: rgba(37, 99, 235, 0.4) !important;
}
/* Adjust for WordPress admin bar */
html[class*="admin-bar"] .peligent-ai-fixed-sidebar {
    top: 32px !important;
    height: calc(100vh - 32px) !important;
}
@media screen and (max-width: 782px) {
    html[class*="admin-bar"] .peligent-ai-fixed-sidebar {
        top: 46px !important;
        height: calc(100vh - 46px) !important;
    }
}
.peligent-ai-sidebar-header {
    background: #111827 !important;
    padding: 16px 20px !important;
    border-bottom: 1px solid #1f2937 !important;
    flex-shrink: 0 !important;
}
.peligent-ai-header-btn:hover {
    opacity: 1 !important;
}
.peligent-ai-header-btn:active {
    opacity: 0.6 !important;
}
.peligent-ai-iframe-container {
    flex: 1 !important;
    overflow: hidden !important;
    background: #ffffff !important;
    position: relative !important;
    display: flex !important;
    flex-direction: column !important;
    min-height: 0 !important;
}
.peligent-ai-iframe {
    width: 100% !important;
    height: 100% !important;
    border: 0 !important;
    display: block !important;
    flex: 1 !important;
    min-height: 0 !important;
}
/* Adjust WordPress admin content to account for sidebar on all pages - LTR only */
/* RTL styles are handled in peligent-rtl.css */
html:not([dir="rtl"]) body.wp-admin:not(.peligent-ai-sidebar-hidden) #wpcontent,
html:not([dir="rtl"]) body.wp-admin:not(.peligent-ai-sidebar-hidden) #wpbody-content {
    margin-right: 480px !important;
    transition: margin-right 0.2s ease !important;
}
html:not([dir="rtl"]) body.wp-admin.folded:not(.peligent-ai-sidebar-hidden) #wpcontent,
html:not([dir="rtl"]) body.wp-admin.folded:not(.peligent-ai-sidebar-hidden) #wpbody-content {
    margin-right: 480px !important;
}
html:not([dir="rtl"]) body.wp-admin.peligent-ai-sidebar-hidden #wpcontent,
html:not([dir="rtl"]) body.wp-admin.peligent-ai-sidebar-hidden #wpbody-content {
    margin-right: 0 !important;
}
html:not([dir="rtl"]) body.wp-admin.peligent-ai-fullscreen #wpcontent,
html:not([dir="rtl"]) body.wp-admin.peligent-ai-fullscreen #wpbody-content {
    margin-right: 0 !important;
}
/* Admin bar chat icon styling */
#wpadminbar #wp-admin-bar-peligent-chat .ab-icon {
    margin-right: 6px !important;
}
#wpadminbar #wp-admin-bar-peligent-chat .ab-icon {
    width: 20px !important;
    height: 20px !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
}
#wpadminbar #wp-admin-bar-peligent-chat .ab-icon img {
    width: 20px !important;
    height: 20px !important;
    max-width: 20px !important;
    max-height: 20px !important;
    display: block !important;
    object-fit: contain !important;
}
#wpadminbar #wp-admin-bar-peligent-chat .ab-icon svg {
    fill: currentColor !important;
}
/* Hide sidebar on mobile/tablet and adjust margins */
@media (max-width: 782px) {
    .peligent-ai-fixed-sidebar {
        display: none !important;
    }
    /* Remove margin when sidebar is hidden on mobile */
    body.wp-admin #wpcontent,
    body.wp-admin #wpbody-content {
        margin-right: 0 !important;
        margin-left: 0 !important;
    }
    .media-modal {
        right: 0 !important;
        left: 0 !important;
    }
}
/* Loading overlay */
.peligent-loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000000;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 20px;
}
.peligent-loading-spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: #2663EB;
    border-radius: 50%;
    animation: peligent-spin 0.8s linear infinite;
}
@keyframes peligent-spin {
    to { transform: rotate(360deg); }
}
.peligent-loading-text {
    color: #ffffff;
    font-size: 16px;
    font-weight: 500;
}
/* Initially hidden sidebar - will be shown if localStorage says so */
.peligent-ai-fixed-sidebar.peligent-ai-initially-hidden {
    display: none !important;
}


/* Floating toggle button for sidebar on all admin pages */
.peligent-floating-toggle {
    position: fixed;
    bottom: 36px;
    right: 36px;
    z-index: 99990;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #2563eb;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
    transition: transform 0.2s, box-shadow 0.2s;
}
.peligent-floating-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 16px rgba(37, 99, 235, 0.5);
}
.peligent-floating-toggle img {
    width: 26px;
    height: 26px;
}
.rtl .peligent-floating-toggle {
    right: auto;
    left: 36px;
}
@media (max-width: 1200px) {
    .peligent-floating-toggle {
        bottom: 24px;
        right: 24px;
        width: 44px;
        height: 44px;
    }
    .peligent-floating-toggle img { width: 22px; height: 22px; }
    .rtl .peligent-floating-toggle { right: auto; left: 24px; }
}
@media (max-width: 960px) {
    .peligent-floating-toggle {
        bottom: 16px;
        right: 16px;
        width: 40px;
        height: 40px;
    }
    .peligent-floating-toggle img { width: 20px; height: 20px; }
    .rtl .peligent-floating-toggle { right: auto; left: 16px; }
}
@media (max-width: 782px) {
    .peligent-floating-toggle {
        bottom: 12px;
        right: 12px;
        width: 38px;
        height: 38px;
    }
    .peligent-floating-toggle img { width: 18px; height: 18px; }
    .rtl .peligent-floating-toggle { right: auto; left: 12px; }
}
