/**
 * ModernFilter Styles
 * 
 * Modern, chip-based filter UI for Yii GridViews
 * Bootstrap 5 compatible with Dark Mode and RTL support
 */

/* ============================================
   Filter Widget Container
   ============================================ */

.modern-filter-widget {
    position: relative;
    margin-bottom: 0.5rem;
    z-index: 100;
    /* Seamlessly connect to header - no gap */
    margin-top: 0;
}

/* ============================================
   Filter Bar
   ============================================ */

.modern-filter-bar {
    position: relative; /* For ::before pseudo-element */
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    /* Glassmorphism to match header */
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-top: none; /* Remove top border for seamless connection */
    border-radius: 0 0 12px 12px;
    box-shadow: 0 8px 32px rgba(31, 38, 135, 0.06);
    min-height: 4rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark mode glassmorphism for filter bar */
[data-bs-theme="dark"] .modern-filter-bar {
    background: rgba(26, 29, 35, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-top: none;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.25);
}

/* ============================================
   Filter Controls (Buttons)
   ============================================ */

.modern-filter-controls {
    display: flex;
    align-items: center;
}

.modern-filter-add-btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    white-space: nowrap;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    /* Override Bootstrap btn-sm for consistency */
    padding: 0.5rem 1rem !important;
    font-size: 0.875rem !important;
    line-height: 1.5 !important;
    min-height: 38px;
}

.modern-filter-add-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(var(--bs-primary-rgb), 0.2);
}

.modern-filter-add-btn:active {
    transform: translateY(0);
}

.modern-filter-add-btn .modern-filter-count {
    font-size: 0.75rem;
    padding: 0.25em 0.5em;
    border-radius: 10rem;
}

.modern-filter-clear-all {
    white-space: nowrap;
    border-radius: 8px;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    /* Override Bootstrap btn-sm for consistency */
    padding: 0.5rem 1rem !important;
    font-size: 0.875rem !important;
    line-height: 1.5 !important;
    min-height: 38px;
}

.modern-filter-clear-all:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(var(--bs-danger-rgb), 0.2);
}

.modern-filter-clear-all:active {
    transform: translateY(0);
}

/* ============================================
   Quick Search Input
   ============================================ */

.modern-filter-quick-search {
    flex: 0 1 auto;
    min-width: 250px;
    max-width: 450px;
    margin-inline-start: auto; /* Push to end (right in LTR, left in RTL) */
}

@media (min-width: 768px) {
    .modern-filter-quick-search {
        min-width: 300px;
    }
}

@media (min-width: 992px) {
    .modern-filter-quick-search {
        min-width: 350px;
    }
}

.modern-filter-quick-search .input-group-text {
    background: rgba(var(--bs-primary-rgb), 0.05);
    border: 1px solid rgba(var(--bs-primary-rgb), 0.15);
    border-inline-end: none; /* RTL: Use logical property instead of border-right */
    color: var(--bs-link-color);
    transition: all 0.2s ease;
    /* Override input-group-sm for consistency */
    padding: 0.5rem 0.75rem !important;
    font-size: 0.875rem !important;
    line-height: 1.5 !important;
}

[data-bs-theme="dark"] .modern-filter-quick-search .input-group-text {
    background: rgba(var(--bs-primary-rgb), 0.1);
    border-color: rgba(var(--bs-primary-rgb), 0.25);
}

.modern-filter-quick-input {
    border-inline-start: none !important; /* RTL: Use logical property instead of border-left */
    border: 1px solid rgba(var(--bs-primary-rgb), 0.15);
    background: rgba(255, 255, 255, 0.6);
    transition: all 0.2s ease;
    /* Override form-control-sm for consistency */
    padding: 0.5rem 0.75rem !important;
    padding-inline-start: 0.75rem !important; /* RTL: Use logical property instead of padding-left */
    font-size: 0.875rem !important;
    line-height: 1.5 !important;
    min-height: 38px;
}

[data-bs-theme="dark"] .modern-filter-quick-input {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(var(--bs-primary-rgb), 0.25);
}

.modern-filter-quick-input:focus {
    border-color: var(--bs-primary);
    background: rgba(255, 255, 255, 0.9);
    box-shadow: 0 0 0 3px rgba(var(--bs-primary-rgb), 0.12);
}

[data-bs-theme="dark"] .modern-filter-quick-input:focus {
    background: rgba(255, 255, 255, 0.08);
}

.modern-filter-quick-input:focus + .input-group-text,
.modern-filter-quick-search .input-group:focus-within .input-group-text {
    border-color: var(--bs-primary);
}

