:root {
    --primary-color: #1976D2;
    --primary-dark: #1565C0;
    --secondary-color: #424242;
    --accent-color: #FF5722;
    --bg-color: #FFFFFF;
    --surface-color: #F5F5F5;
    --text-color: #212121;
    --text-secondary: #757575;
    --border-color: #E0E0E0;
    --hover-color: rgba(0, 0, 0, 0.04);
    --shadow-color: rgba(0, 0, 0, 0.1);
}

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

html, body {
    margin: 0;
    padding: 0;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    background: var(--bg-color);
    color: var(--text-color);
}

.app-container { display: flex; flex-direction: column; min-height: 100vh; }

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    height: 64px;
    background: var(--surface-color);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
    color: var(--primary-color);
    font-weight: 700;
    font-size: 1.25rem;
}

.header-nav { display: flex; gap: 0.5rem; }

.nav-link {
    padding: 0.5rem 1rem;
    text-decoration: none;
    color: var(--text-secondary);
    border-radius: 8px;
}

.nav-link:hover { background: var(--hover-color); color: var(--text-color); }

.header-right { display: flex; align-items: center; gap: 1rem; }

.user-menu { position: relative; }
.user-name { font-weight: 500; cursor: pointer; }
.user-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 12px var(--shadow-color);
    min-width: 180px;
    z-index: 200;
}
.user-menu:hover .user-dropdown { display: block; }
.dropdown-item {
    display: block;
    width: 100%;
    padding: 0.75rem 1rem;
    border: none;
    background: none;
    text-align: left;
    cursor: pointer;
    text-decoration: none;
    color: var(--text-color);
}
.dropdown-item:hover { background: var(--hover-color); }

/* Main */
.app-main { flex: 1; padding: 2rem; max-width: 1400px; margin: 0 auto; width: 100%; }
.app-footer { padding: 1.5rem; background: var(--surface-color); text-align: center; color: var(--text-secondary); }

/* Page Header */
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 2rem; flex-wrap: wrap; gap: 1rem; }
.page-header h1 { margin: 0; font-size: 1.75rem; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    font-size: 0.9375rem;
    font-weight: 500;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
}
.btn-primary { background: var(--primary-color); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--secondary-color); color: white; }
.btn-outline { background: transparent; border: 1px solid var(--border-color); color: var(--text-color); }
.btn-outline:hover { background: var(--hover-color); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* Forms */
.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; margin-bottom: 0.375rem; font-weight: 500; }
.form-control {
    width: 100%;
    padding: 0.625rem 0.875rem;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: white;
}
.form-control:focus { outline: none; border-color: var(--primary-color); }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { display: block; margin-top: 0.25rem; font-size: 0.8125rem; color: var(--text-secondary); }
.checkbox-label { display: flex; align-items: center; gap: 0.5rem; cursor: pointer; }

