:root {
    --primary-blue: #0056b3;
    --secondary-blue: #007bff;
    --accent-green: #28a745;
    --dark-black: #212529;
    --light-black: #343a40;
    --white: #ffffff;
    --gray: #f8f9fa;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--gray);
    margin: 0;
    padding: 0;
}

/* --- Authentication --- */
.login-container {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--dark-black) 0%, var(--primary-blue) 100%);
}

.login-card {
    background: var(--white);
    padding: 2rem;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    width: 100%;
    max-width: 400px;
}

.login-card h2 {
    text-align: center;
    color: var(--dark-black);
    margin-bottom: 1.5rem;
}

/* --- Form Elements --- */
form {
    width: 100%;
}

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--light-black);
}

.form-control {
    width: 100%;
    max-width: 100%;
    padding: 0.75rem;
    border: 1px solid #ddd;
    border-radius: 5px;
    box-sizing: border-box;
}

/* --- Buttons --- */
.btn {
    width: 100%;
    max-width: 100%;
    padding: 0.75rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    transition: background 0.3s;
}

.btn-inline {
    width: 100%;
}

@media (min-width: 768px) {
    .btn-inline {
        width: auto;
    }
}

.btn-primary {
    background-color: var(--primary-blue);
    color: var(--white);
}

.btn-primary:hover {
    background-color: #004085;
}

.btn-success {
    background-color: var(--accent-green);
    color: white;
}

.btn-success:hover {
    background-color: #1e7e34;
}

/* --- Dashboard Layout --- */
.wrapper {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

#sidebar {
    width: 250px;
    min-width: 250px;
    height: 100vh;
    position: fixed;
    top: 0;
    left: 0;
    background: var(--dark-black);
    color: #fff;
    transition: all 0.3s;
    z-index: 1000;
    overflow-y: auto;
}

#sidebar .sidebar-header {
    padding: 20px;
    background: var(--primary-blue);
}

#sidebar .sidebar-header h3 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: bold;
}

#sidebar ul.components {
    padding: 20px 0;
}

#sidebar ul li a, 
#sidebar ul li summary {
    padding: 12px 20px;
    font-size: 1rem;
    display: block;
    color: #adb5bd;
    text-decoration: none;
    border-left: 3px solid transparent;
    transition: all 0.3s;
    cursor: pointer;
}

#sidebar ul li summary {
    list-style: none;
}

#sidebar ul li summary::-webkit-details-marker {
    display: none;
}

#sidebar ul li a:hover, 
#sidebar ul li summary:hover {
    color: var(--accent-green);
    background: rgba(255,255,255,0.05);
    border-left: 3px solid var(--accent-green);
}

#sidebar ul li.active > a,
#sidebar ul li details[open] summary {
    color: white;
    background: rgba(255,255,255,0.1);
    border-left: 3px solid var(--accent-green);
}

#sidebar ul li details ul {
    background: rgba(0,0,0,0.2);
    padding: 0;
    margin: 0;
}

#sidebar ul li details ul li a {
    padding: 10px 20px 10px 40px !important;
    font-size: 0.9rem !important;
    border-left: none !important;
}

#sidebar ul li summary:after {
    content: '\25BC';
    float: right;
    font-size: 0.7rem;
    margin-top: 5px;
    transition: transform 0.3s;
}

#sidebar ul li details[open] summary:after {
    transform: rotate(180deg);
}

#content {
    margin-left: 250px;
    width: calc(100% - 250px);
    padding: 30px;
    min-height: 100vh;
    transition: all 0.3s;
    overflow-x: hidden;
    background-color: var(--gray);
}

.top-nav {
    background: var(--white);
    padding: 15px;
    margin-bottom: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
}

