/* ========================================
   COMPREHENSIVE HORIZONTAL OVERFLOW FIXES
   FOR ARABIC RTL AUTOMOTIVE SERVICE SYSTEM
   ======================================== */

/* CRITICAL: Global overflow prevention */
html {
    overflow-x: hidden !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
}

body {
    overflow-x: hidden !important;
    max-width: 100vw !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    padding: 0 !important;
}

/* Universal box-sizing and max-width */
* {
    box-sizing: border-box !important;
}

*:not(.table):not(.table *):not(.modal):not(.modal *):not(input[type="checkbox"]):not(.operation-checkbox):not(.part-checkbox):not(.login-page):not(.login-page *):not([class*="login"]):not([class*="login"] *) {
    max-width: 100% !important;
}

/* Specific override for checkboxes to prevent max-width: 100% */
input[type="checkbox"],
.operation-checkbox,
.part-checkbox {
    max-width: 15px !important;
    width: 15px !important;
    min-width: 15px !important;
    height: 15px !important;
    flex: none !important;
    transform: scale(0.7) !important;
}

/* ========================================
   CONTAINER AND LAYOUT FIXES
   ======================================== */

/* Bootstrap containers */
.container,
.container-fluid,
.container-sm,
.container-md,
.container-lg,
.container-xl,
.container-xxl {
    overflow-x: hidden !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    padding-left: 15px !important;
    padding-right: 15px !important;
    margin-left: auto !important;
    margin-right: auto !important;
}

/* Bootstrap grid system */
.row {
    margin-left: 0 !important;
    margin-right: 0 !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
}

/* All column classes */
[class*="col-"] {
    padding-left: 8px !important;
    padding-right: 8px !important;
    max-width: 100% !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
}

/* ========================================
   TABLE LAYOUT FIXES
   ======================================== */

.table-responsive {
    overflow-x: auto !important;
    max-width: 100% !important;
    box-sizing: border-box !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 1px solid #dee2e6 !important;
    border-radius: 0.375rem !important;
}

.table {
    width: 100% !important;
    max-width: 100% !important;
    table-layout: fixed !important;
    box-sizing: border-box !important;
    margin-bottom: 0 !important;
    min-width: 800px !important; /* Minimum width for proper column display */
}

.table th,
.table td {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    white-space: normal !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    padding: 0.5rem 0.25rem !important;
    font-size: 0.875rem !important;
    line-height: 1.25 !important;
}

/* Specific column width controls for better layout */
.table th:nth-child(1), .table td:nth-child(1) { width: 20%; }
.table th:nth-child(2), .table td:nth-child(2) { width: 18%; }
.table th:nth-child(3), .table td:nth-child(3) { width: 10%; }
.table th:nth-child(4), .table td:nth-child(4) { width: 12%; }
.table th:nth-child(5), .table td:nth-child(5) { width: 10%; }
.table th:nth-child(6), .table td:nth-child(6) { width: 15%; }
.table th:nth-child(7), .table td:nth-child(7) { width: 10%; }
.table th:nth-child(8), .table td:nth-child(8) { width: 15%; }

/* ========================================
   MODAL AND POPUP FIXES
   ======================================== */

.modal,
.modal-dialog,
.modal-content {
    max-width: 100% !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
}

.modal-dialog {
    margin: 1rem auto !important;
    max-width: min(90vw, 800px) !important;
    width: 100% !important;
}

.modal-body {
    max-width: 100% !important;
    overflow-x: hidden !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    padding: 1rem !important;
}

/* Notification center modal fixes */
.notification-modal-overlay {
    max-width: 100vw !important;
    overflow-x: hidden !important;
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
}

.notification-modal-overlay .modal-container {
    max-width: min(90vw, 600px) !important;
    margin: 1rem auto !important;
    box-sizing: border-box !important;
    overflow: hidden !important;
}

/* ========================================
   FORM AND INPUT FIXES
   ======================================== */

