:root {
    /* Colors */
    --color-primary: #e77600;
    --color-primary-light: #fdf0e6;
    --color-primary-ring: rgba(231, 118, 0, 0.2);
    --color-primary-ring-strong: rgba(231, 118, 0, 0.5);
    
    --color-border: #D5D9D9;
    --color-border-dark: #a6a6a6;
    --color-border-input: #d1d5db;
    --color-border-hover: #e5e7eb;

    --color-bg-light: #f9fafb;
    --color-bg-hover: #f3f4f6;
    --color-bg-white: #ffffff;

    --color-text-main: #111111;
    --color-text-dark: #111827;
    --color-text-muted: #374151;
    --color-text-light: #4b5563;
    --color-text-lighter: #6b7280;

    /* Border Radius */
    --radius-md: 0.375rem;
    --radius-lg: 0.5rem;
}

/* --- Sidebar Styles --- */
.sidebar-tooltip {
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.2s, visibility 0.2s;
}
.sidebar.collapsed .group:hover .sidebar-tooltip {
    visibility: visible;
    opacity: 1;
}

.sidebar {
    transition: width 0.3s ease;
}
@media (min-width: 768px) {
    .sidebar.collapsed {
        width: 4rem;
    }
    .sidebar.collapsed .sidebar-text,
    .sidebar.collapsed .sidebar-logo-text,
    .sidebar.collapsed .sidebar-inline-submenu {
        display: none !important;
    }
    .sidebar.collapsed .overflow-y-auto {
        overflow: visible !important;
    }
}

@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        z-index: 50;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    .sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: 2px 0 8px rgba(0,0,0,0.5);
    }
}

.sidebar.collapsed .sidebar-toggle-icon {
    transform: rotate(180deg);
}


/* --- DataTables Overrides --- */
.dataTables_wrapper {
    font-family: inherit;
    padding-bottom: 0.5rem;
    position: relative;
}
table.dataTable {
    border-collapse: separate !important;
    border-spacing: 0 !important;
    border: 1px solid var(--color-border) !important;
    border-radius: var(--radius-md) !important;
    overflow: hidden !important;
}
table.dataTable.no-footer {
    border-bottom: 1px solid var(--color-border) !important;
}
table.dataTable thead th, table.dataTable thead td {
    border-bottom: 1px solid var(--color-border) !important;
    border-right: 1px solid var(--color-border) !important;
    font-weight: 600;
    color: var(--color-text-muted);
    padding: 10px !important;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background-color: var(--color-bg-light);
}
table.dataTable tbody th, table.dataTable tbody td {
    padding: 10px !important;
    border-top: none !important;
    border-bottom: 1px solid var(--color-border) !important;
    border-right: 1px solid var(--color-border) !important;
    vertical-align: middle;
}

/* Prevent double borders */
table.dataTable thead th:last-child, 
table.dataTable thead td:last-child, 
table.dataTable tbody th:last-child, 
table.dataTable tbody td:last-child {
    border-right: none !important;
}
table.dataTable tbody tr:last-child th, 
table.dataTable tbody tr:last-child td {
    border-bottom: none !important;
}

/* Pagination */
.dataTables_wrapper .dataTables_paginate {
    padding-top: 1rem !important;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}
.dataTables_wrapper .dataTables_paginate .paginate_button {
    padding: 0.35rem 0.85rem !important;
    margin-left: 0 !important;
    border: 1px solid transparent !important;
    border-radius: var(--radius-md) !important;
    background: transparent !important;
    color: var(--color-text-light) !important;
    transition: all 0.2s ease;
    font-size: 0.875rem;
    font-weight: 500;
}
.dataTables_wrapper .dataTables_paginate .paginate_button:hover:not(.disabled) {
    background: var(--color-bg-hover) !important;
    color: var(--color-text-dark) !important;
    border-color: var(--color-border-hover) !important;
}
.dataTables_wrapper .dataTables_paginate .paginate_button.current, 
.dataTables_wrapper .dataTables_paginate .paginate_button.current:hover {
    background: var(--color-primary) !important;
    color: var(--color-bg-white) !important;
    border-color: var(--color-primary) !important;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover,
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:active {
    opacity: 0.5;
    cursor: not-allowed;
    background: transparent !important;
    border-color: transparent !important;
}

/* Search Input */
.dataTables_wrapper .dataTables_filter label {
    font-size: 0;
}
.dataTables_wrapper .dataTables_filter input {
    font-size: 0.875rem;
    border: 1px solid var(--color-border-input);
    border-radius: var(--radius-md);
    padding: 0.5rem 1.25rem 0.5rem 2.5rem;
    margin-left: 0;
    width: 250px;
    background: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="%239ca3af" stroke-width="2"><path stroke-linecap="round" stroke-linejoin="round" d="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"/></svg>') no-repeat 0.85rem center;
    background-size: 1.15rem;
    background-color: var(--color-bg-light);
    outline: none;
    transition: all 0.2s ease;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}
.dataTables_wrapper .dataTables_filter input:focus {
    background-color: var(--color-bg-white);
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px var(--color-primary-ring);
}

/* Length Menu */
.dataTables_wrapper .dataTables_length {
    color: var(--color-text-lighter);
    font-size: 0.875rem;
    display: flex;
    align-items: center;
}
.dataTables_wrapper .dataTables_length select {
    border: 1px solid var(--color-border-input);
    border-radius: var(--radius-lg);
    padding: 0.375rem 2rem 0.375rem 0.75rem;
    margin: 0 0.5rem;
    background-color: var(--color-bg-light);
    color: var(--color-text-muted);
    font-size: 0.875rem;
    font-weight: 500;
    outline: none;
    transition: all 0.2s;
    appearance: none;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="%236b7280"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7"/></svg>');
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    background-size: 1em;
}
.dataTables_wrapper .dataTables_length select:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px var(--color-primary-ring);
    background-color: var(--color-bg-white);
}

