/**
 * App-Friendly CSS - Accessible, Modern & Mobile/Tablet PWA Optimized Layout
 * Applied strictly to application pages (excluding /pos)
 */

/* =========================================================
   1. ACCESSIBILITY, TYPOGRAPHY & TOUCH TARGETS
   ========================================================= */
body:not(.pos-layout-body) {
    font-size: 15px;
    line-height: 1.55;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    text-rendering: optimizeLegibility;
}

/* Clearer, friendly typography hierarchy */
body:not(.pos-layout-body) h1,
body:not(.pos-layout-body) h2,
body:not(.pos-layout-body) h3,
body:not(.pos-layout-body) h4,
body:not(.pos-layout-body) h5,
body:not(.pos-layout-body) h6 {
    font-weight: 700;
    color: #1e293b;
    letter-spacing: -0.015em;
}

html[data-bs-theme="dark"] body:not(.pos-layout-body) h1,
html[data-bs-theme="dark"] body:not(.pos-layout-body) h2,
html[data-bs-theme="dark"] body:not(.pos-layout-body) h3,
html[data-bs-theme="dark"] body:not(.pos-layout-body) h4,
html[data-bs-theme="dark"] body:not(.pos-layout-body) h5,
html[data-bs-theme="dark"] body:not(.pos-layout-body) h6 {
    color: #f1f5f9;
}

/* Touch-friendly inputs, selects and buttons */
body:not(.pos-layout-body) .form-control,
body:not(.pos-layout-body) .form-select {
    min-height: 44px;
    font-size: 15px;
    border-radius: 10px;
    padding: 0.6rem 0.95rem;
    border: 1.5px solid #cbd5e1;
    transition: all 0.2s ease-in-out;
}

html[data-bs-theme="dark"] body:not(.pos-layout-body) .form-control,
html[data-bs-theme="dark"] body:not(.pos-layout-body) .form-select {
    border-color: #334155;
    background-color: #1e293b;
    color: #f8fafc;
}

body:not(.pos-layout-body) .form-control:focus,
body:not(.pos-layout-body) .form-select:focus {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 3.5px rgba(var(--tt-logo-primary-rgb), 0.22);
}

body:not(.pos-layout-body) .form-label {
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 0.4rem;
    color: #334155;
}

html[data-bs-theme="dark"] body:not(.pos-layout-body) .form-label {
    color: #cbd5e1;
}

/* Buttons with comfortable hit target */
body:not(.pos-layout-body) .btn {
    min-height: 42px;
    font-size: 14.5px;
    font-weight: 600;
    border-radius: 10px;
    padding: 0.55rem 1.15rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    transition: all 0.18s ease;
}

body:not(.pos-layout-body) .btn:active {
    transform: scale(0.97);
}

/* =========================================================
   PRIMARY BRAND COLOR ALIGNMENT (-primary components)
   ========================================================= */
body:not(.pos-layout-body) .btn-primary {
    background-color: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
    color: #ffffff !important;
}

body:not(.pos-layout-body) .btn-primary:hover,
body:not(.pos-layout-body) .btn-primary:focus {
    background-color: #12ba91 !important;
    border-color: #10a883 !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(var(--tt-logo-primary-rgb), 0.35) !important;
}

body:not(.pos-layout-body) .btn-outline-primary {
    color: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
    background-color: transparent !important;
}

body:not(.pos-layout-body) .btn-outline-primary:hover,
body:not(.pos-layout-body) .btn-outline-primary:focus,
body:not(.pos-layout-body) .btn-outline-primary:active {
    background-color: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
    color: #ffffff !important;
    box-shadow: 0 4px 12px rgba(var(--tt-logo-primary-rgb), 0.25) !important;
}

body:not(.pos-layout-body) .text-primary {
    color: var(--bs-primary) !important;
}

body:not(.pos-layout-body) .bg-primary {
    background-color: var(--bs-primary) !important;
    color: #ffffff !important;
}

