/* ── Design Tokens ──────────────────────────────────────────────────── */
:root {
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-secondary: #64748b;
    --color-secondary-dark: #475569;
    --color-accent: #8b5cf6;
    --color-success: #16a34a;
    --color-success-bg: #dcfce7;
    --color-danger: #dc2626;
    --color-danger-bg: #fee2e2;
    --color-warning: #d97706;
    --color-warning-bg: #fef3c7;
    --color-info: #0891b2;
    --color-info-bg: #cffafe;

    --color-bg: #f8fafc;
    --color-surface: #ffffff;
    --color-border: #e2e8f0;
    --color-text: #1e293b;
    --color-text-muted: #64748b;
    --color-text-light: #94a3b8;

    --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;

    --text-xs: 0.75rem;
    --text-sm: 0.875rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.25rem;
    --text-2xl: 1.5rem;
    --text-3xl: 1.875rem;

    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;

    --radius-sm: 0.25rem;
    --radius: 0.375rem;
    --radius-lg: 0.5rem;
    --radius-xl: 0.75rem;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);

    --transition: 150ms ease;
}

/* ── Reset & Base ──────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
    font-family: var(--font-sans);
    color: var(--color-text);
    background: var(--color-bg);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

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

img { max-width: 100%; height: auto; display: block; }

h1, h2, h3, h4 { line-height: 1.3; margin-bottom: var(--space-4); color: var(--color-text); }
h1 { font-size: var(--text-3xl); }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }

p { margin-bottom: var(--space-4); }

/* ── Skip Link ─────────────────────────────────────────────────────── */
.skip-link {
    position: absolute;
    top: -100%;
    left: var(--space-4);
    background: var(--color-primary);
    color: white;
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius);
    z-index: 1000;
}
.skip-link:focus { top: var(--space-4); }

/* ── Container ─────────────────────────────────────────────────────── */
.container { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 var(--space-4); }

/* ── Navbar ────────────────────────────────────────────────────────── */
.navbar {
    background: var(--color-surface);
    border-bottom: 1px solid var(--color-border);
    padding: var(--space-3) 0;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.navbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-3);
}

.navbar-brand {
    font-size: var(--text-xl);
    font-weight: 700;
    color: var(--color-primary);
}
.navbar-brand:hover { text-decoration: none; }

.nav-toggle-checkbox { display: none; }

.nav-toggle-label {
    display: none;
    cursor: pointer;
    padding: var(--space-2);
}
.nav-toggle-label span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--color-text);
    margin: 5px 0;
    transition: var(--transition);
}

.navbar-menu {
    display: flex;
    align-items: center;
    gap: var(--space-4);
}

.nav-link {
    color: var(--color-text-muted);
    font-size: var(--text-sm);
    font-weight: 500;
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius);
    transition: color var(--transition), background var(--transition);
}
.nav-link:hover { color: var(--color-primary); background: var(--color-bg); text-decoration: none; }
.nav-link:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

a:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; border-radius: var(--radius-sm); }

.nav-user { display: flex; align-items: center; gap: var(--space-3); margin-left: var(--space-4); padding-left: var(--space-4); border-left: 1px solid var(--color-border); }

.nav-logout-form { display: inline; }

.btn-link {
    background: none;
    border: none;
    cursor: pointer;
    font: inherit;
    color: inherit;
    padding: 0;
}

@media (max-width: 768px) {
    .nav-toggle-label { display: block; }

    .navbar-menu {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: flex-start;
        padding-top: var(--space-3);
    }
    .nav-toggle-checkbox:checked ~ .navbar-menu { display: flex; }

    .nav-user { margin-left: 0; padding-left: 0; border-left: none; border-top: 1px solid var(--color-border); padding-top: var(--space-3); width: 100%; }
}

/* ── Main Content ──────────────────────────────────────────────────── */
main { flex: 1; padding: var(--space-8) 0; }

/* ── Footer ────────────────────────────────────────────────────────── */
.footer {
    background: var(--color-surface);
    border-top: 1px solid var(--color-border);
    padding: var(--space-6) 0;
    text-align: center;
    color: var(--color-text-muted);
    font-size: var(--text-sm);
}

