/**
 * Frontend styles for Mibooko Engine
 */

/* React App container - Basic container styling only */
#mibooko-wp-embed.mibooko-react-app-container,
.mibooko-react-app-container {
    /* Basic container styles */
    width: 100% !important;
    min-height: 800px !important;
    background: #fff !important;
    border: 1px solid #ddd !important;
    border-radius: 8px !important;
    margin: 20px auto !important;
    position: relative !important;
    z-index: 990 !important;
    max-width: none !important;
    display: block !important;
    padding: 0 !important;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1) !important;
    
    /* Create new stacking context for z-index */
    isolation: isolate !important;
}


/* React app root - React will mount here */
#mibooko-wp-embed #mibooko-app-root,
#mibooko-app-root {
    /* Basic layout only, no style resets */
    width: 100% !important;
    min-height: 800px !important;
    display: block !important;
    position: relative !important;
    z-index: 1000 !important;
}

/* Handle fixed positioned elements - convert to absolute within container */
/* This makes them positioned relative to the container instead of viewport */
.mibooko-react-app-container .fixed {
    position: absolute !important;
}

/* Specific overrides for shadcn/ui components that use fixed positioning */
.mibooko-react-app-container [data-radix-popper-content-wrapper],
.mibooko-react-app-container [role="dialog"],
.mibooko-react-app-container [role="alertdialog"],
.mibooko-react-app-container [data-sonner-toaster] {
    position: absolute !important;
}

/* Toast notifications - keep at top of container */
.mibooko-react-app-container [data-sonner-toaster] {
    top: 16px !important;
    right: 16px !important;
}

/* Dialog overlays - cover the container, not the whole page */
.mibooko-react-app-container [data-radix-overlay] {
    position: absolute !important;
    inset: 0 !important;
}

/* Ensure sticky headers work within container */
.mibooko-react-app-container .sticky {
    position: sticky !important;
    top: 0 !important;
    z-index: 10 !important;
}

/* Iframe container */
.mibooko-iframe-container {
    position: relative;
    width: 100%;
    margin: 20px 0;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

/* Iframe styling */
.mibooko-iframe-container iframe {
    display: block;
    width: 100%;
    border: none;
    background: #fff;
}

/* Custom height overrides */
.mibooko-iframe-container[data-height] {
    padding-bottom: 0;
    height: auto;
}

.mibooko-iframe-container[data-height] iframe {
    position: static;
    height: var(--iframe-height, 600px);
}

/* Loading state */
.mibooko-iframe-container.loading::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #0073aa;
    border-radius: 50%;
    animation: mibooko-spin 1s linear infinite;
    z-index: 10;
}

.mibooko-iframe-container.loading::after {
    content: 'Ładowanie Mibooko...';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    margin-top: 30px;
    color: #666;
    font-size: 14px;
    z-index: 10;
}

@keyframes mibooko-spin {
    0% { transform: translate(-50%, -50%) rotate(0deg); }
    100% { transform: translate(-50%, -50%) rotate(360deg); }
}

/* Notifications */
.mibooko-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #0073aa;
    color: white;
    padding: 15px 20px;
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    z-index: 9999;
    max-width: 400px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.mibooko-notification-message {
    flex: 1;
    margin-right: 10px;
}

.mibooko-notification-close {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mibooko-notification-close:hover {
    opacity: 0.8;
}

/* Error notifications */
.mibooko-error {
    position: fixed;
    top: 20px;
    right: 20px;
    background: #dc3232;
    color: white;
    padding: 15px 20px;
    border-radius: 4px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    z-index: 9999;
    max-width: 400px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.mibooko-error-message {
    flex: 1;
    margin-right: 10px;
}

.mibooko-error-close {
    background: none;
    border: none;
    color: white;
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mibooko-error-close:hover {
    opacity: 0.8;
}

/* Mobile responsiveness */
@media screen and (max-width: 768px) {
    .mibooko-react-app-container {
        margin: 10px 0;
        border-radius: 4px;
        min-height: 600px;
    }
    
    #mibooko-app-root {
        min-height: 600px;
    }
    
    .mibooko-iframe-container {
        margin: 10px 0;
        border-radius: 4px;
    }
    
    .mibooko-notification,
    .mibooko-error {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }
    
    .mibooko-notification-message,
    .mibooko-error-message {
        font-size: 14px;
    }
}

/* Print styles */
@media print {
    .mibooko-react-app-container,
    .mibooko-iframe-container {
        display: none;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .mibooko-react-app-container,
    .mibooko-iframe-container {
        border: 2px solid #000;
    }
    
    .mibooko-notification {
        border: 2px solid #000;
    }
    
    .mibooko-error {
        border: 2px solid #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .mibooko-iframe-container.loading::before {
        animation: none;
    }
    
    .mibooko-notification,
    .mibooko-error {
        transition: none;
    }
}
