/* Dealer sites: the glass look (brand.dealer_glass, both tenants).
 *
 * Loaded last in <head> by templates/dealer/_dg.html on every dealer-facing page: the dealer back
 * office (body.dg-dash), the dealer's customer storefront (body.dg-store) and the sign-in /
 * onboarding / prospect pages (body.dg-auth). Everything is scoped under body.dg, so a page
 * without the include is untouched.
 *
 * Each dealer keeps their own colours and their own light/dark choice (body.dg-light /
 * body.dg-dark, from dealers.theme_mode): no theme switch, no font change, nothing of the STL
 * shop's own look. Colours come from the tokens _dg.html writes on body.dg:
 *   --dg-a (primary), --dg-a-rgb, --dg-on-a (text on primary), --dg-ink (primary as readable
 *   text on this theme), --dg-b-rgb (secondary).
 *
 * Motion: blur-out / blur-in page changes (no blur on phones), the active menu item slides to the
 * new one, panels rise in one after another on a fresh visit, totals count up, a soft light
 * follows the mouse over panels (static/js/dealer_glass.js). All of it is off under
 * prefers-reduced-motion.
 */

/* ── Page changes (cross-document View Transitions; browsers without them swap instantly) ── */
@view-transition { navigation: auto; }

::view-transition-old(root) { animation: dg-vt-out .22s cubic-bezier(.65, 0, .35, 1) both; }
::view-transition-new(root) { animation: dg-vt-in .5s cubic-bezier(.22, 1, .36, 1) .1s both; }
@keyframes dg-vt-out { to { opacity: 0; filter: blur(10px); transform: scale(.985); } }
@keyframes dg-vt-in { from { opacity: 0; filter: blur(12px); transform: translateY(8px); } }

/* the back-office menu and the storefront WhatsApp button stay still while the page changes */
body.dg-dash .sidebar { view-transition-name: dg-side; }
body.dg .wa-float { view-transition-name: dg-wa; }
::view-transition-group(dg-side), ::view-transition-group(dg-wa) { animation-duration: .3s; }
::view-transition-old(dg-side), ::view-transition-old(dg-wa) { display: none; }
::view-transition-new(dg-side), ::view-transition-new(dg-wa) { animation: none; }

/* the active menu item slides from the old page's item to the new one */
body.dg-dash .sidebar .nav-link.active { view-transition-name: dg-pill; }
::view-transition-group(dg-pill) { animation-duration: .42s; animation-timing-function: cubic-bezier(.22, 1, .36, 1); }

@media (max-width: 819px) {
    /* phones: same timing, no full-screen blur (the costly part on budget phones) */
    @keyframes dg-vt-out { to { opacity: 0; transform: scale(.985); } }
    @keyframes dg-vt-in { from { opacity: 0; transform: translateY(8px); } }
}

@keyframes dg-rise { from { opacity: 0; transform: translateY(10px); } }

