/* ============ Reset & base ============ */
*, *::before, *::after { box-sizing: border-box; }

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #0f172a;
    --muted: #64748b;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    padding: 0;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { line-height: 1.2; margin-top: 0; }

.container { max-width: 1200px; margin: 0 0; padding: 0 1.5rem; }

.muted { color: var(--muted); }
.small { font-size: 0.875rem; }
.text-danger { color: var(--danger); font-size: 0.875rem; }

/* ============ Header / nav ============ */
.site-header {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.nav {
    display: flex;
    align-items: center;
    gap: 2rem;
    padding-top: 1rem;
    padding-bottom: 1rem;
}

.brand {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
}

.main-nav { display: flex; gap: 1.5rem; flex: 1; }
.main-nav a { color: var(--text); }

.nav-actions {
    display: flex;
    gap: 1.25rem;
    align-items: center;
}
.nav-actions a, .nav-actions .link-button { color: var(--text); }

.cart-link {
    position: relative;
    font-weight: 500;
}

.badge {
    background: var(--primary);
    color: white;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 0.75rem;
    margin-left: 4px;
}

.link-button {
    background: none;
    border: none;
    color: var(--text);
    cursor: pointer;
    padding: 0;
    font: inherit;
}
.link-button:hover { text-decoration: underline; }

.inline-form { display: inline; margin: 0; }

/* ============ Layout ============ */
.main-content { padding: 2rem 1.5rem; min-height: calc(100vh - 200px); }

.site-footer {
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 1.5rem 0;
    text-align: center;
    color: var(--muted);
}

/* ============ Buttons ============ */
.btn {
    display: inline-block;
    padding: 0.6rem 1.25rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-weight: 500;
    cursor: pointer;
    text-align: center;
    transition: background 0.15s;
    font-size: 1rem;
}

.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-hover); text-decoration: none; }

.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); text-decoration: none; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; text-decoration: none; }

.btn-disabled { background: #cbd5e1; color: white; cursor: not-allowed; }

.btn-small { padding: 0.35rem 0.75rem; font-size: 0.875rem; }
.btn-large { padding: 0.85rem 1.5rem; font-size: 1.1rem; }
.btn-block { display: block; width: 100%; }

.btn-link-danger {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font: inherit;
    padding: 0;
}
.btn-link-danger:hover { text-decoration: underline; }

/* ============ Alerts ============ */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
}
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* ============ Hero ============ */
.hero {
    background: linear-gradient(135deg, #1e3a8a, #2563eb);
    color: white;
    padding: 4rem 2rem;
    border-radius: 12px;
    margin-bottom: 3rem;
    text-align: center;
}
.hero h1 { font-size: 2.5rem; margin-bottom: 1rem; }
.hero p { font-size: 1.2rem; margin-bottom: 1.5rem; opacity: 0.95; }
.hero .btn-primary { background: white; color: var(--primary); }
.hero .btn-primary:hover { background: #f1f5f9; }

/* ============ Categories ============ */
.category-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
    margin-bottom: 3rem;
}

.category-card {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    color: var(--text);
    transition: box-shadow 0.15s, transform 0.15s;
}
.category-card:hover {
    box-shadow: var(--shadow);
    transform: translateY(-2px);
    text-decoration: none;
}
.category-card h3 { margin-bottom: 0.5rem; }
.category-card p { color: var(--muted); margin: 0; }

/* ============ Products ============ */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1.5rem;
}

.product-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: box-shadow 0.15s;
    display: flex;
    flex-direction: column;
}
.product-card:hover { box-shadow: 0 4px 12px rgba(0,0,0,0.08); }

.product-card-image {
    height: 220px;
    background: var(--bg);
    display: block;
    overflow: hidden;
}
.product-card-image img {
    width: 100%; height: 100%; object-fit: cover;
}
.placeholder {
    display: flex; align-items: center; justify-content: center;
    height: 100%;
    color: var(--muted);
    background: linear-gradient(135deg, #f1f5f9, #e2e8f0);
}
.placeholder.large { height: 400px; font-size: 1.25rem; }

.product-card-body {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    flex: 1;
}
.product-card-body h3 { font-size: 1rem; margin: 0; }
.product-card-body h3 a { color: var(--text); }
.product-card-body .price { font-size: 1.25rem; font-weight: 600; margin: 0.25rem 0; }
.product-card-body form { margin-top: auto; }

/* Products page */
.products-page {
    display: grid;
    grid-template-columns: 240px 1fr;
    gap: 2rem;
}

.sidebar h3 { margin-bottom: 1rem; }
.category-list { list-style: none; padding: 0; margin: 0; }
.category-list li { margin-bottom: 0.5rem; }
.category-list a {
    display: block;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    color: var(--text);
}
.category-list a:hover { background: var(--surface); text-decoration: none; }
.category-list a.active { background: var(--primary); color: white; }

.search-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}
.search-bar input {
    flex: 1;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
}

/* Product detail */
.product-detail {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 3rem;
    background: var(--surface);
    padding: 2rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.product-detail-image img {
    width: 100%; border-radius: var(--radius);
}
.product-detail-info h1 { font-size: 2rem; margin-bottom: 0.5rem; }
.price-large { font-size: 2rem; font-weight: 700; color: var(--primary); margin: 1rem 0; }
.description { margin: 1.5rem 0; }
.stock-info.in-stock { color: var(--success); }
.stock-info.out-of-stock { color: var(--danger); }
.add-to-cart-form {
    display: flex;
    gap: 1rem;
    align-items: end;
    margin: 1.5rem 0;
}
.add-to-cart-form input[type="number"] {
    width: 80px;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}
.back-link a { color: var(--muted); }

/* ============ Cart ============ */
.cart-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 2rem;
}

