/* ====================================
   CRITICAL MOBILE FIX - RTL Perfect Centering
   Based on CoreUI Bootstrap 5 Framework
   ==================================== */

/* Reset all margins and ensure proper box-sizing */
*, *::before, *::after {
    box-sizing: border-box;
}

/* Sidebar Mobile Fix - CoreUI Official Pattern */
@media (max-width: 991.98px) {
    /* Sidebar - Based on CoreUI v5.3.0 */
    .sidebar {
        --cui-is-mobile: true;
        --cui-sidebar-width: 16rem;
        --cui-sidebar-zindex: 1035;
        position: fixed !important;
        top: 0 !important;
        bottom: 0 !important;
        z-index: var(--cui-sidebar-zindex) !important;
        width: var(--cui-sidebar-width) !important;
        max-width: 85vw !important;
        box-shadow: 0 0 2rem 0 rgba(0, 0, 0, 0.2) !important;
        transition: margin 0.3s ease-in-out !important;
    }
    
    /* LTR - Hidden by default */
    html:not([dir="rtl"]) .sidebar:not(.sidebar-end) {
        inset-inline-start: 0 !important;
        left: 0 !important;
        right: auto !important;
    }
    
    html:not([dir="rtl"]) .sidebar:not(.sidebar-end):not(.show) {
        margin-inline-start: calc(-1 * var(--cui-sidebar-width)) !important;
        margin-left: calc(-1 * var(--cui-sidebar-width)) !important;
    }
    
    /* RTL - Hidden by default */
    html[dir="rtl"] .sidebar.sidebar-end,
    html[dir="rtl"] .sidebar:not(.sidebar-end) {
        inset-inline-end: 0 !important;
        right: 0 !important;
        left: auto !important;
    }
    
    html[dir="rtl"] .sidebar.sidebar-end:not(.show),
    html[dir="rtl"] .sidebar:not(.sidebar-end):not(.show) {
        margin-inline-end: calc(-1 * var(--cui-sidebar-width)) !important;
        margin-right: calc(-1 * var(--cui-sidebar-width)) !important;
    }
    
    /* Show state - Visible */
    .sidebar.show {
        margin-inline-start: 0 !important;
        margin-inline-end: 0 !important;
        margin-left: 0 !important;
        margin-right: 0 !important;
        box-shadow: 0 0 2rem 0 rgba(0, 0, 0, 0.3) !important;
    }
    
    /* Sidebar backdrop - CoreUI Pattern */
    .sidebar-backdrop {
        --cui-backdrop-zindex: 1034;
        --cui-backdrop-bg: #080a0c;
        --cui-backdrop-opacity: 0.5;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        z-index: var(--cui-backdrop-zindex) !important;
        width: 100vw !important;
        height: 100vh !important;
        background-color: var(--cui-backdrop-bg) !important;
        opacity: 0 !important;
        transition: opacity 0.3s ease-in-out !important;
        pointer-events: none !important;
    }
    
    .sidebar-backdrop.fade {
        opacity: 0 !important;
    }
    
    .sidebar-backdrop.show {
        opacity: var(--cui-backdrop-opacity) !important;
        pointer-events: auto !important;
    }
    
    /* Main wrapper - No margin on mobile */
    .wrapper {
        margin-left: 0 !important;
        margin-right: 0 !important;
        --cui-sidebar-occupy-start: 0 !important;
        --cui-sidebar-occupy-end: 0 !important;
    }
    
    /* Header toggler - Always visible on mobile */
    .header-toggler {
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        padding: 0.5rem !important;
        border: 0 !important;
        background: transparent !important;
        cursor: pointer !important;
        margin-right: 0.5rem !important;
    }
    
    [dir="rtl"] .header-toggler {
        margin-right: 0 !important;
        margin-left: 0.5rem !important;
    }
    
    /* Sidebar header */
    .sidebar-header {
        display: flex !important;
        align-items: center !important;
        justify-content: space-between !important;
        padding: 0.75rem 1rem !important;
        min-height: 56px !important;
    }
    
    .sidebar-brand {
        flex-grow: 1 !important;
        display: flex !important;
        align-items: center !important;
    }
    
    /* Close button positioning */
    .sidebar-header .btn-close {
        display: inline-flex !important;
        margin-left: 0.5rem !important;
        opacity: 0.8 !important;
        width: 1em !important;
        height: 1em !important;
        padding: 0.25em !important;
    }
    
    [dir="rtl"] .sidebar-header .btn-close {
        margin-left: 0 !important;
        margin-right: 0.5rem !important;
    }
    
    /* Sidebar navigation */
    .sidebar-nav {
        height: calc(100vh - 56px) !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        padding-bottom: 1rem !important;
    }
    
    /* Sidebar nav items - Better touch targets */
    .sidebar-nav .nav-link {
        padding: 0.75rem 1rem !important;
        min-height: 44px !important;
        display: flex !important;
        align-items: center !important;
        justify-content: flex-start !important;
        text-align: left !important;
        font-size: 0.95rem !important;
        transition: background-color 0.15s ease-in-out !important;
        flex-direction: row !important;
    }
    
    .sidebar-nav .nav-link:hover {
        background-color: rgba(255, 255, 255, 0.05) !important;
    }
    
    .sidebar-nav .nav-link.active {
        background-color: rgba(255, 255, 255, 0.1) !important;
    }
    
    .sidebar-nav .nav-icon {
        margin-left: 0 !important;
        margin-right: 0.75rem !important;
        width: 20px !important;
        height: 20px !important;
        flex-shrink: 0 !important;
    }
    
    /* RTL specific adjustments */
    [dir="rtl"] .sidebar-nav .nav-link {
        flex-direction: row !important;
        text-align: left !important;
        justify-content: flex-start !important;
    }
    
    [dir="rtl"] .sidebar-nav .nav-icon {
        margin-left: 0 !important;
        margin-right: 0.75rem !important;
    }
    
    /* Nav titles */
    .sidebar-nav .nav-title {
        padding: 0.75rem 1rem 0.5rem !important;
        font-size: 0.75rem !important;
        text-transform: uppercase !important;
        letter-spacing: 0.05em !important;
        font-weight: 600 !important;
        opacity: 0.6 !important;
    }
    
    /* Nav divider */
    .sidebar-nav .nav-divider {
        height: 1px !important;
        margin: 0.5rem 0 !important;
        background-color: rgba(255, 255, 255, 0.1) !important;
    }
    
    /* Hide sidebar footer toggle on mobile */
    .sidebar-footer,
    .sidebar-toggler {
        display: none !important;
    }
}