.form-control,
.form-select,
input,
select,
textarea {
    max-width: 100% !important;
    box-sizing: border-box !important;
    width: 100% !important;
}

/* ========================================
   NAVIGATION AND HEADER FIXES
   ======================================== */

nav,
.navbar,
.nav,
header {
    max-width: 100% !important;
    overflow-x: hidden !important;
    overflow-y: visible !important; /* ADDED: Allow badge to overflow vertically */
    box-sizing: border-box !important;
    min-height: auto !important;
    height: auto !important;
}

/* Specific fix for navigation to allow badge overflow */
nav {
    overflow-y: visible !important;
    position: relative !important;
}

/* Notification button specific fixes to prevent badge clipping */
#notifications-popup-button,
#notifications-dropdown-button {
    position: relative !important;
    overflow: visible !important;
}

/* Ensure navigation container allows badges to show */
nav .flex.items-center {
    overflow: visible !important;
    position: relative !important;
}

/* Additional badge visibility fixes */
#notification-badge {
    z-index: 2147483647 !important; /* MAXIMUM: Highest possible 32-bit integer z-index */
    position: absolute !important;
    top: -8px !important; /* INCREASED: Move further up to be fully visible */
    right: -2px !important; /* ADJUSTED: Move slightly right for better visibility */
    pointer-events: none !important;
    transform: none !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    border: 2px solid white !important; /* REDUCED: Thinner border to reduce overlap */
    box-shadow: 0 4px 12px rgba(0,0,0,0.5) !important; /* ADJUSTED: Strong shadow for visibility */
    width: 24px !important; /* STANDARD: Proper size for readability */
    height: 24px !important; /* STANDARD: Proper size for readability */
    font-size: 0.75rem !important; /* STANDARD: Proper font size */
    background-color: #ef4444 !important; /* ADDED: Ensure red background */
    color: white !important; /* ADDED: Ensure white text */
    font-weight: 700 !important; /* ADDED: Bold text */
    border-radius: 50% !important; /* ADDED: Ensure circular shape */
    visibility: visible !important; /* FORCE: Always visible */
    opacity: 1 !important; /* FORCE: Full opacity */
    line-height: 1 !important; /* ADDED: Ensure text is centered vertically */
}

/* Navigation container fixes */
nav .container,
nav .container-fluid,
header .container,
header .container-fluid {
    overflow-x: hidden !important; /* CHANGED: Only hide horizontal overflow, allow vertical for badge */
    overflow-y: visible !important; /* ADDED: Allow badge to overflow vertically */
    max-height: 4.5rem !important; /* Slightly increased navigation height */
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
}

/* Logo container fixes */
nav a,
header a {
    display: flex !important;
    align-items: center !important;
    overflow: hidden !important;
    max-height: 3rem !important;
    line-height: 1 !important;
}

/* ========================================
   COMPONENT SPECIFIC FIXES
   ======================================== */

/* Cards */
.card,
.card-body,
.card-header,
.card-footer {
    max-width: 100% !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
}

/* Buttons */
.btn,
.button,
button {
    max-width: 100% !important;
    box-sizing: border-box !important;
    white-space: nowrap !important;
}

/* Work Order Material Status Buttons */
.material-item .approve-material-btn,
.material-item .reject-material-btn {
    display: none !important; /* Hide approve/reject buttons on work order side */
}

.material-item .consume-material-btn {
    background-color: #2563eb !important;
    border-color: #2563eb !important;
}

.material-item .return-material-btn {
    background-color: #ea580c !important;
    border-color: #ea580c !important;
}

.material-item .return-material-btn:hover {
    background-color: #c2410c !important;
    border-color: #c2410c !important;
}

/* Status badges for simplified workflow */
.material-item .status-badge {
    font-size: 0.75rem !important;
    padding: 0.25rem 0.5rem !important;
    border-radius: 9999px !important;
    display: inline-flex !important;
    align-items: center !important;
    gap: 0.25rem !important;
}

