*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0f1117;
    --bg-card: rgba(255, 255, 255, 0.04);
    --bg-card-hover: rgba(255, 255, 255, 0.08);
    --border-card: rgba(255, 255, 255, 0.08);
    --border-card-hover: rgba(139, 92, 246, 0.4);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #ff6565;
    --accent-glow: rgba(139, 92, 246, 0.25);
    --green: #34d399;
    --green-bg: rgba(52, 211, 153, 0.12);
    --red: #f87171;
    --red-bg: rgba(248, 113, 113, 0.12);
    --surface: rgba(255, 255, 255, 0.03);
    --sidebar-width: 240px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
}

/* ───── Header / Search ───── */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(20px) saturate(1.8);
    -webkit-backdrop-filter: blur(20px) saturate(1.8);
    background: rgba(15, 17, 23, 0.8);
    border-bottom: 1px solid var(--border-card);
    padding: 16px 24px;
}

.header-inner {
    max-width: 1440px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
}

.header h1 {
    font-size: 17px;
    font-weight: 700;
    white-space: nowrap;
    display: flex;
    align-items: center;
    color: #ffd3d3;
    text-transform: uppercase;
}

.search-wrapper {
    flex: 1;
    min-width: 240px;
    position: relative;
}

.search-wrapper svg {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    pointer-events: none;
}

#searchInput {
    width: 100%;
    padding: 11px 16px 11px 42px;
    border: 1px solid var(--border-card);
    border-radius: 12px;
    background: var(--surface);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#searchInput::placeholder {
    color: var(--text-muted);
}

#searchInput:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.result-count {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ───── View Toggle ───── */
.view-toggle {
    display: flex;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border-card);
    border-radius: 10px;
    padding: 3px;
    gap: 2px;
}

.toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 32px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.toggle-btn:hover {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.06);
}

.toggle-btn.active {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

/* ───── Main Content ───── */
.container {
    max-width: 1440px;
    margin: 0 auto;
    padding: 24px;
}

/* ───── Layout: Sidebar + Content ───── */
.layout {
    display: flex;
    gap: 24px;
    align-items: flex-start;
}

/* ───── Category Sidebar ───── */
.sidebar {
    position: sticky;
    top: 90px;
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 16px;
    padding: 16px 0;
    max-height: calc(100vh - 110px);
    overflow-y: auto;
    flex-shrink: 0;
}

.sidebar::-webkit-scrollbar {
    width: 4px;
}

.sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

.sidebar-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 0 16px 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-card);
    margin-bottom: 8px;
}

/* Sidebar close button (visible only on mobile) */
.sidebar-close {
    display: none;
    margin-left: auto;
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 8px;
    transition: color 0.15s, background 0.15s;
}

.sidebar-close:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}

/* Mobile category toggle FAB */
.mobile-cat-toggle {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 200;
    display: none;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border: 1px solid var(--border-card-hover);
    border-radius: 50px;
    background: rgba(15, 17, 23, 0.92);
    backdrop-filter: blur(16px) saturate(1.8);
    -webkit-backdrop-filter: blur(16px) saturate(1.8);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(139, 92, 246, 0.2);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.mobile-cat-toggle:hover {
    transform: translateX(-50%) translateY(-2px);
    box-shadow: 0 6px 32px rgba(0, 0, 0, 0.6), 0 0 0 1px rgba(139, 92, 246, 0.35);
}

.mobile-cat-toggle svg {
    color: var(--accent);
}

/* Mobile sidebar backdrop */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 299;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sidebar-backdrop.visible {
    display: block;
    opacity: 1;
}

.sidebar-list {
    list-style: none;
}

.sidebar-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 16px;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 13px;
    color: var(--text-secondary);
    border-left: 3px solid transparent;
}

.sidebar-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary);
}

.sidebar-item.active {
    background: rgba(255, 101, 101, 0.08);
    color: var(--accent);
    border-left-color: var(--accent);
    font-weight: 500;
}

.cat-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: auto;
    margin-left: 0;
}

.cat-count {
    font-size: 11px;
    font-weight: 600;
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-muted);
    padding: 2px 7px;
    border-radius: 10px;
    min-width: 24px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-item.active .cat-count {
    background: rgba(255, 101, 101, 0.15);
    color: var(--accent);
}

/* ───── Expandable Category Tree ───── */
.cat-expand-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    flex-shrink: 0;
    transition: transform 0.2s ease;
    color: var(--text-muted);
    margin-right: 4px;
}

.sidebar-item.open .cat-expand-icon {
    transform: rotate(90deg);
}

.sidebar-sublist {
    list-style: none;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.sidebar-sublist.expanded {
    max-height: 600px;
}

.sidebar-subitem {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 16px 7px 40px;
    cursor: pointer;
    transition: all 0.15s ease;
    font-size: 12px;
    color: var(--text-muted);
    border-left: 3px solid transparent;
}

.sidebar-subitem:hover {
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
}

.sidebar-subitem.active {
    background: rgba(139, 92, 246, 0.08);
    color: #f29826;
    border-left-color: #f29826;
    font-weight: 500;
}

.sidebar-subitem.active .cat-count {
    background: rgba(139, 92, 246, 0.15);
    color: #f29826;
}

/* ───── Content Area ───── */
.content-area {
    flex: 1;
    min-width: 0;
}

/* ───── Loading State ───── */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    gap: 16px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border-card);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-text {
    font-size: 15px;
    color: var(--text-secondary);
}