/* ============================================
   Filter Chips Container
   ============================================ */

.modern-filter-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
}

/* ============================================
   Individual Filter Chip
   ============================================ */

.modern-filter-chip {
    display: inline-flex;
    align-items: stretch;
    border-radius: 20px;
    overflow: hidden;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    background: rgba(255, 255, 255, 0.9);
    border: 1px solid rgba(0, 0, 0, 0.06);
}

/* Override Bootstrap button borders within chips */
.modern-filter-chip .btn {
    border: none !important;
    border-radius: 0 !important;
}

/* Maintain only the internal divider between label and remove button */
.modern-filter-chip .modern-filter-chip-remove {
    border-inline-start: 1px solid rgba(0, 0, 0, 0.08) !important; /* RTL: Use logical property */
}

[data-bs-theme="dark"] .modern-filter-chip {
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

[data-bs-theme="dark"] .modern-filter-chip .modern-filter-chip-remove {
    border-inline-start: 1px solid rgba(255, 255, 255, 0.08) !important; /* RTL: Use logical property */
}

.modern-filter-chip:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

[data-bs-theme="dark"] .modern-filter-chip:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.modern-filter-chip-label {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: transparent;
}

.modern-filter-chip-label:hover {
    background: linear-gradient(135deg, rgba(var(--bs-primary-rgb), 0.08) 0%, rgba(var(--bs-primary-rgb), 0.04) 100%);
    color: var(--bs-link-color);
}

[data-bs-theme="dark"] .modern-filter-chip-label:hover {
    background: linear-gradient(135deg, rgba(var(--bs-primary-rgb), 0.15) 0%, rgba(var(--bs-primary-rgb), 0.08) 100%);
}

.modern-filter-chip-label strong {
    font-weight: 600;
}

.modern-filter-chip-remove {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 0.75rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: transparent;
}

.modern-filter-chip-remove:hover {
    background: linear-gradient(135deg, rgba(var(--bs-danger-rgb), 0.15) 0%, rgba(var(--bs-danger-rgb), 0.08) 100%);
    color: var(--bs-danger);
}

[data-bs-theme="dark"] .modern-filter-chip-remove:hover {
    background: linear-gradient(135deg, rgba(var(--bs-danger-rgb), 0.25) 0%, rgba(var(--bs-danger-rgb), 0.15) 100%);
}

.modern-filter-chip-remove i {
    font-size: 0.75rem;
}

/* ============================================
   Field Selection Dropdown
   ============================================ */

.modern-filter-dropdown {
    position: absolute;
    min-width: 280px;
    max-width: 420px;
    /* Enhanced glassmorphism for dropdowns */
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 12px;
    box-shadow: 0 12px 48px rgba(31, 38, 135, 0.15);
    z-index: 1050;
    display: none;
    animation: dropdownSlideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-bs-theme="dark"] .modern-filter-dropdown {
    background: rgba(26, 29, 35, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.4);
}

@keyframes dropdownSlideIn {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modern-filter-dropdown-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 12px 12px 0 0;
    background: linear-gradient(135deg, rgba(var(--bs-primary-rgb), 0.05) 0%, rgba(var(--bs-primary-rgb), 0.02) 100%);
}

[data-bs-theme="dark"] .modern-filter-dropdown-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: linear-gradient(135deg, rgba(var(--bs-primary-rgb), 0.08) 0%, rgba(var(--bs-primary-rgb), 0.04) 100%);
}

.modern-filter-dropdown-header h6 {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--bs-body-color);
}

.modern-filter-dropdown-body {
    padding: 0.5rem;
    max-height: 400px;
    overflow-y: auto;
}