body:not(.pos-layout-body) .bg-primary-subtle {
    background-color: rgba(var(--tt-logo-primary-rgb), 0.14) !important;
    color: #0b2454 !important;
}

html[data-bs-theme="dark"] body:not(.pos-layout-body) .bg-primary-subtle {
    background-color: rgba(var(--tt-logo-primary-rgb), 0.2) !important;
    color: #57e7bf !important;
}

body:not(.pos-layout-body) .badge.bg-primary-subtle,
body:not(.pos-layout-body) .badge.text-primary {
    background-color: rgba(var(--tt-logo-primary-rgb), 0.14) !important;
    color: #0d8265 !important;
}

html[data-bs-theme="dark"] body:not(.pos-layout-body) .badge.bg-primary-subtle,
html[data-bs-theme="dark"] body:not(.pos-layout-body) .badge.text-primary {
    background-color: rgba(var(--tt-logo-primary-rgb), 0.22) !important;
    color: #7ff0cf !important;
}

body:not(.pos-layout-body) .border-primary {
    border-color: var(--bs-primary) !important;
}

body:not(.pos-layout-body) .border-primary-subtle {
    border-color: rgba(var(--tt-logo-primary-rgb), 0.3) !important;
}

body:not(.pos-layout-body) .page-item.active .page-link,
body:not(.pos-layout-body) .dataTables_wrapper .dataTables_paginate .paginate_button.current {
    background-color: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
    color: #ffffff !important;
}

body:not(.pos-layout-body) .form-check-input:checked {
    background-color: var(--bs-primary) !important;
    border-color: var(--bs-primary) !important;
}

/* Table action buttons touch size */
body:not(.pos-layout-body) .table .btn.btn-sm,
body:not(.pos-layout-body) .btn-sm {
    min-height: 36px;
    min-width: 36px;
    padding: 0.35rem 0.65rem;
    font-size: 13.5px;
    border-radius: 8px;
}

/* Badges with readable font size */
body:not(.pos-layout-body) .badge {
    font-size: 12.5px !important;
    font-weight: 600;
    padding: 0.38rem 0.65rem;
    border-radius: 6px;
    letter-spacing: 0.02em;
}

/* =========================================================
   2. MODERN CARD & PAGE HEADER STYLING
   ========================================================= */
body:not(.pos-layout-body) .card {
    border-radius: 14px;
    border: 1px solid rgba(226, 232, 240, 0.85);
    box-shadow: 0 2px 8px -2px rgba(15, 23, 42, 0.05), 0 4px 14px -3px rgba(15, 23, 42, 0.04);
    transition: box-shadow 0.2s ease;
}

html[data-bs-theme="dark"] body:not(.pos-layout-body) .card {
    border-color: rgba(51, 65, 85, 0.85);
    box-shadow: 0 2px 8px -2px rgba(0, 0, 0, 0.35);
}

body:not(.pos-layout-body) .card.bg-info-subtle {
    background: linear-gradient(135deg, rgba(var(--tt-logo-primary-rgb), 0.1) 0%, rgba(11, 36, 84, 0.06) 100%) !important;
    border: 1px solid rgba(var(--tt-logo-primary-rgb), 0.2) !important;
    border-radius: 14px;
}

html[data-bs-theme="dark"] body:not(.pos-layout-body) .card.bg-info-subtle {
    background: linear-gradient(135deg, rgba(var(--tt-logo-primary-rgb), 0.14) 0%, rgba(30, 41, 59, 0.6) 100%) !important;
    border-color: rgba(var(--tt-logo-primary-rgb), 0.3) !important;
}

/* Breadcrumb styling */
body:not(.pos-layout-body) .breadcrumb-item {
    font-size: 13.5px;
    font-weight: 500;
}

/* Dropdown menu safe width & viewport alignment */
body:not(.pos-layout-body) .topbar .dropdown-menu {
    max-width: calc(100vw - 32px) !important;
    right: 0 !important;
    left: auto !important;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
}

