/* ============================================================
   Catalogue page — item card layout
   Reuses compendium.css base (controls, search, etc.)
   ============================================================ */

/* ── Controls tweaks for catalogue ───────────────────────────── */
.control-cluster--categories {
    order: 0;
}

/* ── Item grid ───────────────────────────────────────────────── */
.catalogue-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
    gap: 0.85rem;
    margin-top: 0.25rem;
}

/* ── Item card ───────────────────────────────────────────────── */
.item-card {
    display: flex;
    flex-direction: column;
    background: var(--parchment);
    border: 1px solid var(--ink-light);
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
    text-decoration: none;
    color: var(--ink);
    position: relative;
    overflow: hidden;
}

.item-card:hover {
    border-color: var(--gold);
    box-shadow: 0 2px 10px rgba(0,0,0,0.25);
    transform: translateY(-1px);
}

.item-card:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 2px;
}

/* Header row: icon + title + category badge */
.item-card-header {
    display: flex;
    align-items: flex-start;
    gap: 0.7rem;
    padding: 0.75rem 0.85rem 0.45rem;
}

.item-card-icon-wrap {
    flex-shrink: 0;
    width: 64px;
    height: 64px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--ink);
    border: 1px solid var(--ink-light);
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.item-card-icon {
    display: block;
    width: 56px;
    height: 56px;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

.item-card-icon-placeholder {
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    color: rgba(239, 233, 215, 0.3);
    user-select: none;
}

.item-card-meta {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.22rem;
}

.item-card-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--ink);
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.item-card-category {
    display: inline-flex;
    align-items: center;
    font-size: 0.6rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 700;
    padding: 0.15em 0.45em;
    border-width: 1px;
    border-style: solid;
    white-space: nowrap;
    align-self: flex-start;
}