/* ── Buttons ───────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-2) var(--space-5);
    font-size: var(--text-sm);
    font-weight: 500;
    line-height: 1.5;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
    font-family: inherit;
}
.btn:hover { text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--color-primary); outline-offset: 2px; }

.btn-primary { background: var(--color-primary); color: white; }
.btn-primary:hover { background: var(--color-primary-dark); color: white; }

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

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

.btn-success { background: var(--color-success); color: white; }
.btn-success:hover { background: #15803d; color: white; }

.btn-sm { padding: var(--space-1) var(--space-3); font-size: var(--text-xs); }
.btn-full { width: 100%; }

/* ── Badges ────────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 0.15em 0.6em;
    font-size: var(--text-xs);
    font-weight: 600;
    border-radius: 9999px;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}
.badge-primary { background: #dbeafe; color: #1e40af; }
.badge-secondary { background: #f1f5f9; color: #475569; }
.badge-success { background: var(--color-success-bg); color: #15803d; }
.badge-danger { background: var(--color-danger-bg); color: #b91c1c; }
.badge-warning { background: var(--color-warning-bg); color: #92400e; }
.badge-info { background: var(--color-info-bg); color: #0e7490; }

/* ── Alerts / Flash Messages ───────────────────────────────────────── */
.flash-messages { margin-bottom: var(--space-6); }

.alert {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius);
    margin-bottom: var(--space-3);
    font-size: var(--text-sm);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border: 1px solid transparent;
}
.alert-success { background: var(--color-success-bg); color: #15803d; border-color: #bbf7d0; }
.alert-error { background: var(--color-danger-bg); color: #b91c1c; border-color: #fecaca; }
.alert-info { background: var(--color-info-bg); color: #0e7490; border-color: #a5f3fc; }
.alert-warning { background: var(--color-warning-bg); color: #92400e; border-color: #fde68a; }

.alert-close {
    background: none;
    border: none;
    font-size: var(--text-lg);
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
    padding: 0 var(--space-2);
}
.alert-close:hover { opacity: 1; }

/* ── Forms ─────────────────────────────────────────────────────────── */
.form { max-width: 100%; }

.form-group { margin-bottom: var(--space-5); }

.form-label-inline {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    font-size: var(--text-sm);
    color: var(--color-text-muted);
}
.form-label-inline .form-input { display: inline-block; width: auto; }

.form-label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 500;
    margin-bottom: var(--space-1);
    color: var(--color-text);
}

.form-input {
    display: block;
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-base);
    font-family: inherit;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    background: var(--color-surface);
    color: var(--color-text);
    transition: border-color var(--transition), box-shadow var(--transition);
}
.form-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

select.form-input { cursor: pointer; }

.form-textarea { resize: vertical; min-height: 100px; }

.form-error {
    display: block;
    color: var(--color-danger);
    font-size: var(--text-xs);
    margin-top: var(--space-1);
}

.form-hint {
    display: block;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    margin-top: var(--space-1);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
}
@media (max-width: 640px) {
    .form-row { grid-template-columns: 1fr; }
}

.form-actions {
    display: flex;
    gap: var(--space-3);
    margin-top: var(--space-6);
}

.form-container { max-width: 640px; }

.inline-form { display: inline; }

.quantity-input-small { width: 80px; display: inline-block; }

/* ── Auth Container ────────────────────────────────────────────────── */
.auth-container {
    max-width: 420px;
    margin: var(--space-12) auto;
    background: var(--color-surface);
    padding: var(--space-8);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
}
.auth-container h1 { text-align: center; margin-bottom: var(--space-6); }
.auth-link { text-align: center; margin-top: var(--space-6); font-size: var(--text-sm); color: var(--color-text-muted); }

/* ── Tables ────────────────────────────────────────────────────────── */
.table-responsive { overflow-x: auto; margin-bottom: var(--space-6); }

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--text-sm);
}
.table th, .table td {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}
.table th {
    font-weight: 600;
    color: var(--color-text-muted);
    font-size: var(--text-xs);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: var(--color-bg);
}
.table tbody tr:hover { background: #f1f5f9; }

.table-compact th, .table-compact td { padding: var(--space-2) var(--space-3); }

.text-right { text-align: right; }
.text-muted { color: var(--color-text-muted); }
.text-danger { color: var(--color-danger); font-weight: 600; }
.text-success { color: var(--color-success); font-weight: 600; }

.row-disabled { opacity: 0.5; }

.actions-cell { white-space: nowrap; display: flex; gap: var(--space-2); }

/* ── Page Header ───────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}
.page-header h1 { margin-bottom: 0; }

/* ── Breadcrumb ────────────────────────────────────────────────────── */
.breadcrumb {
    font-size: var(--text-sm);
    color: var(--color-text-muted);
    margin-bottom: var(--space-4);
}

/* ── Metrics Grid ──────────────────────────────────────────────────── */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}

