/* Shared responsive safeguards for admin, storefront, account, and auth layouts. */
html,
body {
    width: 100%;
    max-width: 100%;
}

.admin-shell,
.storefront-shell,
.customer-shell,
.auth-shell {
    overflow-x: clip;
}

:where(.admin-shell, .storefront-shell, .customer-shell, .auth-shell) :where(img, video, canvas) {
    max-width: 100%;
    height: auto;
}

:where(.admin-shell, .storefront-shell, .customer-shell, .auth-shell) :where(input, select, textarea, button) {
    max-width: 100%;
}

:where(.admin-shell, .storefront-shell, .customer-shell) :where(.overflow-x-auto, [class*="table-scroll"], [class*="table-wrap"]) {
    -webkit-overflow-scrolling: touch;
}

/* Admin */
.admin-shell .app-layout,
.admin-shell .main-area,
.admin-shell .main-content,
.admin-shell .main-content > *,
.admin-shell .card-glass,
.admin-shell .table-wrap {
    min-width: 0;
    max-width: 100%;
}

.admin-shell .table-wrap > .overflow-x-auto {
    width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
}

.admin-shell .table-wrap table {
    border-collapse: collapse;
}

.admin-shell :where(.modal-box, .ord-box) {
    max-width: calc(100vw - 1.5rem);
    max-height: calc(100dvh - 1.5rem);
    overscroll-behavior: contain;
}

.admin-shell :where(.ord-value, td, .card-glass, .modal-message) {
    overflow-wrap: anywhere;
}

.admin-shell .btn {
    max-width: 100%;
}

/* Storefront and customer pages */
.storefront-shell main,
.customer-shell main,
.storefront-shell main > *,
.customer-shell main > * {
    min-width: 0;
    max-width: 100%;
}

:where(.storefront-shell, .customer-shell) :where(.table-wrap, .table-responsive, .overflow-x-auto) {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
}

:where(.storefront-shell, .customer-shell) :where(.modal-box, [class*="modal-content"], [class*="modal-card"]) {
    max-width: calc(100vw - 1.5rem);
    max-height: calc(100dvh - 1.5rem);
}

:where(.storefront-shell, .customer-shell) :where(p, td, dd, .order-meta, .ord-value) {
    overflow-wrap: anywhere;
}

@media (max-width: 1023px) {
    .admin-shell .sidebar {
        width: min(300px, calc(100vw - 24px));
        max-width: calc(100vw - 24px);
    }

    .admin-shell .header,
    .admin-shell .main-content {
        padding-right: max(1rem, env(safe-area-inset-right));
        padding-left: max(1rem, env(safe-area-inset-left));
    }
}

