:root {
    --primary-color: #4e73df;
    --secondary-color: #858796;
    --success-color: #1cc88a;
    --info-color: #36b9cc;
    --warning-color: #f6c23e;
    --danger-color: #e74a3b;
    --light-color: #f8f9fc;
    --dark-color: #5a5c69;
    --sidebar-bg: #4e73df;
    --sidebar-width: 250px;
    --topbar-height: 70px;
}

body {
    font-family: 'Nunito', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: #f8f9fc;
    color: #5a5c69;
    overflow-x: hidden;
    margin: 0 !important;
    padding: 0 !important;
}

html {
    margin: 0 !important;
    padding: 0 !important;
    height: 100%;
}

/* Wrapper */
#wrapper {
    display: flex;
    width: 100%;
    align-items: stretch;
}

/* Sidebar */
#accordionSidebar {
    width: var(--sidebar-width);
    min-height: 100vh;
    background-color: var(--sidebar-bg);
    background-image: linear-gradient(180deg, #4e73df 10%, #224abe 100%);
    background-size: cover;
    transition: all 0.3s;
    z-index: 1000;
}

#accordionSidebar.toggled {
    width: 0 !important;
    overflow: hidden;
}

.sidebar-brand {
    height: var(--topbar-height);
    text-decoration: none;
    font-size: 1.2rem;
    font-weight: 800;
    padding: 1.5rem 1rem;
    text-align: center;
    letter-spacing: 0.05rem;
    color: #fff !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.sidebar-brand-icon {
    font-size: 2rem;
    margin-right: 0.5rem;
}

.sidebar-divider {
    border-top: 1px solid rgba(255, 255, 255, 0.15);
    margin: 0 1rem 1rem;
}

#accordionSidebar .nav-item .nav-link {
    display: block;
    width: 100%;
    text-align: left;
    padding: 1rem;
    color: rgba(255, 255, 255, 0.8);
    text-decoration: none;
    transition: color 0.2s;
}

#accordionSidebar .nav-item .nav-link:hover,
#accordionSidebar .nav-item .nav-link.active {
    color: #fff;
    font-weight: 700;
}

.nav-item .nav-link i {
    font-size: 0.85rem;
    margin-right: 0.25rem;
    width: 1.5rem;
    text-align: center;
}

.sidebar-heading {
    text-align: left;
    padding: 0 1rem;
    font-weight: 800;
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.4);
    text-transform: uppercase;
}

/* Content Wrapper */
#content-wrapper {
    width: 100%;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    background-color: #f8f9fc;
}

#content {
    flex: 1 0 auto;
}

/* Topbar */
.topbar {
    height: var(--topbar-height);
    box-shadow: 0 .15rem 1.75rem 0 rgba(58, 59, 69, .15) !important;
    z-index: 900;
    background-color: #fff;
}

.topbar .nav-item .nav-link {
    height: var(--topbar-height);
    display: flex;
    align-items: center;
    padding: 0 0.75rem;
    color: #d1d3e2;
}

.topbar .nav-item .nav-link:hover {
    color: #858796;
}

.topbar .dropdown-list {
    width: 20rem !important;
}

.topbar .dropdown-list .dropdown-header {
    background-color: var(--primary-color);
    border: 1px solid var(--primary-color);
    padding: 0.75rem 1rem;
    color: #fff;
    font-weight: 800;
}

/* Cards */
.card {
    border: none;
    box-shadow: 0 .15rem 1.75rem 0 rgba(58, 59, 69, .15);
    border-radius: 0.35rem;
}

.card-header {
    background-color: #f8f9fc;
    border-bottom: 1px solid #e3e6f0;
    padding: 0.75rem 1.25rem;
    font-weight: 700;
    color: var(--primary-color);
}

/* Utilities */
.text-gray-600 {
    color: #858796 !important;
}

.text-gray-800 {
    color: #5a5c69 !important;
}

.shadow {
    box-shadow: 0 .15rem 1.75rem 0 rgba(58, 59, 69, .15) !important;
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.animate-fade-in {
    animation: fadeIn 0.5s ease-out forwards;
}

/* Mobile Overlay for Sidebar */
.mobile-sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-sidebar-overlay.show {
    display: block;
    opacity: 1;
}

/* Responsive */
@media (max-width: 768px) {

    /* Mobile Sidebar - Hidden by default, slides in from left */
    #accordionSidebar {
        position: fixed;
        left: 0;
        top: 0;
        width: 280px;
        height: 100vh;
        transform: translateX(-100%);
        transition: transform 0.3s ease-in-out;
        z-index: 1000;
        display: block !important;
    }

    /* Show sidebar when toggled */
    #accordionSidebar.toggled {
        transform: translateX(0);
        width: 280px !important;
        overflow-y: auto;
    }

    /* Ensure content wrapper takes full width on mobile */
    #content-wrapper {
        width: 100% !important;
        margin-left: 0 !important;
    }

    /* Make sure topbar is full width */
    .topbar {
        width: 100%;
    }

    /* Improve mobile table responsiveness */
    .table-responsive {
        border: none;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    /* Stack buttons vertically on very small screens */
    .btn-group {
        flex-direction: column;
    }

    .btn-group>.btn {
        margin-bottom: 0.5rem;
    }

    /* Improve action button sizing for touch */
    .btn-sm {
        min-width: 44px;
        min-height: 44px;
        padding: 0.5rem;
    }

    /* Card spacing on mobile */
    .card {
        margin-bottom: 1.5rem;
    }

    /* Mobile-friendly dropdowns */
    .dropdown-menu {
        min-width: 200px;
    }
}

