/*
    card-search-panel.css
    Modal chrome + overrides for _CardSearchPanel.cshtml.
    Shared filter-rail / product-card / grid rules live in card-search.css
    (loaded just before this file). Defines .cs-screen / .cs-backdrop
    overlay rules globally so the panel works on every page.
*/

/* ── Overlay host (.cs-screen / .cs-backdrop) ────────────────────
   Defined here so any page that includes _Layout gets the modal
   behaviour (not only pages that load collection.css). */
.cs-backdrop {
    position: fixed;
    inset: 0;
    z-index: 12300;
    background: rgba(0, 0, 0, 0.75);
    opacity: 0;
    pointer-events: none;
    visibility: hidden;
    transition: opacity 0.22s ease, visibility 0s 0.22s;
}
.cs-backdrop.is-open {
    opacity: 1;
    pointer-events: auto;
    visibility: visible;
    transition: opacity 0.22s ease;
}

.cs-screen {
    position: fixed;
    inset: 0;
    z-index: 12400;
    display: flex;
    flex-direction: column;
    background: #0E0C0A;
    opacity: 0;
    pointer-events: none;
    transform: translateY(14px) scale(0.985);
    transition: opacity 0.22s ease, transform 0.22s ease;
}
.cs-screen.is-open {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

@media (max-width: 768px) {
    .cs-screen {
        inset: auto 0 var(--nav-height, 64px) 0;
        height: calc(95dvh - var(--nav-height, 64px));
        max-height: calc(95dvh - var(--nav-height, 64px));
        border-radius: 18px 18px 0 0;
        border-top: 1px solid var(--color-border);
        transform: translateY(100%);
        opacity: 1;
        visibility: hidden;
        transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1), visibility 0s 0.3s;
    }
    .cs-screen.is-open {
        transform: translateY(0);
        opacity: 1;
        visibility: visible;
        transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    }
}

