/* ==========================================================================
   Caravan storefront
   Brand values come from the trader's theme (Caravan Master → Theme studio),
   validated server-side and injected on <html> as CSS variables / data-*:
     --brand, --brand-ink, --accent, --accent-ink, --radius, --font
     data-bs-theme, data-buttons, data-density, data-header, data-hero, data-grid, data-stock
   ========================================================================== */

:root,
[data-bs-theme="light"] {
    --sf-canvas: #f6f7f9;
    --sf-surface: #ffffff;
    --sf-surface-2: #f2f4f7;
    --sf-text: #141821;
    --sf-muted: #667085;
    --sf-border: #e6e8ee;
    --sf-shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 12px 32px -18px rgba(16, 24, 40, .22);
}

[data-bs-theme="dark"] {
    --sf-canvas: #0f1115;
    --sf-surface: #171a21;
    --sf-surface-2: #1d2129;
    --sf-text: #e8eaf0;
    --sf-muted: #9aa3b2;
    --sf-border: #2a2f3a;
    --sf-shadow: 0 1px 0 rgba(255, 255, 255, .03) inset, 0 16px 40px -24px rgba(0, 0, 0, .8);
}

:root {
    --brand: #2f5bd8;
    --brand-ink: #ffffff;
    --accent: #f59e0b;
    --accent-ink: #111418;
    --radius: 12px;
    --font: 'Onest', ui-sans-serif, system-ui, sans-serif;
    --gap: 1.25rem;
    --card-pad: 1rem;
}
[data-density="compact"] { --gap: .75rem; --card-pad: .7rem; }

/* Bootstrap mapping */
:root,
[data-bs-theme] {
    --bs-body-bg: var(--sf-canvas);
    --bs-body-color: var(--sf-text);
    --bs-emphasis-color: var(--sf-text);
    --bs-secondary-color: var(--sf-muted);
    --bs-secondary-bg: var(--sf-surface-2);
    --bs-tertiary-bg: var(--sf-surface-2);
    --bs-border-color: var(--sf-border);
    --bs-primary: var(--brand);
    --bs-link-color: var(--brand);
    --bs-link-hover-color: var(--brand);
    --bs-border-radius: var(--radius);
    --bs-border-radius-sm: calc(var(--radius) * .7);
    --bs-border-radius-lg: calc(var(--radius) * 1.3);
    --bs-body-font-family: var(--font);
}

