/* ============================================
   COMPLETE LAYOUT FIXES & ENHANCEMENTS
   For Fleet Document Management System
============================================ */

/* ========== ROOT VARIABLES & RESET ========== */
:root {
    /* Layout Variables */
    --sidebar-width: 250px;
    --header-height: 70px;
    --footer-height: 60px;
    --content-padding: 20px;
    
    /* Breakpoints */
    --breakpoint-mobile: 991.98px;
    
    /* Transitions */
    --transition-base: 0.3s ease;
}

/* ========== BASE LAYOUT FIXES ========== */
/* Prevent horizontal scroll on body */
body {
    overflow-x: hidden !important;
    width: 100% !important;
    max-width: 100vw !important;
    position: relative !important;
}

/* Layout wrapper - main container */
#layout-wrapper {
    margin-left: 0 !important;
    padding-left: 0 !important;
    width: 100% !important;
    min-height: 100vh;
    position: relative;
    transition: margin-left var(--transition-base);
    background: linear-gradient(135deg, #f5f7fa 0%, #f0f4f8 100%);
}

/* In your global styles.css or base template */
.badge-court-virtual {
    background-color: #9c27b0;
    color: white;
}

.badge-court-regular {
    background-color: #2196f3;
    color: white;
}

.badge-court-other {
    background-color: #00bcd4;
    color: white;
}

.badge-department-traffic {
    background-color: #ff9800;
    color: white;
}

.badge-department-transport {
    background-color: #4caf50;
    color: white;
}

.badge-direct-challan {
    background-color: #9e9e9e;
    color: white;
}

.badge-other-dept {
    background-color: #607d8b;
    color: white;
}

.status-pending {
    background-color: #ffc107;
    color: #212529;
}

.status-disposed {
    background-color: #28a745;
    color: white;
}

/* Common styling classes */
.stats-card {
    border-radius: 10px;
    transition: transform 0.3s, box-shadow 0.3s;
}

.stats-card:hover {
    transform: translateY(-5px);
    box-shadow: 0 10px 20px rgba(0,0,0,0.1) !important;
}

.challan-table-row {
    cursor: pointer;
    transition: background-color 0.2s;
}

/* ========== SIDEBAR LAYOUT (DESKTOP) ========== */
/* Sidebar styling */
.app-menu {
    width: var(--sidebar-width);
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 1001;
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
    transform: translateX(0);
    transition: transform var(--transition-base);
}

/* Adjust layout when sidebar is visible */
/* [data-sidebar-size="lg"] #layout-wrapper {
    margin-left: var(--sidebar-width) !important;
    width: calc(100% - var(--sidebar-width)) !important;
} */

/* Adjust header with sidebar */
/* [data-sidebar-size="lg"] #page-topbar {
    left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
} */

/* ========== HEADER FIXES ========== */
#page-topbar {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    height: var(--header-height);
    z-index: 1002 !important;
    transition: left var(--transition-base), width var(--transition-base);
    background: linear-gradient(135deg, #1a237e 0%, #3949ab 100%);
    backdrop-filter: blur(10px);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* ========== CONTENT AREA FIXES ========== */
/* Main content wrapper (everything except sidebar and overlay) */
#layout-wrapper > div:not(.app-menu):not(.vertical-overlay) {
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height) - var(--footer-height));
    padding-top: var(--content-padding);
    padding-bottom: var(--content-padding);
}

/* Content containers */
.container-fluid {
    padding: var(--content-padding) !important;
    max-width: 100% !important;
    width: 100% !important;
}

.container-fluid,
.container-sm,
.container-md,
.container-lg,
.container-xl {
    margin-left: auto !important;
    margin-right: auto !important;
    padding-left: var(--content-padding) !important;
    padding-right: var(--content-padding) !important;
}

/* ========== MOBILE RESPONSIVENESS ========== */
@media (max-width: 991.98px) {
    /* Hide sidebar by default on mobile */
    .app-menu {
        left: -100% !important;
        transform: translateX(-100%);
        width: 280px;
        z-index: 1005 !important;
    }
    
    /* Show sidebar when toggled */
    .app-menu.show {
        left: 0 !important;
        transform: translateX(0);
    }
    
    /* Full width content on mobile */
    #layout-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
    }
    
    /* Full width header on mobile */
    #page-topbar {
        left: 0 !important;
        width: 100% !important;
    }
    
    /* Mobile overlay */
    .vertical-overlay {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 1004;
        display: none;
        backdrop-filter: blur(2px);
    }
    
    .vertical-overlay.show {
        display: block;
    }
    
    /* Adjust content padding on mobile */
    .container-fluid {
        padding: 15px !important;
    }
}

/* ========== CONTENT ELEMENTS OVERFLOW PREVENTION ========== */
/* Grid system fixes */
.row {
    margin-right: -12px;
    margin-left: -12px;
    display: flex;
    flex-wrap: wrap;
}

.row > [class*="col-"] {
    padding-right: 12px;
    padding-left: 12px;
    position: relative;
    width: 100%;
    min-height: 1px;
}

/* Card overflow prevention */
.card {
    max-width: 100% !important;
    overflow: hidden !important;
    border: none;
    border-radius: 0.75rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    transition: all 0.3s ease;
}

.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

/* Table overflow handling */
.table-responsive {
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch !important;
    border-radius: 0.5rem;
    border: 1px solid #e2e8f0;
}

.table {
    min-width: 600px;
    margin-bottom: 0;
}