/* DataTables Flex Layout */
.dt-top, .dt-bottom {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    gap: 1rem;
}
.dt-top { margin-bottom: 1.25rem; }
.dt-bottom { margin-top: 1.25rem; }

@media (min-width: 768px) {
    .dt-top, .dt-bottom {
        flex-direction: row;
    }
}

.dt-top > .dt-left, .dt-bottom > .dt-left {
    display: flex;
    align-items: center;
    gap: 1rem;
    justify-content: flex-start;
    flex-wrap: wrap;
}

.dt-top > .dt-right, .dt-bottom > .dt-right {
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

/* Overwrite defaults */
.dataTables_wrapper .dataTables_length,
.dataTables_wrapper .dataTables_filter,
.dataTables_wrapper .dataTables_info,
.dataTables_wrapper .dataTables_paginate,
.dataTables_wrapper .dt-buttons {
    margin: 0 !important;
    padding: 0 !important;
    float: none !important;
    text-align: left !important;
}

.dataTables_wrapper .dt-buttons .dt-button {
    background: var(--color-bg-white) !important;
    border: 1px solid var(--color-border) !important;
    color: var(--color-text-main) !important;
    padding: 0.35rem 0.75rem !important;
    border-radius: var(--radius-md) !important;
    font-size: 0.875rem !important;
    margin: 0 !important;
    transition: all 0.2s ease;
    box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05) !important;
}

.dataTables_wrapper .dt-buttons .dt-button:hover {
    background: var(--color-bg-light) !important;
    color: var(--color-primary) !important;
    border-color: var(--color-border) !important;
}

.dataTables_wrapper .dataTables_info {
    font-size: 0.875rem;
    color: var(--color-text-lighter);
}

/* Loader Styles */
.dataTables_wrapper .dataTables_processing {
    position: absolute;
    top: 50% !important;
    left: 50% !important;
    transform: translate(-50%, -50%) !important;
    background: transparent !important;
    border: none !important;
    z-index: 100 !important;
    text-align: center !important;
    margin: 0 !important;
    padding: 0 !important;
    box-shadow: none !important;
    width: auto !important;
    height: auto !important;
}
.dataTables_wrapper .dataTables_processing > div:last-child > div {
    background: var(--color-primary) !important;
}

table.dataTable thead .sorting,
table.dataTable thead .sorting_asc,
table.dataTable thead .sorting_desc {
    background-image: none !important;
}


/* --- Form Elements --- */
input[type="checkbox"] {
    accent-color: var(--color-primary);
    width: 1.1rem;
    height: 1.1rem;
    cursor: pointer;
}


/* --- TomSelect Overrides --- */
.ts-wrapper .ts-control {
    border: 1px solid var(--color-border-dark) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: inset 0 2px 4px 0 rgba(0, 0, 0, 0.06) !important;
    padding: 0.375rem 0.75rem !important;
    min-height: 2.25rem !important;
}
.ts-wrapper.focus .ts-control {
    border-color: var(--color-primary) !important;
    box-shadow: 0 0 0 2px var(--color-primary-ring-strong) !important;
    outline: none !important;
}
.ts-dropdown {
    border: 1px solid var(--color-border-dark) !important;
    border-radius: var(--radius-md) !important;
    margin-top: 0.25rem !important;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
}
.ts-dropdown .option:hover,
.ts-dropdown .option.active {
    background-color: var(--color-bg-hover) !important;
    color: var(--color-text-main) !important;
}
.ts-dropdown .option {
    padding: 0.5rem 0.75rem !important;
}


