/* Cases page refresh. Replaces case-studies.css.
   Single accent palette (no pastel rainbow on filters). */

:root {
    --c-bg: #f8f9fa;
    --c-bg-tint: #e8f5f2;
    --c-ink: #1c2a24;
    --c-ink-soft: #4a4a4a;
    --c-muted: #6d6d6d;
    --c-line: #e5e7eb;
    --c-line-soft: rgba(0, 0, 0, 0.06);
    --c-card: #fff;
    --c-primary: #163021;
    --c-primary-soft: #a8ceb8;
    --c-primary-tint: #e8f5f2;
    --c-accent-1: #3a6b9a; /* system */
    --c-accent-2: #3a9a3a; /* region */
    --c-accent-3: #b8860b; /* type */
    --c-accent-4: #5a3a9a; /* member */
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 12px 24px rgba(0, 0, 0, 0.10);
    --radius: 12px;
    --radius-sm: 8px;
}

body { background: var(--c-bg); }

/* --- Top control bar (search + filter trigger) --- */
.cases-toolbar {
    display: flex;
    align-items: stretch;
    gap: 12px;
    margin: 0 0 16px;
}

.cases-search {
    flex: 1;
    position: relative;
    background: var(--c-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--c-line);
    transition: box-shadow .15s ease, border-color .15s ease;
}
.cases-search:focus-within {
    border-color: var(--c-primary-soft);
    box-shadow: 0 0 0 3px rgba(168, 206, 184, .25);
}
.cases-search .fa-magnifying-glass,
.cases-search .fa-search {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--c-muted);
    font-size: 14px;
    pointer-events: none;
}
.cases-search input {
    width: 100%;
    border: 0;
    background: transparent;
    padding: 14px 44px 14px 44px;
    border-radius: var(--radius);
    font-size: 15px;
    color: var(--c-ink);
    font-family: 'Open Sans', sans-serif;
}
.cases-search input:focus { outline: none; }
.cases-search .clear-btn {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    background: transparent;
    border: 0;
    color: var(--c-muted);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    line-height: 1;
}
.cases-search .clear-btn:hover { color: var(--c-ink); background: var(--c-bg); }

.cases-filter-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--c-card);
    border: 1px solid var(--c-line);
    border-radius: var(--radius);
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    font-weight: 500;
    font-size: 14px;
    color: var(--c-ink);
    box-shadow: var(--shadow-sm);
    transition: all .15s ease;
    line-height: 1.2;
}
.cases-filter-btn i { font-size: 13px; color: var(--c-muted); }
.cases-filter-btn:hover {
    background: var(--c-primary-tint);
    border-color: var(--c-primary-soft);
}
.cases-filter-btn .count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--c-primary);
    color: #fff;
    border-radius: 999px;
    min-width: 22px;
    height: 22px;
    padding: 0 7px;
    font-size: 12px;
    font-weight: 600;
}
.cases-filter-btn .count-badge:empty { display: none; }

/* --- Active filter pills row --- */
.cases-active-pills {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 0 0 16px;
    min-height: 0;
    transition: min-height .15s ease;
}
.cases-active-pills:not(:empty) { min-height: 36px; }

.cases-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--c-card);
    border: 1px solid var(--c-line);
    color: var(--c-ink-soft);
    border-radius: 999px;
    padding: 6px 6px 6px 12px;
    font-size: 13px;
    font-family: 'Poppins', sans-serif;
}
.cases-pill .pill-label { color: var(--c-muted); margin-right: 2px; }
.cases-pill button {
    background: transparent;
    border: 0;
    color: var(--c-muted);
    cursor: pointer;
    border-radius: 50%;
    width: 22px;
    height: 22px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}
.cases-pill button:hover { background: var(--c-bg); color: var(--c-ink); }

.clear-all-btn {
    background: transparent;
    border: 0;
    color: var(--c-primary);
    font-weight: 500;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    font-family: 'Poppins', sans-serif;
    font-size: 13px;
}
.clear-all-btn:hover { background: var(--c-primary-tint); }

/* --- Result count --- */
.cases-result-count {
    color: var(--c-muted);
    font-size: 13px;
    margin: 0 0 12px;
    font-family: 'Poppins', sans-serif;
}

/* --- Studies list --- */
#studies {
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 4px 0;
}

