/* ==========================================================================
   Catalog — Unified styles for /templates and /backgrounds
   Mobile-first: 2 cols → 3 → 4 → 5
   ========================================================================== */

/* Override global p max-width inside catalog */
.cat-page p { max-width: none; }

/* ---- Layout ---- */
.cat-page {
    max-width: 1440px;
    margin: 0 auto;
    padding: calc(var(--nav-height, 72px) + 16px) 0 48px;
}

/* ---- Hero ---- */
.cat-hero {
    padding: 28px 16px 0;
}
.cat-hero h1 {
    font-family: 'Syne', var(--font-family, sans-serif);
    font-size: clamp(22px, 4vw, 32px);
    font-weight: 700;
    color: #12213a;
    margin: 0 0 6px;
    line-height: 1.2;
}
.cat-hero .cat-subtitle {
    color: #6b7280;
    font-size: 14px;
    line-height: 1.5;
    margin: 0 0 16px;
}

/* ---- Alerts ---- */
.cat-alert {
    margin: 0 16px 16px;
    padding: 16px 20px;
    border-radius: 14px;
    background: #fffbeb;
    border: 1px solid #fde68a;
}
.cat-alert--info {
    background: #eff6ff;
    border-color: #bfdbfe;
}
.cat-alert h2 {
    font-size: 16px;
    font-weight: 600;
    margin: 0 0 4px;
}
.cat-alert p {
    font-size: 14px;
    color: #6b7280;
    margin: 0 0 12px;
}

/* ---- Project bar ---- */
.cat-project-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px;
    margin-bottom: 12px;
    font-size: 14px;
}
.cat-project-bar label {
    white-space: nowrap;
    font-weight: 500;
    color: #374151;
}
.cat-project-bar select {
    flex: 1;
    min-width: 0;
    padding: 6px 10px;
    border-radius: 10px;
    border: 1px solid #d1d5db;
    font-size: 14px;
    background: #fff;
    color: #111827;
}

/* ---- Sticky toolbar ---- */
.cat-toolbar {
    position: sticky;
    top: var(--nav-height, 72px);
    z-index: 50;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    padding: 10px 0;
    margin-bottom: 16px;
}

/* Search */
.cat-search {
    position: relative;
    padding: 0 16px;
    margin-bottom: 8px;
}
.cat-search-icon {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 14px;
    pointer-events: none;
    color: #9ca3af;
}
.cat-search-input {
    width: 100%;
    padding: 9px 12px 9px 36px;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    font-size: 14px;
    background: #f9fafb;
    color: #111827;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.cat-search-input:focus {
    border-color: #6366f1;
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
    background: #fff;
}
.cat-search-input::placeholder { color: #9ca3af; }

/* Sort */
.cat-sort-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px;
    margin-bottom: 6px;
}
.cat-sort-select {
    padding: 5px 10px;
    border-radius: 10px;
    border: 1px solid #e5e7eb;
    font-size: 13px;
    background: #fff;
    color: #374151;
}

/* ---- Chips (horizontal scroll) ---- */
.cat-chips-row {
    padding: 0 16px;
    margin-bottom: 4px;
}
.cat-chips-label {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #9ca3af;
    margin-bottom: 6px;
}
.cat-chips {
    display: flex;
    gap: 7px;
    overflow-x: auto;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
    scroll-snap-type: x proximity;
}
.cat-chips::-webkit-scrollbar { display: none; }

.cat-chip {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    background: #f3f4f6;
    color: #374151;
    border: none;
    cursor: pointer;
    white-space: nowrap;
    scroll-snap-align: start;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
    line-height: 1.3;
}
.cat-chip:hover { background: #e5e7eb; text-decoration: none; color: #374151; }
.cat-chip.active {
    background: #111827;
    color: #fff;
}
.cat-chip.active:hover { background: #1f2937; color: #fff; }
.cat-chip .cnt {
    opacity: 0.6;
    font-size: 11px;
}

/* ---- Counter / kicker ---- */
.cat-counter {
    padding: 0 16px;
    margin-bottom: 12px;
    font-size: 13px;
    color: #9ca3af;
}

/* ---- Grid ---- */
.cat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    padding: 0 12px;
}
@media (min-width: 768px) {
    .cat-grid { grid-template-columns: repeat(3, 1fr); gap: 14px; padding: 0 16px; }
}
@media (min-width: 1024px) {
    .cat-grid { grid-template-columns: repeat(4, 1fr); gap: 16px; padding: 0 16px; }
}
@media (min-width: 1440px) {
    .cat-grid { grid-template-columns: repeat(5, 1fr); }
}

/* ---- Card ---- */
.cat-card {
    border-radius: 14px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    display: flex;
    flex-direction: column;
}
.cat-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}
.cat-card:active { transform: scale(0.97); }
.cat-card.is-hidden { display: none; }

