/* ═══════════════════════════════════════════════════════════════════════════
   MIPB Recipe Archive
   ═══════════════════════════════════════════════════════════════════════════ */

/* ── Design tokens ─────────────────────────────────────────────────────────── */
.mipb-archive {
    --ra-green:        #3a7d44;
    --ra-green-dark:   #2d6135;
    --ra-green-light:  #e8f5e9;
    --ra-green-pale:   #f4fbf5;
    --ra-text:         #1a1a1a;
    --ra-text-muted:   #6b7280;
    --ra-border:       #e5e7eb;
    --ra-radius:       12px;
    --ra-radius-sm:    7px;
    --ra-shadow:       0 2px 10px rgba(0,0,0,.07);
    --ra-shadow-hover: 0 10px 32px rgba(0,0,0,.13);
    --ra-transition:   0.2s ease;
    font-family: inherit;
}

/* ── Archive wrapper ────────────────────────────────────────────────────────── */
.mipb-archive {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 16px 60px;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
.mipb-archive-header {
    text-align: center;
    padding: 40px 0 28px;
}
.mipb-archive-title {
    font-size: clamp(1.75rem, 4vw, 2.5rem);
    font-weight: 800;
    color: var(--ra-text);
    margin: 0 0 8px;
    line-height: 1.2;
}
.mipb-archive-subtitle {
    font-size: 1.05rem;
    color: var(--ra-text-muted);
    margin: 0;
}

/* ── Filter panel ───────────────────────────────────────────────────────────── */
.mipb-archive-filters {
    position: sticky;
    top: 0;
    /* z-index is safe here because dropdown panels use position:fixed,
       which escapes all parent stacking contexts — adding z-index to this
       sticky bar no longer traps them. The z-index keeps the bar above
       recipe cards (which carry z-index:0) as the user scrolls. */
    z-index: 100;
    background: #fff;
    border-bottom: 1px solid var(--ra-border);
    box-shadow: 0 2px 8px rgba(0,0,0,.06);
    padding: 12px 0 8px;
    margin-bottom: 28px;
}
.mipb-dropdown {
    position: relative;
}

/* Search bar */
.mipb-filter-search {
    position: relative;
    margin-bottom: 10px;
}
.mipb-search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--ra-text-muted);
    pointer-events: none;
}
.mipb-search-input {
    width: 100%;
    padding: 10px 14px 10px 42px;
    font-size: 0.95rem;
    border: 1.5px solid var(--ra-border);
    border-radius: var(--ra-radius);
    outline: none;
    background: var(--ra-green-pale);
    color: var(--ra-text);
    transition: border-color var(--ra-transition), box-shadow var(--ra-transition);
    box-sizing: border-box;
}
.mipb-search-input:focus {
    border-color: var(--ra-green);
    box-shadow: 0 0 0 3px rgba(58,125,68,.12);
    background: #fff;
}

/* Filter row */
.mipb-filter-row {
    display: flex;
    align-items: center;
    gap: 10px;
    overflow-x: auto;
    scrollbar-width: none;
    padding-bottom: 2px;
}
.mipb-filter-row::-webkit-scrollbar { display: none; }

/* Category pills (scrollable strip) */
.mipb-filter-pills {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
}
.mipb-filter-pills::-webkit-scrollbar { display: none; }

/* Pill buttons */
.mipb-pill {
    display: inline-flex;
    align-items: center;
    padding: 6px 14px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1.5px solid var(--ra-border);
    background: #fff;
    color: var(--ra-text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--ra-transition);
    line-height: 1;
}
.mipb-pill:hover {
    border-color: var(--ra-green);
    color: var(--ra-green);
    background: var(--ra-green-light);
}
.mipb-pill.is-active {
    background: var(--ra-green);
    border-color: var(--ra-green);
    color: #fff;
    font-weight: 600;
}

/* Filter controls group (dropdowns + sort) */
.mipb-filter-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
    margin-left: auto;
}

/* ── Dropdowns ──────────────────────────────────────────────────────────────── */
.mipb-dropdown {
    position: relative;
}

.mipb-dropdown-toggle {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 12px;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1.5px solid var(--ra-border);
    border-radius: var(--ra-radius-sm);
    background: #fff;
    color: var(--ra-text-muted);
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--ra-transition);
    line-height: 1;
}
.mipb-dropdown-toggle svg {
    transition: transform var(--ra-transition);
}
.mipb-dropdown.is-open .mipb-dropdown-toggle svg {
    transform: rotate(180deg);
}
.mipb-dropdown-toggle:hover,
.mipb-dropdown-toggle.has-active {
    border-color: var(--ra-green);
    color: var(--ra-green);
    background: var(--ra-green-light);
}
.mipb-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    background: var(--ra-green);
    color: #fff;
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 700;
}