.case-card {
    position: relative;
    background: var(--c-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--c-line-soft);
    padding: 20px 22px 20px 26px;
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
    cursor: pointer;
    overflow: hidden;
}
.case-card::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 4px;
    background: var(--card-accent, var(--c-primary-soft));
}
.case-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: rgba(0, 0, 0, 0.08);
}
.case-card a.card-link {
    position: absolute;
    inset: 0;
    z-index: 1;
}
.case-card .card-inner { position: relative; z-index: 2; pointer-events: none; }
.case-card .card-inner .tag { pointer-events: auto; }

.case-card .card-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 16px;
    margin-bottom: 8px;
}
.case-card h2.card-title {
    margin: 0;
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    font-size: 18px;
    line-height: 1.3;
    color: var(--c-ink);
}
.case-card .card-arrow {
    color: var(--c-primary);
    font-size: 14px;
    flex-shrink: 0;
    transition: transform .15s ease;
}
.case-card:hover .card-arrow { transform: translateX(3px); }

.case-card .card-meta {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 10px;
    color: var(--c-muted);
    font-size: 12px;
    font-family: 'Poppins', sans-serif;
}
.case-card .card-meta .meta-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.case-card .card-meta .author-avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--c-primary-tint);
    color: var(--c-primary);
    font-size: 11px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.case-card .card-summary {
    color: #5a5a5a;
    font-size: 13.5px;
    line-height: 1.55;
    margin: 0 0 12px;
    font-family: 'Open Sans', sans-serif;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.case-card .card-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.case-card .tag {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 500;
    background: var(--c-bg);
    color: var(--c-ink-soft);
}
.case-card .tag-system { background: #ebf3fb; color: var(--c-accent-1); }
.case-card .tag-region { background: #ebf7eb; color: var(--c-accent-2); }
.case-card .tag-type   { background: #faf3df; color: var(--c-accent-3); }
.case-card .tag-member { background: #efeaf8; color: var(--c-accent-4); }

/* --- Skeleton --- */
.skeleton {
    background: var(--c-card);
    border-radius: var(--radius);
    border: 1px solid var(--c-line-soft);
    padding: 20px 22px;
    overflow: hidden;
}
.skeleton .sk-line {
    height: 14px;
    background: linear-gradient(90deg, #eee 0%, #f5f5f5 50%, #eee 100%);
    background-size: 200% 100%;
    border-radius: 6px;
    animation: sk-shimmer 1.4s infinite linear;
    margin-bottom: 10px;
}
.skeleton .sk-title { height: 20px; width: 60%; }
.skeleton .sk-meta { width: 35%; height: 10px; }
.skeleton .sk-summary-1 { width: 100%; }
.skeleton .sk-summary-2 { width: 80%; }
.skeleton .sk-tag {
    display: inline-block;
    height: 20px;
    width: 70px;
    border-radius: 999px;
    background: linear-gradient(90deg, #eee 0%, #f5f5f5 50%, #eee 100%);
    background-size: 200% 100%;
    animation: sk-shimmer 1.4s infinite linear;
    margin-right: 6px;
}
@keyframes sk-shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* --- Empty state --- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
}
.empty-state .empty-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--c-primary-tint);
    color: var(--c-primary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 16px;
    font-size: 22px;
}
.empty-state h2 {
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    font-size: 18px;
    color: var(--c-ink);
    margin: 0 0 6px;
}
.empty-state p {
    color: var(--c-muted);
    font-size: 14px;
    margin: 0 0 18px;
}
.empty-state .clear-cta {
    background: var(--c-primary);
    color: #fff;
    border: 0;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    font-family: 'Poppins', sans-serif;
    font-weight: 500;
    cursor: pointer;
}
.empty-state .clear-cta:hover { background: #0a1a12; }

/* --- Load more --- */
#load-more-container { text-align: center; margin: 20px 0 0; }
.load-more-btn {
    background: var(--c-card);
    border: 1px solid var(--c-line);
    color: var(--c-ink);
    padding: 10px 22px;
    border-radius: 999px;
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    font-weight: 500;
    font-size: 14px;
    box-shadow: var(--shadow-sm);
    transition: all .15s ease;
}
.load-more-btn:hover {
    background: var(--c-primary-tint);
    border-color: var(--c-primary-soft);
}
.load-more-spinner {
    display: flex;
    justify-content: center;
    padding: 12px 0;
    color: var(--c-primary);
    font-size: 18px;
}

/* Dim existing cards while a new search is in flight. Keeps the list
   stable instead of flashing to skeleton on every keystroke. */
#studies.is-loading {
    opacity: .55;
    pointer-events: none;
    transition: opacity .12s ease;
}

/* --- Filter drawer (offcanvas) --- */
.filter-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(2px);
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
    z-index: 1040;
}
.filter-drawer-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.filter-drawer {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    width: 380px;
    max-width: 90vw;
    background: var(--c-card);
    box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12);
    transform: translateX(100%);
    transition: transform .25s ease;
    z-index: 1050;
    display: flex;
    flex-direction: column;
}
.filter-drawer.open { transform: translateX(0); }

.filter-drawer .drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--c-line);
}
.filter-drawer .drawer-header h3 {
    margin: 0;
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    font-size: 18px;
    color: var(--c-ink);
}
.filter-drawer .drawer-close {
    background: transparent;
    border: 0;
    font-size: 20px;
    color: var(--c-muted);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    line-height: 1;
}
.filter-drawer .drawer-close:hover { background: var(--c-bg); color: var(--c-ink); }

.filter-drawer .drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px 22px;
}