/* Flex layouts */
.d-flex,
.flex,
.flex-row,
.flex-column {
    max-width: 100% !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
}

/* Text content */
p, h1, h2, h3, h4, h5, h6, span, div {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    hyphens: auto !important;
}

/* Media elements */
img,
video,
iframe,
embed,
object {
    max-width: 100% !important;
    height: auto !important;
    box-sizing: border-box !important;
}

/* ========================================
   SUPPLY CHAIN SPECIFIC FIXES
   ======================================== */

.work-order-spare-parts-section,
.spare-parts-table-container,
.section-header {
    max-width: 100% !important;
    overflow-x: hidden !important;
    box-sizing: border-box !important;
}

.section-header {
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    flex-wrap: wrap !important;
    gap: 1rem !important;
}

.section-actions {
    display: flex !important;
    gap: 0.5rem !important;
    flex-shrink: 0 !important;
}

/* ========================================
   MOBILE RESPONSIVE FIXES
   ======================================== */

/* FIXED: Changed from max-width: 768px to max-width: 767px to exclude tablet */
@media (max-width: 767px) {
    .container,
    .container-fluid {
        padding-left: 10px !important;
        padding-right: 10px !important;
    }

    .modal-dialog {
        margin: 0.5rem !important;
        max-width: calc(100vw - 1rem) !important;
    }

    .table {
        font-size: 0.75rem !important;
        min-width: 600px !important;
    }

    .table th,
    .table td {
        padding: 0.25rem 0.125rem !important;
        font-size: 0.75rem !important;
    }

    .btn {
        font-size: 0.875rem !important;
        padding: 0.5rem 0.75rem !important;
    }

    .section-header {
        flex-direction: column !important;
        align-items: stretch !important;
    }

    .section-actions {
        justify-content: center !important;
    }
}

/* TABLET SPECIFIC FIXES - NEW */
@media (min-width: 768px) and (max-width: 1023px) {
    .container,
    .container-fluid {
        padding-left: 15px !important;
        padding-right: 15px !important;
    }

    .modal-dialog {
        margin: 1rem !important;
        max-width: calc(100vw - 2rem) !important;
    }

    .table {
        font-size: 0.875rem !important;
    }

    .table th,
    .table td {
        padding: 0.5rem 0.375rem !important;
        font-size: 0.875rem !important;
    }
}

@media (max-width: 480px) {
    .container,
    .container-fluid {
        padding-left: 5px !important;
        padding-right: 5px !important;
    }
    
    .modal-dialog {
        margin: 0.25rem !important;
        max-width: calc(100vw - 0.5rem) !important;
    }
    
    .table {
        font-size: 0.7rem !important;
        min-width: 500px !important;
    }
    
    .btn {
        font-size: 0.8rem !important;
        padding: 0.4rem 0.6rem !important;
    }
}

/* ========================================
   RTL SPECIFIC FIXES
   ======================================== */

[dir="rtl"] .table-responsive {
    direction: rtl !important;
}

[dir="rtl"] .modal-dialog {
    text-align: right !important;
}

[dir="rtl"] .section-header {
    text-align: right !important;
}

/* ========================================
   SCROLLBAR FIXES - REMOVE LEFT, KEEP RIGHT
   ======================================== */

/* Global scrollbar positioning for RTL */
html {
    scrollbar-gutter: stable both-edges !important;
}

/* Force scrollbar to right side only in RTL */
[dir="rtl"] html,
[dir="rtl"] body {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    scrollbar-width: thin !important;
    scrollbar-color: #cbd5e1 #f1f5f9 !important;
}

/* Remove left scrollbar, keep right scrollbar */
[dir="rtl"] html::-webkit-scrollbar {
    width: 8px !important;
    height: 0px !important;
}

[dir="rtl"] html::-webkit-scrollbar-track {
    background: #f1f5f9 !important;
    border-radius: 4px !important;
}