/* =========================================================
   3. SIDEBAR MODERNIZATION & ACCESSIBILITY
   ========================================================= */
body:not(.pos-layout-body) .sidebar-nav ul .sidebar-item .sidebar-link {
    min-height: 44px;
    padding: 0.65rem 0.9rem;
    font-size: 14.5px;
    font-weight: 500;
    border-radius: 10px;
    margin-bottom: 3px;
    color: #475569;
    display: flex;
    align-items: center;
    transition: all 0.18s ease;
}

body:not(.pos-layout-body) .sidebar-nav ul .sidebar-item .sidebar-link i {
    font-size: 1.28rem;
    margin-right: 0.75rem;
    color: #64748b;
    transition: color 0.18s ease;
}

body:not(.pos-layout-body) .sidebar-nav ul .sidebar-item .sidebar-link:hover {
    background-color: rgba(var(--tt-logo-primary-rgb), 0.1);
    color: var(--tt-logo-secondary);
}

body:not(.pos-layout-body) .sidebar-nav ul .sidebar-item .sidebar-link:hover i {
    color: var(--bs-primary);
}

body:not(.pos-layout-body) .sidebar-nav ul .sidebar-item .sidebar-link.active {
    background: linear-gradient(90deg, var(--bs-primary) 0%, #10c091 100%) !important;
    color: #ffffff !important;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(var(--tt-logo-primary-rgb), 0.35);
}

body:not(.pos-layout-body) .sidebar-nav ul .sidebar-item .sidebar-link.active i {
    color: #ffffff !important;
}

html[data-bs-theme="dark"] body:not(.pos-layout-body) .sidebar-nav ul .sidebar-item .sidebar-link {
    color: #cbd5e1;
}

html[data-bs-theme="dark"] body:not(.pos-layout-body) .sidebar-nav ul .sidebar-item .sidebar-link i {
    color: #94a3b8;
}

html[data-bs-theme="dark"] body:not(.pos-layout-body) .sidebar-nav ul .sidebar-item .sidebar-link:hover {
    background-color: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

/* Sidebar Section Headers */
body:not(.pos-layout-body) .nav-small-cap {
    font-size: 12px !important;
    font-weight: 700 !important;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    padding: 1.25rem 0.9rem 0.45rem 0.9rem !important;
}

/* Fixed User Profile at bottom of sidebar */
body:not(.pos-layout-body) .fixed-profile {
    border-radius: 12px;
    border: 1px solid rgba(203, 213, 225, 0.6);
}

html[data-bs-theme="dark"] body:not(.pos-layout-body) .fixed-profile {
    border-color: rgba(51, 65, 85, 0.8);
    background-color: #1e293b !important;
}

/* =========================================================
   4. MOBILE & TABLET BOTTOM NAVIGATION BAR (PWA)
   ========================================================= */
.app-mobile-bottom-nav {
    display: none;
}

/* Show on tablet & mobile viewports (<= 1024px) or when mobile class is active */
@media screen and (max-width: 1024px), screen and (display-mode: standalone) {
    .app-mobile-bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 64px;
        background: rgba(255, 255, 255, 0.98);
        backdrop-filter: blur(16px);
        -webkit-backdrop-filter: blur(16px);
        border-top: 1px solid rgba(226, 232, 240, 0.9);
        box-shadow: 0 -4px 18px rgba(15, 23, 42, 0.08);
        z-index: 1040;
        align-items: center;
        justify-content: space-around;
        padding-inline: 8px;
        padding-bottom: max(4px, env(safe-area-inset-bottom));
    }

    html[data-bs-theme="dark"] .app-mobile-bottom-nav {
        background: rgba(15, 23, 42, 0.98);
        border-top-color: rgba(51, 65, 85, 0.9);
        box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
    }

    .app-mobile-bottom-nav .nav-tab-item {
        flex: 1;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        padding: 4px 2px;
        min-height: 48px;
        border-radius: 12px;
        color: #64748b;
        text-decoration: none;
        transition: all 0.2s ease;
        position: relative;
    }

    .app-mobile-bottom-nav .nav-tab-item i {
        font-size: 1.4rem;
        margin-bottom: 2px;
        transition: transform 0.2s ease, color 0.2s ease;
    }

    .app-mobile-bottom-nav .nav-tab-item span {
        font-size: 11px;
        font-weight: 600;
        letter-spacing: -0.01em;
        line-height: 1.1;
    }

    .app-mobile-bottom-nav .nav-tab-item:active {
        transform: scale(0.92);
    }

    .app-mobile-bottom-nav .nav-tab-item.active {
        color: var(--bs-primary);
    }

    .app-mobile-bottom-nav .nav-tab-item.active i {
        transform: translateY(-2px);
        color: var(--bs-primary);
    }

    html[data-bs-theme="dark"] .app-mobile-bottom-nav .nav-tab-item {
        color: #94a3b8;
    }

    html[data-bs-theme="dark"] .app-mobile-bottom-nav .nav-tab-item.active {
        color: #16d6a7;
    }

    /* Content space at bottom so bottom nav bar does not overlap content */
    body:not(.pos-layout-body) .body-wrapper {
        padding-bottom: calc(76px + env(safe-area-inset-bottom)) !important;
    }

    /* Better mobile container padding */
    body:not(.pos-layout-body) .container-fluid {
        padding-inline: 12px;
    }

    /* Responsive filter spacing */
    body:not(.pos-layout-body) .datatables .row.g-3 {
        --bs-gutter-y: 0.75rem;
    }

    /* Back button full-width & touch friendly for mobile/tablet */
    .back-button-wrapper {
        width: 100% !important;
        display: flex !important;
        gap: 10px !important;
        margin-top: 1.25rem !important;
        margin-bottom: 1.5rem !important;
    }

    .back-button-wrapper .btn {
        flex: 1 1 0% !important;
        min-height: 46px !important;
        font-size: 14.5px !important;
        font-weight: 600 !important;
        border-radius: 12px !important;
        padding: 10px 16px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 6px !important;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.04) !important;
    }

    .back-button-wrapper .btn-back {
        background-color: #f8fafc !important;
        border: 1.5px solid #cbd5e1 !important;
        color: #334155 !important;
    }

    .back-button-wrapper .btn-back:hover,
    .back-button-wrapper .btn-back:active {
        background-color: #f1f5f9 !important;
        border-color: #94a3b8 !important;
        color: #0f172a !important;
        transform: scale(0.98) !important;
    }

    html[data-bs-theme="dark"] .back-button-wrapper .btn-back {
        background-color: #1e293b !important;
        border-color: #334155 !important;
        color: #cbd5e1 !important;
    }

    html[data-bs-theme="dark"] .back-button-wrapper .btn-back:hover,
    html[data-bs-theme="dark"] .back-button-wrapper .btn-back:active {
        background-color: #334155 !important;
        border-color: #475569 !important;
        color: #f8fafc !important;
    }
}