/* Mobile devices (phones, less than 768px) */
@media (max-width: 767.98px) {
    /* Force body to not overflow */
    html, body {
        overflow-x: hidden !important;
        width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
    }
    
    /* Sidebar - Smaller width on very small devices */
    .sidebar {
        width: 260px !important;
        max-width: 85vw !important;
    }
    
    /* Sidebar nav items - Compact on small screens */
    .sidebar-nav .nav-link {
        padding: 0.625rem 0.875rem !important;
        font-size: 0.9rem !important;
    }
    
    .sidebar-nav .nav-icon {
        width: 18px !important;
        height: 18px !important;
        margin-left: 0.625rem !important;
    }
    
    [dir="rtl"] .sidebar-nav .nav-icon {
        margin-left: 0 !important;
        margin-right: 0.625rem !important;
    }
    
    /* Header toggler - Larger touch target */
    .header-toggler {
        padding: 0.625rem !important;
        min-width: 44px !important;
        min-height: 44px !important;
    }
    
    .header-toggler .icon {
        width: 24px !important;
        height: 24px !important;
    }
    
    /* Container - Perfect centering with equal padding */
    .container,
    .container-fluid,
    .container-sm,
    .container-md,
    .container-lg,
    .container-xl,
    .container-xxl {
        width: 100% !important;
        padding-right: 1rem !important;
        padding-left: 1rem !important;
        margin-right: auto !important;
        margin-left: auto !important;
        max-width: 100% !important;
    }
    
    /* Row - Remove negative margins that cause alignment issues */
    .row {
        --bs-gutter-x: 1rem !important;
        margin-right: calc(-0.5 * var(--bs-gutter-x)) !important;
        margin-left: calc(-0.5 * var(--bs-gutter-x)) !important;
    }
    
    /* Columns - Equal padding */
    [class*="col-"],
    [class^="col-"] {
        padding-right: calc(var(--bs-gutter-x) * 0.5) !important;
        padding-left: calc(var(--bs-gutter-x) * 0.5) !important;
    }
    
    /* Full width columns on mobile */
    .col-12,
    .col-lg-8,
    .col-lg-10,
    .col-xl-7,
    .col-xl-9 {
        width: 100% !important;
        flex: 0 0 100% !important;
        max-width: 100% !important;
    }
    
    /* Cards - Remove all side margins */
    .card {
        margin-left: 0 !important;
        margin-right: 0 !important;
        margin-bottom: 1rem !important;
        border-radius: 0.75rem !important;
    }
    
    .card-body {
        padding: 1rem !important;
    }
    
    .card-header {
        padding: 0.75rem 1rem !important;
    }
    
    /* Navbar - Full width */
    .navbar {
        margin-left: -1rem !important;
        margin-right: -1rem !important;
        width: calc(100% + 2rem) !important;
        border-radius: 0 !important;
        padding-left: 1rem !important;
        padding-right: 1rem !important;
    }
    
    /* Forms - Full width */
    .form-control,
    .form-select,
    .form-check-input {
        width: 100% !important;
        max-width: 100% !important;
    }
    
    .input-group {
        width: 100% !important;
    }
    
    /* Buttons - Better touch targets */
    .btn {
        min-height: 44px !important;
        padding: 0.5rem 1rem !important;
    }
    
    .btn-lg {
        min-height: 48px !important;
        padding: 0.75rem 1.5rem !important;
    }
    
    /* Tables - Horizontal scroll */
    .table-responsive {
        display: block !important;
        width: 100% !important;
        overflow-x: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }
    
    .table-responsive > .table {
        margin-bottom: 0 !important;
    }
    
    /* Modal - Full screen on mobile */
    .modal {
        padding: 0 !important;
    }
    
    .modal-dialog {
        margin: 0 !important;
        max-width: 100% !important;
        height: 100vh !important;
    }
    
    .modal-content {
        height: 100% !important;
        border-radius: 0 !important;
        border: 0 !important;
    }
    
    /* Alerts */
    .alert {
        margin-bottom: 1rem !important;
        border-radius: 0.5rem !important;
    }
    
    /* Badges - Better wrapping */
    .badge {
        white-space: normal !important;
        word-wrap: break-word !important;
    }
    
    /* Typography - Responsive sizing */
    h1, .h1 {
        font-size: calc(1.375rem + 1.5vw) !important;
    }
    
    h2, .h2 {
        font-size: calc(1.325rem + 0.9vw) !important;
    }
    
    h3, .h3 {
        font-size: calc(1.3rem + 0.6vw) !important;
    }
    
    .display-1 {
        font-size: calc(2.5rem + 3vw) !important;
    }
    
    .display-2 {
        font-size: calc(2rem + 2.5vw) !important;
    }
    
    .display-3 {
        font-size: calc(1.75rem + 2vw) !important;
    }
    
    .display-4 {
        font-size: calc(1.5rem + 1.5vw) !important;
    }
    
    .lead {
        font-size: 1rem !important;
    }
}