[dir="rtl"] html::-webkit-scrollbar-thumb {
    background: #cbd5e1 !important;
    border-radius: 4px !important;
    border: 1px solid #e2e8f0 !important;
}

[dir="rtl"] html::-webkit-scrollbar-thumb:hover {
    background: #94a3b8 !important;
}

/* Ensure no dual scrollbars */
[dir="rtl"] body {
    overflow-y: hidden !important;
    overflow-x: hidden !important;
}

/* Container scrollbar fixes */
[dir="rtl"] .container,
[dir="rtl"] .container-fluid,
[dir="rtl"] .main-content,
[dir="rtl"] .content-wrapper {
    overflow-y: visible !important;
    overflow-x: hidden !important;
}

/* Table container scrollbar positioning */
[dir="rtl"] .table-responsive {
    scrollbar-width: thin !important;
    scrollbar-color: #cbd5e1 #f1f5f9 !important;
}

[dir="rtl"] .table-responsive::-webkit-scrollbar {
    width: 0px !important;
    height: 8px !important;
}

[dir="rtl"] .table-responsive::-webkit-scrollbar-track {
    background: #f1f5f9 !important;
    border-radius: 4px !important;
}

[dir="rtl"] .table-responsive::-webkit-scrollbar-thumb {
    background: #cbd5e1 !important;
    border-radius: 4px !important;
}

/* Modal scrollbar fixes */
[dir="rtl"] .modal-body {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    scrollbar-width: thin !important;
}

[dir="rtl"] .modal-body::-webkit-scrollbar {
    width: 6px !important;
    height: 0px !important;
}

/* Remove scrollbars from navigation */
[dir="rtl"] nav,
[dir="rtl"] header,
[dir="rtl"] .navbar {
    overflow: hidden !important;
}

/* ========================================
   LOGO SIZING FIXES
   ======================================== */

/* Consistent logo sizing across the application */
img[src*="logo.png"],
img[alt*="Logo"],
img[alt*="logo"] {
    max-height: 4rem !important; /* h-16 equivalent (64px) */
    width: auto !important;
    object-fit: contain !important;
}

/* Header logo specific sizing */
nav img[src*="logo.png"],
header img[src*="logo.png"] {
    max-height: 4rem !important; /* h-16 equivalent (64px) */
    height: 4rem !important; /* Force height to 64px */
    width: auto !important;
}

/* Login page logo sizing */
.login img[src*="logo.png"],
[class*="login"] img[src*="logo.png"] {
    max-height: 3rem !important; /* h-12 equivalent (48px) */
    width: auto !important;
}

/* Logo text styling - prevent vertical scroll */
nav span,
header span,
nav a span,
header a span {
    line-height: 1.2 !important;
    max-height: 2rem !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    display: inline-block !important;
    vertical-align: middle !important;
}

/* Specific fixes for Arabic text in logo */
nav span[class*="self-center"],
header span[class*="self-center"] {
    font-size: 1.125rem !important; /* text-lg */
    line-height: 1.1 !important;
    max-height: 1.5rem !important;
    overflow: hidden !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
}