.modern-filter-fields-list {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.modern-filter-field-btn {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.625rem 1rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    text-align: start; /* RTL: Use logical property instead of 'left' */
    font-size: 0.875rem;
    color: var(--bs-body-color);
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.modern-filter-field-btn:hover {
    background: linear-gradient(135deg, rgba(var(--bs-primary-rgb), 0.08) 0%, rgba(var(--bs-primary-rgb), 0.04) 100%);
    border-color: rgba(var(--bs-primary-rgb), 0.15);
    color: var(--bs-link-color);
    transform: translateX(4px);
}

/* RTL: Reverse hover animation direction */
[dir="rtl"] .modern-filter-field-btn:hover {
    transform: translateX(-4px);
}

[data-bs-theme="dark"] .modern-filter-field-btn:hover {
    background: linear-gradient(135deg, rgba(var(--bs-primary-rgb), 0.15) 0%, rgba(var(--bs-primary-rgb), 0.08) 100%);
}

.modern-filter-field-btn i {
    opacity: 0.6;
}

.modern-filter-field-btn:hover i {
    opacity: 1;
}

/* ============================================
   Edit Dropdown
   ============================================ */

.modern-filter-edit-dropdown {
    position: absolute;
    min-width: 320px;
    max-width: 520px;
    /* Enhanced glassmorphism for edit dropdowns */
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(20px) saturate(180%);
    -webkit-backdrop-filter: blur(20px) saturate(180%);
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 12px;
    box-shadow: 0 12px 48px rgba(31, 38, 135, 0.15);
    z-index: 1060;
    display: none;
    animation: dropdownSlideIn 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-bs-theme="dark"] .modern-filter-edit-dropdown {
    background: rgba(26, 29, 35, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 12px 48px rgba(0, 0, 0, 0.4);
}

.modern-filter-edit-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 12px 12px 0 0;
    background: linear-gradient(135deg, rgba(var(--bs-primary-rgb), 0.05) 0%, rgba(var(--bs-primary-rgb), 0.02) 100%);
}

[data-bs-theme="dark"] .modern-filter-edit-header {
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    background: linear-gradient(135deg, rgba(var(--bs-primary-rgb), 0.08) 0%, rgba(var(--bs-primary-rgb), 0.04) 100%);
}

.modern-filter-edit-header h6 {
    margin: 0;
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--bs-body-color);
}

.modern-filter-edit-body {
    padding: 1rem;
    max-height: 400px;
    overflow-y: auto;
}

.modern-filter-edit-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 0 0 12px 12px;
    background: linear-gradient(135deg, rgba(var(--bs-primary-rgb), 0.02) 0%, rgba(var(--bs-primary-rgb), 0.01) 100%);
}

[data-bs-theme="dark"] .modern-filter-edit-footer {
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: linear-gradient(135deg, rgba(var(--bs-primary-rgb), 0.04) 0%, rgba(var(--bs-primary-rgb), 0.02) 100%);
}

/* ============================================
   Multiselect Checkbox List
   ============================================ */

.modern-filter-multiselect {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 250px;
    overflow-y: auto;
    padding: 0.5rem;
    background-color: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.25rem;
}

.modern-filter-multiselect .form-check {
    margin-bottom: 0;
    padding-inline-start: 1.5rem; /* RTL: Use logical property instead of padding-left */
}

.modern-filter-multiselect .form-check-label {
    font-size: 0.875rem;
    cursor: pointer;
    user-select: none;
}

.modern-filter-multiselect .form-check-input {
    cursor: pointer;
}

/* ============================================
   Autocomplete Results
   ============================================ */

.modern-filter-autocomplete-results {
    position: absolute;
    width: calc(100% - 2rem);
    max-height: 200px;
    overflow-y: auto;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.25rem;
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.1);
    z-index: 1070;
    margin-top: 0.25rem;
}

.modern-filter-autocomplete-results .list-group-item {
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
    border: none;
    border-bottom: 1px solid var(--bs-border-color);
    cursor: pointer;
}

.modern-filter-autocomplete-results .list-group-item:last-child {
    border-bottom: none;
}

.modern-filter-autocomplete-results .list-group-item:hover,
.modern-filter-autocomplete-results .list-group-item.active {
    background-color: var(--bs-primary-bg-subtle);
    color: var(--bs-link-color);
}

/* ============================================
   Multi-select Autocomplete Tags
   ============================================ */

.modern-filter-tags-input {
    position: relative;
}

.modern-filter-tags-container {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
    padding: 0.375rem 0.5rem;
    background: var(--bs-body-bg);
    border: 1px solid var(--bs-border-color);
    border-radius: 0.375rem;
    min-height: 2.5rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.modern-filter-tags-container:focus-within {
    border-color: var(--bs-primary);
    box-shadow: 0 0 0 0.2rem rgba(var(--bs-primary-rgb), 0.25);
}

.modern-filter-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: var(--bs-primary);
    color: white;
    border-radius: 0.25rem;
    font-size: 0.8125rem;
    line-height: 1.4;
    white-space: nowrap;
    animation: tagSlideIn 0.2s ease-out;
}

@keyframes tagSlideIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modern-filter-tag-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    padding: 0;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.15s;
    font-size: 0.625rem;
}