/* Extra small devices (phones in portrait mode, less than 576px) */
@media (max-width: 575.98px) {
    .container,
    .container-fluid {
        padding-right: 0.75rem !important;
        padding-left: 0.75rem !important;
    }
    
    .row {
        --bs-gutter-x: 0.75rem !important;
    }
    
    .card-body {
        padding: 0.75rem !important;
    }
    
    .btn {
        font-size: 0.9rem !important;
    }
    
    h1, .h1 {
        font-size: 1.75rem !important;
    }
    
    h2, .h2 {
        font-size: 1.5rem !important;
    }
    
    .display-4 {
        font-size: 1.75rem !important;
    }
}

/* RTL-specific fixes */
@media (max-width: 767.98px) {
    [dir="rtl"] .container,
    [dir="rtl"] .container-fluid {
        padding-right: 1rem !important;
        padding-left: 1rem !important;
    }
    
    [dir="rtl"] .row {
        margin-right: calc(-0.5 * var(--bs-gutter-x)) !important;
        margin-left: calc(-0.5 * var(--bs-gutter-x)) !important;
    }
    
    [dir="rtl"] [class*="col-"] {
        padding-right: calc(var(--bs-gutter-x) * 0.5) !important;
        padding-left: calc(var(--bs-gutter-x) * 0.5) !important;
    }
    
    [dir="rtl"] .navbar {
        margin-left: -1rem !important;
        margin-right: -1rem !important;
    }
    
    [dir="rtl"] .card {
        margin-left: 0 !important;
        margin-right: 0 !important;
    }
}

/* Landscape orientation on mobile */
@media (max-width: 767.98px) and (orientation: landscape) {
    .modal-dialog {
        height: auto !important;
        max-height: 95vh !important;
        margin: 0.5rem auto !important;
    }
    
    .modal-content {
        height: auto !important;
        max-height: 95vh !important;
    }
}

