/**
 * 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 (max-width: 1024px), (display-mode: standalone) {
    .app-mobile-bottom-nav {
        display: flex !important;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        height: 68px;
        background: rgba(255, 255, 255, 0.96);
        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(6px, env(safe-area-inset-bottom));
    }

    html[data-bs-theme="dark"] .app-mobile-bottom-nav {
        background: rgba(15, 23, 42, 0.96);
        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: 6px 4px;
        min-height: 52px;
        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.45rem;
        margin-bottom: 2px;
        transition: transform 0.2s ease, color 0.2s ease;
    }

    .app-mobile-bottom-nav .nav-tab-item span {
        font-size: 11.5px;
        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(80px + env(safe-area-inset-bottom)) !important;
    }

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

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

/* Explicit class for mobile/tablet detection via JS */
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(80px + env(safe-area-inset-bottom)) !important;
}

/* =========================================================
   5. DATATABLES & TABLE UX ENHANCEMENTS
   ========================================================= */
body:not(.pos-layout-body) table.dataTable {
    border-collapse: separate !important;
    border-spacing: 0;
    border-radius: 10px;
    overflow: hidden;
}

body:not(.pos-layout-body) table.dataTable thead th {
    background-color: #f8fafc;
    color: #475569;
    font-size: 13.5px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding: 0.85rem 1rem;
    border-bottom: 2px solid #e2e8f0;
}

html[data-bs-theme="dark"] body:not(.pos-layout-body) table.dataTable thead th {
    background-color: #1e293b;
    color: #cbd5e1;
    border-bottom-color: #334155;
}

body:not(.pos-layout-body) table.dataTable tbody td {
    padding: 0.85rem 1rem;
    font-size: 14.5px;
    vertical-align: middle;
}

/* Table row hover highlight */
body:not(.pos-layout-body) table.dataTable tbody tr:hover {
    background-color: rgba(var(--tt-logo-primary-rgb), 0.05);
}

/* DataTables search input & pagination */
body:not(.pos-layout-body) .dataTables_wrapper .dataTables_filter input {
    min-height: 38px;
    border-radius: 8px;
    padding: 0.4rem 0.8rem;
    font-size: 14px;
    border: 1.5px solid #cbd5e1;
    margin-left: 0.5rem;
}

body:not(.pos-layout-body) .dataTables_wrapper .dataTables_paginate {
    padding-top: 0.5rem;
}

body:not(.pos-layout-body) .dataTables_wrapper .dataTables_paginate .paginate_button {
    min-height: 36px;
    min-width: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px !important;
    margin: 0 2px;
    font-weight: 600;
}

/* Mobile & Tablet Specific Table & DataTables Refinements */
@media (max-width: 767.98px) {
    body:not(.pos-layout-body) .dataTables_wrapper .dataTables_filter {
        text-align: left !important;
        margin-bottom: 0.75rem;
        width: 100%;
    }

    body:not(.pos-layout-body) .dataTables_wrapper .dataTables_filter label {
        width: 100%;
        display: block;
    }

    body:not(.pos-layout-body) .dataTables_wrapper .dataTables_filter input {
        width: 100% !important;
        margin-left: 0 !important;
        display: block;
    }

    body:not(.pos-layout-body) .dataTables_wrapper .dataTables_info {
        text-align: center !important;
        float: none !important;
        margin-bottom: 0.35rem;
    }

    body:not(.pos-layout-body) .dataTables_wrapper .dataTables_paginate {
        text-align: center !important;
        float: none !important;
        display: flex;
        justify-content: center;
        flex-wrap: wrap;
        gap: 3px;
    }

    body:not(.pos-layout-body) .table-responsive {
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
    }
}

/* 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;
}

