/**
 * Side Panel Component
 * Smooth sliding panel from the right edge of viewport
 * Replaces Bootstrap modal functionality
 */

/* Overlay backdrop */
.side-panel-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 9998; /* Increased from 1049 to ensure it's above all content */
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease-in-out, visibility 0.3s ease-in-out;
}

.side-panel-overlay.active {
    opacity: 1;
    visibility: visible;
}

/* Side panel container */
.side-panel {
    position: fixed;
    top: 0;
    right: 0;
    height: 100%;
    width: 100%;
    max-width: 800px; /* Increased from 600px to 800px for wider panel */
    background-color: #fff;
    box-shadow: -2px 0 16px rgba(0, 0, 0, 0.15);
    z-index: 9999; /* Increased from 1050 to highest level */
    transform: translateX(100%);
    transition: transform 0.35s cubic-bezier(0.4, 0.0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.side-panel.active {
    transform: translateX(0);
}

/* Panel header */
.side-panel-header {
    padding: 1.5rem;
    border-bottom: 1px solid #e7e7e7;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    background-color: #fff;
    position: sticky;
    top: 0;
    z-index: 10; /* Ensure header stays above scrolling content */
}

.side-panel-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin: 0;
    color: #333;
}

.side-panel-close {
    background: none;
    border: none;
    padding: 0.5rem;
    cursor: pointer;
    color: #6c757d;
    font-size: 1.5rem;
    line-height: 1;
    transition: color 0.2s ease-in-out;
    display: flex;
    align-items: center;
    justify-content: center;
}

.side-panel-close:hover {
    color: #000;
}

.side-panel-close:focus {
    outline: 2px solid #0d6efd;
    outline-offset: 2px;
}

/* Panel body - scrolling content area */
.side-panel-body {
    padding: 1.5rem;
    overflow-y: scroll; /* Enable vertical scrolling */
    overflow-x: hidden; /* Prevent horizontal scrolling */
    flex: 1; /* Takes remaining space between header and footer */
    overscroll-behavior: contain; /* Prevent scroll chaining */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

/* Custom scrollbar styling */
.side-panel-body::-webkit-scrollbar {
    width: 8px;
}

.side-panel-body::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.side-panel-body::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.side-panel-body::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* Panel footer */
.side-panel-footer {
    padding: 1.5rem;
    border-top: 1px solid #e7e7e7;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.75rem;
    flex-shrink: 0;
    background-color: #fff;
    position: sticky;
    bottom: 0;
    z-index: 10; /* Ensure footer stays above scrolling content */
}

/* Responsive adjustments */
@media (max-width: 992px) {
    .side-panel {
        max-width: 700px; /* Slightly narrower on tablets */
    }
}

@media (max-width: 768px) {
    .side-panel {
        max-width: 100%;
        width: 100%;
    }
    
    .side-panel-header,
    .side-panel-body,
    .side-panel-footer {
        padding: 1rem;
    }
}

/* Dark theme support */
@media (prefers-color-scheme: dark) {
    .side-panel {
        background-color: #1a1a1a;
    }
    
    .side-panel-header,
    .side-panel-footer {
        background-color: #1a1a1a;
        border-color: #333;
    }
    
    .side-panel-title {
        color: #fff;
    }
    
    .side-panel-close {
        color: #adb5bd;
    }
    
    .side-panel-close:hover {
        color: #fff;
    }
    
    .side-panel-body::-webkit-scrollbar-track {
        background: #2a2a2a;
    }
    
    .side-panel-body::-webkit-scrollbar-thumb {
        background: #555;
    }
    
    .side-panel-body::-webkit-scrollbar-thumb:hover {
        background: #666;
    }
}

/* Prevent body scroll when panel is open */
body.side-panel-open {
    overflow: hidden;
}

/* Animation improvements */
@media (prefers-reduced-motion: reduce) {
    .side-panel,
    .side-panel-overlay {
        transition: none;
    }
}

/* ============================================================================
   OFFCANVAS OVERRIDE
   Applies 90% width to Bootstrap offcanvas component
   ============================================================================ */
.offcanvas-tabbed-edit {
    width: 90% !important;
    max-width: 90% !important;
}
