:root {
    color-scheme: light dark;
    --bg: #faf8f5;
    --text: #2b2620;
    --muted: #7a7268;
    --accent: #8a5a2b;
    --accent-dark: #6d4620;
    --border: #e7e0d6;
    --card: #ffffff;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #17130f;
        --text: #ece5db;
        --muted: #a89e90;
        --accent: #cf8f52;
        --accent-dark: #e0a468;
        --border: #37302a;
        --card: #221c17;
    }
}

* {
    box-sizing: border-box;
}

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

a {
    color: var(--accent);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

.container {
    max-width: 1040px;
    margin: 0 auto;
    padding: 0 1rem;
}

.site-header {
    background: var(--card);
    border-bottom: 1px solid var(--border);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 1rem;
    padding-bottom: 1rem;
}

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

.header-search {
    flex: 1 1 auto;
    max-width: 360px;
    margin: 0 1.25rem;
}

.header-search input[type="search"] {
    width: 100%;
}

.main-nav {
    flex: 0 0 auto;
    white-space: nowrap;
}

.main-nav a {
    margin-left: 1.25rem;
    color: var(--text);
}

@media (max-width: 640px) {
    .header-inner {
        flex-wrap: wrap;
    }

    .header-search {
        order: 3;
        flex-basis: 100%;
        max-width: none;
        margin: 0.75rem 0 0;
    }

    main.container {
        padding-top: 1.25rem;
    }
}

main.container {
    padding-top: 2rem;
    padding-bottom: 3rem;
    min-height: 60vh;
}

/* The page already has breathing room from the header via padding-top; the
   first heading/paragraph's own top margin would double that gap. */
main.container > :first-child {
    margin-top: 0;
}

.site-footer {
    border-top: 1px solid var(--border);
    color: var(--muted);
    padding: 1.5rem 0;
    font-size: 0.9rem;
}

.flash {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}

.flash-success {
    background: #e6f4ea;
    color: #1e5631;
}

.flash-error {
    background: #fbeaea;
    color: #8a1f1f;
}

.category-filter {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.category-filter a {
    padding: 0.35rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    background: var(--card);
}

.category-filter a.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1.25rem;
}

.product-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.1rem;
    display: flex;
    flex-direction: column;
}

.product-card h3 {
    margin: 0 0 0.35rem;
    font-size: 1.05rem;
}

.product-card .price {
    font-weight: 700;
    color: var(--accent-dark);
    margin: 0.5rem 0;
}

.product-card .muted {
    color: var(--muted);
    font-size: 0.85rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.55rem 1rem;
    border-radius: 6px;
    /* transparent 1px border so a plain .btn and a bordered .btn-secondary end
       up exactly the same height regardless of the element (button vs a). */
    border: 1px solid transparent;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1.2;
    text-decoration: none;
    vertical-align: middle;
}

.btn:hover {
    background: var(--accent-dark);
    text-decoration: none;
}

.btn[disabled] {
    background: var(--muted);
    cursor: not-allowed;
}

.btn-secondary {
    background: transparent;
    color: var(--accent);
    border: 1px solid var(--accent);
}

.product-detail {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    max-width: 640px;
}

.product-detail .price {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--accent-dark);
}

table.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card);
}

table.table th,
table.table td {
    padding: 0.65rem 0.8rem;
    border-bottom: 1px solid var(--border);
    text-align: left;
}

.text-muted {
    color: var(--muted);
}

.out-of-stock {
    color: #8a1f1f;
    font-size: 0.85rem;
}

.qty-input {
    width: 64px;
    padding: 0.35rem;
}

.inline-form,
.add-to-cart {
    display: inline-flex;
    gap: 0.4rem;
    align-items: center;
    margin: 0;
}

.checkout-layout {
    display: grid;
    grid-template-columns: 1.4fr 1fr;
    gap: 2rem;
    align-items: start;
}