body {
    font-family: var(--font);
    background: var(--sf-canvas);
    color: var(--sf-text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}
main { flex: 1; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3, h4, h5, h6 { color: var(--sf-text); letter-spacing: -0.015em; }
.text-muted { color: var(--sf-muted) !important; }
.text-dark { color: var(--sf-text) !important; }
.text-primary { color: var(--brand) !important; }
.bg-light, .bg-white { background-color: var(--sf-surface-2) !important; }
.card, .bg-body { background: var(--sf-surface); color: var(--sf-text); }
.card { border: 1px solid var(--sf-border) !important; border-radius: var(--radius) !important; box-shadow: var(--sf-shadow) !important; }
.card-header, .card-footer { background: transparent !important; border-color: var(--sf-border) !important; }
.rounded-4, .rounded-3 { border-radius: var(--radius) !important; }
.fw-extrabold { font-weight: 800; }

/* ---------- Announcement + header ---------- */
.sf-announcement {
    background: var(--accent);
    color: var(--accent-ink);
    text-align: center;
    font-size: .85rem;
    font-weight: 600;
    padding: .45rem 1rem;
}
.sf-header {
    position: sticky; top: 0; z-index: 1030;
    background: color-mix(in srgb, var(--sf-surface) 88%, transparent);
    backdrop-filter: blur(14px);
    border-bottom: 1px solid var(--sf-border);
}
.sf-header-inner {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 1rem;
    min-height: 68px;
}
.sf-brand {
    display: inline-flex; align-items: center; gap: .6rem;
    font-weight: 700; font-size: 1.2rem; color: var(--sf-text);
}
.sf-brand:hover { color: var(--sf-text); }
.sf-brand-mark {
    width: 36px; height: 36px; display: grid; place-items: center;
    border-radius: calc(var(--radius) * .8 + 2px);
    background: var(--brand); color: var(--brand-ink); font-size: 1rem;
}
.sf-search-wrap { min-width: 0; }
.sf-search { position: relative; max-width: 520px; width: 100%; margin: 0 auto; }
.sf-search .form-control { border-radius: 999px; padding-left: 2.6rem; background: var(--sf-surface-2); border-color: transparent; }
.sf-search .bi { position: absolute; left: 1rem; top: 50%; transform: translateY(-50%); color: var(--sf-muted); }
.sf-actions { display: flex; align-items: center; gap: .5rem; justify-self: end; }
.sf-icon-btn {
    position: relative; width: 42px; height: 42px; border-radius: 50%;
    display: grid; place-items: center; color: var(--sf-text); background: transparent; border: 0;
}
.sf-icon-btn:hover { background: var(--sf-surface-2); color: var(--sf-text); }
.sf-icon-btn .bi { font-size: 1.25rem; }
.cart-badge {
    position: absolute; top: 2px; right: 0;
    min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px;
    font-size: .68rem; line-height: 18px; text-align: center; font-weight: 700;
    background: var(--brand) !important; color: var(--brand-ink) !important;
}
.sf-avatar {
    width: 36px; height: 36px; border-radius: 50%;
    display: grid; place-items: center; font-weight: 700; font-size: .85rem;
    background: var(--brand); color: var(--brand-ink);
}

/* Centered header layout: brand in the middle */
[data-header="center"] .sf-header-inner { grid-template-columns: 1fr auto 1fr; }
[data-header="center"] .sf-brand { grid-column: 2; grid-row: 1; justify-self: center; }
[data-header="center"] .sf-search-wrap { grid-column: 1; grid-row: 1; }
[data-header="center"] .sf-search { max-width: 280px; margin: 0; }
[data-header="center"] .sf-actions { grid-column: 3; grid-row: 1; }

/* ---------- Buttons follow the theme ---------- */
.btn { border-radius: var(--radius); font-weight: 600; }
.btn-primary {
    --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand); --bs-btn-color: var(--brand-ink);
    --bs-btn-hover-bg: color-mix(in srgb, var(--brand) 88%, black); --bs-btn-hover-border-color: color-mix(in srgb, var(--brand) 88%, black); --bs-btn-hover-color: var(--brand-ink);
    --bs-btn-active-bg: color-mix(in srgb, var(--brand) 80%, black); --bs-btn-active-border-color: color-mix(in srgb, var(--brand) 80%, black); --bs-btn-active-color: var(--brand-ink);
    --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand); --bs-btn-disabled-color: var(--brand-ink);
}
[data-buttons="outline"] .btn-primary {
    --bs-btn-bg: transparent; --bs-btn-color: var(--brand);
    --bs-btn-hover-bg: var(--brand); --bs-btn-hover-color: var(--brand-ink);
    --bs-btn-disabled-bg: transparent; --bs-btn-disabled-color: var(--brand);
    border-width: 1.5px;
}
[data-buttons="pill"] .btn { border-radius: 999px; }
.btn-outline-secondary, .btn-light {
    --bs-btn-bg: var(--sf-surface); --bs-btn-color: var(--sf-text); --bs-btn-border-color: var(--sf-border);
    --bs-btn-hover-bg: var(--sf-surface-2); --bs-btn-hover-color: var(--sf-text); --bs-btn-hover-border-color: var(--sf-border);
}

/* ---------- Forms ---------- */
.form-control, .form-select {
    background-color: var(--sf-surface); color: var(--sf-text);
    border-color: var(--sf-border); border-radius: var(--radius); min-height: 44px;
}
.form-control:focus, .form-select:focus {
    background-color: var(--sf-surface); color: var(--sf-text);
    border-color: var(--brand); box-shadow: 0 0 0 4px color-mix(in srgb, var(--brand) 18%, transparent);
}
.form-control::placeholder { color: color-mix(in srgb, var(--sf-muted) 85%, transparent); }
.form-label { font-weight: 600; font-size: .85rem; }
.input-group > .btn { border-radius: var(--radius); }

