/* Embed Modal Styles */
/* Modal Size Fix */
.modal-xl .modal-body {
    min-height: 60vh;
    padding: 2rem;
}

.modal-xl .modal-content {
    min-height: 80vh;
}

#embedPreview {
    min-height: 500px;
}

.embed-modal-expanded #embedPreview {
    height: 600px;
}

.embed-modal-expanded .preview-expand-btn i {
    transform: rotate(180deg);
}

/* Copy Button States */
.copy-success {
    background-color: #50cd89 !important;
    color: white !important;
    border-color: #50cd89 !important;
}

.copy-success i {
    display: none;
}

.copy-success::after {
    content: "✓ Copied";
}

/* Embed Preview Container */
.embed-preview-container {
    transition: height 0.3s ease;
}

/* Embed Code Textarea */
#embedCodeArea {
    resize: none;
    white-space: pre-wrap;
    word-break: break-all;
    font-family: 'Courier New', Courier, monospace;
    font-size: 12px;
    line-height: 1.4;
    background-color: #f8f9fa;
    border: 1px solid #e9ecef;
}

/* Copy Button Animation */
.copy-btn {
    transition: all 0.2s ease;
    position: relative;
}

.copy-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.copy-btn:active {
    transform: scale(0.95);
}

/* CRITICAL: Force backdrop removal */
.modal-backdrop {
    z-index: 1040 !important;
}

.modal-backdrop.show {
    opacity: 0.5 !important;
}

/* Force remove ANY backdrop that shouldn't be there */
body:not(.modal-open) .modal-backdrop {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
}

/* Ensure modal z-index */
.modal {
    z-index: 1050 !important;
}

.modal.show {
    display: block !important;
}

/* CRITICAL: Body state management */
body.modal-open {
    overflow: hidden !important;
}

body:not(.modal-open) {
    overflow: auto !important;
    padding-right: 0 !important;
    margin-right: 0 !important;
}

/* Force hidden state for modal when not shown */
.modal:not(.show) {
    display: none !important;
}

/* Chart Embed Styles */
.chart-embed-container {
    width: 100%;
    height: 100%;
    border-radius: 8px;
    overflow: hidden;
    background: white;
}

.chart-embed-title {
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    color: #333;
    margin: 10px 0;
    padding: 0 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chart-embed-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: white;
    border-radius: 8px;
    padding: 10px;
    min-height: 300px;
}

.chart-embed-footer {
    position: absolute;
    bottom: 5px;
    right: 10px;
    font-size: 11px;
    color: #999;
    text-decoration: none;
    z-index: 10;
}

.chart-embed-footer:hover {
    color: #3E97FF;
    text-decoration: none;
}

/* Embed Preview Iframe Styling */
#embedPreview {
    border: 1px solid #e9ecef;
    border-radius: 8px;
    background: white;
    transition: height 0.3s ease;
}

/* Modal Content Improvements */
#embedModal .modal-content {
    border: none;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

#embedModal .modal-header {
    border-bottom: 1px solid #f1f3f4;
    padding: 1.5rem 1.5rem 1rem;
}

#embedModal .modal-body {
    padding: 1rem 1.5rem;
}

#embedModal .modal-footer {
    border-top: 1px solid #f1f3f4;
    padding: 1rem 1.5rem 1.5rem;
}

/* Tab Styling */
#embedModal .nav-tabs {
    border-bottom: 1px solid #e9ecef;
}

#embedModal .nav-tabs .nav-link {
    border: none;
    border-bottom: 2px solid transparent;
    color: #6c757d;
    font-weight: 500;
}

#embedModal .nav-tabs .nav-link.active {
    color: #3E97FF;
    border-bottom-color: #3E97FF;
    background: none;
}

#embedModal .nav-tabs .nav-link:hover {
    color: #3E97FF;
    border-bottom-color: rgba(62, 151, 255, 0.3);
}

/* Form Elements */
#embedModal .form-control,
#embedModal .form-select {
    border: 1px solid #e9ecef;
    border-radius: 6px;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

#embedModal .form-control:focus,
#embedModal .form-select:focus {
    border-color: #3E97FF;
    box-shadow: 0 0 0 0.2rem rgba(62, 151, 255, 0.25);
}

/* Switch Styling */
#embedModal .form-check-input:checked {
    background-color: #3E97FF;
    border-color: #3E97FF;
}

/* Responsive Improvements */
@media (max-width: 768px) {
    #embedModal .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }

    #embedModal .modal-body {
        padding: 1rem;
    }

    #embedCodeArea {
        font-size: 11px;
    }

    .chart-embed-title {
        font-size: 14px;
    }
}

/* Loading State */
.embed-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
}

.embed-loading .spinner-border {
    width: 2rem;
    height: 2rem;
    color: #3E97FF;
}

/* Error State */
.embed-error {
    text-align: center;
    padding: 2rem;
    color: #dc3545;
}

.embed-error i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

/* Prevent modal flickering - IMPROVED */
.modal.fade .modal-dialog {
    transition: transform 0.15s ease-out;
    transform: translate(0, -25px);
}

.modal.show .modal-dialog {
    transform: none;
}

/* Ensure proper z-index stacking - CRITICAL */
.modal-backdrop {
    z-index: 1040 !important;
}

.modal {
    z-index: 1050 !important;
}

/* Emergency cleanup styles - CRITICAL */
.modal-backdrop:not(.show) {
    display: none !important;
}

/* Force cleanup any stuck elements */
.modal-backdrop.fade:not(.show) {
    opacity: 0 !important;
    display: none !important;
}

/* Custom scrollbar for code textarea */
#embedCodeArea::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

#embedCodeArea::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

#embedCodeArea::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

#embedCodeArea::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Button improvements */
.btn.copy-btn {
    white-space: nowrap;
    min-width: 100px;
}

/* Preview container improvements */
.bg-light {
    background-color: #f8f9fa !important;
}

/* Ensure iframe responsiveness */
iframe {
    max-width: 100%;
    height: auto;
}

/* EMERGENCY: Remove any stuck modal states */
@keyframes forceHideBackdrop {
    to {
        opacity: 0 !important;
        visibility: hidden !important;
        display: none !important;
    }
}

.modal-backdrop.stuck {
    animation: forceHideBackdrop 0.1s forwards;
}