/* Tablet and small desktop adjustments */
@media (min-width: 769px) and (max-width: 991px) {
    #accordionSidebar {
        width: 220px;
    }
}

/* Ensure body doesn't shift when sidebar opens */
body.sidebar-toggled {
    overflow-x: hidden;
}

/* Sidebar Submenu Styling */
.sidebar .collapse-inner {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 0.35rem;
    margin: 0 1rem;
    padding: 0.5rem 0;
}

.sidebar .collapse-header {
    margin: 0;
    white-space: nowrap;
    padding: 0.5rem 1.5rem;
    text-transform: uppercase;
    font-weight: 800;
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.4);
}

.sidebar .collapse-item {
    position: relative;
    display: block;
    padding: 0.5rem 1.5rem;
    margin: 0 0.5rem;
    color: rgba(255, 255, 255, 0.8);
    background-color: transparent;
    border-radius: 0.35rem;
    font-size: 0.85rem;
    text-decoration: none;
    transition: all 0.2s;
}

.sidebar .collapse-item:hover,
.sidebar .collapse-item.active {
    background-color: rgba(255, 255, 255, 0.1);
    color: #fff;
    text-decoration: none;
}

/* Additional Mobile Optimizations */
@media (max-width: 576px) {
    /* Very small screens - Extra optimizations */

    /* Stack action buttons in tables */
    .table td .d-flex {
        flex-wrap: wrap;
        gap: 0.5rem !important;
    }

    /* Make table cells more readable */
    .table {
        font-size: 0.875rem;
    }

    .table th,
    .table td {
        padding: 0.75rem 0.5rem;
    }

    /* Optimize page headers */
    h1 {
        font-size: 1.75rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    /* Make buttons full-width on very small screens for better touch */
    .btn-block-mobile {
        width: 100%;
        display: block;
        margin-bottom: 0.5rem;
    }

    /* Improve card padding */
    .card-body {
        padding: 1rem;
    }

    /* Better spacing for mobile */
    .mb-4 {
        margin-bottom: 1.5rem !important;
    }

    /* Improve form control spacing */
    .form-control,
    .form-select {
        font-size: 16px;
        /* Prevents zoom on iOS */
    }
}

/* Scroll to top button */
.scroll-to-top {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    display: none;
    width: 2.75rem;
    height: 2.75rem;
    text-align: center;
    color: #fff;
    background: var(--primary-color);
    line-height: 2.75rem;
    border-radius: 0.35rem;
    z-index: 998;
    transition: all 0.3s ease;
}

.scroll-to-top:hover {
    background: var(--dark-color);
    color: #fff;
}

.scroll-to-top:focus {
    color: #fff;
}

/* Mobile touch improvements */
@media (hover: none) and (pointer: coarse) {
    /* This targets touch devices */

    /* Increase clickable areas */
    .nav-link,
    .btn,
    a {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }

    /* Remove hover effects on touch devices */
    .btn:hover,
    .nav-link:hover {
        transform: none;
    }

    /* Better touch feedback */
    .btn:active,
    .nav-link:active {
        transform: scale(0.98);
        transition: transform 0.1s;
    }
}

/* Landscape mode on mobile */
@media (max-width: 768px) and (orientation: landscape) {
    #accordionSidebar {
        width: 240px;
    }

    .topbar {
        height: 60px;
    }
}

/* Mobile Card-Based Table Layout */
@media (max-width: 767px) {

    /* Transform tables into card layout on mobile */
    .table-responsive {
        border: none;
    }

    .table-responsive table {
        border: none;
    }

    /* Hide table header on mobile */
    .table-responsive thead {
        display: none;
    }

    /* Make each table row a card */
    .table-responsive tbody tr {
        display: block;
        margin-bottom: 1rem;
        background: #fff;
        border: 1px solid #e3e6f0;
        border-radius: 0.5rem;
        box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075);
        overflow: hidden;
    }

    /* Make each cell a row within the card */
    .table-responsive tbody td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 0.75rem 1rem;
        border: none;
        border-bottom: 1px solid #f8f9fc;
        text-align: right;
    }

    .table-responsive tbody td:last-child {
        border-bottom: none;
    }

    /* Add labels before data using data-label attribute */
    .table-responsive tbody td::before {
        content: attr(data-label);
        font-weight: 700;
        text-align: left;
        color: var(--dark-color);
        flex: 0 0 40%;
        padding-right: 1rem;
    }

    /* Special handling for action buttons column */
    .table-responsive tbody td:last-child {
        background-color: #f8f9fc;
        padding: 1rem;
        justify-content: center;
    }

    .table-responsive tbody td:last-child::before {
        display: none;
    }

    /* Ensure buttons layout properly in cards */
    .table-responsive tbody td .d-flex {
        flex-wrap: wrap;
        justify-content: center;
        gap: 0.5rem;
        width: 100%;
    }

    .table-responsive tbody td .btn {
        min-width: 44px;
        min-height: 44px;
    }

    /* Style badges and status indicators */
    .table-responsive tbody td .badge {
        font-size: 0.875rem;
        padding: 0.375rem 0.75rem;
    }

    /* Links should be more prominent */
    .table-responsive tbody td a {
        color: var(--primary-color);
        font-weight: 600;
    }

    /* Make form elements in tables work better */
    .table-responsive tbody td form {
        margin: 0;
    }
}


/* Print styles */
@media print {

    #accordionSidebar,
    .topbar,
    .scroll-to-top,
    .btn,
    .mobile-sidebar-overlay {
        display: none !important;
    }

    #content-wrapper {
        width: 100% !important;
        margin: 0 !important;
    }
}