/* Shared responsive layout for catalog pages (Display + Web) */

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

body {
    overflow-x: hidden;
}

img,
video {
    max-width: 100%;
    height: auto;
}

.app-container {
    width: 100%;
    max-width: 1440px;
    margin: 0 auto;
}

/* ===== Header ===== */
@media (max-width: 767px) {
    .header {
        padding: 10px 16px !important;
        flex-wrap: wrap;
        gap: 8px;
        align-items: flex-start;
    }

    .header-left {
        gap: 8px !important;
        min-width: 0;
        flex: 1 1 100%;
        flex-wrap: wrap;
    }

    .header-right {
        gap: 10px !important;
        flex-shrink: 0;
        flex-wrap: wrap;
        justify-content: flex-end;
        width: 100%;
    }

    .header-right a {
        font-size: 12px !important;
    }

    .logo-box {
        min-width: 0;
        flex: 1 1 auto;
    }

    .logo-box .logo-sub,
    .header .logo-sub {
        display: none !important;
    }

    .header img[alt="logo"],
    .header-left img {
        height: 36px !important;
        width: auto !important;
    }

    .logo-box .logo-text,
    .header .logo-text,
    .logo-box > span {
        font-size: 15px !important;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 52vw;
    }

    .vehicle-type-switcher {
        width: 100%;
        margin-top: 0 !important;
        justify-content: flex-start;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .vehicle-type-switcher::-webkit-scrollbar {
        display: none;
    }

    .vehicle-type-tab {
        flex-shrink: 0;
        padding: 6px 10px !important;
        font-size: 12px !important;
    }
}

@media (min-width: 768px) and (max-width: 1024px) {
    .header {
        padding: 12px 20px !important;
    }

    .header img[alt="logo"],
    .header-left img {
        height: 48px !important;
        width: auto !important;
    }
}

/* ===== Search area ===== */
@media (max-width: 767px) {
    .search-area {
        padding: 14px 16px !important;
    }

    .search-tabs {
        gap: 14px;
        overflow-x: auto;
        white-space: nowrap;
        padding-bottom: 4px;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .search-tabs::-webkit-scrollbar {
        display: none;
    }

    .search-tab {
        font-size: 13px;
        flex-shrink: 0;
    }

    .filter-row {
        gap: 8px;
    }

    .filter-item,
    .filter-part_name,
    .filter-transdesc,
    .filter-brand,
    .filter-series,
    .filter-engineModel {
        width: 100% !important;
        min-width: 0;
    }

    .single-search .input-wrap {
        flex-direction: column;
        align-items: stretch;
    }

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

    .search-btn,
    .reset-btn {
        min-height: 36px;
        width: 100%;
    }

    .filter-row .search-btn,
    .filter-row .reset-btn {
        width: auto;
        flex: 1 1 auto;
    }
}

/* ===== Home explorer / category nav ===== */
@media (max-width: 767px) {
    .cat-nav {
        padding: 0 16px !important;
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        overflow: visible;
        white-space: normal;
    }

    .cat-item {
        padding: 12px 8px;
        font-size: 12px;
    }

    .main-content {
        padding: 12px 16px !important;
    }

    .car-explorer {
        grid-template-columns: 1fr !important;
        gap: 12px;
        padding: 12px !important;
    }

    .explorer-left {
        order: 1;
    }

    .explorer-center {
        order: 0;
        min-height: auto;
    }

    .explorer-center img {
        max-height: 260px;
    }

    .explorer-right {
        order: 2;
    }

    .part-card-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 6px;
    }

    .hot-parts {
        padding: 12px;
        margin-top: 12px;
    }

    .hot-part-item {
        min-width: 90px;
        padding: 10px 8px;
    }
}

@media (min-width: 768px) and (max-width: 1024px) {
    .cat-nav {
        padding: 0 24px !important;
        grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    }

    .car-explorer {
        grid-template-columns: 160px minmax(0, 1fr) minmax(0, 220px) !important;
    }
}

/* ===== Search results ===== */
@media (max-width: 767px) {
    .results-layout {
        grid-template-columns: 1fr !important;
        padding: 12px 16px calc(72px + env(safe-area-inset-bottom, 0px)) !important;
        gap: 12px;
    }

    .results-sidebar {
        position: static !important;
        max-height: none !important;
        top: auto !important;
    }

    .structure-panel {
        display: none;
    }

    .side-series-panel {
        max-height: none;
    }

    .side-series-body {
        max-height: 220px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .results-main {
        padding: 12px !important;
    }

    .results-title {
        font-size: 15px;
        line-height: 1.4;
        word-break: break-word;
    }

    .result-cards {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: 8px;
    }

    .result-card-img-wrap {
        height: 64px;
    }

    .results-pagination {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }

    .results-pagination-right {
        justify-content: center;
        flex-wrap: wrap;
    }

    .fab-structure {
        right: 16px;
        bottom: calc(16px + env(safe-area-inset-bottom, 0px));
        height: 40px;
        padding: 0 12px;
        font-size: 11px;
    }

    body.has-catalog-side-actions:has(.fab-structure) .fab-structure {
        bottom: calc(56px + 12px + env(safe-area-inset-bottom, 0px));
    }
}

@media (max-width: 480px) {
    .result-cards {
        grid-template-columns: 1fr !important;
    }

    .part-card-grid {
        grid-template-columns: 1fr !important;
    }
}

@media (min-width: 768px) and (max-width: 1024px) {
    .results-layout {
        grid-template-columns: 220px minmax(0, 1fr) !important;
        padding: 12px 24px 24px !important;
    }

    .result-cards {
        grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    }
}

/* ===== Detail page ===== */
@media (max-width: 767px) {
    .back-bar {
        padding: 10px 16px;
        font-size: 13px;
    }

    .detail-main {
        grid-template-columns: 1fr !important;
        padding: 20px 16px !important;
    }

    .detail-tabs {
        padding: 0 16px;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
    }

    .detail-tabs::-webkit-scrollbar {
        display: none;
    }

    .detail-tab {
        white-space: nowrap;
        flex-shrink: 0;
    }

    .tab-content {
        padding: 14px 12px;
    }
}

/* ===== Cart / orders / login common ===== */
@media (max-width: 767px) {
    .app-container {
        max-width: 100%;
        padding-left: 0;
        padding-right: 0;
    }

    .page-title {
        font-size: 18px;
        padding-left: 16px;
        padding-right: 16px;
    }

    .cart-panel,
    .order-panel,
    .login-panel {
        margin-left: 16px;
        margin-right: 16px;
        border-radius: 8px;
    }

    .table-scroll {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    .table-scroll > table {
        min-width: 640px;
    }

    .btn-submit-order,
    .cart-footer .btn-submit-order {
        width: 100%;
        justify-content: center;
    }

    .toast-container {
        left: 16px !important;
        right: 16px !important;
        top: 12px !important;
        transform: none !important;
        align-items: stretch;
    }

    .toast-item {
        white-space: normal;
        text-align: center;
    }

    .modal-overlay {
        padding: 0 !important;
    }

    .modal-box {
        width: 100vw !important;
        max-height: 100vh;
        border-radius: 0 !important;
    }

    .confirm-box {
        width: min(380px, calc(100vw - 32px));
    }
}

/* ===== Features bar (fallback if inline styles missing) ===== */
@media (max-width: 768px) {
    .catalog-features-bar,
    .features-bar {
        margin: 12px 16px 20px !important;
        flex-direction: column;
        align-items: stretch;
        overflow: visible;
        padding: 16px !important;
        gap: 4px;
    }

    .catalog-features-bar .feature-item,
    .features-bar .feature-item {
        max-width: none;
        min-width: 0;
        justify-content: flex-start;
    }
}

/* ===== Side contact button / panel ===== */
@media (max-width: 767px) {
    body.has-catalog-side-actions {
        padding-bottom: calc(56px + env(safe-area-inset-bottom, 0px));
    }

    .catalog-side-actions {
        top: auto;
        bottom: 0;
        right: 0;
        left: 0;
        transform: none;
        flex-direction: row;
        justify-content: flex-end;
        gap: 8px;
        padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px));
        background: linear-gradient(to top, rgba(245, 247, 250, 0.98), rgba(245, 247, 250, 0.88));
        pointer-events: none;
    }

    .catalog-side-action-btn {
        width: auto;
        min-width: 44px;
        min-height: 44px;
        flex-direction: row;
        border-radius: 999px;
        padding: 10px 14px;
        box-shadow: 0 2px 12px rgba(0, 0, 0, 0.12);
    }

    .catalog-side-action-btn span {
        writing-mode: horizontal-tb;
        letter-spacing: 0;
        font-size: 13px;
    }

    .catalog-side-action-btn:hover,
    .catalog-side-action-btn:focus-visible {
        width: auto;
    }

    .catalog-side-panel-box {
        width: 100vw;
        max-width: 100vw;
    }

    .catalog-side-panel-body {
        padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    }
}