/* --- Flatpickr Overrides --- */
.flatpickr-day.selected, 
.flatpickr-day.startRange, 
.flatpickr-day.endRange, 
.flatpickr-day.selected.inRange, 
.flatpickr-day.startRange.inRange, 
.flatpickr-day.endRange.inRange, 
.flatpickr-day.selected:focus, 
.flatpickr-day.startRange:focus, 
.flatpickr-day.endRange:focus, 
.flatpickr-day.selected:hover, 
.flatpickr-day.startRange:hover, 
.flatpickr-day.endRange:hover, 
.flatpickr-day.selected.prevMonthDay, 
.flatpickr-day.startRange.prevMonthDay, 
.flatpickr-day.endRange.prevMonthDay, 
.flatpickr-day.selected.nextMonthDay, 
.flatpickr-day.startRange.nextMonthDay, 
.flatpickr-day.endRange.nextMonthDay {
    background: var(--color-primary) !important;
    border-color: var(--color-primary) !important;
}

.flatpickr-day.selected.startRange + .endRange:not(:nth-child(7n+1)), 
.flatpickr-day.startRange.startRange + .endRange:not(:nth-child(7n+1)), 
.flatpickr-day.endRange.startRange + .endRange:not(:nth-child(7n+1)) {
    box-shadow: -10px 0 0 var(--color-primary) !important;
}

.flatpickr-day.inRange,
.flatpickr-day.prevMonthDay.inRange,
.flatpickr-day.nextMonthDay.inRange,
.flatpickr-day.today.inRange,
.flatpickr-day.prevMonthDay.today.inRange,
.flatpickr-day.nextMonthDay.today.inRange,
.flatpickr-day:hover,
.flatpickr-day.prevMonthDay:hover,
.flatpickr-day.nextMonthDay:hover,
.flatpickr-day:focus,
.flatpickr-day.prevMonthDay:focus,
.flatpickr-day.nextMonthDay:focus {
    background: var(--color-primary-light) !important;
    border-color: transparent !important;
}

.flatpickr-day.today {
    border-color: var(--color-primary) !important;
}

.flatpickr-day.today:hover,
.flatpickr-day.today:focus {
    background: var(--color-primary) !important;
    color: var(--color-bg-white) !important;
    border-color: var(--color-primary) !important;
}


/* --- Global Scrollbar --- */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: rgba(156, 163, 175, 0.5);
    border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover {
    background: rgba(156, 163, 175, 0.8);
}

/* Fix for DataTables ColVis dropdown styling with Tailwind */
.dataTables_wrapper div.dt-button-collection {
    position: absolute !important;
    background-color: white !important;
    border: 1px solid #e5e7eb !important;
    border-radius: 0.375rem !important;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06) !important;
    padding: 0.5rem 0 !important;
    z-index: 50 !important;
    margin-top: 0.25rem !important;
    max-height: 400px !important;
    overflow-y: auto !important;
}
.dataTables_wrapper div.dt-button-collection button.dt-button, 
.dataTables_wrapper div.dt-button-collection a.dt-button {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    width: 100% !important;
    text-align: left !important;
    padding: 0.625rem 1rem !important;
    font-size: 0.875rem !important;
    color: #374151 !important;
    background: transparent !important;
    border: none !important;
    border-radius: 0 !important;
    margin: 0 !important;
    cursor: pointer !important;
    box-shadow: none !important;
    border-bottom: 1px solid #f3f4f6 !important;
}
.dataTables_wrapper div.dt-button-collection button.dt-button:last-child, 
.dataTables_wrapper div.dt-button-collection a.dt-button:last-child {
    border-bottom: none !important;
}
.dataTables_wrapper div.dt-button-collection button.dt-button:hover,
.dataTables_wrapper div.dt-button-collection a.dt-button:hover {
    background-color: #f9fafb !important;
    color: #111827 !important;
}
.dataTables_wrapper div.dt-button-collection button.dt-button.active,
.dataTables_wrapper div.dt-button-collection a.dt-button.active {
    background-color: #f0fdf4 !important;
    color: #166534 !important;
    font-weight: 500 !important;
}
/* Hide default DataTables tick if any, and add custom elegant checkmark */
.dataTables_wrapper div.dt-button-collection button.dt-button span.dt-button-down-arrow {
    display: none !important;
}
.dataTables_wrapper div.dt-button-collection button.dt-button.active::after,
.dataTables_wrapper div.dt-button-collection a.dt-button.active::after {
    content: '✓';
    font-weight: bold;
    color: #16a34a;
    margin-left: auto;
}
.dataTables_wrapper div.dt-button-background {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 49 !important;
    background: transparent !important;
}

/* Datatable Text Wrap */
table.dataTable.wrap-text td, table.dataTable.wrap-text th {
    white-space: normal !important;
    word-break: break-word !important;
}