/* ── Shared ─────────────────────────────────────────────────────────────── */
body.dg { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

/* a soft glow of the dealer's colour behind the page */
body.dg::before {
    content: "";
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    background:
        radial-gradient(900px 520px at 8% -10%, rgba(var(--dg-a-rgb), .16), transparent 62%),
        radial-gradient(760px 460px at 100% 0%, rgba(var(--dg-a-rgb), .09), transparent 60%);
}
body.dg.dg-light::before {
    background:
        radial-gradient(900px 520px at 8% -10%, rgba(var(--dg-a-rgb), .12), transparent 62%),
        radial-gradient(760px 460px at 100% 0%, rgba(var(--dg-a-rgb), .07), transparent 60%);
}

/* glass panel tokens per theme */
body.dg {
    --dg-ease: cubic-bezier(.22, 1, .36, 1);
    --dg-card: linear-gradient(180deg, rgba(255, 255, 255, .06), rgba(255, 255, 255, .025));
    --dg-card-solid: rgba(24, 24, 27, .72);
    --dg-card-b: rgba(255, 255, 255, .09);
    --dg-rim: inset 0 1px 0 rgba(255, 255, 255, .07);
    --dg-shadow: 0 14px 34px -20px rgba(0, 0, 0, .85);
    --dg-field: rgba(255, 255, 255, .05);
    --dg-field-b: rgba(255, 255, 255, .12);
    --dg-hover: rgba(255, 255, 255, .06);
    --dg-light-a: .14;
}
body.dg.dg-light {
    --dg-card: linear-gradient(180deg, rgba(255, 255, 255, .92), rgba(255, 255, 255, .78));
    --dg-card-solid: rgba(255, 255, 255, .86);
    --dg-card-b: rgba(15, 15, 25, .08);
    --dg-rim: inset 0 1px 0 rgba(255, 255, 255, .9);
    --dg-shadow: 0 1px 2px rgba(15, 15, 25, .05), 0 14px 32px -18px rgba(15, 15, 25, .22);
    --dg-field: #fff;
    --dg-field-b: rgba(15, 15, 25, .14);
    --dg-hover: rgba(15, 15, 25, .05);
    --dg-light-a: .10;
}

/* cursor light: dealer_glass.js sets --mx/--my on the panel under the mouse and marks it dg-lit */
/* panels the light can sit in; sticky ones (filters, cart summary) are already a containing block */
body.dg .stat-card, body.dg .form-card, body.dg .confirm-card, body.dg .login-card,
body.dg-dash .page-body [style*="background:var(--surface)"] { position: relative; }
body.dg .dg-glow::after {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: inherit;
    pointer-events: none;
    z-index: 3;
    opacity: 0;
    transition: opacity .3s ease;
    background: radial-gradient(300px circle at var(--mx, -999px) var(--my, -999px), rgba(var(--dg-a-rgb), var(--dg-light-a)), transparent 65%);
}
body.dg .dg-glow.dg-lit::after { opacity: 1; }

body.dg select option { background: #fff; color: #111; }

/* the dealer's own "Sale" label next to a crossed-out price */
body.dg .dealer-sale-tag {
    border-radius: 999px;
    padding: 2px 9px;
    letter-spacing: .02em;
    box-shadow: 0 4px 12px -6px rgba(var(--dg-a-rgb), .9);
}

/* ── Back office (always the dark portal, tinted with the dealer's colour) ───────────────── */
body.dg-dash {
    /* pages colour links and figures with var(--accent): use the readable shade of the dealer's
       colour on this dark portal (identical when their colour already reads) */
    --accent: var(--dg-ink);
    --surface: rgba(22, 22, 25, .62);
    --surface2: rgba(255, 255, 255, .06);
    --border: rgba(255, 255, 255, .085);
}
body.dg-dash .sidebar {
    background: rgba(14, 14, 17, .6);
    -webkit-backdrop-filter: blur(18px) saturate(150%);
    backdrop-filter: blur(18px) saturate(150%);
    border-right: 1px solid rgba(255, 255, 255, .07);
}
body.dg-dash .sidebar-logo { border-bottom-color: rgba(255, 255, 255, .06); padding: 18px 16px; }
body.dg-dash .sidebar-logo img { border-radius: 10px; box-shadow: 0 0 0 1px rgba(255, 255, 255, .08), 0 6px 16px -8px rgba(var(--dg-a-rgb), .8); }
body.dg-dash .sidebar-logo .logo-text { color: var(--dg-ink); }
body.dg-dash .nav-section { border-bottom: 0; padding: 6px 0; }
body.dg-dash .nav-section-title { padding: 8px 22px 6px; opacity: .8; }
body.dg-dash .nav-link {
    margin: 1px 10px;
    padding: 8px 12px;
    border-radius: 999px;
    color: rgba(255, 255, 255, .78);
    transition: background .2s ease, color .2s ease, box-shadow .2s ease;
}
body.dg-dash .nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; }
body.dg-dash .nav-link.active {
    background: rgba(var(--dg-a-rgb), .16);
    color: var(--dg-ink);
    box-shadow: inset 0 0 0 1px rgba(var(--dg-a-rgb), .38), 0 8px 20px -10px rgba(var(--dg-a-rgb), .7);
}
body.dg-dash .nav-badge { background: var(--dg-a); color: var(--dg-on-a); }
body.dg-dash .sidebar-footer { border-top-color: rgba(255, 255, 255, .06); }
body.dg-dash .sidebar-footer a:hover { color: var(--dg-ink); }

body.dg-dash .dash-topbar {
    background: rgba(13, 13, 16, .6);
    -webkit-backdrop-filter: blur(16px) saturate(150%);
    backdrop-filter: blur(16px) saturate(150%);
    border-bottom-color: rgba(255, 255, 255, .06);
}
body.dg-dash .topbar-title { font-weight: 700; letter-spacing: -.01em; }
body.dg-dash .topbar-portal-link {
    color: var(--dg-ink);
    padding: 6px 14px;
    border-radius: 999px;
    border: 1px solid rgba(var(--dg-a-rgb), .4);
    background: rgba(var(--dg-a-rgb), .08);
    transition: background .2s ease;
}
body.dg-dash .topbar-portal-link:hover { text-decoration: none; background: rgba(var(--dg-a-rgb), .18); }
body.dg-dash .page-body { padding: 28px; }

body.dg-dash .stat-cards { gap: 14px; }
body.dg-dash .stat-card,
body.dg-dash .page-body [style*="background:var(--surface)"] {
    background: var(--dg-card) !important;
    border: 1px solid var(--dg-card-b) !important;
    border-radius: 16px !important;
    box-shadow: var(--dg-rim), var(--dg-shadow);
}
body.dg-dash .stat-card { padding: 18px; overflow: hidden; }
body.dg-dash .stat-card .stat-value { color: var(--dg-ink); font-variant-numeric: tabular-nums; letter-spacing: -.02em; font-size: 28px; }

body.dg-dash .data-table {
    border-collapse: separate;
    border-spacing: 0;
    background: rgba(255, 255, 255, .025);
    border: 1px solid rgba(255, 255, 255, .07);
    border-radius: 14px;
    overflow: hidden;
}
body.dg-dash .data-table th { background: rgba(255, 255, 255, .04); border-bottom-color: rgba(255, 255, 255, .07); }
body.dg-dash .data-table td { border-bottom-color: rgba(255, 255, 255, .05); }
body.dg-dash .data-table tr:last-child td { border-bottom: 0; }
body.dg-dash .data-table tr:hover td { background: rgba(var(--dg-a-rgb), .06); }

body.dg-dash .btn { border-radius: 999px; transition: transform .15s ease, filter .15s ease, background .15s ease; }
body.dg-dash .btn:hover { opacity: 1; transform: translateY(-1px); filter: brightness(1.08); }
body.dg-dash .btn-primary { background: var(--dg-a); color: var(--dg-on-a); box-shadow: 0 8px 20px -10px rgba(var(--dg-a-rgb), .8); }
body.dg-dash .btn-secondary { background: rgba(255, 255, 255, .06); border-color: rgba(255, 255, 255, .12); }
body.dg-dash .form-control { background: var(--dg-field); border-color: var(--dg-field-b); border-radius: 10px; padding: 8px 12px; }
body.dg-dash .form-control:focus { border-color: var(--dg-a); box-shadow: 0 0 0 3px rgba(var(--dg-a-rgb), .22); }
body.dg-dash .alert { border-radius: 12px; }
body.dg-dash .page-link { border-radius: 999px; border-color: rgba(255, 255, 255, .1); min-width: 32px; text-align: center; }
body.dg-dash .page-link.active, body.dg-dash .page-link:hover { background: var(--dg-a); color: var(--dg-on-a); border-color: var(--dg-a); }

/* phones: the menu becomes a scrolling row of pills above the page */
@media (max-width: 819px) {
    body.dg-dash { flex-direction: column; }
    body.dg-dash .sidebar {
        width: 100%;
        height: auto;
        flex-direction: row;
        align-items: center;
        overflow-x: auto;
        overflow-y: hidden;
        z-index: 20;
        border-right: 0;
        border-bottom: 1px solid rgba(255, 255, 255, .07);
        scrollbar-width: none;
    }
    body.dg-dash .sidebar::-webkit-scrollbar { display: none; }
    body.dg-dash .sidebar-logo { flex-shrink: 0; border-bottom: 0; padding: 10px 6px 10px 12px; }
    body.dg-dash .sidebar-logo img { width: 30px; height: 30px; }
    body.dg-dash .sidebar-logo .logo-sub { display: none; }
    body.dg-dash .sidebar-logo .logo-text { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    body.dg-dash .nav-section { display: flex; flex-shrink: 0; padding: 0; }
    body.dg-dash .nav-section-title { display: none; }
    body.dg-dash .nav-link { white-space: nowrap; margin: 0 2px; padding: 7px 12px; }
    body.dg-dash .sidebar-footer { flex-shrink: 0; margin: 0; border-top: 0; padding: 0 12px; white-space: nowrap; }
    body.dg-dash .sidebar-footer br { display: none; }
    body.dg-dash .dash-main { width: 100%; }
    body.dg-dash .dash-topbar { position: static; padding: 12px 16px; }
    body.dg-dash .page-body { padding: 16px; }
    body.dg-dash .stat-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    body.dg-dash .stat-card .stat-value { font-size: 22px; }
    body.dg-dash .page-body > table, body.dg-dash .page-body .data-table { display: block; overflow-x: auto; }
    body.dg-dash .data-table td, body.dg-dash .data-table th { white-space: nowrap; }
    /* two-panel rows (dashboard, analytics, order detail) stack on a phone */
    body.dg-dash .page-body [style*="grid-template-columns:1fr 1fr"] { grid-template-columns: 1fr !important; }
}

/* ── Customer storefront (portal, product, cart, checkout, order confirmed) ────────────── */
body.dg-store .dealer-header,
body.dg-store .dealer-nav {
    background: rgba(var(--dg-b-rgb), .8);
    -webkit-backdrop-filter: blur(16px) saturate(160%);
    backdrop-filter: blur(16px) saturate(160%);
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
body.dg-store .dealer-mobile-menu { background: rgba(var(--dg-b-rgb), .94); -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
body.dg-store .dealer-brand img, body.dg-store .dealer-nav-brand img { border-radius: 10px; }
body.dg-store .dealer-search input,
body.dg-store .dealer-mobile-menu .mobile-search input { border-radius: 999px; padding-left: 16px; }
body.dg-store .dealer-search input:focus { box-shadow: 0 0 0 3px rgba(var(--dg-a-rgb), .25); }
body.dg-store .dealer-cart-btn { border-radius: 999px; }
body.dg-store .cart-badge { background: var(--dg-a); color: var(--dg-on-a); }

body.dg-store .dealer-trust-icon { background: rgba(var(--dg-a-rgb), .14); box-shadow: inset 0 0 0 1px rgba(var(--dg-a-rgb), .28); }
body.dg-store .dealer-banner { border-radius: 22px; box-shadow: 0 30px 60px -34px rgba(var(--dg-a-rgb), .55); }

body.dg-store .filters-sidebar,
body.dg-store .cart-table,
body.dg-store .cart-summary,
body.dg-store .form-card,
body.dg-store .confirm-card,
body.dg-store .gallery-main,
body.dg-store .detail-specs,
body.dg-store .empty-state {
    background: var(--dg-card);
    border: 1px solid var(--dg-card-b);
    border-radius: 18px;
    box-shadow: var(--dg-rim), var(--dg-shadow);
}
body.dg-store.dg-light .gallery-main { background: #eef0f2 !important; }
body.dg-store .filter-feature-btn { border-radius: 12px; }
body.dg-store .filter-feature-btn.active {
    background: var(--dg-a) !important;
    color: var(--dg-on-a) !important;
    border-color: transparent !important;
}
body.dg-store .filter-clear { color: var(--dg-ink); }
body.dg-store .sort-select,
body.dg-store .dealer-filter-toggle { border-radius: 999px; }
body.dg-store .form-control { background: var(--dg-field); border: 1px solid var(--dg-field-b); border-radius: 10px; }
body.dg-store .form-control:focus { border-color: var(--dg-a); box-shadow: 0 0 0 3px rgba(var(--dg-a-rgb), .22); outline: none; }

body.dg-store .product-card {
    background: var(--dg-card);
    border: 1px solid var(--dg-card-b);
    border-radius: 18px;
    box-shadow: var(--dg-rim), var(--dg-shadow);
    transition: transform .35s var(--dg-ease), box-shadow .35s var(--dg-ease), border-color .35s ease;
}
body.dg-store .product-card:hover {
    transform: translateY(-4px);
    border-color: rgba(var(--dg-a-rgb), .55);
    box-shadow: var(--dg-rim), 0 20px 42px -20px rgba(var(--dg-a-rgb), .6);
}
body.dg-store .card-image-wrap img { transition: transform .5s var(--dg-ease); }
/* the rotated corner ribbon is replaced by the "Sale" label beside the price */
body.dg-store .sale-ribbon { display: none; }

body.dg-store .price-sale,
body.dg-store .price-regular,
body.dg-store .detail-price-sale,
body.dg-store .detail-price-regular { color: var(--dg-ink) !important; }

body.dg-store .btn-cart,
body.dg-store .btn-checkout,
body.dg-store .btn-primary {
    background: var(--dg-a);
    color: var(--dg-on-a) !important;
    border: 0;
    border-radius: 999px;
    box-shadow: 0 8px 18px -10px rgba(var(--dg-a-rgb), .85);
    transition: transform .15s ease, filter .15s ease, box-shadow .15s ease;
}
body.dg-store .btn-cart { padding: 8px 15px; }
body.dg-store .btn-cart:hover,
body.dg-store .btn-checkout:hover,
body.dg-store .btn-primary:hover { background: var(--dg-a); filter: brightness(1.08); transform: translateY(-1px); text-decoration: none; }
body.dg-store .btn-cart.in-cart {
    background: transparent;
    color: var(--dg-ink) !important;
    border: 1px solid rgba(var(--dg-a-rgb), .55);
    box-shadow: none;
}
body.dg-store .btn-secondary,
body.dg-store .btn-whatsapp { border-radius: 999px; }
body.dg-store .page-link { border-radius: 999px; min-width: 34px; text-align: center; }
body.dg-store .page-link.active,
body.dg-store .page-link:hover { background: var(--dg-a); color: var(--dg-on-a); border-color: var(--dg-a); text-decoration: none; }
body.dg-store .delivery-option { border-radius: 14px; }
body.dg-store .thumb, body.dg-store .gallery-thumbs img { border-radius: 10px; }

@media (max-width: 600px) {
    /* phone header: the floating WhatsApp button already covers WhatsApp; keep links on one line */
    body.dg-store .dealer-nav-links a[href^="https://wa.me"] { display: none; }
    body.dg-store .dealer-nav-links a { white-space: nowrap; }
    body.dg-store .dealer-header-inner { gap: 10px; }
    body.dg-store .dealer-brand .dname { font-size: 15px; }
    body.dg-store .dealer-banner { border-radius: 16px; }
    body.dg-store .product-card { border-radius: 16px; }
    body.dg-store .product-card:hover { transform: none; }
}

/* ── Sign-in, onboarding and prospect pages (the portal's own colours, as before) ──────── */
/* no colour glow here: these pages carry no dealer's colours, so the light behind them is neutral */
body.dg.dg-auth::before {
    background:
        radial-gradient(900px 520px at 8% -10%, rgba(255, 255, 255, .06), transparent 62%),
        radial-gradient(760px 460px at 100% 0%, rgba(255, 255, 255, .035), transparent 60%);
}
body.dg-auth .login-card,
body.dg-auth .card,
body.dg-auth .filters-sidebar {
    background: var(--dg-card) !important;
    border: 1px solid var(--dg-card-b) !important;
    border-radius: 20px !important;
    box-shadow: var(--dg-rim), var(--dg-shadow);
}
body.dg-auth .login-card { -webkit-backdrop-filter: blur(18px) saturate(150%); backdrop-filter: blur(18px) saturate(150%); }
body.dg-auth .topbar { background: rgba(14, 14, 17, .6) !important; -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
body.dg-auth input:not([type=checkbox]):not([type=radio]):not([type=color]),
body.dg-auth textarea,
body.dg-auth select { border-radius: 10px !important; }
body.dg-auth input:focus, body.dg-auth textarea:focus, body.dg-auth select:focus { box-shadow: 0 0 0 3px rgba(var(--dg-a-rgb), .22); }
body.dg-auth .btn-login,
body.dg-auth .btn-submit,
body.dg-auth .btn {
    border-radius: 999px !important;
    transition: transform .15s ease, filter .15s ease;
}
body.dg-auth .btn-login:hover, body.dg-auth .btn-submit:hover, body.dg-auth .btn:hover { opacity: 1; filter: brightness(1.08); transform: translateY(-1px); }
body.dg-auth .error, body.dg-auth .ok { border-radius: 12px; }
body.dg-auth .palette-card { border-radius: 12px; }

/* ── Entrance: panels rise in one after another on a fresh visit (not when the page arrived
      through a page-change transition, which already animates it) ── */
@media (prefers-reduced-motion: no-preference) {
    html:not(.dg-vt) body.dg-dash .page-body > :not(.stat-cards),
    html:not(.dg-vt) body.dg-dash .stat-cards > .stat-card,
    html:not(.dg-vt) body.dg-store .product-grid > .product-card:nth-child(-n+12),
    html:not(.dg-vt) body.dg-auth .login-card,
    html:not(.dg-vt) body.dg-auth .container > .card {
        animation: dg-rise .55s var(--dg-ease) backwards;
    }
    html:not(.dg-vt) body.dg .stat-cards > :nth-child(2),
    html:not(.dg-vt) body.dg .product-grid > :nth-child(2),
    html:not(.dg-vt) body.dg .page-body > :nth-child(2),
    html:not(.dg-vt) body.dg .container > .card:nth-of-type(2) { animation-delay: .05s; }
    html:not(.dg-vt) body.dg .stat-cards > :nth-child(3),
    html:not(.dg-vt) body.dg .product-grid > :nth-child(3),
    html:not(.dg-vt) body.dg .page-body > :nth-child(3),
    html:not(.dg-vt) body.dg .container > .card:nth-of-type(3) { animation-delay: .1s; }
    html:not(.dg-vt) body.dg .stat-cards > :nth-child(4),
    html:not(.dg-vt) body.dg .product-grid > :nth-child(4),
    html:not(.dg-vt) body.dg .page-body > :nth-child(4),
    html:not(.dg-vt) body.dg .container > .card:nth-of-type(4) { animation-delay: .15s; }
    html:not(.dg-vt) body.dg .product-grid > :nth-child(5),
    html:not(.dg-vt) body.dg .page-body > :nth-child(5) { animation-delay: .2s; }
    html:not(.dg-vt) body.dg .product-grid > :nth-child(6),
    html:not(.dg-vt) body.dg .page-body > :nth-child(n+6) { animation-delay: .24s; }
    html:not(.dg-vt) body.dg .product-grid > :nth-child(7) { animation-delay: .28s; }
    html:not(.dg-vt) body.dg .product-grid > :nth-child(8) { animation-delay: .31s; }
    html:not(.dg-vt) body.dg .product-grid > :nth-child(9) { animation-delay: .34s; }
    html:not(.dg-vt) body.dg .product-grid > :nth-child(10) { animation-delay: .36s; }
    html:not(.dg-vt) body.dg .product-grid > :nth-child(11) { animation-delay: .38s; }
    html:not(.dg-vt) body.dg .product-grid > :nth-child(12) { animation-delay: .4s; }
}

@media (prefers-reduced-motion: reduce) {
    ::view-transition-group(*), ::view-transition-old(*), ::view-transition-new(*) { animation: none !important; }
    body.dg .product-card, body.dg .btn, body.dg .btn-cart, body.dg .nav-link { transition: none !important; }
    body.dg-store .product-card:hover { transform: none; }
}