.filter-drawer .drawer-footer {
    padding: 16px 22px;
    border-top: 1px solid var(--c-line);
    display: flex;
    justify-content: space-between;
    gap: 12px;
    background: var(--c-bg);
}
.filter-drawer .drawer-footer .clear-all-btn {
    padding: 10px 14px;
}
.filter-drawer .drawer-footer .apply-btn {
    background: var(--c-primary);
    color: #fff;
    border: 0;
    padding: 10px 22px;
    border-radius: var(--radius-sm);
    font-family: 'Poppins', sans-serif;
    font-weight: 500;
    cursor: pointer;
}
.filter-drawer .drawer-footer .apply-btn:hover { background: #0a1a12; }

.drawer-section { margin-bottom: 18px; }
.drawer-section:last-child { margin-bottom: 0; }
.drawer-section .section-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    background: transparent;
    border: 0;
    padding: 8px 0;
    cursor: pointer;
    font-family: 'Poppins', sans-serif;
    font-weight: 600;
    font-size: 14px;
    color: var(--c-ink);
}
.drawer-section .section-head .chev { transition: transform .15s ease; font-size: 11px; color: var(--c-muted); }
.drawer-section.collapsed .section-head .chev { transform: rotate(-90deg); }
.drawer-section .section-options {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 6px 0 4px;
    max-height: 320px;
    overflow-y: auto;
}
.drawer-section.collapsed .section-options { display: none; }

.drawer-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13.5px;
    color: var(--c-ink-soft);
    font-family: 'Open Sans', sans-serif;
    transition: background .12s ease;
}
.drawer-option:hover { background: var(--c-bg); }
.drawer-option input[type="checkbox"] {
    appearance: none;
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--c-line);
    border-radius: 4px;
    cursor: pointer;
    flex-shrink: 0;
    position: relative;
    background: #fff;
    margin: 0;
}
.drawer-option input[type="checkbox"]:checked {
    background: var(--c-primary);
    border-color: var(--c-primary);
}
.drawer-option input[type="checkbox"]:checked::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 4px;
    height: 8px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}
.drawer-option:has(input:checked) {
    background: var(--c-primary-tint);
    color: var(--c-ink);
    font-weight: 500;
}

/* Mobile: drawer becomes a bottom sheet */
@media (max-width: 768px) {
    .filter-drawer {
        top: auto;
        right: 0;
        left: 0;
        bottom: 0;
        height: 85vh;
        width: 100%;
        max-width: 100%;
        transform: translateY(100%);
        border-top-left-radius: 16px;
        border-top-right-radius: 16px;
        box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.12);
    }
    .filter-drawer.open { transform: translateY(0); }

    .cases-toolbar { flex-direction: column; align-items: stretch; gap: 10px; }
    .cases-filter-btn { justify-content: center; }
}

/* Container tweaks */
.cases-shell {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px 20px 60px;
}
@media (min-width: 1200px) {
    .cases-shell { max-width: 1180px; }
}

/* Sticky header (kept from prior styles, simplified) */
#mainNav {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(5px);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}
#account-info { gap: 12px; }