.cart-table {
    width: 100%;
    background: var(--surface);
    border-radius: var(--radius);
    border-collapse: collapse;
    border: 1px solid var(--border);
}
.cart-table th, .cart-table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.cart-table th { background: var(--bg); font-weight: 600; }
.cart-table tr:last-child td { border-bottom: none; }

.cart-product-cell {
    display: flex;
    align-items: center;
    gap: 1rem;
}
.cart-thumb {
    width: 60px; height: 60px;
    object-fit: cover;
    border-radius: var(--radius);
}

.qty-form {
    display: flex; gap: 0.5rem; align-items: center; margin: 0;
}
.qty-form input {
    width: 70px;
    padding: 0.4rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.cart-summary, .order-summary {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    height: fit-content;
}
.cart-summary h3, .order-summary h3 { margin-bottom: 1rem; }

.summary-row, .summary-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
}
.summary-row.total {
    font-size: 1.25rem;
    font-weight: 700;
    margin-top: 0.5rem;
}

.empty-state {
    text-align: center;
    padding: 3rem;
    background: var(--surface);
    border-radius: var(--radius);
}

/* ============ Checkout ============ */
.checkout-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 2rem;
}
.checkout-form, .auth-form, .admin-form {
    background: var(--surface);
    padding: 2rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.checkout-form h3 { margin-top: 1.5rem; margin-bottom: 1rem; }
.checkout-form h3:first-child { margin-top: 0; }

.guest-banner {
    background: #fef3c7;
    border: 1px solid #fcd34d;
    color: #78350f;
    padding: 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
}
.guest-banner p { margin: 0; }

.guest-followup {
    background: var(--bg);
    padding: 1rem;
    border-radius: var(--radius);
    margin: 1.5rem 0;
}

/* ============ Forms ============ */
.form-group { margin-bottom: 1rem; }
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}
.form-group label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 500;
    font-size: 0.95rem;
}
.form-control {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    font-family: inherit;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-check { display: flex; align-items: center; gap: 0.5rem; }
.form-check label { margin: 0; }

.form-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1.5rem;
}

/* ============ Auth ============ */
.auth-page {
    max-width: 480px;
    margin: 2rem auto;
}
.auth-page h1 { text-align: center; margin-bottom: 1.5rem; }
.auth-page > p { text-align: center; margin-top: 1.5rem; }

/* ============ Success / cancel pages ============ */
.success-page, .cancel-page, .error-page {
    max-width: 700px;
    margin: 2rem auto;
    text-align: center;
}
.success-icon {
    width: 80px;
    height: 80px;
    background: var(--success);
    color: white;
    font-size: 3rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1.5rem;
}
.lead { font-size: 1.2rem; color: var(--muted); margin-bottom: 2rem; }

.order-card {
    background: var(--surface);
    padding: 2rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    text-align: left;
    margin-bottom: 2rem;
}
.order-card-header {
    display: flex;
    justify-content: space-between;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
}
.order-items { list-style: none; padding: 0; }
.order-items li {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid var(--border);
}

.actions {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

/* ============ Orders / status ============ */
.orders-table, .admin-table {
    width: 100%;
    background: var(--surface);
    border-collapse: collapse;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
}
.orders-table th, .orders-table td,
.admin-table th, .admin-table td {
    padding: 0.85rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
.orders-table th, .admin-table th { background: var(--bg); font-weight: 600; }
.admin-table .actions { display: flex; gap: 0.5rem; }

.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 500;
}
.status-pending { background: #fef3c7; color: #78350f; }
.status-paid { background: #dcfce7; color: #166534; }
.status-processing { background: #dbeafe; color: #1e3a8a; }
.status-shipped { background: #e0e7ff; color: #3730a3; }
.status-delivered { background: #d1fae5; color: #064e3b; }
.status-cancelled, .status-refunded { background: #fee2e2; color: #991b1b; }

/* ============ Admin ============ */
.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}
.admin-card {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    color: var(--text);
}
.admin-card:hover {
    text-decoration: none;
    box-shadow: var(--shadow);
}

.admin-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.order-detail-layout {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 2rem;
}
.order-detail-main, .order-detail-sidebar {
    background: var(--surface);
    padding: 1.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
}
.order-detail-sidebar h3 { margin-top: 1.5rem; }
.order-detail-sidebar h3:first-child { margin-top: 0; }
.code {
    font-family: monospace;
    font-size: 0.85rem;
    background: var(--bg);
    padding: 0.5rem;
    border-radius: var(--radius);
    word-break: break-all;
}

/* ============ Responsive ============ */
@media (max-width: 900px) {
    .nav { flex-wrap: wrap; gap: 1rem; }
    .main-nav, .nav-actions { gap: 1rem; }
    .products-page { grid-template-columns: 1fr; }
    .product-detail,
    .cart-layout,
    .checkout-layout,
    .order-detail-layout { grid-template-columns: 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .hero h1 { font-size: 1.8rem; }
}


.thumbnail-strip {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}
.thumbnail {
    width: 70px; height: 70px;
    object-fit: cover;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
}
.thumbnail:hover { border-color: var(--primary); }