.checkout-form input[type="text"],
.checkout-form input[type="email"],
.checkout-form textarea {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font: inherit;
    margin-bottom: 0.9rem;
}

.checkout-form label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.payment-box {
    max-width: 560px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.75rem;
}

.payment-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-top: 1rem;
}

@media (max-width: 720px) {
    .checkout-layout {
        grid-template-columns: 1fr;
    }
}

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.back-arrow {
    font-size: 1.1em;
    line-height: 1;
}

.cart-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 1.5rem;
}

/* On phones the 5-column cart table has no room, so each row becomes a card
   with the column name as an inline label (via the td's data-label). */
@media (max-width: 640px) {
    .cart-table thead {
        display: none;
    }

    .cart-table,
    .cart-table tbody,
    .cart-table tfoot,
    .cart-table tr,
    .cart-table td,
    .cart-table th {
        display: block;
    }

    .cart-table tbody tr {
        border: 1px solid var(--border);
        border-radius: 10px;
        padding: 0.4rem 0.9rem;
        margin-bottom: 1rem;
    }

    .cart-table td {
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 1rem;
        border-bottom: none;
        padding: 0.4rem 0;
    }

    .cart-table td::before {
        content: attr(data-label);
        font-weight: 600;
        color: var(--muted);
    }

    .cart-table tfoot tr {
        display: flex;
        justify-content: space-between;
        border: none;
        padding: 0.6rem 0.9rem;
        font-weight: 700;
    }

    .cart-table tfoot th {
        padding: 0;
        border-bottom: none;
    }

    .cart-table tfoot th:empty {
        display: none;
    }

    .cart-actions {
        flex-direction: column;
    }

    .cart-actions .btn {
        width: 100%;
    }
}

/* --- Admin --- */
.admin-layout {
    display: grid;
    grid-template-columns: 200px 1fr;
    gap: 2rem;
    align-items: start;
}

.admin-sidebar nav {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.admin-sidebar a {
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    color: var(--text);
}

.admin-sidebar a:hover {
    background: var(--card);
    text-decoration: none;
}

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

.stat-cards {
    display: flex;
    gap: 1rem;
    margin: 1rem 0 2rem;
}

.stat-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem 1.75rem;
    display: flex;
    flex-direction: column;
}

.stat-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent-dark);
}

.stat-label {
    color: var(--muted);
}

.row-actions {
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.link-button {
    background: none;
    border: none;
    color: #8a1f1f;
    cursor: pointer;
    padding: 0;
    font: inherit;
}

.order-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin: 1.5rem 0;
}

.badge {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
}

.badge-pending { background: #fff3cd; color: #7a5b00; }
.badge-paid { background: #e6f4ea; color: #1e5631; }
.badge-failed { background: #fbeaea; color: #8a1f1f; }
.badge-cancelled { background: #eee; color: #555; }

@media (max-width: 720px) {
    .admin-layout,
    .order-detail-grid {
        grid-template-columns: 1fr;
    }
}

/* --- Product images --- */
.product-thumb {
    display: block;
    aspect-ratio: 3 / 2;
    border-radius: 8px;
    overflow: hidden;
    background: #f1ece4;
    margin-bottom: 0.6rem;
}

.product-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.2s ease;
}

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

.product-thumb-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    font-size: 2.5rem;
}

.product-detail-image {
    width: 100%;
    max-width: 640px;
    aspect-ratio: 16 / 9;
    object-fit: cover;
    border-radius: 10px;
}

.admin-thumb {
    width: 56px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
    display: block;
}

/* Form controls follow the theme instead of the browser default, so the
   search box (and every other input) stays readable in dark and light mode. */
input,
textarea,
select {
    font: inherit;
    color: var(--text);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.5rem 0.65rem;
}

input:focus,
textarea:focus,
select:focus {
    outline: 2px solid var(--accent);
    outline-offset: 1px;
}

input::placeholder,
textarea::placeholder {
    color: var(--muted);
}

