/**
 * Custom MMS Admin Styles
 * Loaded via UNFOLD STYLES setting
 */

/* Select2 width fixes */
.select2.select2-container {
    width: 100% !important;
    max-width: 65rem !important;
}

/* Grid layout classes */
.grid-rows-4 {
    grid-template-rows: repeat(4, minmax(0, 1fr));
}

.gap-4 {
    gap: 1rem;
}

.grid-cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.grid-cols-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.col-span-2 {
    grid-column: span 2 / span 2;
}

.col-span-3 {
    grid-column: span 3 / span 3;
}

/* Responsive grid override */
@media (min-width: 51px) and (max-width: 1200px) {
    .grid {
        display: block !important;
    }
}

/* Select2 Dark Theme */
html.dark .select2-container--default .select2-selection--single {
    background-color: #212529 !important;
}

html.dark .select2-container--default .select2-selection--single .select2-selection__rendered {
    color: #fff !important;
}

html.dark .select2 select2-container select2-container--admin-autocomplete select2-container--below {
    background-color: black !important;
}

html.dark .select2-dropdown {
    background-color: rgb(17 24 39 / var(--tw-bg-opacity)) !important;
}

html.dark .select2-selection {
    background-color: rgb(17 24 39 / var(--tw-bg-opacity)) !important;
}

html.dark .select2-container--default .select2-results__option[aria-selected=true] {
    background-color: rgb(17 24 39 / var(--tw-bg-opacity)) !important;
}

html.dark #main_form {
    background-color: rgb(31 41 55 / var(--tw-bg-opacity)) !important;
}

.bg-red {
    --tw-bg-opacity: 1;
    background-color: rgb(17 27 51);
}

/* Site name first letter styling */
#site-name::first-letter {
    color: red;
    font-size: 16pt;
}

/* RTL Support for Arabic */
[dir="rtl"] .datetimeshortcuts {
    right: auto;
    left: 0;
}

[dir="rtl"] .timezonewarning {
    right: auto;
    left: 5rem;
}

[dir="rtl"] th {
    text-align: right;
}

[dir="rtl"] td {
    text-align: right;
}

/* Horizontal filter grid styles */
#filter-form .grid {
    grid-auto-flow: dense;
}

#filter-form .grid > div {
    min-width: 0;
}

#filter-form .grid input[type="text"],
#filter-form .grid select {
    width: 100%;
}

/* Ensure filter inputs match Unfold styling */
#filter-form input[type="text"]:not([class*="bg-"]) {
    border: 1px solid rgb(229 231 235);
    border-radius: 0.375rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    width: 100%;
}

html.dark #filter-form input[type="text"]:not([class*="bg-"]) {
    border-color: rgb(55 65 81);
    background-color: rgb(17 24 39);
    color: rgb(229 231 235);
}

#filter-form select {
    border: 1px solid rgb(229 231 235);
    border-radius: 0.375rem;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    width: 100%;
    background-color: white;
}

html.dark #filter-form select {
    border-color: rgb(55 65 81);
    background-color: rgb(17 24 39);
    color: rgb(229 231 235);
}

/* Ensure sidebar is blurred along with content when calendar/modal opens */
/* Sidebar wrapper is z-60 by default, lower it below modal overlay (z-50) */
#nav-sidebar,
.relative.z-60 {
    z-index: 40 !important;
}

/* Calendar popup must be above the blur overlay */
.calendarbox,
.clockbox,
.calendar-cancel,
.calendar-shortcuts,
div[class*="calendar"] {
    z-index: 9999 !important;
}

/* Date range filter - inputs take full width */
#filter-form .flex-row.gap-2 {
    width: 100%;
}

#filter-form .flex-row.gap-2 .flex-1 {
    flex: 1 1 0%;
    min-width: 0;
}

#filter-form .flex-row.gap-2 input[type="text"],
#filter-form .flex-row.gap-2 input {
    width: 100% !important;
}

/* Autocomplete/Select2 dropdown arrow spacing */
.select2-container--default .select2-selection--single .select2-selection__arrow {
    right: 8px;
}

/* Autocomplete/Select2 dropdown solid background in dark mode */
html.dark .select2-container--default .select2-dropdown {
    background-color: rgb(17 24 39) !important;
    border-color: rgb(55 65 81);
}

html.dark .select2-container--default .select2-results {
    background-color: rgb(17 24 39) !important;
}

html.dark .select2-results__option {
    background-color: rgb(17 24 39) !important;
}

html.dark .select2-container--default .select2-results__option--highlighted,
html.dark .select2-container--default .select2-results__option--highlighted[aria-selected],
html.dark .select2-results__option:hover {
    background-color: rgb(55 65 81) !important;
}

html.dark .select2-container--default .select2-search--dropdown .select2-search__field {
    background-color: rgb(31 41 55);
    border-color: rgb(55 65 81);
    color: rgb(229 231 235);
}

/* Select2 results list container */
html.dark .select2-results__options {
    background-color: rgb(17 24 39) !important;
}

html.dark li.select2-results__option {
    background-color: rgb(17 24 39) !important;
    color: rgb(229 231 235);
}

/* Filter buttons - always position at the last column of the grid */
#filter-form .filter-buttons-container {
    grid-column: -2 / -1;  /* Start at second-to-last line, end at last line */
    justify-self: end;
    align-self: end;  /* Align to bottom of grid cell */
}

/* On mobile (1 column), let it flow naturally */
@media (max-width: 639px) {
    #filter-form .filter-buttons-container {
        grid-column: auto;
        justify-self: stretch;
    }
}