/* Preview area */
.cat-card-preview {
    position: relative;
    width: 100%;
    background: #f3f4f6;
    overflow: hidden;
}
.cat-card-preview--portrait { aspect-ratio: 9 / 16; }
.cat-card-preview--square { aspect-ratio: 1; }
.cat-card-preview--landscape { aspect-ratio: 16 / 9; }

.cat-card-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}
.cat-card-preview-fallback {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    color: #fff;
    padding: 12px;
    text-align: center;
}

/* Favorite badge on card */
.cat-card-fav {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(4px);
    border: none;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.15s;
    z-index: 2;
    padding: 0;
    line-height: 1;
}
.cat-card-fav:hover { transform: scale(1.15); }

/* "New" badge on card */
.cat-card-new {
    position: absolute;
    top: 6px;
    left: 6px;
    padding: 2px 8px;
    border-radius: 6px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    z-index: 2;
}

/* Card meta (bottom) */
.cat-card-meta {
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 6px;
    min-height: 38px;
}
.cat-card-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    color: #111827;
}
.cat-card-code {
    font-family: 'SF Mono', 'Fira Code', monospace;
    font-size: 11px;
    font-weight: 600;
    color: #6b7280;
    background: #f3f4f6;
    padding: 2px 7px;
    border-radius: 6px;
    flex-shrink: 0;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    border: none;
    line-height: 1.4;
}
.cat-card-code:hover { background: #e5e7eb; color: #111827; }
.cat-card-code.copied { background: #22c55e; color: #fff; }

/* ---- Empty state ---- */
.cat-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 48px 20px;
    color: #9ca3af;
}
.cat-empty h3 {
    font-size: 18px;
    font-weight: 600;
    color: #374151;
    margin-bottom: 6px;
}
.cat-empty p { font-size: 14px; }

/* ---- Load more ---- */
.cat-load-more-wrap {
    text-align: center;
    padding: 24px 16px;
}
.cat-load-more-wrap.is-hidden { display: none; }
.cat-load-more {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 32px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    background: #111827;
    color: #fff;
    border: none;
    cursor: pointer;
    transition: background 0.15s;
}
.cat-load-more:hover { background: #1f2937; }
.cat-load-more:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- CTA block ---- */
.cat-cta {
    text-align: center;
    padding: 48px 20px;
    margin: 24px 16px 0;
    border-radius: 20px;
    background: #f9fafb;
    border: 1px solid #e5e7eb;
}
.cat-cta h2 {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 8px;
    color: #111827;
}
.cat-cta p {
    font-size: 14px;
    color: #6b7280;
    margin-bottom: 16px;
}

/* ---- Modal (bottom sheet mobile / centered desktop) ---- */
.cat-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 200;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s, visibility 0.2s;
}
.cat-modal-overlay.open { opacity: 1; visibility: visible; }

.cat-modal {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 201;
    background: #fff;
    border-radius: 20px 20px 0 0;
    max-height: 92vh;
    overflow-y: auto;
    transform: translateY(100%);
    transition: transform 0.3s cubic-bezier(0.32, 0.72, 0, 1);
    padding-bottom: env(safe-area-inset-bottom, 0);
    overscroll-behavior: contain;
}
.cat-modal.open { transform: translateY(0); }

/* Desktop: centered popup */
@media (min-width: 768px) {
    .cat-modal {
        bottom: auto;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%) scale(0.95);
        max-width: 520px;
        max-height: 85vh;
        border-radius: 20px;
        opacity: 0;
        transition: transform 0.25s, opacity 0.25s;
    }
    .cat-modal.open {
        transform: translate(-50%, -50%) scale(1);
        opacity: 1;
    }
}