/* Touch device optimizations */
@media (hover: none) and (pointer: coarse) {
    /* Better touch targets for all clickable elements */
    a, button, .btn, .nav-link, .dropdown-item {
        min-height: 44px !important;
        display: inline-flex !important;
        align-items: center !important;
    }
    
    /* Remove hover effects on touch devices */
    *:hover {
        transition: none !important;
    }
}

/* Agreement Box - Responsive Design */
.agreement-box {
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden !important;
}

.agreement-text {
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    hyphens: auto !important;
    width: 100% !important;
}

.agreement-checkbox {
    flex-shrink: 0 !important;
}

@media (max-width: 767.98px) {
    .agreement-box {
        padding: 0.875rem !important;
        border-width: 1.5px !important;
    }
    
    .agreement-text {
        font-size: 0.875rem !important;
        line-height: 1.7 !important;
    }
    
    .agreement-text strong {
        display: block !important;
        margin-bottom: 0.25rem !important;
        font-size: 0.9rem !important;
    }
    
    .agreement-checkbox {
        width: 20px !important;
        height: 20px !important;
        min-width: 20px !important;
        margin-top: 3px !important;
    }
    
    .agreement-icon {
        width: 16px !important;
        height: 16px !important;
    }
}

@media (max-width: 575.98px) {
    .agreement-box {
        padding: 0.75rem !important;
    }
    
    .agreement-text {
        font-size: 0.8125rem !important;
        line-height: 1.65 !important;
    }
    
    .agreement-text strong {
        font-size: 0.875rem !important;
    }
    
    .agreement-checkbox {
        width: 18px !important;
        height: 18px !important;
        min-width: 18px !important;
    }
    
    .agreement-icon {
        width: 14px !important;
        height: 14px !important;
        margin-left: 3px !important;
    }
}

/* RTL Support for Agreement Box */
[dir="rtl"] .agreement-box .d-flex {
    flex-direction: row-reverse !important;
}

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

[dir="rtl"] .agreement-icon {
    margin-left: 5px !important;
    margin-right: 0 !important;
}

/* Hero Title - Allow 2 Lines on Mobile, Single Line on Desktop */
.hero-title {
    display: block !important;
    width: 100% !important;
    /* Single line on large screens */
    white-space: nowrap !important;
    font-size: clamp(1rem, 4vw, 2.5rem) !important;
    line-height: 1.3 !important;
}

@media (max-width: 767.98px) {
    .hero-title {
        /* Allow wrapping on mobile - 2 lines */
        white-space: normal !important;
        font-size: clamp(1.1rem, 4.5vw, 1.8rem) !important;
        line-height: 1.4 !important;
    }
}

@media (max-width: 575.98px) {
    .hero-title {
        /* Better readable on small phones */
        white-space: normal !important;
        font-size: clamp(0.95rem, 4.2vw, 1.4rem) !important;
        line-height: 1.4 !important;
    }
}

@media (max-width: 375px) {
    .hero-title {
        /* iPhone SE and smaller devices */
        white-space: normal !important;
        font-size: clamp(0.85rem, 4vw, 1.2rem) !important;
        line-height: 1.4 !important;
    }
}

@media (max-width: 320px) {
    .hero-title {
        /* Very small devices like iPhone 5/SE */
        white-space: normal !important;
        font-size: clamp(0.8rem, 3.8vw, 1.1rem) !important;
        line-height: 1.4 !important;
    }
}

@media (min-width: 576px) and (max-width: 767.98px) {
    .hero-title {
        white-space: normal !important;
        font-size: clamp(1.1rem, 4.5vw, 1.6rem) !important;
        line-height: 1.4 !important;
    }
}

@media (min-width: 768px) and (max-width: 991.98px) {
    .hero-title {
        /* Single line on tablets */
        white-space: nowrap !important;
        font-size: clamp(1.3rem, 3.5vw, 1.8rem) !important;
        line-height: 1.3 !important;
    }
}

@media (min-width: 992px) {
    .hero-title {
        /* Single line on desktop */
        white-space: nowrap !important;
        font-size: clamp(1.6rem, 4vw, 2.5rem) !important;
        line-height: 1.3 !important;
    }
}

/* Print styles */
@media print {
    .sidebar,
    .header,
    .footer,
    .navbar,
    .btn,
    .no-print {
        display: none !important;
    }
    
    .container,
    .container-fluid {
        max-width: 100% !important;
        padding: 0 !important;
    }
    
    .card {
        border: 1px solid #000 !important;
        page-break-inside: avoid !important;
    }
}