/* --- UI Components --- */
.card {
    background: #fff;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
    margin-bottom: 20px;
    width: 100%;
    overflow-x: auto;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.container {
    max-width: 1200px;
    margin: auto;
    padding: 15px;
}

.alert {
    padding: 0.75rem;
    margin-bottom: 1rem;
    border-radius: 5px;
    text-align: center;
}

.alert-danger {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

/* --- Modals --- */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    overflow-y: auto;
}

.modal-content {
    background-color: var(--white);
    margin: 2% auto;
    padding: 25px;
    width: 90%;
    max-width: 1000px;
    border-radius: 8px;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

/* --- Tables --- */
.table-container, .table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 10px;
}

table th, table td {
    padding: 12px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

@media (max-width: 768px) {
    table {
        min-width: 100%;
    }
    
    table th, table td {
        padding: 8px;
        font-size: 0.85rem;
    }
}

/* Specific styling for money/currency values */
.money, .currency, .amount {
    white-space: nowrap !important;
    font-weight: 600;
    color: var(--dark-black);
}

table th {
    background-color: var(--gray);
    color: var(--dark-black);
}

/* --- Responsive Utilities --- */
.mobile-toggle {
    display: none;
}

/* Mobile & Tablets (up to 768px) */
@media (max-width: 768px) {
    .mobile-toggle {
        display: block !important;
    }

    .wrapper {
        flex-direction: column;
    }

    #sidebar {
        position: relative;
        width: 100%;
        min-width: 100%;
        max-width: 100%;
        height: auto;
        min-height: auto;
        border-bottom: 2px solid var(--primary-blue);
    }

    #sidebar .sidebar-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 15px 20px;
    }

    #sidebar ul.components {
        padding: 0;
        display: none;
    }

    #sidebar.active ul.components {
        display: block;
    }

    #content {
        margin-left: 0;
        width: 100%;
        flex: none;
        padding: 15px;
    }

    .top-nav {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
        text-align: center;
    }

    .card {
        padding: 15px;
    }

    table {
        font-size: 0.85rem;
        display: table !important; /* Force table layout */
        width: 100% !important;
        overflow-x: auto;
        white-space: nowrap;
    }

    /* Target specific modals for full width items table */
    .modal-content table {
        display: table !important;
        min-width: 800px !important; /* Ensure columns have space */
    }

    .table-container {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    table th, table td {
        padding: 8px;
    }

    /* Select2 Mobile Fixes */
    .select2-container--open .select2-dropdown {
        z-index: 9999 !important;
    }
    .select2-container .select2-selection--single {
        height: 45px !important;
        display: flex !important;
        align-items: center !important;
    }
    
    /* Ensure dropdown stays below if possible */
    .select2-container--default .select2-dropdown--above {
        border-top: 1px solid #aaa !important;
        border-bottom: none !important;
        border-radius: 4px 4px 0 0 !important;
    }
    .select2-container--default .select2-dropdown--below {
        border-top: none !important;
        border-radius: 0 0 4px 4px !important;
    }

    /* Force Select2 dropdown to always appear below the search box */
    .select2-container--default.select2-container--open .select2-dropdown--above {
        top: 45px !important; /* Move it down from the top position */
        border-top: none !important;
        border-bottom: 1px solid #aaa !important;
        border-radius: 0 0 4px 4px !important;
    }
    
    /* Ensure the search box inside the dropdown is clear */
    .select2-search--dropdown {
        padding: 8px !important;
    }
    .select2-search--dropdown .select2-search__field {
        height: 40px !important;
        padding: 5px 10px !important;
    }

    .modal-content {
        width: 95% !important;
        margin: 5% auto !important;
        padding: 15px !important;
    }

    .form-group {
        margin-bottom: 0.8rem;
    }

    h2 {
        font-size: 1.5rem;
    }

    .btn {
        padding: 0.6rem;
    }

    div[style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
    }

    .login-card {
        margin: 20px;
        padding: 1.5rem;
    }
}

/* Tablets (769px to 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
    #sidebar {
        min-width: 200px;
        max-width: 200px;
    }
    
    div[style*="grid-template-columns"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }
}