/* Landscape compact layout on mobile devices */
@media screen and (max-width: 991.98px) and (orientation: landscape) and (max-height: 500px) {
    .app-mobile-bottom-nav {
        height: 48px !important;
        padding-bottom: 0 !important;
    }
    .app-mobile-bottom-nav .nav-tab-item {
        min-height: 40px !important;
        padding: 2px !important;
    }
    .app-mobile-bottom-nav .nav-tab-item i {
        font-size: 1.25rem !important;
        margin-bottom: 0 !important;
    }
    .app-mobile-bottom-nav .nav-tab-item span {
        font-size: 10px !important;
    }
    body:not(.pos-layout-body) .body-wrapper {
        padding-bottom: 58px !important;
    }
}

/* Explicit class for mobile/tablet detection via JS */
@media screen {
    body.is-mobile-device .app-mobile-bottom-nav,
    body.is-tablet-device .app-mobile-bottom-nav {
        display: flex !important;
    }

    body.is-mobile-device:not(.pos-layout-body) .body-wrapper,
    body.is-tablet-device:not(.pos-layout-body) .body-wrapper {
        padding-bottom: calc(76px + env(safe-area-inset-bottom)) !important;
    }
}

/* Strict print hiding for navigation */
@media print {
    .app-mobile-bottom-nav,
    nav.app-mobile-bottom-nav,
    body.is-mobile-device .app-mobile-bottom-nav,
    body.is-tablet-device .app-mobile-bottom-nav {
        display: none !important;
        visibility: hidden !important;
        opacity: 0 !important;
        height: 0 !important;
        overflow: hidden !important;
    }

    body:not(.pos-layout-body) .body-wrapper,
    body.is-mobile-device:not(.pos-layout-body) .body-wrapper,
    body.is-tablet-device:not(.pos-layout-body) .body-wrapper {
        padding-bottom: 0 !important;
        margin-bottom: 0 !important;
    }
}

