/* ============================================================
   InitiativesList – Accessible & Modern Styles
   WCAG 2.2 Level AA compliant
   ============================================================ */

/* --- Single-Line Filter Bar --- */
.initiatives-filter-bar {
    position: relative;
    z-index: 100;
    background: #fff;
    padding: 1rem 1.5rem;
    border-radius: 1rem;
    box-shadow: 0 2px 12px rgba(108, 59, 94, 0.06);
    margin-bottom: 1.25rem;
    transition: box-shadow 0.3s ease, transform 0.2s ease;
    border: 1px solid #f0eef2;
}

.initiatives-filter-bar.is-stuck {
    position: fixed;
    top: 70px;
    left: 0;
    right: 0;
    max-width: 1140px;
    margin-left: auto;
    margin-right: auto;
    padding-left: 1.5rem;
    padding-right: 1.5rem;
    border-radius: 0 0 1rem 1rem;
    box-shadow: 0 8px 32px rgba(108, 59, 94, 0.1);
    border-color: transparent;
}

.filter-bar-placeholder {
    display: none;
}

.filter-bar-placeholder.active {
    display: block;
}

/* Single-line flex layout */
.filter-row {
    display: flex;
    align-items: flex-end;
    gap: 1rem;
    flex-wrap: nowrap;
}

.filter-row .filter-field {
    flex: 1;
    min-width: 0;
}

.filter-row .filter-actions-inline {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
    padding-bottom: 0.25rem;
}

/* --- Bottom-border input fields --- */
.filter-field {
    position: relative;
}

.filter-field .filter-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: #6c3b5e;
    margin-bottom: 0.25rem;
    letter-spacing: 0.03em;
    text-transform: none;
    transition: color 0.2s;
}

.filter-field .filter-input {
    width: 100%;
    border: none;
    border-bottom: 2px solid #e0dce3;
    border-radius: 0;
    background: transparent;
    padding: 0.5rem 0.25rem;
    font-size: 0.95rem;
    color: #212529;
    min-height: 40px;
    transition: border-color 0.25s ease, background-color 0.2s ease;
    -webkit-appearance: none;
    appearance: none;
}

.filter-field .filter-input::placeholder {
    color: #adb5bd;
    font-weight: 400;
}

/* Hover state */
.filter-field .filter-input:hover {
    border-bottom-color: #b8a0c8;
    background-color: rgba(108, 59, 94, 0.02);
}

/* Focus state */
.filter-field .filter-input:focus {
    outline: none;
    border-bottom-color: #6c3b5e;
    background-color: rgba(108, 59, 94, 0.03);
    box-shadow: 0 2px 0 0 #6c3b5e;
}

.filter-field .filter-input:focus + .filter-label,
.filter-field:focus-within .filter-label {
    color: #6c3b5e;
}

/* Select dropdown arrow for bottom-border style */
.filter-field select.filter-input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236c3b5e' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: left 0.5rem center;
    padding-inline-start: 1.5rem;
}

[dir="ltr"] .filter-field select.filter-input {
    background-position: right 0.5rem center;
    padding-inline-start: 0.25rem;
    padding-inline-end: 1.5rem;
}

/* Search input with icon */
.filter-field .search-input-wrap {
    position: relative;
    display: flex;
    align-items: center;
}

.filter-field .search-input-wrap .filter-input {
    padding-inline-start: 2rem;
}

.filter-field .search-input-wrap .search-icon {
    position: absolute;
    inset-inline-start: 0.25rem;
    top: 50%;
    transform: translateY(-50%);
    color: #6c3b5e;
    font-size: 0.9rem;
    pointer-events: none;
    opacity: 0.7;
}

/* --- Primary action button (Filter/Search) --- */
.btn-filter-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 44px;
    min-width: 44px;
    padding: 0.625rem 1.5rem;
    border: none;
    border-radius: 2rem;
    font-size: 0.9rem;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #6c3b5e 0%, #8a4d7a 50%, #a15f8f 100%);
    box-shadow: 0 4px 16px rgba(108, 59, 94, 0.3);
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.25s ease, background 0.3s ease;
    text-decoration: none;
    white-space: nowrap;
}

.btn-filter-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px rgba(108, 59, 94, 0.4);
    background: linear-gradient(135deg, #7a4569 0%, #9c5a8a 50%, #b06fa0 100%);
}

.btn-filter-primary:focus-visible {
    outline: 3px solid #6c3b5e;
    outline-offset: 3px;
    transform: translateY(-1px);
}