.modern-filter-tag-remove:hover {
    background: rgba(255, 255, 255, 0.4);
}

.modern-filter-tag-remove i {
    font-size: 0.625rem;
}

.modern-filter-tags-search {
    flex: 1;
    min-width: 120px;
    border: none;
    outline: none;
    background: transparent;
    padding: 0.25rem;
    font-size: 0.875rem;
    color: var(--bs-body-color); /* Ensure text is visible in both light and dark modes */
}

.modern-filter-tags-search::placeholder {
    color: var(--bs-secondary-color);
}

/* Dark mode adjustments for tags */
[data-bs-theme="dark"] .modern-filter-tags-container {
    background-color: var(--bs-dark);
    border-color: var(--bs-secondary);
}

[data-bs-theme="dark"] .modern-filter-tag {
    background: var(--bs-primary);
}

/* ============================================
   Dark Mode Support
   ============================================ */

[data-bs-theme="dark"] .modern-filter-dropdown,
[data-bs-theme="dark"] .modern-filter-edit-dropdown {
    background-color: var(--bs-dark);
    border-color: var(--bs-secondary);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.5);
}

[data-bs-theme="dark"] .modern-filter-dropdown-header,
[data-bs-theme="dark"] .modern-filter-edit-header,
[data-bs-theme="dark"] .modern-filter-edit-footer {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: var(--bs-secondary);
}

[data-bs-theme="dark"] .modern-filter-multiselect {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: var(--bs-secondary);
}

[data-bs-theme="dark"] .modern-filter-autocomplete-results {
    background-color: var(--bs-dark);
    border-color: var(--bs-secondary);
    box-shadow: 0 0.25rem 0.5rem rgba(0, 0, 0, 0.5);
}

/* ============================================
   RTL Support
   ============================================ */

/* Note: Most RTL support is now handled via logical properties (inline-start, inline-end)
   These rules provide additional RTL-specific adjustments */

[dir="rtl"] .modern-filter-chip-label {
    border-inline-start: none !important;
    border-inline-end: 1px solid var(--bs-border-color);
}

[dir="rtl"] .modern-filter-chip-remove {
    border-inline-end: 1px solid var(--bs-border-color);
    border-inline-start: none;
}

[dir="rtl"] .modern-filter-field-btn {
    text-align: start; /* Already uses logical property */
}

/* ============================================
   Responsive Design
   ============================================ */