/* =========================================================
   5. DATATABLES & TABLE UX ENHANCEMENTS
   Handled modularly via assets/css/datatable/ (desktop, tablet, mobile)
   ========================================================= */

/* Modal Scroll & Dynamic List Enhancements */
body:not(.pos-layout-body) .modal-dialog-scrollable .modal-content {
    max-height: calc(100vh - 2.5rem);
}

body:not(.pos-layout-body) .modal-dialog-scrollable form {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    min-height: 0;
    overflow: hidden;
}

body:not(.pos-layout-body) .modal-dialog-scrollable .modal-body {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
}

#materials-container::-webkit-scrollbar {
    width: 6px;
}

#materials-container::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 4px;
}

/* =========================================================
   6. COLLAPSIBLE FILTER TOGGLE UX
   ========================================================= */
.filter-chevron {
    transition: transform 0.2s ease-in-out;
}

[data-bs-toggle="collapse"][aria-expanded="true"] .filter-chevron {
    transform: rotate(180deg);
}

#filterSection .bg-light {
    background-color: #f8fafc !important;
    border: 1px solid #e2e8f0 !important;
}

html[data-bs-theme="dark"] #filterSection .bg-light {
    background-color: #1e293b !important;
    border-color: #334155 !important;
}

/* =========================================================
   7. SELECT2 BOOTSTRAP 5 & DARK MODE ALIGNMENT
   ========================================================= */
.select2-container .select2-selection--single {
    height: 38px !important;
    border: 1px solid #dfe5ef !important;
    border-radius: 7px !important;
    padding: 4px 8px !important;
    display: flex !important;
    align-items: center !important;
    background-color: #fff !important;
}

.select2-container .select2-selection--single .select2-selection__rendered {
    color: #2a3547 !important;
    line-height: normal !important;
    padding-left: 2px !important;
}

.select2-container .select2-selection--single .select2-selection__arrow {
    height: 36px !important;
    right: 8px !important;
}

html[data-bs-theme="dark"] .select2-container .select2-selection--single {
    background-color: #1e293b !important;
    border-color: #334155 !important;
}

html[data-bs-theme="dark"] .select2-container .select2-selection--single .select2-selection__rendered {
    color: #cbd5e1 !important;
}

html[data-bs-theme="dark"] .select2-dropdown {
    background-color: #1e293b !important;
    border-color: #334155 !important;
    color: #cbd5e1 !important;
}

html[data-bs-theme="dark"] .select2-container--default .select2-results__option--highlighted[aria-selected] {
    background-color: var(--bs-primary) !important;
    color: #fff !important;
}

html[data-bs-theme="dark"] .select2-container--default .select2-search--dropdown .select2-search__field {
    background-color: #0f172a !important;
    border-color: #334155 !important;
    color: #cbd5e1 !important;
}