.mipb-dropdown-panel {
    /* Fixed positioning escapes all CSS stacking contexts (Oxygen builder, etc.)
       JS sets top/right/left each time the panel opens. */
    position: fixed;
    min-width: 200px;
    max-width: 280px;
    background: #fff;
    border: 1.5px solid var(--ra-border);
    border-radius: var(--ra-radius);
    box-shadow: var(--ra-shadow-hover);
    z-index: 99999;
    padding: 8px 0 0;
}
.mipb-dropdown-scroll {
    max-height: 260px;
    overflow-y: auto;
    padding: 0 8px 8px;
    scrollbar-width: thin;
    scrollbar-color: var(--ra-border) transparent;
}

/* Checkbox labels */
.mipb-checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 6px;
    font-size: 0.875rem;
    color: var(--ra-text);
    cursor: pointer;
    border-radius: var(--ra-radius-sm);
    transition: background var(--ra-transition);
}
.mipb-checkbox-label:hover { background: var(--ra-green-pale); }
.mipb-checkbox-label input[type="checkbox"] {
    accent-color: var(--ra-green);
    width: 15px;
    height: 15px;
    flex-shrink: 0;
    cursor: pointer;
}

/* Dropdown footer (for badge panel) */
.mipb-dropdown-footer {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 8px;
    border-top: 1px solid var(--ra-border);
}

/* Time option buttons */
.mipb-time-option {
    display: block;
    width: 100%;
    text-align: left;
    padding: 9px 14px;
    font-size: 0.875rem;
    background: none;
    border: none;
    color: var(--ra-text-muted);
    cursor: pointer;
    transition: background var(--ra-transition), color var(--ra-transition);
}
.mipb-time-option:hover { background: var(--ra-green-pale); color: var(--ra-green); }
.mipb-time-option.is-active {
    background: var(--ra-green-light);
    color: var(--ra-green);
    font-weight: 600;
}

/* Sort select */
.mipb-sort-wrap select {
    padding: 7px 28px 7px 10px;
    font-size: 0.85rem;
    font-weight: 500;
    border: 1.5px solid var(--ra-border);
    border-radius: var(--ra-radius-sm);
    background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7280' stroke-width='2.5'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E") no-repeat right 8px center;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    color: var(--ra-text-muted);
    cursor: pointer;
    transition: border-color var(--ra-transition);
}
.mipb-sort-wrap select:focus {
    outline: none;
    border-color: var(--ra-green);
}

/* ── Filter status bar (chips + count) ──────────────────────────────────────── */
.mipb-filter-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 8px;
    min-height: 28px;
}
.mipb-active-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    flex: 1;
}
.mipb-active-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 4px 10px 4px 12px;
    background: var(--ra-green);
    color: #fff;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: background var(--ra-transition);
}
.mipb-active-chip:hover { background: var(--ra-green-dark); }
.mipb-active-chip svg { opacity: 0.8; }

.mipb-result-count {
    font-size: 0.82rem;
    color: var(--ra-text-muted);
    white-space: nowrap;
    flex-shrink: 0;
}

/* ── Loading ────────────────────────────────────────────────────────────────── */
/* Use class-based visibility so CSS display:flex doesn't fight the hidden attr */
.mipb-grid-loading {
    display: none;
    align-items: center;
    justify-content: center;
    padding: 24px;
}
.mipb-grid-loading.is-visible {
    display: flex;
}
.mipb-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--ra-green-light);
    border-top-color: var(--ra-green);
    border-radius: 50%;
    animation: mipb-spin 0.7s linear infinite;
}
@keyframes mipb-spin { to { transform: rotate(360deg); } }

/* ── Recipe grid ────────────────────────────────────────────────────────────── */
.mipb-recipe-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 22px;
    transition: opacity 0.2s ease;
}

@media (max-width: 1100px) {
    .mipb-recipe-grid { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 720px) {
    .mipb-recipe-grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }
}
@media (max-width: 440px) {
    .mipb-recipe-grid { grid-template-columns: 1fr; }
}