@media (max-width: 767px) {
    :where(.admin-shell, .storefront-shell, .customer-shell, .auth-shell) input:not([type="checkbox"]):not([type="radio"]):not([type="file"]),
    :where(.admin-shell, .storefront-shell, .customer-shell, .auth-shell) select,
    :where(.admin-shell, .storefront-shell, .customer-shell, .auth-shell) textarea {
        font-size: 16px !important;
    }

    .admin-shell .table-wrap table {
        min-width: 680px;
    }

    .admin-shell .table-wrap {
        overflow-x: auto;
        overscroll-behavior-inline: contain;
    }

    .admin-shell :where(.ord-grid, .joki-detail-grid, .product-meta) {
        grid-template-columns: minmax(0, 1fr) !important;
    }

    .admin-shell .admin-filter-bar {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        align-items: stretch;
    }

    .admin-shell .admin-filter-bar > *,
    .admin-shell .admin-filter-bar .input-field,
    .admin-shell .admin-filter-bar .btn {
        width: 100%;
        min-width: 0;
    }

    .admin-shell :where(.page-header, .card-header) {
        align-items: stretch;
    }

    .admin-shell :where(.page-header, .card-header) > :where(.btn, a.btn, button.btn) {
        width: 100%;
    }

    .admin-shell :where(.ord-header, .ord-body) {
        padding-right: 1rem;
        padding-left: 1rem;
    }

    .admin-shell .ord-section > div[style*="display:flex"] {
        flex-wrap: wrap;
        gap: .75rem;
    }

    .admin-shell .ord-section .flex.items-center {
        flex-wrap: wrap;
    }

    .admin-shell .ord-section .flex.items-center > :where(.input-field, .btn) {
        width: 100% !important;
        max-width: none !important;
    }

    .admin-shell .btn:not(.btn-xs) {
        min-height: 42px;
    }

    :where(.storefront-shell, .customer-shell) .btn {
        max-width: 100%;
        white-space: normal;
        text-align: center;
    }

    :where(.storefront-shell, .customer-shell) :where(table) {
        font-size: .82rem;
    }

    .auth-shell .auth-page {
        align-items: flex-start;
        min-height: 100dvh;
        padding: max(1rem, env(safe-area-inset-top)) max(.85rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(.85rem, env(safe-area-inset-left));
    }

    .auth-shell .auth-container {
        width: 100%;
        margin: auto 0;
    }
}

/* Mobile performance mode: keep controls responsive and stop decorative loops. */
@keyframes mobile-performance-spin {
    to { transform: rotate(360deg); }
}

@media (max-width: 860px) {
    .storefront-shell *,
    .storefront-shell *::before,
    .storefront-shell *::after,
    .customer-shell *,
    .customer-shell *::before,
    .customer-shell *::after {
        animation: none !important;
        will-change: auto !important;
    }

    .storefront-shell :is(.spin, .spin-slow, .spinner, [class*="-spinner"], [class*="__spinner"], .is-loading svg, [aria-busy="true"] svg),
    .customer-shell :is(.spin, .spin-slow, .spinner, [class*="-spinner"], [class*="__spinner"], .is-loading svg, [aria-busy="true"] svg) {
        animation: mobile-performance-spin .85s linear infinite !important;
    }

    .storefront-shell .dark-meteor-field span {
        animation: dark-meteor-fall var(--meteor-duration) linear var(--meteor-delay) infinite !important;
        will-change: transform !important;
    }

    .storefront-shell :is(.site-ambient, .rank-cloud) {
        display: none !important;
    }

    .storefront-shell :is(
        .mobile-menu,
        .mobile-menu-backdrop,
        .mobile-bottom-nav,
        .auth-dropdown-menu,
        .search-suggest,
        .gd-mobile-bar,
        .popup-overlay
    ) {
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
    }

    .storefront-shell .site-header {
        -webkit-backdrop-filter: blur(18px) saturate(125%) !important;
        backdrop-filter: blur(18px) saturate(125%) !important;
    }

    .storefront-shell .account-dialog::backdrop {
        -webkit-backdrop-filter: none !important;
        backdrop-filter: none !important;
    }

    .storefront-shell :is(.hero-banner-card, .stock-showcase-slide, .home-testi-lane, .payment-track, .frontend-promo .payment-track) {
        transition: none !important;
    }

    .storefront-shell :is(.home-testi-lane-wrap, .payment-track-wrap) {
        overflow-x: auto !important;
        overscroll-behavior-inline: contain;
        scroll-snap-type: x proximity;
    }

    .storefront-shell .home-testi-section {
        padding-right: 0;
        padding-left: 0;
    }

    .storefront-shell .home-testi-lane-wrap {
        overflow-x: hidden !important;
        overscroll-behavior-inline: auto;
        scroll-snap-type: none;
    }

    .storefront-shell .home-testi-card,
    .storefront-shell .payment-track > * {
        scroll-snap-align: start;
    }

    .storefront-shell :is(.rank-side-icon, .rank-auto-logo img) {
        filter: none !important;
    }

    .storefront-shell :is(
        .games-section,
        .testi-section,
        .home-testi-section,
        .frontend-promo,
        .payment-section,
        .site-footer
    ) {
        content-visibility: auto;
        contain-intrinsic-size: auto 520px;
    }

    .storefront-shell :is(.btn, a, button, .game-card, .popular-topup-card, .article-card) {
        -webkit-tap-highlight-color: transparent;
    }
}

@media (max-width: 860px) and (prefers-reduced-motion: no-preference) {
    .storefront-shell .home-testi-lane {
        animation: home-testi-scroll 38s linear infinite !important;
        animation-play-state: running !important;
        will-change: transform !important;
    }
}

@media (max-width: 479px) {
    .admin-shell .header {
        padding-right: max(.75rem, env(safe-area-inset-right));
        padding-left: max(.75rem, env(safe-area-inset-left));
    }

    .admin-shell .main-content {
        padding-right: max(.75rem, env(safe-area-inset-right));
        padding-left: max(.75rem, env(safe-area-inset-left));
    }

    .admin-shell .header-right,
    .admin-shell .header-left {
        min-width: 0;
    }

    .admin-shell .user-menu .user-dropdown {
        position: fixed;
        top: 62px;
        right: max(.75rem, env(safe-area-inset-right));
        left: max(.75rem, env(safe-area-inset-left));
        min-width: 0;
    }

    .admin-shell :where(.modal-overlay, .ord-modal) {
        padding: .75rem;
    }

    .admin-shell :where(.modal-box, .ord-box) {
        width: 100%;
        margin: 0;
        border-radius: 15px;
    }

    .admin-shell .table-wrap table {
        min-width: 620px;
    }

    .storefront-shell .mobile-bottom-nav > :where(a, button) {
        min-width: 0;
        padding-inline: 2px;
    }

    .storefront-shell .mobile-bottom-nav span {
        width: 100%;
    }
}

@media (prefers-reduced-motion: reduce) {
    :where(.admin-shell, .storefront-shell, .customer-shell, .auth-shell) *,
    :where(.admin-shell, .storefront-shell, .customer-shell, .auth-shell) *::before,
    :where(.admin-shell, .storefront-shell, .customer-shell, .auth-shell) *::after {
        scroll-behavior: auto !important;
    }
}

@media (max-width: 860px) {
    .storefront-shell .gateway-payment-notice-track {
        animation: gatewayPaymentMarquee 28s linear infinite !important;
        animation-play-state: running !important;
        will-change: transform !important;
    }

    .storefront-shell .stock-showcase-window {
        overflow: hidden !important;
        scroll-snap-type: none !important;
    }

    .storefront-shell .stock-showcase-track {
        animation: stock-marquee var(--stock-marquee-duration, 45s) linear infinite !important;
        will-change: transform !important;
    }

    .storefront-shell .stock-showcase-group[aria-hidden="true"] {
        display: flex !important;
    }

    .storefront-shell .stock-showcase-art-motion {
        display: block !important;
        animation: stock-art-wind-sway 5.6s ease-in-out infinite !important;
        will-change: transform !important;
    }

    .storefront-shell .stock-showcase-slide.is-active :is(.stock-showcase-track, .stock-showcase-art-motion) {
        animation-play-state: running !important;
    }

    .storefront-shell .stock-showcase-slide:not(.is-active) :is(.stock-showcase-track, .stock-showcase-art-motion) {
        animation-play-state: paused !important;
    }
}
