/* =========================================================
   Categories Page Styling — 3-Column Portrait Grid
   ========================================================= */

:root {
    --cat-bg: #090d16;
    --cat-surface: #111827;
    --cat-surface-hover: #1f293d;
    --cat-text: #ffffff;
    --cat-text-muted: #94a3b8;
    --cat-accent: #3b82f6;
    --cat-card-radius: 6px;
}

[data-theme="light"] {
    --cat-bg: #f8fafc;
    --cat-surface: #ffffff;
    --cat-surface-hover: #f1f5f9;
    --cat-text: #0f172a;
    --cat-text-muted: #64748b;
    --cat-accent: #2563eb;
}

body.categories-page {
    background-color: var(--cat-bg);
    color: var(--cat-text);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.3s ease, color 0.3s ease;
}

/* ── Header ── */
.categories-header {
    position: sticky;
    top: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: rgba(9, 13, 22, 0.92);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

[data-theme="light"] .categories-header {
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.categories-header-left {
    display: flex;
    align-items: center;
    gap: 14px;
}

.cat-back-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--cat-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
}

[data-theme="light"] .cat-back-btn {
    background: rgba(0, 0, 0, 0.05);
}

.cat-back-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.06);
}

.cat-back-btn:active {
    transform: scale(0.92);
}

.categories-page-title {
    font-size: 1.05rem;
    font-weight: 700;
    margin: 0;
    color: var(--cat-text);
    letter-spacing: -0.2px;
    transition: font-size 0.2s ease;
}

.categories-page-title.category-drilldown-title {
    font-size: 0.95rem;
    font-weight: 700;
    max-width: 240px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.categories-header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.categories-header-actions.cat-hidden {
    display: none !important;
}

.cat-action-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: var(--cat-text);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
}

[data-theme="light"] .cat-action-btn {
    background: rgba(0, 0, 0, 0.05);
}

.cat-action-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.06);
}

/* ── Main Container (Edge-to-edge compact spacing) ── */
.categories-main {
    flex: 1;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
    padding: 4px 1.5px 100px;
    box-sizing: border-box;
}

/* ── 3-Column Categories Grid (Ultra-compact 1.5px gap) ── */
.categories-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5px;
    width: 100%;
    box-sizing: border-box;
}

@media (min-width: 768px) {
    .categories-main {
        padding: 8px 6px 100px;
    }
    .categories-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 6px;
    }
}

@media (min-width: 1024px) {
    .categories-grid {
        grid-template-columns: repeat(5, 1fr);
        gap: 8px;
    }
}

/* ── Portrait Category Card (Larger & Taller) ── */
.category-card {
    position: relative;
    aspect-ratio: 3 / 4.5;
    min-height: 155px;
    border-radius: var(--cat-card-radius);
    overflow: hidden;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.22);
    background-color: #1a2234;
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.25s ease;
    border: none !important;
}

.category-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}

.category-card:active {
    transform: scale(0.97);
}

.category-card-bg {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    transition: transform 0.4s ease;
}

.category-card:hover .category-card-bg {
    transform: scale(1.06);
}

/* Vibrant Card Color Tint & Deep Bottom Gradient Overlay for 2-Line Text */
.category-card-overlay {
    position: absolute;
    inset: 0;
    background: linear-gradient(
        to top,
        rgba(0, 0, 0, 0.95) 0%,
        rgba(0, 0, 0, 0.78) 42%,
        rgba(0, 0, 0, 0.25) 75%,
        transparent 100%
    );
    z-index: 1;
    pointer-events: none;
}

/* Category Content at bottom */
.category-card-content {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 8px 4px 6px 4px;
    z-index: 2;
    pointer-events: none;
}

.category-card-title {
    font-size: clamp(0.66rem, 2.6vw, 0.73rem);
    font-weight: 700;
    color: #ffffff;
    line-height: 1.15;
    margin: 0 0 2px;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.85);
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: normal;
    overflow-wrap: break-word;
    letter-spacing: -0.2px;
}

