/* ============================================
   LAYOUT FIXES - CENTERED & BALANCED CONTENT
   Ensures all pages use consistent, centered layouts
   ============================================ */

/* ============================================
   MAIN CONTAINER SYSTEM
   ============================================ */
.nxl-container {
    width: 100%;
    min-height: calc(100vh - 64px);
    display: flex;
    flex-direction: column;
    margin-top: 64px;
}

.nxl-content {
    flex: 1;
    width: 100%;
    padding: 0;
    position: relative;
}

/* ============================================
   CONTENT CENTERING & MAX-WIDTH
   ============================================ */
.main-content {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    padding: 2rem;
}

/* Ensure content area uses proper grid/flex */
.main-content .row {
    margin-left: 0;
    margin-right: 0;
}

.main-content .row > [class*="col-"] {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}

/* ============================================
   RESPONSIVE CONTAINER SYSTEM
   ============================================ */
@media (min-width: 1200px) {
    .main-content {
        max-width: 1400px;
        margin: 0 auto;
        padding: 2rem 3rem;
    }
}

@media (min-width: 1600px) {
    .main-content {
        max-width: 1600px;
    }
}

/* ============================================
   CARD & TABLE LAYOUTS
   ============================================ */
.card {
    width: 100%;
    margin-bottom: 1.5rem;
}

.card-body {
    width: 100%;
}

.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Ensure tables don't break layout */
table {
    width: 100%;
    table-layout: auto;
}

/* ============================================
   FIX ONE-SIDED CONTENT ISSUES
   ============================================ */
/* Remove any hardcoded left/right positioning that causes drift */
.nxl-content > * {
    position: relative;
}

/* Ensure flex containers are balanced */
.tw-flex {
    display: flex;
}

.tw-flex-col {
    flex-direction: column;
}

.tw-items-center {
    align-items: center;
}

.tw-justify-center {
    justify-content: center;
}

.tw-justify-between {
    justify-content: space-between;
}

/* ============================================
   GRID SYSTEM FIXES
   ============================================ */
/* Ensure Bootstrap grid works properly */
.row {
    display: flex;
    flex-wrap: wrap;
    margin-left: -0.75rem;
    margin-right: -0.75rem;
}

.row > * {
    flex-shrink: 0;
    width: 100%;
    max-width: 100%;
    padding-left: 0.75rem;
    padding-right: 0.75rem;
}

/* ============================================
   MOBILE RESPONSIVE FIXES
   ============================================ */
@media (max-width: 768px) {
    .main-content {
        width: 100%;
        max-width: 100%;
        padding: 1rem;
    }
    
    /* Stack columns on mobile */
    .row > [class*="col-"] {
        flex: 0 0 100%;
        max-width: 100%;
    }
    
    /* Ensure cards are full width on mobile */
    .card {
        margin-left: 0;
        margin-right: 0;
    }
}

/* ============================================
   TABLET RESPONSIVE FIXES
   ============================================ */
@media (min-width: 769px) and (max-width: 1199px) {
    .main-content {
        max-width: 100%;
        padding: 1.5rem;
    }
}

/* ============================================
   PREVENT LAYOUT SHIFT
   ============================================ */
/* Reserve space for dynamic content */
#ajax-content {
    min-height: 200px;
    position: relative;
}

/* Prevent content jump on load */
.table-responsive {
    min-height: 100px;
}

/* ============================================
   CENTERED EMPTY STATES
   ============================================ */
.empty-state,
.error-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    max-width: 600px;
    margin: 2rem auto;
    text-align: center;
}

/* ============================================
   FIX ABSOLUTE POSITIONING ISSUES
   ============================================ */
/* Ensure absolute positioned elements don't break layout */
.nxl-content [style*="position: absolute"] {
    position: relative !important;
}

/* Only allow absolute positioning in specific contexts */
.modal,
.dropdown-menu,
.tooltip {
    position: absolute;
}

/* ============================================
   OVERFLOW FIXES
   ============================================ */
body {
    overflow-x: hidden;
}

.nxl-container {
    overflow-x: hidden;
}

.nxl-content {
    overflow-x: hidden;
}

/* Allow horizontal scroll only for tables */
.table-responsive {
    overflow-x: auto;
    overflow-y: visible;
}

/* ============================================
   DARK MODE COMPATIBILITY
   ============================================ */
.app-skin-dark .nxl-content,
.dark-theme .nxl-content {
    background: var(--bg-page, #1a1d29) !important;
}

.app-skin-dark .main-content,
.dark-theme .main-content {
    color: var(--text-main, #e4e6eb);
}

.app-skin-dark .card,
.dark-theme .card {
    background: var(--bg-card, #252836);
    border-color: var(--border-color, #2d3142);
}

.app-skin-dark .table,
.dark-theme .table {
    color: var(--text-main, #e4e6eb);
}

.app-skin-dark .table thead th,
.dark-theme .table thead th {
    color: var(--text-muted, #9ca3af);
    border-color: var(--border-color, #2d3142);
}

.app-skin-dark .table tbody td,
.dark-theme .table tbody td {
    border-color: var(--border-color, #2d3142);
}

/* ============================================
   AJAX CONTENT CENTERING FIXES
   ============================================ */
/* Ensure AJAX-loaded content maintains proper layout */
.nxl-content {
    box-sizing: border-box;
    margin-left: 0;
    margin-right: 0;
    padding: 0;
}

/* Prevent content from drifting to one side after AJAX load */
.nxl-content .main-content {
    margin-left: auto;
    margin-right: auto;
    padding-left: 0;
    padding-right: 0;
}

/* Ensure all direct children of .nxl-content are properly aligned */
.nxl-content > .main-content,
.nxl-content > .row,
.nxl-content > .card {
    margin-left: auto;
    margin-right: auto;
}

/* Fix for content that might have hardcoded positioning */
.nxl-content [style*="left"],
.nxl-content [style*="right"] {
    position: relative !important;
    left: auto !important;
    right: auto !important;
}

/* Ensure flex containers maintain center alignment */
.nxl-content .tw-flex {
    justify-content: flex-start;
}

.nxl-content .tw-flex.tw-justify-center {
    justify-content: center;
}

.nxl-content .tw-flex.tw-justify-between {
    justify-content: space-between;
}

/* Prevent width issues after AJAX injection */
.nxl-content * {
    max-width: 100%;
    box-sizing: border-box;
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .nxl-content {
        padding: 0;
        max-width: 100%;
    }
    
    .main-content {
        max-width: 100%;
    }
}