.cat-modal-handle {
    width: 36px;
    height: 4px;
    background: #d1d5db;
    border-radius: 2px;
    margin: 10px auto 0;
}
@media (min-width: 768px) {
    .cat-modal-handle { display: none; }
}

.cat-modal-close {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.06);
    border: none;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #374151;
    z-index: 5;
    transition: background 0.15s;
}
.cat-modal-close:hover { background: rgba(0, 0, 0, 0.12); }

.cat-modal-preview {
    width: 100%;
    max-height: 50vh;
    object-fit: contain;
    background: #f9fafb;
    display: block;
}

.cat-modal-body {
    padding: 16px 20px 28px;
}
.cat-modal-title {
    font-size: 18px;
    font-weight: 700;
    margin: 0 0 4px;
    color: #111827;
}
.cat-modal-subtitle {
    font-size: 13px;
    color: #6b7280;
    margin: 0 0 12px;
}
.cat-modal-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}
.cat-modal-tag {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
    color: #fff;
}
.cat-modal-info {
    font-size: 13px;
    color: #6b7280;
    margin-bottom: 12px;
    line-height: 1.6;
}

/* Modal slider */
.cat-modal-slider {
    position: relative;
    overflow: hidden;
    background: #f3f4f6;
}
.cat-modal-slider-track {
    display: flex;
    transition: transform 0.3s ease;
}
.cat-modal-slider-track img {
    width: 100%;
    flex-shrink: 0;
    object-fit: contain;
    max-height: 50vh;
    display: block;
}
.cat-modal-slider-dots {
    display: flex;
    justify-content: center;
    gap: 5px;
    padding: 8px 0;
}
.cat-modal-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #d1d5db;
    border: none;
    padding: 0;
    cursor: pointer;
    transition: background 0.15s;
}
.cat-modal-dot.active { background: #111827; }

.cat-modal-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 16px;
}
.cat-modal-actions .btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: background 0.15s;
}
.cat-modal-actions .btn-primary {
    background: #111827;
    color: #fff;
}
.cat-modal-actions .btn-primary:hover { background: #1f2937; }
.cat-modal-actions .btn-secondary {
    background: #f3f4f6;
    color: #374151;
}
.cat-modal-actions .btn-secondary:hover { background: #e5e7eb; }
.cat-modal-actions .btn-copy.copied {
    background: #22c55e;
    color: #fff;
}

/* ---- Fav hint tooltip ---- */
.cat-fav-hint {
    position: absolute;
    z-index: 300;
    background: #1f2937;
    color: #fff;
    padding: 8px 14px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.4;
    max-width: 260px;
    opacity: 0;
    transform: translateY(-4px);
    transition: opacity 0.2s, transform 0.2s;
    pointer-events: auto;
}
.cat-fav-hint.visible {
    opacity: 1;
    transform: translateY(0);
}
.cat-fav-hint a { color: #93c5fd; text-decoration: underline; }

/* ---- Responsive tweaks ---- */
@media (min-width: 768px) {
    .cat-hero { padding: 36px 24px 0; }
    .cat-search { padding: 0 24px; }
    .cat-chips-row { padding: 0 24px; }
    .cat-sort-row { padding: 0 24px; }
    .cat-counter { padding: 0 24px; }
    .cat-grid { padding: 0 20px; }
    .cat-project-bar { padding: 0 24px; }
    .cat-alert { margin: 0 24px 16px; }
    .cat-cta { margin: 24px 24px 0; }
}

@media (min-width: 1024px) {
    .cat-hero { padding: 40px 32px 0; }
    .cat-hero .cat-subtitle { font-size: 15px; }
}

/* Pagination (no-JS fallback, hidden when JS active) */
.cat-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 24px 0 8px;
    font-size: 14px;
}
.cat-pagination a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    border-radius: 8px;
    background: #f3f4f6;
    color: #374151;
    text-decoration: none;
    font-weight: 500;
    transition: background 0.15s;
}
.cat-pagination a:hover { background: #e5e7eb; }
.cat-pagination .is-current {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
    border-radius: 8px;
    background: #111827;
    color: #fff;
    font-weight: 600;
}
.cat-pagination .is-disabled {
    color: #d1d5db;
    cursor: default;
}
.js .cat-pagination { display: none; }
.js .cat-page--backgrounds .cat-pagination { display: flex; }