.btn-filter-primary:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(108, 59, 94, 0.3);
}

/* --- Secondary action button (Clear) --- */
.btn-filter-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    min-height: 44px;
    min-width: 44px;
    padding: 0.625rem 1.25rem;
    border: 1.5px solid #dee2e6;
    border-radius: 2rem;
    font-size: 0.9rem;
    font-weight: 600;
    color: #6c757d;
    background: #fff;
    cursor: pointer;
    transition: border-color 0.2s, color 0.2s, background 0.2s;
    text-decoration: none;
    white-space: nowrap;
}

.btn-filter-secondary:hover {
    border-color: #dc3545;
    color: #dc3545;
    background: rgba(220, 53, 69, 0.04);
}

.btn-filter-secondary:focus-visible {
    outline: 3px solid #6c3b5e;
    outline-offset: 3px;
}

/* --- Responsive: stack on smaller screens --- */
@media (max-width: 991.98px) {
    .filter-row {
        flex-wrap: wrap;
    }
    .filter-row .filter-field {
        flex: 1 1 calc(50% - 0.5rem);
        min-width: calc(50% - 0.5rem);
    }
    .filter-row .filter-actions-inline {
        flex: 1 1 100%;
        justify-content: center;
        padding-top: 0.75rem;
    }
}

@media (max-width: 575.98px) {
    .filter-row .filter-field {
        flex: 1 1 100%;
    }
    .initiatives-filter-bar {
        padding: 0.875rem 1rem;
    }
}

/* --- Minimum font size 16px for legibility --- */
.initiatives-page label,
.initiatives-page input,
.initiatives-page select,
.initiatives-page button,
.initiatives-page a,
.initiatives-page p,
.initiatives-page div {
    font-size: 1rem; /* 16px base */
}

/* --- Touch target minimum 44x44px --- */
.initiatives-page .btn,
.initiatives-page .page-link,
.initiatives-page .category-pill,
.initiatives-page .subcategory-pill,
.initiatives-page .btn-back-to-top,
.initiatives-page .initiative-card-link {
    min-height: 44px;
    min-width: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
}

/* --- Focus indicators (visible, high contrast) --- */
.initiatives-page *:focus-visible {
    outline: 3px solid #6c3b5e;
    outline-offset: 2px;
    border-radius: 4px;
}

/* --- Category pills (wrapping multi-row layout) --- */
.category-nav {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem 0;
    flex-wrap: wrap;
}

.category-nav::-webkit-scrollbar {
    display: none;
}

