.communities-page {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: #333;
}

/* ── Intro ─────────────────────────────────────────────── */
.comm-intro { margin-bottom: 24px; }
.comm-intro h2 { font-size: 22px; font-weight: 700; color: #222; margin-bottom: 8px; letter-spacing: -0.02em; }
.comm-intro p  { color: #555; font-size: 15px; line-height: 1.7; margin-bottom: 6px; }
.comm-intro a  { color: #00568F; font-weight: 600; }

/* ── Stats cards ────────────────────────────────────────── */
.comm-stats-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 14px;
    margin-bottom: 24px;
}
.comm-stat-card {
    background: #fff;
    border: 1px solid #e4e4e4;
    border-radius: 12px;
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    transition: box-shadow 0.2s;
}
.comm-stat-card:hover { box-shadow: 0 4px 14px rgba(0,86,143,0.1); }
.comm-stat-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 20px;
}
.comm-stat-icon.blue  { background: #eaf4ff; color: #00568F; }
.comm-stat-icon.green { background: #edfaf3; color: #1a8a4a; }
.comm-stat-icon.amber { background: #fff8ec; color: #d97706; }
.comm-stat-text strong {
    display: block;
    font-size: 26px;
    font-weight: 800;
    color: #111;
    line-height: 1.1;
    letter-spacing: -0.5px;
}
.comm-stat-text span {
    font-size: 12px;
    color: #888;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ── Filter / search bar ────────────────────────────────── */
.comm-filter-bar {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 22px;
    flex-wrap: wrap;
}
.comm-search-wrap {
    flex: 1;
    min-width: 220px;
    position: relative;
}
.comm-search-wrap i {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: #999;
    font-size: 14px;
    pointer-events: none;
}
.comm-search-input {
    width: 100%;
    padding: 10px 14px 10px 36px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    color: #333;
    background: #fff;
    transition: border-color 0.2s, box-shadow 0.2s;
    height: 42px;
}
.comm-search-input:focus {
    outline: none;
    border-color: #00568F;
    box-shadow: 0 0 0 3px rgba(0,86,143,0.1);
}
.comm-sort-select {
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    color: #333;
    background: #fff;
    min-width: 200px;
    height: 42px;
    transition: border-color 0.2s;
    cursor: pointer;
}
.comm-sort-select:focus { outline: none; border-color: #00568F; }
.comm-search-btn {
    padding: 0 20px;
    height: 42px;
    background: #00568F;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}
.comm-search-btn:hover { background: #004070; }
.comm-clear-btn {
    padding: 0 14px;
    height: 42px;
    background: #f5f5f5;
    color: #555;
    border: 1px solid #ddd;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 5px;
    transition: background 0.2s;
    white-space: nowrap;
}
.comm-clear-btn:hover { background: #eee; color: #333; text-decoration: none; }

/* ── Results line ───────────────────────────────────────── */
.comm-results-line {
    font-size: 14px;
    color: #666;
    margin-bottom: 18px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.comm-results-line strong { color: #222; }

/* ── Grid ───────────────────────────────────────────────── */
.communities-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 22px;
    margin-bottom: 30px;
}

/* ── Card ───────────────────────────────────────────────── */
.community-card {
    background: #fff;
    border: 1px solid #e4e4e4;
    border-radius: 14px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transition: all 0.25s ease;
}
.community-card:hover {
    box-shadow: 0 8px 24px rgba(0,86,143,0.13);
    transform: translateY(-3px);
    border-color: #b8d8f0;
}

/* ── Card thumbnail ─────────────────────────────────────── */
.comm-card-thumb {
    height: 130px;
    background: linear-gradient(135deg, #00568F 0%, #0080cc 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
}
.comm-card-thumb::before,
.comm-card-thumb::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    background: rgba(255,255,255,0.07);
    pointer-events: none;
}
.comm-card-thumb::before { width: 110px; height: 110px; top: -30px; right: -25px; }
.comm-card-thumb::after  { width: 70px;  height: 70px;  bottom: -20px; left: -15px; }

/* ── Circular avatar ────────────────────────────────────── */
.comm-card-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    border: 3px solid rgba(255,255,255,0.9);
    box-shadow: 0 4px 14px rgba(0,0,0,0.2);
    overflow: hidden;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
    background: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
}
.comm-card-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.comm-card-avatar-initials {
    font-size: 28px;
    font-weight: 800;
    color: #00568F;
    text-transform: uppercase;
    line-height: 1;
    user-select: none;
}

/* ── Card body ──────────────────────────────────────────── */
.comm-card-body { padding: 16px 18px 12px; flex: 1; display: flex; flex-direction: column; }
.comm-card-title {
    font-size: 17px;
    font-weight: 700;
    color: #00568F;
    margin: 0 0 10px 0;
    line-height: 1.4;
    text-decoration: none;
    display: block;
    transition: color 0.2s;
}
.comm-card-title:hover { color: #004070; text-decoration: underline; }
.comm-card-desc {
    color: #555;
    font-size: 14px;
    line-height: 1.65;
    margin-bottom: 14px;
    flex: 1;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* ── Meta badges ────────────────────────────────────────── */
.comm-card-meta { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 4px; }
.comm-meta-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 11px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}
.comm-meta-badge.opps    { background: #eaf4ff; color: #00568F; border: 1px solid #b8d8f0; }
.comm-meta-badge.orgs    { background: #f0f9eb; color: #3a7d44; border: 1px solid #b8dfc4; }
.comm-meta-badge.no-data { background: #f7f7f7; color: #999;    border: 1px solid #e5e5e5; }
.comm-meta-badge i { font-size: 11px; }

/* ── Card footer ────────────────────────────────────────── */
.comm-card-footer {
    padding: 12px 18px;
    border-top: 1px solid #f0f0f0;
    background: #fafafa;
}
.comm-view-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px;
    border-radius: 8px;
    background: #00568F;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    text-decoration: none;
    transition: all 0.2s ease;
}
.comm-view-btn:hover {
    background: #004070;
    color: #fff;
    text-decoration: none;
    box-shadow: 0 2px 8px rgba(0,86,143,0.3);
}

/* ── Empty / no-results states ──────────────────────────── */
.comm-no-results {
    text-align: center;
    padding: 50px 20px;
    background: #fafafa;
    border: 1px dashed #ddd;
    border-radius: 12px;
}
.comm-no-results i  { font-size: 40px; color: #c8dff0; margin-bottom: 14px; display: block; }
.comm-no-results h4 { font-size: 18px; font-weight: 600; color: #444; margin-bottom: 8px; }
.comm-no-results p  { font-size: 14px; color: #777; }

.comm-empty-state { text-align: center; padding: 70px 20px; }
.comm-empty-state i  { font-size: 48px; color: #c8dff0; margin-bottom: 16px; display: block; }
.comm-empty-state h4 { font-size: 20px; font-weight: 600; color: #222; margin-bottom: 10px; }
.comm-empty-state p  { font-size: 15px; color: #777; }

/* ── View toggle buttons ────────────────────────────────── */
.comm-view-toggle {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
}
.comm-view-btn-toggle {
    width: 34px;
    height: 34px;
    border: 1px solid #ddd;
    background: #fff;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #888;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
}
.comm-view-btn-toggle:hover { border-color: #00568F; color: #00568F; }
.comm-view-btn-toggle.active { background: #00568F; border-color: #00568F; color: #fff; }

/* ── List view layout ───────────────────────────────────── */
.communities-grid.list-view {
    grid-template-columns: 1fr;
    gap: 14px;
}
.communities-grid.list-view .community-card {
    flex-direction: row;
    align-items: stretch;
    border-radius: 12px;
}
.communities-grid.list-view .comm-card-thumb {
    width: 110px;
    height: auto;
    min-height: 100px;
    flex-shrink: 0;
    border-radius: 0;
}
.communities-grid.list-view .comm-card-avatar {
    width: 62px;
    height: 62px;
}
.communities-grid.list-view .comm-card-avatar-initials {
    font-size: 20px;
}
.communities-grid.list-view .comm-card-body {
    padding: 14px 16px;
    justify-content: center;
}
.communities-grid.list-view .comm-card-desc {
    -webkit-line-clamp: 2;
    margin-bottom: 8px;
}
.communities-grid.list-view .comm-card-footer {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    border-top: none;
    border-left: 1px solid #f0f0f0;
    min-width: 150px;
    flex-shrink: 0;
}
.communities-grid.list-view .comm-view-btn {
    white-space: nowrap;
    padding: 10px 16px;
}

/* ── Province dropdown arrow — always visible ───────────── */
/* Re-declare the arrow at every breakpoint so responsive
   border overrides in opportunities.css don't strip it */
.communities-page .province-dropdown {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2300568f' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e") !important;
    background-position: right 0.5rem center !important;
    background-repeat: no-repeat !important;
    background-size: 1.2em 1.2em !important;
    padding-right: 2rem !important;
    position: relative;
    z-index: 2;
    width: 100%;
    max-width: 100%;
}

/* ── Search row stacking — responsive at all relevant breakpoints ── */
/* Stack below 992px for all layouts */
@media (max-width: 991px) {
    .communities-page .unified-search-container .row {
        flex-direction: column !important;
        height: auto !important;
    }
    .communities-page .unified-search-container [class*="col-"] {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
        margin-bottom: 6px;
    }
    .communities-page .unified-search-container [class*="col-"]:last-child {
        margin-bottom: 0;
    }
    /* Re-assert caret inside stacked layout - ensure it's always visible */
    .communities-page .province-dropdown {
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2300568f' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e") !important;
        background-position: right 0.75rem center !important;
        background-repeat: no-repeat !important;
        background-size: 1.2em 1.2em !important;
        padding-right: 2.2rem !important;
        z-index: 10 !important;
        position: relative;
    }
}

/* Fix for 990px to 1430px - override opportunities.css for sidebar layout */
@media (min-width: 992px) and (max-width: 1430px) {
    /* Remove container border/padding from opportunities.css */
    .right_module .communities-page .unified-search-container {
        background: transparent !important;
        border: none !important;
        padding: 0 !important;
        margin-bottom: 1.5rem;
    }
    /* Row with border wrapping all three elements */
    .right_module .communities-page .unified-search-container .row {
        display: flex;
        align-items: stretch;
        margin: 0;
        height: 48px;
        border: 2px solid #00568f;
        border-radius: 8px;
        overflow: visible;
    }
    .right_module .communities-page .unified-search-container [class*="col-"] {
        padding: 0;
        display: flex;
    }
    /* Ensure proper widths in sidebar context */
    .right_module .communities-page .unified-search-container .col-md-3 {
        flex: 0 0 200px !important;
        max-width: 200px !important;
        width: 200px !important;
    }
    .right_module .communities-page .unified-search-container .col-md-7 {
        flex: 1 1 auto !important;
        max-width: none !important;
        width: auto !important;
    }
    .right_module .communities-page .unified-search-container .col-md-2 {
        flex: 0 0 auto !important;
        max-width: 60px !important;
        width: 60px !important;
    }
    /* Province dropdown - no individual border, just divider */
    .right_module .communities-page .unified-search-container .col-md-3 .province-dropdown {
        height: 48px !important;
        border: none !important;
        border-right: 1px solid #dfe2e5 !important;
        border-radius: 0 !important;
        font-size: 16px;
        font-weight: 500;
        background: #fff !important;
        flex: none !important;
        width: 200px !important;
        min-width: 200px !important;
        max-width: 200px !important;
        padding: 0 2.5rem 0 1rem !important;
        color: #1E1E1E;
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2300568f' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e") !important;
        background-position: right 0.5rem center !important;
        background-repeat: no-repeat !important;
        background-size: 1.2em 1.2em !important;
        -webkit-appearance: none !important;
        -moz-appearance: none !important;
        appearance: none !important;
        position: relative;
        z-index: 10;
    }
    /* Search input - no individual border */
    .right_module .communities-page .unified-search-container .col-md-7 .search-input {
        height: 48px !important;
        border: none !important;
        border-right: 1px solid #dfe2e5 !important;
        border-radius: 0 !important;
        font-size: 16px;
        font-weight: 500;
        background: #fff !important;
        flex: 1;
        padding: 0 1rem !important;
        color: #1E1E1E;
    }
    /* Search button - no individual border */
    .right_module .communities-page .unified-search-container .col-md-2 .btn-search {
        height: 48px !important;
        border: none !important;
        border-radius: 0 !important;
        background: linear-gradient(135deg, #00568f 0, #549ac9 100%) !important;
        color: #fff;
        font-weight: 600;
        flex: 1;
    }
}

/* Stack in sidebar (right_module) context up to ~1350px where col-md-3 gets too narrow */
@media (max-width: 991px) {
    .right_module .communities-page .unified-search-container .row {
        flex-direction: column !important;
        height: auto !important;
    }
    .right_module .communities-page .unified-search-container [class*="col-"] {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 100% !important;
        margin-bottom: 6px;
    }
    .right_module .communities-page .unified-search-container [class*="col-"]:last-child {
        margin-bottom: 0;
    }
    /* Re-assert caret in sidebar layout - ensure it's always visible */
    .right_module .communities-page .province-dropdown {
        background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%2300568f' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='m6 8 4 4 4-4'/%3e%3c/svg%3e") !important;
        background-position: right 0.75rem center !important;
        background-repeat: no-repeat !important;
        background-size: 1.2em 1.2em !important;
        padding-right: 2.2rem !important;
        z-index: 10 !important;
        position: relative;
    }
}

/* ── Responsive ─────────────────────────────────────────── */
@media (max-width: 576px) {
    .comm-stats-row { grid-template-columns: 1fr; }
    .comm-filter-bar { flex-direction: column; align-items: stretch; }
    .comm-sort-select { min-width: unset; width: 100%; }
    /* Ensure province dropdown caret is visible on small screens */
    .communities-page .province-dropdown,
    .right_module .communities-page .province-dropdown {
        background-position: right 0.5rem center !important;
        background-size: 1em 1em !important;
        padding-right: 1.8rem !important;
        z-index: 10 !important;
    }
}

@media (max-width: 768px) {
    .communities-grid { grid-template-columns: 1fr; }
    /* Force grid view on mobile — list view toggle is hidden */
    .communities-grid.list-view {
        grid-template-columns: 1fr;
    }
    .communities-grid.list-view .community-card {
        flex-direction: column;
    }
    .communities-grid.list-view .comm-card-thumb {
        width: 100%;
        height: 130px;
    }
    .communities-grid.list-view .comm-card-footer {
        border-left: none;
        border-top: 1px solid #f0f0f0;
        min-width: unset;
    }
}
@media (min-width: 769px) and (max-width: 1024px) {
    .communities-grid { grid-template-columns: repeat(2, 1fr); }
}