.category-card-count {
    font-size: 0.60rem;
    font-weight: 500;
    color: rgba(255, 255, 255, 0.85);
    margin: 0;
    letter-spacing: 0.1px;
    line-height: 1.1;
}

@media (min-width: 480px) {
    .category-card-title {
        font-size: 0.82rem;
    }
    .category-card-count {
        font-size: 0.70rem;
    }
}

/* ── Category Products View (Drill-down) ── */
.category-products-view {
    display: none;
    animation: fadeInView 0.25s ease-out forwards;
}

@keyframes fadeInView {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.category-nav-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 15px;
    gap: 10px;
    flex-wrap: wrap;
}

.btn-back-to-grid {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.1);
    color: var(--cat-text);
    border: none;
    font-weight: 700;
    font-size: 0.88rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

[data-theme="light"] .btn-back-to-grid {
    background: rgba(0, 0, 0, 0.06);
}

.btn-back-to-grid:hover {
    background: var(--cat-accent);
    color: #ffffff;
}

.current-category-badge {
    font-size: 0.95rem;
    font-weight: 800;
    color: var(--cat-text);
}

.category-product-search-box {
    position: relative;
    width: 100%;
    margin-bottom: 18px;
}

.category-product-search-box input {
    width: 100%;
    padding: 12px 16px 12px 42px;
    border-radius: 50px;
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: var(--cat-text);
    font-size: 0.92rem;
    outline: none;
    box-sizing: border-box;
    transition: background 0.2s, box-shadow 0.2s;
}

[data-theme="light"] .category-product-search-box input {
    background: #ffffff;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.06);
}

.category-product-search-box input:focus {
    background: rgba(255, 255, 255, 0.14);
    box-shadow: 0 0 0 2px var(--cat-accent);
}

.category-product-search-box i {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--cat-text-muted);
    font-size: 0.95rem;
}

/* ── Category Products Grid ── */
.cat-products-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

@media (min-width: 640px) {
    .cat-products-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 16px;
    }
}

@media (min-width: 1024px) {
    .cat-products-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 20px;
    }
}

.cat-product-card {
    background: var(--cat-surface);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    border: none !important;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    cursor: pointer;
}

.cat-product-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.25);
}

.cat-prod-img-box {
    position: relative;
    width: 100%;
    aspect-ratio: 1;
    background: #0f172a;
    overflow: hidden;
}

.cat-prod-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.3s ease;
}

.cat-product-card:hover .cat-prod-img {
    transform: scale(1.05);
}

.cat-prod-condition-badge {
    display: none !important;
}

.cat-prod-body {
    padding: 10px 12px 12px;
    display: flex;
    flex-direction: column;
    flex: 1;
    justify-content: space-between;
}

.cat-prod-title {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--cat-text);
    margin: 0 0 4px;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.cat-prod-seller {
    font-size: 0.76rem;
    color: var(--cat-text-muted);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.cat-prod-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
    padding-top: 6px;
}

.cat-prod-price {
    font-size: 0.98rem;
    font-weight: 800;
    color: #10b981;
}

.cat-add-cart-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: #3b82f6;
    color: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.82rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.cat-add-cart-btn:hover {
    background: #2563eb;
    transform: scale(1.1);
}

.cat-add-cart-btn:active {
    transform: scale(0.9);
}

/* ── Empty State ── */
.category-empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--cat-text-muted);
}

.category-empty-state i {
    font-size: 3rem;
    color: #64748b;
    margin-bottom: 14px;
    opacity: 0.6;
}

.category-empty-state h3 {
    margin: 0 0 6px;
    font-size: 1.15rem;
    color: var(--cat-text);
}

.category-empty-state p {
    font-size: 0.88rem;
    margin: 0 0 20px;
}

.btn-explore-all {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 24px;
    border-radius: 25px;
    background: var(--cat-accent);
    color: #ffffff;
    font-weight: 700;
    font-size: 0.9rem;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s ease;
}

.btn-explore-all:hover {
    background: #2563eb;
    transform: translateY(-2px);
}