/* ───── Product Grid ───── */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 16px;
}

/* ───── Product Card ───── */
.product-card {
    background: var(--bg-card);
    border: 1px solid var(--border-card);
    border-radius: 16px;
    overflow: hidden;
    transition: transform 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease;
    cursor: default;
    display: flex;
    flex-direction: column;
}

.product-card:hover {
    transform: translateY(-4px);
    border-color: var(--border-card-hover);
    box-shadow: 0 8px 30px rgba(139, 92, 246, 0.1), 0 2px 8px rgba(0, 0, 0, 0.3);
}

/* Thumbnail */
.card-thumb {
    width: 100%;
    aspect-ratio: 1;
    background: var(--surface);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.card-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: transform 0.4s ease;
}

.product-card:hover .card-thumb img {
    transform: scale(1.06);
}

.card-thumb .placeholder-icon {
    color: var(--text-muted);
    opacity: 0.3;
}

.thumb-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Discount badge */
.discount-badge {
    position: absolute;
    top: 10px;
    right: 10px;
    color: white;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 8px;
    backdrop-filter: blur(8px);
    border: 1px solid #068706;
    background: #068706;
}

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

.card-category {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--accent);
}

.card-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.card-company {
    font-size: 12px;
    color: var(--text-muted);
}

.card-pricing {
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid var(--border-card);
    display: flex;
    align-items: baseline;
    gap: 8px;
    flex-wrap: wrap;
}

.price-special {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.price-mrp {
    font-size: 13px;
    color: var(--text-muted);
    text-decoration: line-through;
}

.card-plu {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: auto;
}

/* ───── Product Table ───── */
.product-table-wrapper {
    overflow-x: auto;
    border-radius: 14px;
    border: 1px solid var(--border-card);
    background: var(--bg-card);
}

.product-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.product-table thead th {
    position: sticky;
    top: 0;
    background: rgba(15, 17, 23, 0.95);
    backdrop-filter: blur(8px);
    padding: 12px 16px;
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-card);
    white-space: nowrap;
}

.product-table tbody tr {
    transition: background 0.15s ease;
    animation: fadeUp 0.3s ease both;
}

.product-table tbody tr:hover {
    background: rgba(255, 255, 255, 0.03);
}

.product-table tbody td {
    padding: 11px 16px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    vertical-align: middle;
}

.product-table tbody tr:last-child td {
    border-bottom: none;
}

/* Table columns */
.col-plu {
    font-family: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
    font-size: 12px;
    color: var(--text-muted) !important;
    white-space: nowrap;
}

.col-name {
    font-weight: 500;
    color: var(--text-primary) !important;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.col-right {
    text-align: right !important;
}

.col-sp {
    font-weight: 600;
    color: var(--text-primary) !important;
}

.col-company {
    color: var(--text-muted) !important;
    max-width: 150px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.table-cat-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 500;
    padding: 3px 10px;
    border-radius: 20px;
    background: rgba(255, 101, 101, 0.1);
    color: var(--accent);
    white-space: nowrap;
}

.table-discount {
    font-weight: 600;
    color: var(--green);
    background: var(--green-bg);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 12px;
}

.table-empty {
    text-align: center;
    padding: 48px 20px !important;
    color: var(--text-muted) !important;
}

.table-empty svg {
    margin-bottom: 8px;
    opacity: 0.5;
}

/* ───── No Results ───── */
.no-results {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

.no-results svg {
    width: 48px;
    height: 48px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

/* ───── Animations ───── */
@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(12px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.product-card {
    animation: fadeUp 0.35s ease both;
}

/* ───── Responsive ───── */
@media (max-width: 900px) {

    /* Show mobile FAB */
    .mobile-cat-toggle {
        display: flex !important;
    }

    /* Show close button in sidebar */
    .sidebar-close {
        display: flex;
    }

    /* Sidebar becomes a fixed slide-in drawer */
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 300;
        width: 280px;
        min-width: 280px;
        max-height: 100vh;
        border-radius: 0 16px 16px 0;
        background: rgba(15, 17, 23, 0.97);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        transform: translateX(-100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        padding-top: 24px;
    }

    .sidebar.open {
        transform: translateX(0);
    }

    .layout {
        gap: 0;
    }
}

@media (max-width: 600px) {
    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 10px;
    }

    .header-inner {
        gap: 12px;
    }

    .container {
        padding: 16px;
    }

    .card-body {
        padding: 10px 12px 14px;
    }

    .price-special {
        font-size: 16px;
    }

    .product-table {
        font-size: 12px;
    }

    .product-table thead th,
    .product-table tbody td {
        padding: 8px 10px;
    }
}