.metric-card {
    background: var(--color-surface);
    padding: var(--space-5);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}
.metric-label { font-size: var(--text-sm); color: var(--color-text-muted); font-weight: 500; }
.metric-value { font-size: var(--text-2xl); font-weight: 700; color: var(--color-text); }

/* ── Dashboard ─────────────────────────────────────────────────────── */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-6);
    margin-bottom: var(--space-6);
}
@media (max-width: 768px) {
    .dashboard-grid { grid-template-columns: 1fr; }
}

.dashboard-section {
    background: var(--color-surface);
    padding: var(--space-5);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: var(--space-6);
}
.dashboard-section h2 { font-size: var(--text-lg); margin-bottom: var(--space-4); }

.status-list { margin-bottom: var(--space-4); }

.status-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-2) 0;
    border-bottom: 1px solid var(--color-border);
}
.status-row:last-child { border-bottom: none; }

/* ── Product Grid ──────────────────────────────────────────────────── */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: var(--space-6);
    margin-bottom: var(--space-8);
}

.product-card {
    background: var(--color-surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
    transition: box-shadow var(--transition), transform var(--transition);
}
.product-card:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }

.product-card-image { aspect-ratio: 4/3; overflow: hidden; background: var(--color-bg); }
.product-card-image img { width: 100%; height: 100%; object-fit: cover; }

.product-card-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--color-text-light);
    font-size: var(--text-sm);
    background: var(--color-bg);
    aspect-ratio: 4/3;
}
.product-card-placeholder.large { aspect-ratio: auto; min-height: 300px; }

.product-card-body { padding: var(--space-4); }

.product-card-title { font-size: var(--text-base); margin-bottom: var(--space-1); }
.product-card-title a { color: var(--color-text); }
.product-card-title a:hover { color: var(--color-primary); }

.product-card-seller { font-size: var(--text-xs); color: var(--color-text-muted); margin-bottom: var(--space-2); }

.product-card-price { font-size: var(--text-lg); font-weight: 700; color: var(--color-text); margin-bottom: var(--space-3); }

/* ── Product Detail ────────────────────────────────────────────────── */
.product-detail {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-8);
    margin-bottom: var(--space-8);
}
@media (max-width: 768px) {
    .product-detail { grid-template-columns: 1fr; }
}

.product-detail-image { border-radius: var(--radius-lg); overflow: hidden; background: var(--color-bg); }
.product-detail-image img { width: 100%; }
.product-detail-info { min-width: 0; }

.product-detail-seller { color: var(--color-text-muted); font-size: var(--text-sm); }
.product-detail-price { font-size: var(--text-3xl); font-weight: 700; margin: var(--space-4) 0; }
.product-detail-desc { color: var(--color-text-muted); line-height: 1.7; margin-bottom: var(--space-6); }
.product-detail-stock { font-size: var(--text-sm); font-weight: 500; margin-bottom: var(--space-4); }
.stock-available { color: var(--color-success); }
.stock-unavailable { color: var(--color-danger); }

.product-detail-form { display: flex; align-items: flex-end; gap: var(--space-4); }
.quantity-input { display: flex; flex-direction: column; }
.quantity-input .form-input { width: 80px; }

/* ── Catalog Filters ───────────────────────────────────────────────── */
.catalog-filters { margin-bottom: var(--space-6); }

.filter-row {
    display: flex;
    gap: var(--space-3);
    flex-wrap: wrap;
    align-items: flex-end;
}
.filter-group { flex: 1; min-width: 140px; }
.filter-search { flex: 2; }

.filter-bar {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    align-items: center;
    margin-bottom: var(--space-6);
}

/* ── Checkout ──────────────────────────────────────────────────────── */
.checkout-layout {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: var(--space-8);
}
@media (max-width: 768px) {
    .checkout-layout { grid-template-columns: 1fr; }
}