/* ---------- Hero ---------- */
.sf-hero {
    position: relative; overflow: hidden;
    border-radius: calc(var(--radius) * 1.4 + 4px);
    padding: clamp(1.5rem, 4vw, 3.25rem);
    margin-bottom: 1.75rem;
    color: var(--brand-ink);
    background: linear-gradient(120deg, var(--brand), color-mix(in srgb, var(--brand) 55%, var(--accent)));
}
[data-hero="solid"] .sf-hero { background: var(--brand); }
[data-hero="minimal"] .sf-hero { background: var(--sf-surface); color: var(--sf-text); border: 1px solid var(--sf-border); }
.sf-hero::after {
    content: ""; position: absolute; right: -5rem; top: -6rem; width: 22rem; height: 22rem; border-radius: 50%;
    background: radial-gradient(circle, rgba(255,255,255,.22), transparent 65%); pointer-events: none;
}
[data-hero="minimal"] .sf-hero::after { background: radial-gradient(circle, color-mix(in srgb, var(--brand) 16%, transparent), transparent 65%); }
.sf-hero > * { position: relative; z-index: 1; }
.sf-hero h1 { color: inherit; font-weight: 800; font-size: clamp(1.8rem, 4vw, 2.9rem); line-height: 1.05; margin: .5rem 0 .75rem; max-width: 18ch; }
.sf-hero p { opacity: .85; max-width: 46ch; margin: 0; }
.sf-hero .eyebrow { font-size: .75rem; letter-spacing: .12em; text-transform: uppercase; font-weight: 700; opacity: .8; }
.sf-hero .btn-hero { background: var(--brand-ink); color: var(--brand); border: 0; padding: .7rem 1.4rem; }
[data-hero="minimal"] .sf-hero .btn-hero { background: var(--brand); color: var(--brand-ink); }

/* Category chips */
.sf-chips { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .25rem; margin-bottom: 1.5rem; scrollbar-width: none; }
.sf-chips::-webkit-scrollbar { display: none; }
.sf-chip {
    flex: 0 0 auto; padding: .5rem 1rem; border-radius: 999px; font-size: .88rem; font-weight: 600;
    background: var(--sf-surface); border: 1px solid var(--sf-border); color: var(--sf-text);
}
.sf-chip:hover { border-color: var(--brand); color: var(--brand); }
.sf-chip.active { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }

/* ---------- Product grid ---------- */
.product-grid { display: grid; gap: var(--gap); grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 768px) { .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (min-width: 992px) {
    [data-grid="2"] .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    [data-grid="3"] .product-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    [data-grid="4"] .product-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}
.product-card {
    display: flex; flex-direction: column;
    background: var(--sf-surface); border: 1px solid var(--sf-border);
    border-radius: var(--radius); overflow: hidden; box-shadow: var(--sf-shadow);
    transition: transform .2s ease;
}
.product-card:hover { transform: translateY(-3px); }
.image-container { position: relative; padding-top: 100%; background: var(--sf-surface-2); overflow: hidden; }
.product-image { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.placeholder-image {
    position: absolute; inset: 0; display: grid; place-items: center; font-size: 2.5rem;
    color: color-mix(in srgb, var(--brand) 55%, var(--sf-muted));
    background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 12%, var(--sf-surface-2)), color-mix(in srgb, var(--accent) 16%, var(--sf-surface-2)));
}
.sf-stock-badge {
    position: absolute; left: .6rem; top: .6rem; z-index: 1;
    font-size: .7rem; font-weight: 700; padding: .25rem .55rem; border-radius: 999px;
}
.sf-stock-badge.out { background: #111418; color: #fff; }
.sf-stock-badge.low { background: var(--accent); color: var(--accent-ink); }
[data-stock="off"] .sf-stock-badge { display: none; }
.card-content { padding: var(--card-pad); display: flex; flex-direction: column; gap: .35rem; flex: 1; }
.category-tag { font-size: .72rem; font-weight: 600; color: var(--sf-muted); text-transform: uppercase; letter-spacing: .06em; }
.product-title { font-size: .98rem; font-weight: 600; margin: 0; line-height: 1.35; }
.product-title a { color: var(--sf-text); }
.price-stock { display: flex; align-items: baseline; justify-content: space-between; gap: .5rem; margin-top: auto; padding-top: .35rem; }
.product-price { font-weight: 800; font-size: 1.1rem; color: var(--sf-text); }
.stock-status { font-size: .75rem; color: var(--sf-muted); white-space: nowrap; }
.btn-add-to-cart { width: 100%; margin-top: .5rem; }

/* ---------- Tables, badges, alerts, breadcrumbs ---------- */
.table { --bs-table-bg: transparent; --bs-table-color: var(--sf-text); --bs-table-border-color: var(--sf-border); }
.table thead th, .table tfoot th, .table tfoot td { background: var(--sf-surface-2) !important; color: var(--sf-muted); }
.badge { border-radius: 999px; font-weight: 600; }
.bg-primary { background-color: var(--brand) !important; color: var(--brand-ink) !important; }
.bg-primary-subtle { background: color-mix(in srgb, var(--brand) 14%, transparent) !important; }
.border-primary-subtle { border-color: color-mix(in srgb, var(--brand) 35%, transparent) !important; }
.alert { border-radius: var(--radius); border: 1px solid var(--sf-border); }
.breadcrumb { --bs-breadcrumb-divider-color: var(--sf-muted); --bs-breadcrumb-item-active-color: var(--sf-muted); }
.pagination {
    --bs-pagination-bg: var(--sf-surface); --bs-pagination-color: var(--sf-text); --bs-pagination-border-color: var(--sf-border);
    --bs-pagination-hover-bg: var(--sf-surface-2); --bs-pagination-hover-color: var(--sf-text);
    --bs-pagination-active-bg: var(--brand); --bs-pagination-active-border-color: var(--brand); --bs-pagination-active-color: var(--brand-ink);
    --bs-pagination-disabled-bg: var(--sf-surface); --bs-pagination-disabled-color: var(--sf-muted);
    gap: .35rem;
}
.pagination .page-link { border-radius: var(--radius) !important; }
.dropdown-menu {
    --bs-dropdown-bg: var(--sf-surface); --bs-dropdown-color: var(--sf-text); --bs-dropdown-link-color: var(--sf-text);
    --bs-dropdown-link-hover-bg: var(--sf-surface-2); --bs-dropdown-border-color: var(--sf-border);
    border-radius: var(--radius); box-shadow: var(--sf-shadow);
}
.toast { background: var(--sf-surface); color: var(--sf-text); border-radius: var(--radius); }
.toast-header { background: transparent; color: var(--sf-text); }

/* ---------- Footer ---------- */
.sf-footer { border-top: 1px solid var(--sf-border); background: var(--sf-surface); padding: 2.5rem 0; margin-top: 3rem; }
.sf-footer small { color: var(--sf-muted); }

/* ---------- Auth ---------- */
.sf-auth-card, .auth-card { max-width: 440px; margin: 0 auto; background: var(--sf-surface); border: 1px solid var(--sf-border); border-radius: calc(var(--radius) * 1.3 + 4px); box-shadow: var(--sf-shadow); padding: 2rem; }

@media (max-width: 767.98px) {
    .sf-header-inner { grid-template-columns: auto 1fr; row-gap: .25rem; }
    .sf-search-wrap { grid-column: 1 / -1; grid-row: 2; padding-bottom: .75rem; }
    .sf-search { max-width: none; }
    [data-header="center"] .sf-header-inner { grid-template-columns: 1fr auto 1fr; }
    [data-header="center"] .sf-search-wrap { grid-column: 1 / -1; grid-row: 2; }
    [data-header="center"] .sf-search { max-width: none; }
    .sf-hide-sm { display: none !important; }
    .stock-status { display: none; }
}

/* ---------- Orders: status, progress, timeline ---------- */
.sf-status { display: inline-flex; align-items: center; gap: .35rem; padding: .25rem .65rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.sf-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.sf-status-warning { background: color-mix(in srgb, #f59e0b 16%, transparent); color: #b7791f; }
.sf-status-info { background: color-mix(in srgb, #0ea5e9 14%, transparent); color: #0284c7; }
.sf-status-primary { background: color-mix(in srgb, var(--brand) 14%, transparent); color: var(--brand); }
.sf-status-success { background: color-mix(in srgb, #10b981 15%, transparent); color: #059669; }
.sf-status-danger { background: color-mix(in srgb, #ef4444 14%, transparent); color: #dc2626; }
.sf-status-secondary { background: var(--sf-surface-2); color: var(--sf-muted); }
[data-bs-theme="dark"] .sf-status-warning { color: #fbbf24; }
[data-bs-theme="dark"] .sf-status-info { color: #38bdf8; }
[data-bs-theme="dark"] .sf-status-success { color: #34d399; }
[data-bs-theme="dark"] .sf-status-danger { color: #f87171; }

.sf-progress { height: 6px; border-radius: 6px; background: var(--sf-surface-2); overflow: hidden; }
.sf-progress > i { display: block; height: 100%; border-radius: 6px; background: var(--brand); }
.sf-progress.cancelled > i { background: #ef4444; opacity: .5; }

.sf-timeline { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(6, 1fr); position: relative; }
.sf-timeline::before { content: ""; position: absolute; left: 8%; right: 8%; top: 18px; height: 2px; background: var(--sf-border); }
.sf-timeline li { position: relative; display: flex; flex-direction: column; align-items: center; gap: .45rem; text-align: center; }
.sf-timeline-dot { position: relative; z-index: 1; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: var(--sf-surface); border: 2px solid var(--sf-border); color: var(--sf-muted); }
.sf-timeline-label { font-size: .75rem; color: var(--sf-muted); font-weight: 600; }
.sf-timeline li.done .sf-timeline-dot { background: color-mix(in srgb, var(--brand) 14%, var(--sf-surface)); border-color: var(--brand); color: var(--brand); }
.sf-timeline li.current .sf-timeline-dot { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); box-shadow: 0 0 0 6px color-mix(in srgb, var(--brand) 18%, transparent); }
.sf-timeline li.current .sf-timeline-label { color: var(--sf-text); }
.sf-cancelled { padding: 1rem; border-radius: var(--radius); background: color-mix(in srgb, #ef4444 10%, var(--sf-surface)); color: var(--sf-text); font-weight: 600; }
@media (max-width: 575.98px) {
    .sf-timeline { grid-template-columns: 1fr; gap: .75rem; }
    .sf-timeline::before { left: 18px; right: auto; top: 0; bottom: 0; width: 2px; height: auto; }
    .sf-timeline li { flex-direction: row; text-align: left; }
}

/* Panels used on checkout / order pages */
.sf-panel { background: var(--sf-surface); border: 1px solid var(--sf-border); border-radius: calc(var(--radius) + 2px); box-shadow: var(--sf-shadow); padding: 1.5rem; }
.sf-panel-title { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; display: flex; align-items: center; gap: .5rem; }
.sf-panel-title .bi { color: var(--brand); }
.sf-steps { display: flex; align-items: center; gap: .5rem; font-size: .85rem; font-weight: 600; color: var(--sf-muted); margin-bottom: 1.25rem; flex-wrap: wrap; }
.sf-steps .on { color: var(--brand); }
.sf-steps .bi-chevron-right { font-size: .7rem; }
.sf-line-item { display: flex; align-items: center; gap: .85rem; padding: .7rem 0; border-bottom: 1px solid var(--sf-border); }
.sf-line-item:last-child { border-bottom: 0; }
.sf-thumb { width: 48px; height: 48px; flex-shrink: 0; border-radius: calc(var(--radius) * .7); display: grid; place-items: center; color: color-mix(in srgb, var(--brand) 60%, var(--sf-muted)); background: linear-gradient(135deg, color-mix(in srgb, var(--brand) 12%, var(--sf-surface-2)), color-mix(in srgb, var(--accent) 16%, var(--sf-surface-2))); }
.sf-thumb { position: relative; overflow: hidden; }
.sf-thumb-lg { width: 70px; height: 70px; }
.sf-thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.sf-summary-row { display: flex; justify-content: space-between; padding: .35rem 0; color: var(--sf-muted); }
.sf-summary-total { display: flex; justify-content: space-between; align-items: baseline; padding-top: .85rem; margin-top: .5rem; border-top: 1px solid var(--sf-border); font-weight: 800; font-size: 1.15rem; }
.sf-note { display: flex; gap: .65rem; align-items: flex-start; padding: .85rem 1rem; border-radius: var(--radius); background: var(--sf-surface-2); font-size: .88rem; color: var(--sf-muted); }
.sf-note .bi { color: var(--brand); font-size: 1.1rem; }
.sf-order-card { display: flex; flex-direction: column; gap: .75rem; }
.min-w-0 { min-width: 0; }
/* Compatible branding and list layout from the CMS theme editor. */
.sf-brand-logo { width: 40px; height: 40px; object-fit: contain; border-radius: var(--radius); }
html[data-shadow="none"] .product-card { box-shadow: none; }
html[data-shadow="strong"] .product-card { box-shadow: 0 12px 32px rgba(0,0,0,.18); }
.product-grid.product-list { grid-template-columns: minmax(0,1fr); }
.product-list .product-card { display: grid; grid-template-columns: 160px minmax(0,1fr); }
.product-list .image-container { height: 160px; }
@media (max-width: 480px) { .product-list .product-card { grid-template-columns: 100px minmax(0,1fr); } .product-list .image-container { height: 120px; } }