.table thead th {
    background: linear-gradient(135deg, #1a237e 0%, #3949ab 100%);
    color: white;
    border: none;
    padding: 1rem;
    font-weight: 600;
}

/* Form elements overflow prevention */
.form-control,
.form-select {
    max-width: 100% !important;
    width: 100% !important;
    border: 2px solid #e2e8f0;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    transition: all 0.3s ease;
}

.form-control:focus,
.form-select:focus {
    border-color: #3949ab;
    box-shadow: 0 0 0 0.2rem rgba(57, 73, 171, 0.25);
}

/* Input groups */
.input-group {
    max-width: 100% !important;
    width: 100% !important;
}

/* Button groups */
.btn-group {
    flex-wrap: wrap !important;
    gap: 0.5rem !important;
}

.btn-group .btn {
    margin: 2px;
}

/* ========== STICKY FOOTER IMPLEMENTATION ========== */
html, body {
    height: 100%;
}

#layout-wrapper {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* Main content area */
#layout-wrapper > div:not(.app-menu):not(.vertical-overlay) {
    flex: 1 0 auto;
}

/* Footer */
.footer {
    flex-shrink: 0;
    background: linear-gradient(180deg, #1a1a2e 0%, #16213e 100%);
    color: rgba(255, 255, 255, 0.8);
    padding: 1.5rem 0;
    margin-top: auto;
}

/* ========== Z-INDEX MANAGEMENT ========== */
/* Ensure proper stacking order */
.app-menu {
    z-index: 1001 !important;
}

#page-topbar {
    z-index: 1002 !important;
}

.vertical-overlay {
    z-index: 1004 !important;
}

.modal {
    z-index: 1060 !important;
}

.dropdown-menu {
    z-index: 1050 !important;
}

/* ========== PRINT STYLES ========== */
@media print {
    /* Hide non-essential elements */
    .app-menu,
    #page-topbar,
    .vertical-overlay,
    .no-print {
        display: none !important;
    }
    
    /* Reset layout for printing */
    #layout-wrapper {
        margin-left: 0 !important;
        width: 100% !important;
    }
    
    /* Reset positioning */
    #page-topbar {
        position: static !important;
        left: 0 !important;
        width: 100% !important;
    }
    
    /* Remove backgrounds and shadows for printing */
    .card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
    }
    
    .table {
        border: 1px solid #000 !important;
    }
    
    /* Ensure content is visible */
    .container-fluid {
        padding: 0 !important;
        margin: 0 !important;
    }
}

/* ========== UTILITY CLASSES ========== */
/* Clear floats */
.clearfix::after {
    content: "";
    clear: both;
    display: table;
}

/* Text truncation */
.text-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Loading state */
.loading {
    position: relative;
    opacity: 0.7;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid rgba(0, 0, 0, 0.1);
    border-top-color: #3949ab;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Smooth scroll for anchor links */
html {
    scroll-behavior: smooth;
    scroll-padding-top: calc(var(--header-height) + 20px);
}

/* Selection styling */
::selection {
    background-color: rgba(57, 73, 171, 0.2);
    color: #1a237e;
}

/* Focus outlines for accessibility */
:focus {
    outline: 2px solid #3949ab;
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

/* ========== CUSTOM SCROLLBAR ========== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #1a237e 0%, #3949ab 100%);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #3949ab;
}

/* Sidebar specific scrollbar */
.app-menu::-webkit-scrollbar {
    width: 6px;
}

.app-menu::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.1);
}

.app-menu::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
}

.app-menu::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* ========== DARK MODE SUPPORT ========== */
@media (prefers-color-scheme: dark) {
    body {
        background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);
        color: #e2e8f0;
    }
    
    .card {
        background: #1e293b;
        border-color: #334155;
        color: #e2e8f0;
    }
    
    .table {
        background: #1e293b;
        color: #e2e8f0;
        border-color: #334155;
    }
    
    .table thead th {
        background: linear-gradient(135deg, #2d3748 0%, #4a5568 100%);
    }
    
    .form-control,
    .form-select {
        background: #334155;
        border-color: #475569;
        color: #e2e8f0;
    }
    
    .form-control:focus,
    .form-select:focus {
        border-color: #6366f1;
        box-shadow: 0 0 0 0.2rem rgba(99, 102, 241, 0.25);
    }
}

/* ========== PERFORMANCE OPTIMIZATIONS ========== */
/* Hardware acceleration for animations */
.app-menu,
#page-topbar,
.card {
    transform: translateZ(0);
    backface-visibility: hidden;
}

/* Reduce motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ========== FIX FOR SPECIFIC ELEMENTS ========== */
/* Fix for images not exceeding container */
img {
    max-width: 100%;
    height: auto;
}

/* Fix for iframes and embeds */
iframe,
embed,
object {
    max-width: 100%;
}

/* Fix for pre/code blocks */
pre,
code {
    white-space: pre-wrap;
    word-wrap: break-word;
    max-width: 100%;
}

/* Fix for long words/URLs */
.text-break {
    word-wrap: break-word;
    word-break: break-word;
    overflow-wrap: break-word;
}

/* ========== ERROR STATE VISUALIZATION (DEBUG) ========== */
/* Uncomment to debug layout issues */
/*
.layout-debug #layout-wrapper {
    outline: 2px solid red !important;
}

.layout-debug .app-menu {
    outline: 2px solid blue !important;
}

.layout-debug #page-topbar {
    outline: 2px solid orange !important;
}

.layout-debug .container-fluid {
    outline: 2px solid green !important;
}
*/