/* Alerts */
.alert { padding: 1rem; border-radius: 8px; margin-bottom: 1rem; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
.text-danger { color: #dc2626; font-size: 0.875rem; }

/* Empty State */
.empty-state { text-align: center; padding: 4rem 2rem; }
.empty-icon { font-size: 4rem; opacity: 0.5; }
.empty-state h3 { margin: 1rem 0 0.5rem; }
.empty-state p { color: var(--text-secondary); margin-bottom: 1.5rem; }

/* Login */
.login-layout {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
    padding: 2rem;
}
.login-container { width: 100%; max-width: 400px; }
.login-card { background: white; border-radius: 16px; padding: 2.5rem; box-shadow: 0 20px 40px rgba(0,0,0,0.2); }
.login-header { text-align: center; margin-bottom: 2rem; }
.login-logo { font-size: 3rem; }
.login-header h1 { margin: 0.5rem 0 0.25rem; }
.login-header p { margin: 0; color: var(--text-secondary); }

/* Password Page */
.password-page { display: flex; justify-content: center; padding: 2rem 0; }
.password-card { background: var(--surface-color); border-radius: 16px; padding: 2.5rem; max-width: 440px; width: 100%; }
.password-card h1 { margin: 0 0 1.5rem; text-align: center; }
.form-actions { display: flex; gap: 1rem; margin-top: 1.5rem; }
.form-actions .btn { flex: 1; }

/* Catalog */
.catalog-content {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}
.search-box { display: flex; gap: 0.5rem; }
.search-input { max-width: 300px; }
.filter-sidebar {
    position: relative;
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: var(--surface-color);
    border: 1px solid var(--border-color);
    border-radius: 12px;
}

    .filter-sidebar h3 {
        width: 100%;
        margin: 0 0 0.25rem 0;
        font-size: 1rem;
    }

    .filter-sidebar .filter-level {
        margin-bottom: 0;
    }

        .filter-sidebar .filter-level select {
            min-width: 160px;
        }

    .filter-sidebar .btn-outline.btn-sm {
        align-self: flex-end;
    }
.results-header { margin-bottom: 1.5rem; color: var(--text-secondary); display: flex; justify-content: space-between; align-items: center; }
.sort-control { display: flex; align-items: center; gap: 0.5rem; }
.sort-control label { font-size: 0.85rem; white-space: nowrap; }
.sort-control select { padding: 0.35rem 0.5rem; border: 1px solid var(--border-color); border-radius: 6px; background: var(--surface-color); color: var(--text-color); font-size: 0.85rem; cursor: pointer; }

/* Product Grid */
.product-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1.5rem;
}
.product-card { background: var(--surface-color); border-radius: 12px; overflow: hidden; box-shadow: 0 2px 8px var(--shadow-color); }
.product-image { height: 120px; display: flex; align-items: stretch; justify-content: center; font-size: 3rem;}
.product-info { padding: 1rem; }
.product-name { margin: 0 0 0.25rem; font-size: 1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-code { margin: 0 0 0.5rem; font-size: 0.8125rem; color: var(--text-secondary); }
/* Swapped layout: ProductID shown first with the prominent (h4-sized) style,
   description shown underneath with the smaller/secondary style. */
.product-code-main { margin: 0 0 0.25rem; font-size: 1rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.product-name-sub { margin: 0 0 0.5rem; font-size: 0.8125rem; color: var(--text-secondary); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.no-image-placeholder { height: 120px; display: flex; align-items: center; justify-content: center; font-size: 3rem; opacity: .3 }
.price { font-size: 1.25rem; font-weight: 700; color: var(--primary-color); }
.in-stock { color: #16a34a; font-size: 0.8125rem; }
.out-of-stock { color: #dc2626; font-size: 0.8125rem; }
.on-order { color: #d97706; font-size: 0.8125rem; }
.product-actions { padding: 1rem; border-top: 1px solid var(--border-color); display: flex; gap: 0.5rem; align-items: center; }
.qty-input { width: 60px; padding: 0.5rem; text-align: center; border: 1px solid var(--border-color); border-radius: 4px; }

/* Cart */
.cart-content { display: grid; grid-template-columns: 1fr 340px; gap: 2rem; align-items: start; }
.cart-items { background: var(--surface-color); border-radius: 12px; overflow: hidden; }
.cart-header { display: grid; grid-template-columns: 2fr 1fr 150px 100px 50px; gap: 1rem; padding: 1rem 1.5rem; background: var(--hover-color); font-weight: 600; font-size: 0.8125rem; color: var(--text-secondary); }
.cart-item { display: grid; grid-template-columns: 2fr 1fr 150px 100px 50px; gap: 1rem; padding: 1.5rem; align-items: center; border-bottom: 1px solid var(--border-color); }
.item-details h4 { margin: 0 0 0.25rem; font-size: 0.9375rem; }
.item-code { margin: 0; font-size: 0.8125rem; color: var(--text-secondary); }
.btn-remove { background: none; border: none; cursor: pointer; font-size: 1.25rem; opacity: 0.6; }
.btn-remove:hover { opacity: 1; }

/* Summary */
.cart-summary, .checkout-summary { background: var(--surface-color); border-radius: 12px; padding: 1.5rem; position: sticky; top: 80px; }
.cart-summary h3, .checkout-summary h3 { margin: 0 0 1.5rem; }
.summary-row { display: flex; justify-content: space-between; padding: 0.75rem 0; border-bottom: 1px solid var(--border-color); }
.summary-row.total { border: none; font-size: 1.25rem; font-weight: 700; padding-top: 1rem; margin-top: 0.5rem; }
.btn-checkout, .btn-place-order { margin-top: 1.5rem; padding: 1rem; }

/* Checkout */
.checkout-content { display: grid; grid-template-columns: 1fr 380px; gap: 2rem; align-items: start; }
.checkout-section { background: var(--surface-color); border-radius: 12px; padding: 1.5rem; margin-bottom: 1.5rem; }
.checkout-section h3 { margin: 0 0 1rem; font-size: 1rem; }
.order-items-list { display: flex; flex-direction: column; gap: 0.5rem; }
.order-item { display: flex; justify-content: space-between; padding: 0.5rem 0; border-bottom: 1px solid var(--border-color); }
.item-name { flex: 1; }
.item-qty { color: var(--text-secondary); margin: 0 1rem; }

/* Confirmation */
.order-confirmation { background: var(--surface-color); border-radius: 16px; padding: 3rem; text-align: center; max-width: 600px; margin: 0 auto; }
.confirmation-icon { width: 80px; height: 80px; background: #dcfce7; color: #16a34a; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 2.5rem; margin: 0 auto 1.5rem; }
.order-number { font-size: 1.125rem; }
.confirmation-details { text-align: left; margin: 2rem 0; padding: 1.5rem; background: var(--hover-color); border-radius: 8px; }
.confirmation-actions { display: flex; gap: 1rem; justify-content: center; margin-top: 2rem; }

/* Orders */
.orders-list { display: flex; flex-direction: column; gap: 1rem; }
.order-card { background: var(--surface-color); border-radius: 12px; overflow: hidden; }
.order-header { display: grid; grid-template-columns: 1fr auto; gap: 1rem; padding: 1.25rem 1.5rem; align-items: center; text-decoration: none; color: inherit; }
.order-header:hover { background: var(--hover-color); }
.order-info { display: flex; flex-direction: column; gap: 0.25rem; }
.order-number { font-weight: 600; color: var(--primary-color); }
.order-date { font-size: 0.875rem; color: var(--text-secondary); }
.status-badge { padding: 0.25rem 0.75rem; border-radius: 20px; font-size: 0.8125rem; font-weight: 500; }
.status-warning { background: #fef3c7; color: #92400e; }
.status-info { background: #dbeafe; color: #1e40af; }
.status-primary { background: #e0e7ff; color: #3730a3; }
.status-secondary { background: #f3f4f6; color: #374151; }
.status-success { background: #dcfce7; color: #166534; }
.status-danger { background: #fee2e2; color: #991b1b; }
.order-total { font-weight: 700; font-size: 1.125rem; }
.order-details { padding: 0 1.5rem 1.5rem; border-top: 1px solid var(--border-color); }
.details-section { margin-top: 1.25rem; }
.details-section h4 { margin: 0 0 0.5rem; font-size: 0.875rem; color: var(--text-secondary); text-transform: uppercase; }
.details-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.order-summary-details { margin-top: 1.5rem; padding-top: 1rem; max-width: 300px; margin-left: auto; }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 2rem; padding-top: 2rem; }
.page-info { color: var(--text-secondary); }

/* Responsive */
@media (max-width: 1024px) {
    .catalog-content, .cart-content, .checkout-content { grid-template-columns: 1fr; }
    .filter-sidebar, .cart-summary, .checkout-summary { position: static; }
}
@media (max-width: 768px) {
    .app-header { padding: 0 1rem; }
    .header-nav { display: none; }
    .app-main { padding: 1rem; }
    .cart-header { display: none; }
    .cart-item { grid-template-columns: 1fr; gap: 0.5rem; }
}

.product-image img {
    max-width: 100%;
    height: auto;
}

.product-image img[src=""],
.product-image img:not([src]) {
    display: none;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary-color);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.cart-nav-link {
    display: flex;
    align-items: center;
    gap: 0;
}

.cart-badge {
    background: var(--accent-color);
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    margin-left: -24px;
}

.filter-sidebar .filter-level {
    margin-bottom: 0;
    display: flex;
    flex-direction: column;
}

.filter-sidebar .checkbox-label {
    white-space: nowrap;
}

.filter-sidebar > form {
    display: flex;
    flex-direction: column;
    gap: 0;
    width: 100%;
}

.filter-toggles {
    display: flex;
    gap: 1rem;
    padding-bottom: 0.75rem;
    margin-bottom: 0.75rem;
}

.filter-dropdowns {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.75rem;
    width: 100%;
}

.filter-dropdowns select {
    padding-right: 1.5rem;
    background-position: right 0.4rem center;
    width: 100%;
}

.filter-dropdowns .filter-level {
    flex: 0 0 calc((100% - 3.75rem) / 6); /* 6 per row, accounting for 5 gaps of 0.75rem */
    min-width: 0;
}

.filter-clear {
    margin-left: auto;
    display: flex;
    align-items: flex-end;
}

.filter-clear-btn {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.filter-clear .btn:hover {
    background: var(--accent-color);
    border-color: var(--accent-color);
}

button.dropdown-item {
    width: 100%;
    background: none;
    border: none;
    font: inherit;
    cursor: pointer;
    text-align: left;
}

.filter-search-bar {
    position: absolute;
    top: 0.75rem;
    right: 1rem;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.filter-search-bar .search-input {
    width: 220px;
}

.clear-search {
    font-size: 0.8rem;
    text-decoration: none;
    cursor: pointer;
    padding: 0.375rem 0.75rem;
    border-radius: 8px;
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
    white-space: nowrap;
}

.clear-search:hover {
    background: var(--accent-color);
    color: white;
    border-color: var(--accent-color);
}

.item-variant {
    margin: 0.15rem 0 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
}