@media (max-width: 768px) {
    .modern-filter-bar {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .modern-filter-controls {
        width: 100%;
        justify-content: space-between;
    }
    
    .modern-filter-chips {
        width: 100%;
    }
    
    .modern-filter-quick-search {
        width: 100%;
        max-width: 100%;
        margin-top: 0.5rem;
    }
    
    .modern-filter-dropdown,
    .modern-filter-edit-dropdown {
        inset-inline: 0 !important; /* RTL: Use logical property for left+right positioning */
        max-width: calc(100vw - 2rem);
        margin: 0 1rem;
    }
}

/* ============================================
   Accessibility
   ============================================ */

.modern-filter-chip-remove:focus,
.modern-filter-field-btn:focus,
.modern-filter-add-btn:focus,
.modern-filter-clear-all:focus {
    outline: 2px solid var(--bs-primary);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .modern-filter-bar {
        border-width: 2px;
    }
    
    .modern-filter-chip {
        border-width: 2px;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    .modern-filter-chip,
    .modern-filter-chip-label,
    .modern-filter-chip-remove,
    .modern-filter-field-btn {
        transition: none;
    }
}

/* ============================================
   Loading State
   ============================================ */

.modern-filter-widget.loading {
    pointer-events: none;
    opacity: 0.6;
}

.modern-filter-widget.loading::after {
    content: '';   
    position: absolute;
    top: 50%;
    left: 50%;
    width: 1.5rem;
    height: 1.5rem;
    margin: -0.75rem 0 0 -0.75rem;
    border: 3px solid var(--bs-primary);
    border-inline-end-color: transparent; /* RTL: Use logical property instead of border-right-color */
    border-radius: 50%;
    animation: spinner-border 0.75s linear infinite;
}

@keyframes spinner-border {
    to {
        transform: rotate(360deg);
    }
}

/* ============================================
   Empty State
   ============================================ */

.modern-filter-chips.modern-filter-chips-has-message:empty::before {
    content: '';
}

.modern-filter-chips-empty-message {
    color: var(--bs-secondary-color);
    font-size: 0.875rem;
    font-style: italic;
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.25rem 0;
}

/* RTL support for empty message */
[dir="rtl"] .modern-filter-chips-empty-message {
    text-align: right;
}

/* ============================================
   Print Styles
   ============================================ */

@media print {
    .modern-filter-controls {
        display: none;
    }
    
    .modern-filter-chip-remove {
        display: none;
    }
    
    .modern-filter-dropdown,
    .modern-filter-edit-dropdown {
        display: none !important;
    }
}

/* ============================================
   Flatpickr Integration for Date Range
   ============================================ */

/* Ensure Flatpickr calendar appears above edit dropdown */
.flatpickr-calendar {
    z-index: 1070 !important; /* Higher than edit dropdown (1060) */
}

/* Style the daterange input to match other filter inputs */
.modern-filter-edit-body .flatpickr-daterange {
    width: 100%;
}

/* Visual feedback when only one date is selected (partial selection) */
.flatpickr-daterange.partial-selection {
    border-color: #ffc107 !important;
    background-color: #fff3cd;
}

[data-bs-theme="dark"] .flatpickr-daterange.partial-selection {
    background-color: rgba(255, 193, 7, 0.15);
    border-color: #ffc107 !important;
}

/* Ensure Flatpickr input is styled consistently */
.flatpickr-input.flatpickr-daterange {
    cursor: pointer;
}

/* Dark mode compatibility for Flatpickr */
[data-bs-theme="dark"] .flatpickr-calendar {
    background-color: var(--bs-dark);
    border-color: var(--bs-border-color);
    box-shadow: 0 0.5rem 1rem rgba(0, 0, 0, 0.5);
}

[data-bs-theme="dark"] .flatpickr-day {
    color: var(--bs-body-color);
}

[data-bs-theme="dark"] .flatpickr-day:hover,
[data-bs-theme="dark"] .flatpickr-day.selected {
    background-color: var(--bs-primary);
    border-color: var(--bs-primary);
}

/* ============================================
   Chip/Tag Input Field
   ============================================ */

/* Container that holds chips and input */
.chip-input-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    align-items: center;
    padding: 0.375rem 0.5rem;
    min-height: 2.5rem;
    border: 1px solid #dee2e6;
    border-radius: 0.375rem;
    background-color: #fff;
    cursor: text;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.chip-input-container:focus-within {
    border-color: #86b7fe;
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

/* Individual chip/tag */
.chip-input-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background-color: #0d6efd;
    color: #fff;
    border-radius: 0.25rem;
    font-size: 0.875rem;
    line-height: 1.2;
    white-space: nowrap;
    animation: chipFadeIn 0.2s ease-out;
}

@keyframes chipFadeIn {
    from {
        opacity: 0;
        transform: scale(0.8);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Remove button inside chip */
.chip-input-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1rem;
    height: 1rem;
    padding: 0;
    margin: 0;
    margin-inline-start: 0.25rem; /* RTL: Use logical property instead of margin-left */
    background: rgba(255, 255, 255, 0.3);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
    transition: background-color 0.15s ease-in-out;
}

.chip-input-remove:hover {
    background: rgba(255, 255, 255, 0.5);
}

.chip-input-remove:active {
    background: rgba(255, 255, 255, 0.7);
}

/* Input field inside chip container */
.chip-input-field {
    flex: 1;
    min-width: 120px;
    border: none;
    outline: none;
    background: transparent;
    padding: 0.25rem 0;
    font-size: 0.875rem;
    color: var(--bs-body-color);
    caret-color: var(--bs-body-color);
}

.chip-input-field::placeholder {
    color: #6c757d;
    opacity: 0.7;
}

/* Invalid input feedback */
.chip-input-field.is-invalid {
    animation: shake 0.3s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-5px); }
    75% { transform: translateX(5px); }
}

/* Show red border on container when input is invalid */
.chip-input-container:has(.chip-input-field.is-invalid) {
    border-color: #dc3545;
    box-shadow: 0 0 0 0.25rem rgba(220, 53, 69, 0.25);
}

/* Dark mode support */
[data-bs-theme="dark"] .chip-input-container {
    background-color: #212529;
    border-color: #495057;
}

[data-bs-theme="dark"] .chip-input-container:focus-within {
    border-color: #6ea8fe;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

[data-bs-theme="dark"] .chip-input-tag {
    background-color: #0a58ca;
    color: #fff;
}

[data-bs-theme="dark"] .chip-input-field {
    color: #dee2e6;
}

[data-bs-theme="dark"] .chip-input-field::placeholder {
    color: #adb5bd;
}