@media (min-width: 769px) {
    .cs-screen {
        inset: auto;
        top: 50%;
        left: 50%;
        width: min(960px, calc(100vw - 3rem));
        height: min(85vh, 760px);
        max-height: 85vh;
        border-radius: 16px;
        border: 1px solid rgba(200, 135, 42, 0.2);
        box-shadow: 0 24px 72px rgba(0, 0, 0, 0.6);
        transform: translate(-50%, -46%) scale(0.96);
        opacity: 0;
        transition: transform 0.22s cubic-bezier(0.32, 0.72, 0, 1), opacity 0.22s ease;
    }
    .cs-screen.is-open {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

.cs-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(200, 135, 42, 0.2);
    background: #1A1612;
}
.cs-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: 'Cinzel', serif;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--color-gold, #C8872A);
    letter-spacing: 0.05em;
}
.cs-close {
    width: 36px; height: 36px;
    border-radius: 50%;
    border: 1px solid rgba(200, 135, 42, 0.2);
    background: transparent;
    color: var(--color-muted, #A89880);
    font-size: 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.cs-close:hover {
    background: rgba(200, 135, 42, 0.15);
    color: var(--color-gold, #C8872A);
}

/* Panel modal uses .cs-screen as host. Reset inner padding/background so
   the inner .search-page grid fills the modal body. */
.card-search-screen {
    padding: 0;
    background: var(--color-surface);
    display: flex;
    flex-direction: column;
}

/* Header row inside the modal. Reuses .cs-header from collection.css and
   adds room for a context badge ("Deck · Commander", etc.). */
.csp-header-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
    flex: 1;
}
.csp-ctx-badge {
    font-family: var(--font-body);
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    padding: 0.18rem 0.55rem;
    border-radius: 999px;
    background: rgba(200, 135, 42, 0.12);
    color: var(--color-accent);
    border: 1px solid rgba(200, 135, 42, 0.35);
    text-transform: uppercase;
    white-space: nowrap;
}

/* Inner page wrapper — search-page-card is the flex column that fills
   the modal body; the inner .search-page grid lays out filter + main. */
.card-search-screen .search-page-card {
    flex: 1;
    min-height: 0;
    height: auto;
    border-radius: 0;
    contain: layout paint;
}

/* On desktop the shared .search-page defaults to 300px filter rail which
   is fine; the modal width (960px) accommodates it. */

/* Panel-specific filter rail width: slightly narrower to leave more room
   for the grid inside the modal. */
@media (min-width: 769px) {
    .card-search-screen .search-page {
        grid-template-columns: 260px 1fr;
    }
}

/* Mobile filter toggle button — shown only ≤768px, toggles the filter panel
   open/closed. Hidden on desktop (filter is always visible). */
.csp-filter-mobile-toggle {
    display: none;
    background: rgba(14, 12, 10, 0.6);
    border: 1px solid rgba(200, 135, 42, 0.25);
    color: var(--color-muted);
    padding: 0.55rem 0.9rem;
    border-radius: 8px;
    font-family: var(--font-body);
    font-size: 0.85rem;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
    align-items: center;
    gap: 0.4rem;
}
.csp-filter-mobile-toggle[aria-expanded="true"] {
    color: var(--color-accent);
    border-color: var(--color-accent);
}
@media (max-width: 768px) {
    .csp-filter-mobile-toggle { display: inline-flex; }
}

/* Search-bar inside the main column (desktop & mobile). On desktop we
   still show it (duplicate of filter-panel desktop search is fine —
   keeps the panel fast-access). */
.csp-search-bar {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-shrink: 0;
    margin-bottom: 0.25rem;
}
.csp-input-wrap {
    position: relative;
    flex: 1;
    min-width: 0;
}
.csp-search-icon {
    position: absolute;
    right: 2.2rem;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(200, 135, 42, 0.5);
    pointer-events: none;
    font-size: 0.85rem;
}
.csp-clear-btn {
    position: absolute;
    right: 0.4rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: rgba(200, 135, 42, 0.55);
    cursor: pointer;
    padding: 0.25rem 0.4rem;
    line-height: 1;
    font-size: 0.8rem;
    border-radius: 4px;
    transition: color 0.12s;
}
.csp-clear-btn:hover { color: var(--color-accent); }
.csp-input {
    width: 100%;
    background: rgba(14, 12, 10, 0.7);
    border: 1px solid rgba(200, 135, 42, 0.25);
    border-radius: 8px;
    color: var(--color-text);
    padding: 0.6rem 3.8rem 0.6rem 0.8rem;
    font-family: var(--font-body);
    font-size: 0.95rem;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.csp-input:focus {
    outline: none;
    border-color: var(--color-accent);
    box-shadow: 0 0 0 3px rgba(200, 135, 42, 0.15);
}

/* Toast (add confirmation) */
.csp-toast {
    position: absolute;
    left: 50%;
    bottom: 1rem;
    transform: translateX(-50%) translateY(1rem);
    background: var(--color-surface, #1a1612);
    border: 1px solid var(--color-accent, #c8872a);
    color: var(--color-text);
    padding: 0.65rem 1.1rem;
    border-radius: 999px;
    font-family: var(--font-body);
    font-size: 0.88rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 10;
}
.csp-toast.is-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

/* Load-more spinner (infinite scroll page fetches) */
.csp-load-more {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    color: var(--color-muted);
    font-family: var(--font-body);
    font-size: 0.85rem;
    padding: 1rem;
}

/* Empty + loading states for the panel's grid */
.csp-empty,
.csp-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    color: var(--color-muted);
    font-family: var(--font-body);
    font-size: 0.9rem;
    padding: 2.5rem 1rem;
    grid-column: 1 / -1;
}
.csp-empty i,
.csp-loading i { font-size: 1.6rem; color: rgba(200, 135, 42, 0.45); }

/* Panel's product-card keeps accent cursor; inline add-button is
   always visible on touch screens (covered by shared CSS), but also
   ensure it's visible on hover for panel (inherited). */
.card-search-screen .search-main {
    padding: 1rem 1.25rem 1.25rem;
}

/* Keep the main scroll area tall enough to avoid jitter in the modal */
.card-search-screen .card-grid {
    align-content: start;
}

/* Finish-chip selector row (per-tile) — Non-Foil / Foil / Etched / Holo / etc.
   Chips appear only when the card has ≥2 available finishes. */
.csp-finish-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
    margin: 0.35rem 0 0.15rem;
}
.csp-finish-chip {
    appearance: none;
    background: rgba(14, 12, 10, 0.55);
    border: 1px solid rgba(200, 135, 42, 0.28);
    color: var(--color-muted, #A89880);
    font-family: var(--font-body);
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.02em;
    padding: 0.22rem 0.55rem;
    border-radius: 4px;
    cursor: pointer;
    transition: background 0.12s ease, color 0.12s ease, border-color 0.12s ease;
    white-space: nowrap;
}
.csp-finish-chip:hover {
    color: var(--color-accent, #C8872A);
    border-color: rgba(200, 135, 42, 0.55);
}
.csp-finish-chip.is-active {
    background: rgba(200, 135, 42, 0.18);
    border-color: var(--color-accent, #C8872A);
    color: var(--color-accent, #C8872A);
}

/* ── MTG mana-color pip buttons ──────────────────────────────────────────── */
.csp-color-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}
.csp-color-pip {
    width: 2rem;
    height: 2rem;
    padding: 0;
    border-radius: 50%;
    font-size: 0.72rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 2px solid transparent;
    transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
    cursor: pointer;
}
.csp-color-pip:hover { transform: scale(1.12); }
.csp-color-pip.is-active { border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,0.35); }

/* Standard MTG mana colors */
.csp-color-pip[data-mtg-color="W"] { background: #E8E4D0; color: #3a3020; }
.csp-color-pip[data-mtg-color="U"] { background: #0E68AB; color: #fff; }
.csp-color-pip[data-mtg-color="B"] { background: #2D2D2D; color: #ccc; border-color: rgba(255,255,255,0.12); }
.csp-color-pip[data-mtg-color="R"] { background: #D3202A; color: #fff; }
.csp-color-pip[data-mtg-color="G"] { background: #00733E; color: #fff; }
.csp-color-pip[data-mtg-color="C"] { background: #9C9C9C; color: #1a1a1a; }