.category-pill,
.subcategory-pill {
    white-space: nowrap;
    border-radius: 2rem;
    padding: 0.5rem 1.25rem;
    border: 1.5px solid #e0dce3;
    background: #fafafa;
    color: #555;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.category-pill:hover,
.category-pill:focus-visible,
.subcategory-pill:hover,
.subcategory-pill:focus-visible {
    border-color: #6c3b5e;
    color: #6c3b5e;
    background: rgba(108, 59, 94, 0.05);
    box-shadow: 0 2px 8px rgba(108, 59, 94, 0.12);
}

.category-pill[aria-current="true"],
.subcategory-pill[aria-current="true"] {
    background: linear-gradient(135deg, #6c3b5e, #8a4d7a);
    color: #fff;
    border-color: transparent;
    font-weight: 600;
    box-shadow: 0 3px 12px rgba(108, 59, 94, 0.25);
}

/* --- Subcategory group container (visually linked to parent) --- */
.subcategory-group {
    background: #f9f7fa;
    border: 1px solid #ebe7ed;
    border-radius: 0.75rem;
    padding: 0.75rem 1rem;
    margin-top: 0.5rem;
    position: relative;
}

.subcategory-group::before {
    content: '';
    position: absolute;
    top: -6px;
    inset-inline-start: 1.5rem;
    width: 12px;
    height: 12px;
    background: #f9f7fa;
    border-top: 1px solid #ebe7ed;
    border-inline-start: 1px solid #ebe7ed;
    transform: rotate(45deg);
}

.subcategory-group .subcategory-group-label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    color: #6c3b5e;
    margin-bottom: 0.5rem;
    letter-spacing: 0.02em;
}

.subcategory-group .category-nav {
    padding: 0;
}

/* --- Initiative cards --- */
.initiative-card {
    position: relative;
    border: 1px solid #dee2e6;
    border-radius: 0.75rem;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #fff;
}

.initiative-card:hover,
.initiative-card:focus-within {
    transform: translateY(-4px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.initiative-card .card-img-wrapper {
    width: 100%;
    aspect-ratio: 4 / 3;
    overflow: hidden;
    position: relative;
}

.initiative-card .card-img-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.initiative-card .card-content {
    padding: 1rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    text-align: center;
}

.initiative-card .card-title {
    font-size: 1rem;
    font-weight: 700;
    color: #212529;
    margin-bottom: 0.25rem;
    line-height: 1.4;
}

.initiative-card .card-org {
    font-size: 0.95rem;
    font-weight: 600;
    color: #555;
    margin-bottom: 0.75rem;
}

.initiative-card .btn-donate {
    background: #6c3b5e;
    color: #fff;
    border: none;
    border-radius: 2rem;
    padding: 0.625rem 1.5rem;
    font-weight: 700;
    font-size: 1rem;
    min-height: 44px;
    min-width: 44px;
    text-decoration: none;
    transition: background 0.2s, box-shadow 0.2s;
}

.initiative-card .btn-donate:hover,
.initiative-card .btn-donate:focus-visible {
    background: #8a4d7a;
    box-shadow: 0 4px 12px rgba(108, 59, 94, 0.4);
}

/* --- Preferred/star button --- */
.initiative-card .btn-preferred {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    z-index: 10;
    background: rgba(255, 255, 255, 0.9);
    border: none;
    border-radius: 50%;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 1.25rem;
    transition: background 0.2s;
}

[dir="rtl"] .initiative-card .btn-preferred {
    right: auto;
    left: 0.5rem;
}

.initiative-card .btn-preferred:hover,
.initiative-card .btn-preferred:focus-visible {
    background: rgba(255, 255, 255, 1);
}

.initiative-card .btn-preferred .active {
    color: #6c3b5e;
}

.initiative-card .btn-preferred .not-active {
    color: #80c8bd96;
}

/* --- Back to Top button --- */
.btn-back-to-top {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 1000;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #6c3b5e;
    color: #fff;
    border: none;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    font-size: 1.25rem;
    cursor: pointer;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s, visibility 0.3s, background 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

[dir="rtl"] .btn-back-to-top {
    right: auto;
    left: 2rem;
}

.btn-back-to-top.visible {
    opacity: 1;
    visibility: visible;
}

.btn-back-to-top:hover,
.btn-back-to-top:focus-visible {
    background: #8a4d7a;
}

/* --- No results state --- */
.no-results {
    text-align: center;
    padding: 3rem 1rem;
}

.no-results .no-results-icon {
    font-size: 3rem;
    color: #80c8bd;
    margin-bottom: 1rem;
}

.no-results .no-results-text {
    font-size: 1.125rem;
    color: #555;
    margin-bottom: 1.5rem;
}

/* --- Filter action buttons (legacy compat) --- */
.filter-actions .btn {
    min-height: 44px;
    min-width: 44px;
    font-size: 1rem;
}

/* --- Pagination accessibility --- */
.initiatives-page .pagination .page-link {
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
}

/* --- Skip link for keyboard users --- */
/*.skip-link {
    position: absolute;
    top: -100%;
    left: 0;
    background: #6c3b5e;
    color: #fff;
    padding: 0.75rem 1.5rem;
    z-index: 10000;
    font-size: 1rem;
    text-decoration: none;
    border-radius: 0 0 0.5rem 0;
}

.skip-link:focus {
    top: 0;
}
*/
/* --- High contrast improvements --- */
.initiatives-page .form-label {
    font-weight: 600;
    color: #212529;
}

/* Filter inputs use bottom-border style; other form controls retain standard styling */
.initiatives-page .form-control:not(.filter-input),
.initiatives-page .form-select:not(.filter-input) {
    border: 2px solid #6c757d;
    font-size: 1rem;
    min-height: 44px;
}

.initiatives-page .form-control:not(.filter-input):focus,
.initiatives-page .form-select:not(.filter-input):focus {
    border-color: #6c3b5e;
    box-shadow: 0 0 0 3px rgba(108, 59, 94, 0.25);
}

/* --- Live region for screen readers --- */
.sr-live-region {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* --- Skeleton loading animation --- */
@keyframes skeleton-pulse {
    0% { background-position: -200px 0; }
    100% { background-position: calc(200px + 100%) 0; }
}

.skeleton-card {
    border: 1px solid #dee2e6;
    border-radius: 0.75rem;
    overflow: hidden;
    height: 100%;
    display: flex;
    flex-direction: column;
    background: #fff;
}

.skeleton-img {
    width: 100%;
    aspect-ratio: 4 / 3;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200px 100%;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
}

.skeleton-text {
    height: 1rem;
    border-radius: 4px;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200px 100%;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
    margin: 0.5rem 1rem;
}

.skeleton-text.short {
    width: 60%;
    margin-left: auto;
    margin-right: auto;
}

.skeleton-btn {
    height: 44px;
    width: 120px;
    border-radius: 2rem;
    background: linear-gradient(90deg, #f0f0f0 25%, #e0e0e0 50%, #f0f0f0 75%);
    background-size: 200px 100%;
    animation: skeleton-pulse 1.5s ease-in-out infinite;
    margin: 0.75rem auto;
}

/* --- Infinite scroll sentinel --- */
.scroll-sentinel {
    height: 1px;
    width: 100%;
}

/* --- Loading spinner for infinite scroll --- */
.loading-spinner {
    text-align: center;
    padding: 2rem;
    display: none;
}

.loading-spinner.active {
    display: block;
}

.loading-spinner .spinner {
    display: inline-block;
    width: 2rem;
    height: 2rem;
    border: 3px solid #dee2e6;
    border-top-color: #6c3b5e;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Slow network banner --- */
.slow-network-banner {
    display: none;
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffc107;
    border-radius: 0.5rem;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    text-align: center;
    font-size: 0.95rem;
}

.slow-network-banner.visible {
    display: block;
}

/* --- Select2 theme override for filter bar --- */
.filter-field .select2-container {
    width: 100% !important;
}

.filter-field .select2-container--default .select2-selection--single {
    border: none;
    border-bottom: 2px solid #e0dce3;
    border-radius: 0;
    background: transparent;
    min-height: 40px;
    padding: 0.25rem 0;
    transition: border-color 0.25s ease, background-color 0.2s ease;
}

.filter-field .select2-container--default .select2-selection--single:hover {
    border-bottom-color: #b8a0c8;
    background-color: rgba(108, 59, 94, 0.02);
}

.filter-field .select2-container--default.select2-container--open .select2-selection--single,
.filter-field .select2-container--default.select2-container--focus .select2-selection--single {
    border-bottom-color: #6c3b5e;
    background-color: rgba(108, 59, 94, 0.03);
    box-shadow: 0 2px 0 0 #6c3b5e;
    outline: none;
}

.filter-field .select2-container--default .select2-selection--single .select2-selection__rendered {
    color: #212529;
    font-size: 0.95rem;
    padding-inline-start: 0.25rem;
    padding-inline-end: 1.5rem;
    line-height: 36px;
}

.filter-field .select2-container--default .select2-selection--single .select2-selection__placeholder {
    color: #adb5bd;
}

.filter-field .select2-container--default .select2-selection--single .select2-selection__arrow {
    height: 36px;
    top: 2px;
}

.filter-field .select2-container--default .select2-selection--single .select2-selection__arrow b {
    border-color: #6c3b5e transparent transparent transparent;
}

.filter-field .select2-container--default.select2-container--open .select2-selection--single .select2-selection__arrow b {
    border-color: transparent transparent #6c3b5e transparent;
}

.filter-field .select2-container--default .select2-selection--single .select2-selection__clear {
    color: #6c757d;
    font-size: 1.1rem;
    margin-inline-end: 0.25rem;
}

/* Select2 dropdown styling */
.select2-container--default .select2-dropdown {
    border: 1px solid #e0dce3;
    border-radius: 0.5rem;
    box-shadow: 0 4px 16px rgba(108, 59, 94, 0.12);
    overflow: hidden;
}

.select2-container--default .select2-search--dropdown .select2-search__field {
    border: none;
    border-bottom: 2px solid #e0dce3;
    border-radius: 0;
    padding: 0.625rem 0.75rem;
    font-size: 0.95rem;
}

.select2-container--default .select2-search--dropdown .select2-search__field:focus {
    border-bottom-color: #6c3b5e;
    outline: none;
    box-shadow: none;
}

.select2-container--default .select2-results__option--highlighted.select2-results__option--selectable {
    background: rgba(108, 59, 94, 0.08);
    color: #6c3b5e;
}

.select2-container--default .select2-results__option--selected {
    background: rgba(108, 59, 94, 0.12);
    color: #6c3b5e;
    font-weight: 600;
}