.checkout-shipping { min-width: 0; }

.checkout-summary {
    background: var(--color-surface);
    padding: var(--space-5);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    align-self: start;
    position: sticky;
    top: 80px;
}

.order-summary-items { margin-bottom: var(--space-4); }

.summary-item {
    display: flex;
    justify-content: space-between;
    gap: var(--space-3);
    padding: var(--space-2) 0;
    font-size: var(--text-sm);
    border-bottom: 1px solid var(--color-border);
}
.summary-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.summary-item-price { white-space: nowrap; font-weight: 500; }
.summary-total {
    padding-top: var(--space-4);
    font-size: var(--text-lg);
    text-align: right;
}

/* ── Cart Actions ──────────────────────────────────────────────────── */
.cart-actions {
    display: flex;
    gap: var(--space-3);
    align-items: center;
    flex-wrap: wrap;
}

/* ── Confirmation ──────────────────────────────────────────────────── */
.confirmation-container { max-width: 700px; margin: 0 auto; text-align: center; }
.confirmation-container h1 { color: var(--color-success); }
.confirmation-id { font-size: var(--text-xl); font-weight: 600; color: var(--color-text-muted); }
.order-details-card {
    background: var(--color-surface);
    padding: var(--space-6);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin: var(--space-6) 0;
    text-align: left;
}
.confirmation-actions { display: flex; gap: var(--space-3); justify-content: center; }

/* ── Detail Grid ───────────────────────────────────────────────────── */
.detail-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: var(--space-6);
}
@media (max-width: 768px) {
    .detail-grid { grid-template-columns: 1fr; }
}

.detail-list { margin-bottom: var(--space-4); }
.detail-list dt { font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; color: var(--color-text-muted); margin-top: var(--space-3); }
.detail-list dd { margin: var(--space-1) 0 0 0; }

/* ── Status Update Form ────────────────────────────────────────────── */
.status-update-form {
    display: flex;
    gap: var(--space-3);
    align-items: flex-end;
    margin-top: var(--space-4);
}
.status-update-form .form-input { width: auto; flex: 1; }

/* ── Settings ──────────────────────────────────────────────────────── */
.settings-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr;
    gap: var(--space-8);
}
@media (max-width: 768px) {
    .settings-grid { grid-template-columns: 1fr; }
}
.settings-sidebar { min-width: 0; display: flex; flex-direction: column; gap: var(--space-6); }

.settings-section {
    background: var(--color-surface);
    padding: var(--space-6);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: var(--space-6);
}
.settings-section h2 { font-size: var(--text-lg); margin-bottom: var(--space-4); }

/* ── MFA Setup ─────────────────────────────────────────────────────── */
.mfa-setup { text-align: center; }
.mfa-qr { margin-bottom: var(--space-6); }
.qr-image { margin: var(--space-4) auto; max-width: 200px; }
.mfa-secret-details { margin-top: var(--space-3); }
.mfa-secret-code {
    display: block;
    margin-top: var(--space-2);
    padding: var(--space-3);
    background: var(--color-bg);
    border-radius: var(--radius);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    word-break: break-all;
}
.mfa-setup .form { text-align: left; max-width: 360px; margin: 0 auto; }

/* ── Pagination ────────────────────────────────────────────────────── */
.pagination {
    display: flex;
    justify-content: center;
    gap: var(--space-1);
    margin: var(--space-6) 0;
}

.pagination-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 var(--space-3);
    font-size: var(--text-sm);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    color: var(--color-text);
    background: var(--color-surface);
    transition: all var(--transition);
}
.pagination-link:hover { background: var(--color-bg); text-decoration: none; }
.pagination-link.active { background: var(--color-primary); color: white; border-color: var(--color-primary); }
.pagination-link.disabled { opacity: 0.4; pointer-events: none; }
.pagination-ellipsis { display: inline-flex; align-items: center; padding: 0 var(--space-2); color: var(--color-text-muted); }

/* ── Empty State ───────────────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: var(--space-12) var(--space-4);
    color: var(--color-text-muted);
}
.empty-state p { font-size: var(--text-lg); margin-bottom: var(--space-4); }

/* ── Order Shipping Info ───────────────────────────────────────────── */
.order-shipping-info {
    background: var(--color-surface);
    padding: var(--space-5);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-top: var(--space-6);
}