/* ── Recipe card ────────────────────────────────────────────────────────────── */
.mipb-recipe-card {
    border-radius: var(--ra-radius);
    background: #fff;
    border: 1px solid var(--ra-border);
    box-shadow: var(--ra-shadow);
    overflow: hidden;
    transition: transform var(--ra-transition), box-shadow var(--ra-transition);
    position: relative;
    /* z-index:0 creates a stacking context at ground level so that hover
       transforms (translateY) never push cards above the sticky filter bar. */
    z-index: 0;
}
.mipb-recipe-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--ra-shadow-hover);
}

.mipb-card-link {
    display: flex;
    flex-direction: column;
    height: 100%;
    text-decoration: none;
    color: inherit;
}
.mipb-card-link:hover { color: inherit; }

/* Card image */
.mipb-card-image {
    position: relative;
    aspect-ratio: 3 / 2;
    overflow: hidden;
    background: var(--ra-green-light);
    flex-shrink: 0;
}
.mipb-card-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
}
.mipb-recipe-card:hover .mipb-card-image img {
    transform: scale(1.04);
}
.mipb-card-no-image {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    background: linear-gradient(135deg, var(--ra-green-light), var(--ra-green-pale));
}

/* Profile match overlay */
.mipb-card-profile-match {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: var(--ra-green);
    color: #fff;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 5px 10px;
    display: flex;
    align-items: center;
    gap: 4px;
    letter-spacing: 0.02em;
}

/* Card body */
.mipb-card-body {
    padding: 14px 16px 16px;
    display: flex;
    flex-direction: column;
    flex: 1;
    gap: 5px;
}

/* Category chip */
.mipb-card-category {
    display: inline-block;
    font-size: 0.72rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--ra-green);
    line-height: 1;
}

/* Card title */
.mipb-card-title {
    font-size: 0.975rem;
    font-weight: 700;
    line-height: 1.35;
    color: var(--ra-text);
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Card description */
.mipb-card-desc {
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--ra-text-muted);
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Meta row */
.mipb-card-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-top: auto;
    padding-top: 6px;
}
.mipb-card-meta-item {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--ra-text-muted);
    font-weight: 500;
}
.mipb-card-meta-item svg { flex-shrink: 0; opacity: 0.7; }

/* Badge pills */
.mipb-card-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}
.mipb-card-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.7rem;
    font-weight: 600;
    background: var(--ra-green-light);
    color: var(--ra-green-dark);
    white-space: nowrap;
}
.mipb-badge--more {
    background: var(--ra-border);
    color: var(--ra-text-muted);
}

/* ── No results state ───────────────────────────────────────────────────────── */
.mipb-no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--ra-text-muted);
}
.mipb-no-results span {
    display: block;
    font-size: 3.5rem;
    margin-bottom: 14px;
}
.mipb-no-results p {
    font-size: 1rem;
    margin-bottom: 20px;
}

/* ── Buttons ────────────────────────────────────────────────────────────────── */
.mipb-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 22px;
    border-radius: var(--ra-radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all var(--ra-transition);
    line-height: 1;
}
.mipb-btn--outline {
    border-color: var(--ra-green);
    color: var(--ra-green);
    background: transparent;
}
.mipb-btn--outline:hover {
    background: var(--ra-green);
    color: #fff;
}
.mipb-btn--primary {
    background: var(--ra-green);
    color: #fff;
    border-color: var(--ra-green);
}
.mipb-btn--primary:hover { background: var(--ra-green-dark); border-color: var(--ra-green-dark); }
.mipb-btn--xs {
    padding: 5px 12px;
    font-size: 0.78rem;
}
.mipb-btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ── Load more ──────────────────────────────────────────────────────────────── */
.mipb-load-more-wrap {
    text-align: center;
    margin-top: 36px;
}

/* ── Mobile adjustments ─────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .mipb-archive-filters {
        position: static;  /* don't stick on mobile — wastes too much viewport */
    }
    .mipb-filter-controls {
        margin-left: 0;
    }
    .mipb-dropdown-panel {
        left: 0;
        right: auto;
    }
    .mipb-filter-row {
        flex-wrap: nowrap;
    }
    .mipb-archive-header { padding: 24px 0 18px; }
}

/* ── AI-generated recipe badge on archive cards ───────────────────────────── */
.mipb-card-ai-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(109, 40, 217, 0.82);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 4px 9px;
    border-radius: 20px;
    letter-spacing: 0.2px;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    pointer-events: none;
    user-select: none;
    line-height: 1.4;
}
