/* =========================================================
   UI Kit polish — Flatpickr, Select2, AppLoader
   ========================================================= */

/* ---------- Global loader ---------- */
.app-loader {
    align-items: center;
    display: none;
    inset: 0;
    justify-content: center;
    pointer-events: all;
    position: fixed;
    z-index: 2000;
}

.app-loader.is-visible,
.app-loader:not([hidden]) {
    display: flex;
}

.app-loader[hidden] {
    display: none !important;
}

.app-loader__backdrop {
    backdrop-filter: blur(2px);
    background: rgba(15, 23, 42, 0.28);
    inset: 0;
    position: absolute;
}

.app-loader__panel {
    align-items: center;
    background: var(--bg-surface, #fff);
    border: 1px solid var(--border-default, #e2e8f0);
    border-radius: 14px;
    box-shadow: var(--shadow-lg, 0 24px 60px rgba(15, 23, 42, 0.12));
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    min-width: 160px;
    padding: 1.25rem 1.5rem;
    position: relative;
    z-index: 1;
}

.app-loader__spinner {
    animation: app-loader-spin 0.75s linear infinite;
    border: 3px solid var(--border-default, #e2e8f0);
    border-radius: 50%;
    border-top-color: var(--brand-primary, #1e3a8a);
    height: 32px;
    width: 32px;
}

.app-loader__text {
    color: var(--text-secondary, #64748b);
    font-size: 0.8125rem;
    font-weight: 600;
    letter-spacing: -0.01em;
}

@keyframes app-loader-spin {
    to { transform: rotate(360deg); }
}

html.app-loading,
html.app-loading body {
    cursor: progress;
}

/* ---------- Control parity (Select2, Flatpickr ↔ .form-control) ---------- */
.select2-container--bootstrap-5 {
    display: block;
    font-family: var(--control-font-family) !important;
    font-size: var(--control-font-size) !important;
    line-height: var(--control-line-height);
    width: 100% !important;
}

/* ---------- Flatpickr theme ---------- */
.flatpickr-calendar {
    border: 1px solid var(--border-default, #e2e8f0) !important;
    border-radius: 12px !important;
    box-shadow: var(--shadow-md, 0 12px 32px rgba(15, 23, 42, 0.08)) !important;
    font-family: var(--control-font-family) !important;
    font-size: var(--control-font-size) !important;
    line-height: var(--control-line-height);
}

.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange,
.flatpickr-day.selected:hover {
    background: var(--brand-primary, #1e3a8a) !important;
    border-color: var(--brand-primary, #1e3a8a) !important;
}

.flatpickr-months .flatpickr-month,
.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-current-month input.cur-year,
.flatpickr-time input,
span.flatpickr-weekday,
.flatpickr-day {
    color: var(--text-primary, #0f172a);
    fill: var(--text-primary, #0f172a);
    font-family: var(--control-font-family) !important;
    font-size: var(--control-font-size) !important;
}

.flatpickr-input[readonly],
input.flatpickr-input,
input.flatpickr-input.form-control,
.form-control.flatpickr-input,
.form-control-sm.flatpickr-input,
input.form-control-sm.flatpickr-input {
    background-color: var(--control-bg, #fff) !important;
    color: var(--text-primary) !important;
    cursor: pointer;
    font-family: var(--control-font-family) !important;
    font-size: var(--control-font-size) !important;
    height: var(--input-height) !important;
    letter-spacing: var(--letter-normal);
    line-height: var(--control-line-height) !important;
    min-height: var(--input-height) !important;
    padding: 0.5rem 0.85rem !important;
}

/* ---------- Select2 — mirror .form-select layout system-wide ---------- */
.select2-container--bootstrap-5 .select2-selection {
    align-items: center !important;
    background-color: var(--control-bg) !important;
    border: 1px solid var(--control-border) !important;
    border-radius: var(--radius-sm) !important;
    box-shadow: none !important;
    color: var(--text-primary) !important;
    display: flex !important;
    font-family: var(--control-font-family) !important;
    font-size: var(--control-font-size) !important;
    height: var(--input-height) !important;
    line-height: var(--control-line-height) !important;
    min-height: var(--input-height) !important;
    padding: 0 !important;
    position: relative !important;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast),
        background-color var(--transition-fast);
}

.select2-container--bootstrap-5:not(.select2-container--disabled) .select2-selection:hover {
    border-color: var(--border-strong) !important;
}

.select2-container--bootstrap-5.select2-container--disabled .select2-selection {
    background-color: var(--bg-surface-2) !important;
    cursor: not-allowed;
}

.select2-container--bootstrap-5 .select2-selection--single {
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='%2364748b' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M2 5l6 6 6-6'/%3e%3c/svg%3e") !important;
    background-position: right 0.85rem center !important;
    background-repeat: no-repeat !important;
    background-size: 14px 10px !important;
    padding: 0 !important;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered,
.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__rendered,
.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice,
.select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice__display,
.select2-container--bootstrap-5 .select2-selection--multiple .select2-search--inline .select2-search__field {
    color: var(--text-primary) !important;
    font-family: var(--control-font-family) !important;
    font-size: var(--control-font-size) !important;
    font-weight: 400;
    letter-spacing: var(--letter-normal);
    line-height: var(--control-line-height) !important;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    padding: 0.5rem 2.25rem 0.5rem 0.85rem !important;
    text-overflow: ellipsis;
    white-space: nowrap;
    width: 100%;
}

.select2-container--bootstrap-5 .select2-selection--single:has(.select2-selection__clear) .select2-selection__rendered {
    padding-inline-end: 3.75rem !important;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__placeholder {
    color: var(--text-muted) !important;
    font-family: var(--control-font-family) !important;
    font-size: var(--control-font-size) !important;
}

/* Clear control: hide Select2's raw "×" text (avoids ghost bar next to chevron). */
.select2-container--bootstrap-5 .select2-selection--single .select2-selection__clear {
    align-items: center !important;
    background: transparent !important;
    border: 0 !important;
    box-shadow: none !important;
    color: transparent !important;
    display: inline-flex !important;
    font-size: 0 !important;
    height: 1.1rem !important;
    justify-content: center !important;
    letter-spacing: 0 !important;
    line-height: 0 !important;
    margin: 0 !important;
    opacity: 0.75;
    overflow: hidden !important;
    padding: 0 !important;
    position: absolute !important;
    right: 2.35rem !important;
    text-indent: -9999px !important;
    text-shadow: none !important;
    top: 50% !important;
    transform: translateY(-50%) !important;
    transition: opacity var(--transition-fast);
    width: 1.1rem !important;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__clear::before {
    color: var(--text-muted) !important;
    content: '\00d7';
    display: block !important;
    font-family: var(--font-sans, system-ui, sans-serif) !important;
    font-size: 0.95rem !important;
    font-weight: 600 !important;
    left: 50%;
    line-height: 1 !important;
    position: absolute !important;
    text-indent: 0 !important;
    top: 50%;
    transform: translate(-50%, -50%);
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__clear:hover {
    opacity: 1;
}

.select2-container--bootstrap-5 .select2-selection--single .select2-selection__clear:hover::before {
    color: var(--fin-negative) !important;
}

.select2-container--bootstrap-5 .select2-selection--multiple {
    height: auto !important;
    min-height: var(--input-height) !important;
    padding: 0.25rem 0.4rem !important;
}

.select2-container--bootstrap-5.select2-container--focus .select2-selection,
.select2-container--bootstrap-5.select2-container--open .select2-selection {
    background-color: #fff !important;
    border-color: var(--brand-primary) !important;
    box-shadow: var(--focus-ring) !important;
}

/* Validation state for Select2 */
select.is-invalid + .select2-container .select2-selection {
    border-color: var(--fin-negative, #dc2626) !important;
}

select.is-valid + .select2-container .select2-selection {
    border-color: var(--fin-positive, #059669) !important;
}

.select2-container--bootstrap-5 .select2-dropdown {
    background-color: var(--bg-surface) !important;
    border-color: var(--border-default, #e2e8f0) !important;
    border-radius: var(--radius-md) !important;
    box-shadow: var(--shadow-md) !important;
    color: var(--text-primary) !important;
    font-family: var(--control-font-family) !important;
    font-size: var(--control-font-size) !important;
    overflow: hidden;
    padding: 0.35rem !important;
}

.select2-container--bootstrap-5 .select2-dropdown .select2-search {
    padding: 0.35rem 0.4rem 0.5rem !important;
}

.select2-container--bootstrap-5 .select2-results__option {
    border-radius: var(--radius-sm) !important;
    color: var(--text-primary) !important;
    font-family: var(--control-font-family) !important;
    font-size: var(--control-font-size) !important;
    line-height: var(--control-line-height);
    margin: 0.1rem 0 !important;
    padding: 0.5rem 0.75rem !important;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.select2-container--bootstrap-5 .select2-results__option--selectable {
    cursor: pointer;
}

.select2-container--bootstrap-5 .select2-results__option--highlighted,
.select2-container--bootstrap-5 .select2-results__option--selectable:hover {
    background-color: var(--bg-surface-hover) !important;
    color: var(--text-primary) !important;
}

.select2-container--bootstrap-5 .select2-results__option--selected {
    background-color: var(--brand-primary-soft) !important;
    color: var(--brand-primary) !important;
    font-weight: 500;
}

.select2-container--bootstrap-5 .select2-results__option--selected.select2-results__option--highlighted {
    background-color: rgba(var(--brand-primary-rgb), 0.14) !important;
    color: var(--brand-primary-hover) !important;
}

.select2-container--bootstrap-5 .select2-results__option--disabled,
.select2-container--bootstrap-5 .select2-results__option[aria-disabled="true"] {
    background-color: transparent !important;
    color: var(--text-muted) !important;
    cursor: not-allowed;
    opacity: 0.7;
}

.select2-container--bootstrap-5 .select2-results__option--group {
    color: var(--text-secondary) !important;
    font-size: var(--font-size-xs) !important;
    font-weight: 600;
    letter-spacing: 0.04em;
    padding: 0.35rem 0.75rem !important;
    text-transform: uppercase;
}

.select2-container--bootstrap-5 .select2-results__message {
    color: var(--text-secondary) !important;
}

.select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field {
    border-radius: 8px !important;
    border-color: var(--border-default) !important;
    color: var(--text-primary) !important;
    font-family: var(--control-font-family) !important;
    font-size: var(--control-font-size) !important;
    line-height: var(--control-line-height) !important;
    min-height: var(--input-height-sm) !important;
    padding: 0.35rem 0.65rem !important;
}

/* Dense form-select-sm + select2 */
.form-select-sm + .select2-container--bootstrap-5 {
    font-size: var(--control-font-size-sm) !important;
}

.form-select-sm + .select2-container--bootstrap-5 .select2-selection {
    font-size: var(--control-font-size-sm) !important;
    height: var(--input-height-sm) !important;
    min-height: var(--input-height-sm) !important;
}

.form-select-sm + .select2-container--bootstrap-5 .select2-selection--single {
    background-position: right 0.65rem center !important;
    background-size: 12px 9px !important;
}

.form-select-sm + .select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered,
.form-select-sm + .select2-container--bootstrap-5 .select2-selection--single .select2-selection__placeholder,
.form-select-sm + .select2-container--bootstrap-5 .select2-results__option,
.form-select-sm + .select2-container--bootstrap-5 .select2-search--dropdown .select2-search__field {
    font-size: var(--control-font-size-sm) !important;
}

.form-select-sm + .select2-container--bootstrap-5 .select2-selection--single .select2-selection__rendered {
    padding: 0.3rem 2rem 0.3rem 0.65rem !important;
}

.form-select-sm + .select2-container--bootstrap-5 .select2-selection--single:has(.select2-selection__clear) .select2-selection__rendered {
    padding-inline-end: 3.25rem !important;
}

.form-select-sm + .select2-container--bootstrap-5 .select2-selection--single .select2-selection__clear {
    height: 1rem !important;
    right: 2rem !important;
    width: 1rem !important;
}

.form-select-sm + .select2-container--bootstrap-5 .select2-selection--single .select2-selection__clear::before {
    font-size: 0.85rem !important;
}

.form-control-sm.flatpickr-input,
input.form-control-sm.flatpickr-input {
    font-family: var(--control-font-family) !important;
    font-size: var(--control-font-size-sm) !important;
    height: var(--input-height-sm) !important;
    line-height: var(--control-line-height) !important;
    min-height: var(--input-height-sm) !important;
    padding: 0.3rem 0.65rem !important;
}

.form-select-sm + .select2-container--bootstrap-5 .select2-selection--multiple .select2-selection__choice__display,
.form-select-sm + .select2-container--bootstrap-5 .select2-selection--multiple .select2-search--inline .select2-search__field {
    font-size: var(--control-font-size-sm) !important;
}

/* Modal: ensure dropdown above modal content */
.modal .select2-container--open {
    z-index: 1080;
}

.modal .flatpickr-calendar.open {
    z-index: 1085;
}

/* ---------- Horizontal Scrollable Tab Navigation ---------- */
.fin-tabs-wrapper {
    overflow-x: auto;
    scrollbar-width: thin;
    padding-bottom: 4px;
}

.fin-tabs-wrapper::-webkit-scrollbar {
    height: 4px;
}

.fin-tabs-wrapper::-webkit-scrollbar-thumb {
    background: var(--border-default, #e2e8f0);
    border-radius: 4px;
}

.fin-tabs {
    gap: 0.35rem;
}

.fin-tabs .nav-link {
    background: var(--bg-surface, #ffffff);
    border: 1px solid var(--border-default, #e2e8f0);
    border-radius: 8px;
    color: var(--text-secondary, #64748b);
    font-size: 0.8125rem;
    font-weight: 500;
    transition: all 0.15s ease-in-out;
}

.fin-tabs .nav-link:hover {
    background: var(--bg-hover, #f8fafc);
    color: var(--text-primary, #0f172a);
}

.fin-tabs .nav-link.active {
    background: var(--brand-primary, #1e3a8a);
    border-color: var(--brand-primary, #1e3a8a);
    color: #ffffff !important;
    font-weight: 600;
    box-shadow: 0 4px 12px rgba(var(--brand-primary-rgb), 0.25);
}