/* Category colour themes */
.item-cat--headwear { background: rgba(100, 80, 180, 0.15); color: #7c62c4; border-color: #7c62c4; }
.item-cat--tops     { background: rgba(40, 150, 130, 0.15); color: #289682; border-color: #289682; }
.item-cat--feet     { background: rgba(140, 100, 60,  0.15); color: #8c643c; border-color: #8c643c; }
.item-cat--righthand { background: rgba(200, 160, 30,  0.15); color: #a88020; border-color: #a88020; }
.item-cat--lefthand  { background: rgba(60, 100, 180,  0.15); color: #3c64b4; border-color: #3c64b4; }
.item-cat--hind      { background: rgba(50, 140, 80,   0.15); color: #328c50; border-color: #328c50; }
.item-cat--necklaces { background: rgba(180, 50, 100,  0.15); color: #b43264; border-color: #b43264; }
.item-cat--misc,
.item-cat--other     { background: rgba(100, 100, 100, 0.12); color: #646464; border-color: #646464; }

/* Body: description + context */
.item-card-body {
    padding: 0 0.85rem 0.55rem;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.item-card-desc {
    font-size: 0.8rem;
    color: var(--ink);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.item-card-context {
    font-size: 0.73rem;
    color: var(--ink-light);
    font-style: italic;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Footer: owner avatars + count */
.item-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.45rem 0.85rem 0.6rem;
    border-top: 1px solid rgba(44, 36, 22, 0.12);
    margin-top: auto;
    gap: 0.5rem;
}

.item-card-owners {
    display: flex;
    align-items: center;
    gap: 0.18rem;
}

.owner-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--gold);
    margin-right: -4px;
    background: var(--ink);
    flex-shrink: 0;
}

.owner-avatar-placeholder {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--ink-light);
    border: 1px solid var(--gold);
    margin-right: -4px;
    flex-shrink: 0;
}

.owner-avatar-overflow {
    margin-left: 8px;
    font-size: 0.72rem;
    color: var(--ink-light);
    white-space: nowrap;
    flex-shrink: 0;
}

.item-card-holder-count {
    font-size: 0.75rem;
    color: var(--ink-light);
    white-space: nowrap;
    flex-shrink: 0;
    margin-left: auto;
}

.item-card-holder-count strong {
    color: var(--ink);
    font-weight: 700;
}

.item-card-zero {
    color: rgba(44, 36, 22, 0.35);
}

/* ── Owner popup ─────────────────────────────────────────────── */
.owner-popup {
    position: fixed;
    inset: 0;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
}

.owner-popup[hidden] {
    display: none;
}

.owner-popup-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(16, 14, 11, 0.75);
    cursor: pointer;
}

.owner-popup-panel {
    position: relative;
    background: var(--parchment);
    border: 1px solid var(--gold);
    max-width: 460px;
    width: calc(100% - 2rem);
    max-height: calc(100vh - 4rem);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
}

.owner-popup-header {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.75rem 1rem;
    background: var(--ink);
    border-bottom: 1px solid var(--gold);
    flex-shrink: 0;
}

.owner-popup-item-icon {
    width: 40px;
    height: 40px;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    flex-shrink: 0;
    background: rgba(255,255,255,0.05);
}

.owner-popup-title-group {
    flex: 1;
    min-width: 0;
}

.owner-popup-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--gold);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.owner-popup-subtitle {
    font-size: 0.75rem;
    color: var(--parchment);
    opacity: 0.7;
}

.owner-popup-close {
    background: none;
    border: none;
    color: var(--parchment);
    opacity: 0.7;
    cursor: pointer;
    font-size: 1rem;
    padding: 0.2rem 0.3rem;
    flex-shrink: 0;
    line-height: 1;
}

.owner-popup-close:hover {
    opacity: 1;
    color: var(--gold);
}

.owner-popup-body {
    overflow-y: auto;
    padding: 0.5rem 0;
    flex: 1;
}

.owner-popup-empty {
    padding: 1.5rem;
    text-align: center;
    color: var(--ink-light);
    font-style: italic;
}

.owner-popup-row {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.45rem 0.85rem;
    border-bottom: 1px solid rgba(44, 36, 22, 0.1);
    text-decoration: none;
    color: var(--ink);
    transition: background 0.1s;
}

.owner-popup-row:last-child {
    border-bottom: none;
}

.owner-popup-row:hover {
    background: rgba(201, 162, 39, 0.08);
}

.owner-popup-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    object-fit: cover;
    border: 1px solid var(--gold);
    flex-shrink: 0;
    background: var(--ink);
}

.owner-popup-avatar-placeholder {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--ink-light);
    border: 1px solid rgba(201, 162, 39, 0.4);
    flex-shrink: 0;
}

.owner-popup-info {
    flex: 1;
    min-width: 0;
}

.owner-popup-name {
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.owner-popup-handle {
    font-size: 0.72rem;
    font-family: monospace;
    color: var(--ink-light);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Category filter badge colours (catalogue-specific) ───────── */
.cat-filter-badge {
    font-family: inherit;
    cursor: pointer;
    border-width: 1px;
    border-style: solid;
    font-size: 0.63rem;
    padding: 0.16rem 0.42rem;
    letter-spacing: 0.04em;
    text-transform: capitalize;
    transition: opacity 0.15s, transform 0.1s;
    white-space: nowrap;
    background: transparent;
    color: var(--parchment);
    border-color: rgba(239, 233, 215, 0.4);
}

.cat-filter-badge:hover {
    transform: translateY(-1px);
    border-color: var(--gold);
    color: var(--gold);
}

.cat-filter-badge--active {
    background: rgba(201, 162, 39, 0.2);
    border-color: var(--gold) !important;
    color: var(--gold) !important;
    outline: 1px solid var(--gold);
    outline-offset: 1px;
}

.cat-filter-badge--dim {
    opacity: 0.38;
}

/* ── Empty/loading states ────────────────────────────────────── */
.loading-text {
    grid-column: 1 / -1;
    text-align: center;
    padding: 3rem;
    color: var(--ink-light);
    font-style: italic;
}

/* ── Responsive ─────────────────────────────────────────────── */
@media (max-width: 768px) {
    .catalogue-grid {
        grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
        gap: 0.65rem;
    }

    .item-card-icon-wrap {
        width: 52px;
        height: 52px;
    }

    .item-card-icon {
        width: 44px;
        height: 44px;
    }

    .item-card-title {
        font-size: 0.88rem;
    }
}

@media (max-width: 480px) {
    .catalogue-grid {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }

    .item-card-header {
        padding: 0.6rem 0.7rem 0.35rem;
        gap: 0.55rem;
    }

    .item-card-icon-wrap {
        width: 48px;
        height: 48px;
    }

    .item-card-icon {
        width: 40px;
        height: 40px;
    }

    .item-card-body {
        padding: 0 0.7rem 0.45rem;
    }

    .item-card-footer {
        padding: 0.38rem 0.7rem 0.5rem;
    }
}