/* Mobile responsive logo sizing */
/* FIXED: Changed from max-width: 768px to max-width: 767px */
@media (max-width: 767px) {
    nav img[src*="logo.png"],
    header img[src*="logo.png"] {
        max-height: 3rem !important; /* h-12 equivalent (48px) */
        height: 3rem !important;
    }

    .login img[src*="logo.png"],
    [class*="login"] img[src*="logo.png"] {
        max-height: 2.5rem !important; /* h-10 equivalent (40px) */
    }

    /* Reduce text size on mobile */
    nav span[class*="self-center"],
    header span[class*="self-center"] {
        font-size: 1rem !important; /* text-base */
        max-height: 1.25rem !important;
    }

    /* HEADER FIX: Ensure header doesn't overflow on mobile */
    nav {
        overflow: hidden !important;
        max-width: 100vw !important;
    }

    /* HEADER FIX: Mobile header container */
    nav .container {
        max-width: 100% !important;
        overflow-x: hidden !important; /* CHANGED: Only hide horizontal overflow */
        overflow-y: visible !important; /* ADDED: Allow badge to overflow vertically */
        justify-content: space-between !important;
    }

    /* HEADER FIX: Mobile user menu container */
    nav .flex.items-center.flex-shrink-0 {
        overflow: visible !important;
        flex-shrink: 0 !important;
    }

    /* MOBILE MENU ALIGNMENT FIXES */
    #mobile-menu ul li a {
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        text-align: left !important;
    }

    /* Ensure consistent icon alignment */
    #mobile-menu .w-10.h-10 {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
    }

    /* Fine-tune icon positioning for better visual balance */
    #mobile-menu .w-10.h-10 i {
        transform: translateX(-4px) !important;
        position: relative !important;
    }

    /* Ensure text is properly aligned */
    #mobile-menu span {
        display: flex !important;
        align-items: center !important;
        text-align: left !important;
        flex: 1 !important;
    }
}

/* Tablet responsive logo sizing - NEW */
@media (min-width: 768px) and (max-width: 1023px) {
    nav img[src*="logo.png"],
    header img[src*="logo.png"] {
        max-height: 3.5rem !important; /* 56px */
        height: 3.5rem !important;
    }

    /* HEADER FIX: Ensure header doesn't overflow on tablet */
    nav {
        overflow-x: hidden !important; /* CHANGED: Only hide horizontal overflow */
        overflow-y: visible !important; /* ADDED: Allow badge to overflow vertically */
        max-width: 100vw !important;
    }

    /* HEADER FIX: Tablet header container */
    nav .container {
        max-width: 100% !important;
        overflow-x: hidden !important; /* CHANGED: Only hide horizontal overflow */
        overflow-y: visible !important; /* ADDED: Allow badge to overflow vertically */
        justify-content: space-between !important;
    }

    /* HEADER FIX: Tablet user menu container */
    nav .flex.items-center.flex-shrink-0 {
        overflow: visible !important;
        flex-shrink: 0 !important;
    }

    /* TABLET MENU ALIGNMENT FIXES */
    #mobile-menu ul li a {
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        text-align: left !important;
    }

    /* Ensure consistent icon alignment on tablet */
    #mobile-menu .w-10.h-10 {
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        flex-shrink: 0 !important;
    }

    /* Tablet icon positioning fine-tuning */
    #mobile-menu .w-10.h-10 i {
        transform: translateX(-5px) !important;
        position: relative !important;
    }

    /* Ensure text is properly aligned on tablet */
    #mobile-menu span {
        display: flex !important;
        align-items: center !important;
        text-align: left !important;
        flex: 1 !important;
    }
}

@media (max-width: 480px) {
    nav img[src*="logo.png"],
    header img[src*="logo.png"] {
        max-height: 2.5rem !important; /* h-10 equivalent (40px) */
        height: 2.5rem !important;
    }

    .login img[src*="logo.png"],
    [class*="login"] img[src*="logo.png"] {
        max-height: 2rem !important; /* h-8 equivalent (32px) */
    }

    /* Further reduce text size on small mobile */
    nav span[class*="self-center"],
    header span[class*="self-center"] {
        font-size: 0.875rem !important; /* text-sm */
        max-height: 1rem !important;
    }
}

/* ========================================
   DEBUGGING HELPERS (Remove in production)
   ======================================== */

/* Uncomment to highlight elements causing overflow */
/*
* {
    outline: 1px solid red !important;
}

.container,
.container-fluid {
    outline: 2px solid blue !important;
}

.row {
    outline: 2px solid green !important;
}

[class*="col-"] {
    outline: 1px solid orange !important;
}
*/
