/**
 * Thunder EV — Mobile-only responsive layer
 * Load LAST on public pages. Desktop (768px+) is untouched by this file.
 */

/* —— Mobile (767px and below) —— */
@media (max-width: 767px) {
  /* Global */
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

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

  main,
  .section,
  .tev-mp-main,
  .tev-cart-main,
  .tev-cpo-main,
  .tev-assoc-main,
  .tev-admin-main,
  .tev-subpage-main,
  .tev-seo-landing__main,
  .products-column,
  .tab-panels,
  .marketplace-layout {
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }

  .tev-page-shell,
  .tev-mp-page-shell,
  .container,
  .tev-container {
    width: 100%;
    max-width: 100%;
    padding-left: clamp(12px, 4vw, 16px);
    padding-right: clamp(12px, 4vw, 16px);
    box-sizing: border-box;
  }

  input:not([type="checkbox"]):not([type="radio"]),
  select,
  textarea,
  .tev-form-field input,
  .tev-form-field select,
  .tev-form-field textarea {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  button,
  .btn,
  .cta-small,
  .tev-btn,
  .tev-btn-primary,
  .tev-btn-secondary,
  .tev-mp-btn,
  .tev-mp-btn-secondary,
  a.cta-small {
    min-height: 44px;
  }

  /* Mobile header standard */
  .hero .nav,
  .tev-mp-nav,
  .tev-seo-landing__header-inner,
  .tev-subnav {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding-left: 12px;
    padding-right: 12px;
  }

  .tev-nav-menu-btn {
    display: inline-flex;
  }

  .tev-mp-nav__titles h1,
  .tev-mp-nav__titles p,
  #page-heading,
  #page-subheading {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  .tev-mp-nav__actions,
  .nav-ctas-right,
  .tev-mp-cart-btn {
    flex-shrink: 0;
  }

  .tev-mp-search-dock {
    left: 0;
    right: 0;
    width: 100%;
    max-width: 100%;
    padding: 0 12px;
    box-sizing: border-box;
  }

  .tev-mp-search-panel,
  .tev-mp-search-input-wrap,
  #tev-part-lookup {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  /* Home */
  body.tev-home-page .hero {
    padding-left: 12px;
    padding-right: 12px;
  }

  body.tev-home-page .hero-text h1,
  body.tev-home-page .hero-text h1#tev-hero-heading {
    font-size: clamp(1.35rem, 6vw, 1.85rem);
    line-height: 1.25;
  }

  body.tev-home-page .hero-actions,
  body.tev-home-page .hero-cta-row,
  body.tev-home-page .nav-ctas-right {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  body.tev-home-page .hero-actions .btn,
  body.tev-home-page .hero-actions .cta-small,
  body.tev-home-page .hero-cta-row .btn {
    width: 100%;
    text-align: center;
    box-sizing: border-box;
  }

  body.tev-home-page .marketplace-layout {
    grid-template-columns: 1fr;
  }

  body.tev-home-page .card-grid,
  body.tev-home-page .charger-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }

  body.tev-home-page .card,
  body.tev-home-page .product-card,
  body.tev-home-page .charger-card {
    width: 100%;
    max-width: 100%;
  }

  body.tev-home-page .tev-ticker-strip,
  body.tev-home-page .partners-ticker,
  body.tev-home-page .tev-mp-customers-scroll,
  body.tev-home-page .brand-scroll {
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  body.tev-home-page .tev-home-footer__grid,
  body.tev-home-page .footer-grid {
    grid-template-columns: 1fr;
    gap: 1.25rem;
  }

  body.tev-home-page #planner-panel,
  body.tev-home-page .tev-roi-calc,
  body.tev-home-page .glass-panel {
    padding-left: 12px;
    padding-right: 12px;
  }

  /* Category tiles */
  .tev-seo-category-cards {
    grid-template-columns: 1fr;
    gap: 0.4rem;
    width: 100%;
    margin-left: 0;
    margin-right: 0;
    padding-left: 12px;
    padding-right: 12px;
    box-sizing: border-box;
  }

  .tev-subpage-category-tiles {
    width: 100%;
    padding-left: 12px;
    padding-right: 12px;
    box-sizing: border-box;
  }

  /* Product list */
  .tev-mp-grid,
  .products-grid,
  #productGrid,
  #vendor-grid {
    grid-template-columns: 1fr;
    gap: 0.75rem;
    padding-left: 12px;
    padding-right: 12px;
  }

  .tev-mp-card,
  .tev-marketplace-card,
  .product-card-item {
    width: 100%;
    max-width: 100%;
  }

  .tev-mp-card__media img,
  .tev-mp-card__image img {
    width: 100%;
    max-height: 220px;
    object-fit: contain;
  }

  .tev-mp-card__actions,
  .tev-mp-card__footer {
    flex-direction: column;
    align-items: stretch;
    gap: 0.45rem;
  }

  .tev-mp-card__actions .tev-mp-btn,
  .tev-mp-card__actions .tev-mp-btn-secondary,
  .tev-mp-card__actions a {
    width: 100%;
    text-align: center;
    box-sizing: border-box;
  }

  body.tev-marketplace-page .tev-mp-toolbar,
  body.tev-marketplace-page .tev-mp-filter-bar,
  body.tev-marketplace-page .tev-mp-filters {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding-left: 12px;
    padding-right: 12px;
  }

  body.tev-marketplace-page .tev-mp-filter-bar select,
  body.tev-marketplace-page .tev-mp-toolbar select {
    width: 100%;
  }

  .tev-mp-filter-drawer__panel {
    width: min(100%, 360px);
    max-width: 100%;
  }

  .tev-mp-compare-table-wrap,
  #tev-spec-compare-wrap .tev-mp-compare-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* Product detail */
  .tev-pd-main,
  .tev-pd-page-main,
  .tev-detail-split {
    padding-left: 12px;
    padding-right: 12px;
  }

  .tev-detail-split,
  .tev-pd-layout {
    display: flex;
    flex-direction: column;
    gap: 1rem;
  }

  .tev-detail-split__media,
  .tev-pd-gallery,
  .tev-pd-hero-wrap {
    order: -1;
    width: 100%;
  }

  .tev-detail-hero,
  .tev-pd-hero img {
    width: 100%;
    max-height: min(55vh, 360px);
    object-fit: contain;
  }

  .tev-detail-actions,
  .tev-pd-actions,
  .tev-pd-cta-row {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .tev-detail-actions button,
  .tev-detail-actions .tev-mp-btn,
  .tev-pd-actions button,
  .tev-pd-checkout-btn,
  .tev-pd-add-cart-btn {
    width: 100%;
    min-height: 44px;
  }

  .tev-pd-spec-row,
  .tev-pd-spec-grid,
  .tev-detail-specs {
    flex-direction: column;
    align-items: stretch;
  }

  .tev-pd-pdf-viewer,
  .tev-pd-docs iframe {
    width: 100%;
    min-height: min(50vh, 320px);
  }

  /* Cart */
  body.tev-cart-page .tev-cart-grid {
    grid-template-columns: 1fr;
  }

  body.tev-cart-page .tev-cart-items-card {
    border-right: none;
    border-bottom: 1px solid #e2e8f0;
  }

  .cart-item {
    display: grid;
    grid-template-columns: 72px 1fr;
    gap: 0.65rem;
    padding: 12px;
  }

  .cart-item__aside {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .cart-item__qty,
  .cart-qty-controls {
    min-height: 44px;
  }

  .cart-item__remove,
  .cart-item-remove {
    min-height: 44px;
    padding: 0.35rem 0.75rem;
  }

  .tev-cart-sidebar,
  .tev-cart-sidebar__box {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding: 12px;
  }

  .tev-cart-checkout-btn,
  .tev-cart-action--checkout,
  #cartProceedCheckout,
  #checkoutProceedPayment,
  #checkoutPayBtn {
    width: 100%;
    min-height: 48px;
    box-sizing: border-box;
  }

  .tev-cart-promo__row {
    flex-direction: column;
    align-items: stretch;
  }

  .tev-gst-collapsible summary {
    padding: 0.35rem 0;
  }

  /* Checkout */
  body.tev-checkout-active .tev-cart-grid,
  .tev-amz-layout,
  .tev-amz-main {
    grid-template-columns: 1fr;
  }

  .checkout-panel,
  .tev-amz-sticky {
    position: static;
    top: auto;
    max-height: none;
    overflow: visible;
  }

  .tev-checkout-details-grid,
  .tev-checkout-form-grid,
  .tev-form-row,
  .checkout-panel .form-row-2,
  .checkout-panel .form-row-3,
  .addr-grid,
  .addr-grid-3,
  .tev-amz-gst-fields {
    grid-template-columns: 1fr;
  }

  .tev-checkout-view-card,
  .tev-amz-sec,
  .tev-billing-info-block {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

  .tev-checkout-view-card__edit,
  #cartGstSection,
  #cartDeliverySection,
  #cartBillingSection,
  #cartContactSection {
    width: 100%;
    overflow: visible;
  }

  .tev-checkout-progress,
  .tev-amz-progress {
    flex-wrap: wrap;
    gap: 0.35rem;
    justify-content: flex-start;
    padding: 0 12px;
  }

  .tev-amz-checkout__head,
  .tev-checkout-view-card__head {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .tev-checkout-view-card__edit button,
  .tev-amz-sec button.tev-btn,
  #checkoutGstSaveBtnPrimary,
  #checkoutAddressSaveBtn {
    width: 100%;
    min-height: 44px;
  }

  /* Login / register */
  .tev-onboard__grid,
  .tev-auth-layout {
    grid-template-columns: 1fr;
  }

  .tev-onboard-hero {
    min-height: auto;
    padding: 1.25rem 12px;
  }

  .tev-auth-panel,
  .tev-auth-card,
  .login-card,
  .tev-login-wrap {
    width: 100%;
    max-width: 100%;
    margin-left: auto;
    margin-right: auto;
    padding: 1rem 12px;
    box-sizing: border-box;
  }

  .tev-auth-card .google-btn,
  .tev-google-login-btn,
  #googleLoginBtn {
    width: 100%;
    min-height: 44px;
    box-sizing: border-box;
  }

  .tev-auth-alert,
  .tev-form-error,
  .tev-form-success {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  /* Customer portal */
  body.tev-customer-portal .tev-cpo-layout {
    grid-template-columns: 1fr;
  }

  body.tev-customer-portal .tev-kpi-grid,
  body.tev-customer-portal .tev-form {
    grid-template-columns: 1fr;
  }

  body.tev-customer-portal .tev-cpo-order-card,
  body.tev-customer-portal .order-card {
    width: 100%;
  }

  body.tev-customer-portal .tev-cpo-table-wrap,
  body.tev-customer-portal .table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Vendor / associate */
  .tev-assoc-layout,
  .tev-assoc-app {
    grid-template-columns: 1fr;
  }

  .tev-assoc-kpi-grid,
  .tev-assoc-stats {
    grid-template-columns: 1fr;
  }

  .tev-assoc-toolbar,
  .tev-assoc-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .tev-assoc-products-table-wrap,
  .tev-assoc-orders-table-wrap,
  .tev-vendor-table-wrap {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tev-assoc-upload,
  .tev-ai-extract-panel,
  .tev-vendor-product-form {
    width: 100%;
    padding-left: 12px;
    padding-right: 12px;
    box-sizing: border-box;
  }

  /* Admin */
  body.tev-admin-body .tev-admin-shell {
    grid-template-columns: 1fr;
  }

  .tev-admin-topbar {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.65rem 12px;
  }

  .tev-admin-menu-toggle {
    display: inline-flex;
  }

  .tev-dash-toolbar,
  .tev-admin-toolbar,
  .tev-crm-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .tev-chart-row,
  .stats-grid,
  .stats-row,
  .tev-admin-kpi-grid {
    grid-template-columns: 1fr;
  }

  .tev-admin-main table,
  .tev-crm-table-wrap,
  .tev-admin-table-wrap,
  .glass-panel:has(table) {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* AI planner */
  .tev-planner-wizard,
  #planner-panel .glass-panel {
    padding-left: 12px;
    padding-right: 12px;
  }

  .tev-planner-wizard-header,
  .tev-planner-wizard-header__actions {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .tev-planner-wizard-body,
  .tev-planner-step {
    padding: 0.75rem 0;
  }

  .tev-planner-wizard-footer,
  .tev-planner-nav {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }

  .tev-planner-wizard-footer button,
  .tev-planner-nav button,
  #tevPlannerGeneratePdf,
  .tev-planner-pdf-btn {
    width: 100%;
    min-height: 44px;
  }

  .tev-planner-results table,
  .tev-roi-table-wrap {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* Proposal / PDF preview */
  .tpr-preview-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
    padding: 12px;
  }

  .tpr-preview-toolbar .btn,
  .tpr-preview-toolbar button {
    width: 100%;
    min-height: 44px;
  }

  #tprFrame,
  .tpr-preview-frame,
  .proposal-preview iframe {
    width: 100%;
    height: min(70vh, 520px);
  }

  /* Compliance / contact / legal */
  .tev-compliance,
  .tev-compliance article,
  .tev-seo-landing__main,
  .contact-page,
  .about-page {
    padding-left: 12px;
    padding-right: 12px;
  }

  .tev-compliance-table,
  .tev-spec-table,
  table.tev-table {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tev-contact-actions,
  .tev-seo-landing__hero-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .tev-contact-actions a,
  .tev-contact-actions button {
    width: 100%;
    min-height: 44px;
    text-align: center;
    box-sizing: border-box;
  }

  /* CRM / accounting */
  .tev-crm-lead-card,
  .tev-lead-card {
    width: 100%;
    box-sizing: border-box;
  }

  .tev-crm-drawer,
  .tev-vendor-order-modal__panel {
    width: 100%;
    max-width: 100%;
  }

  .tev-accounting-summary,
  .tev-settlement-cards {
    grid-template-columns: 1fr;
  }

  /* Modals */
  .modal-overlay {
    padding: 12px;
    align-items: flex-end;
  }

  .modal-overlay .modal-content,
  .modal-box,
  .tev-modal__panel,
  .tev-modal__panel--wide,
  .tev-payment-limit-modal__box,
  .tev-quote-modal__panel {
    width: 100%;
    max-width: 100%;
    margin: 0;
    max-height: 92vh;
    overflow-y: auto;
    border-radius: 12px 12px 0 0;
    box-sizing: border-box;
  }

  .tev-quote-footer,
  .tev-detail-actions {
    position: sticky;
    bottom: 0;
    background: #fff;
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  /* Sticky header — avoid covering content */
  .tev-subnav,
  .tev-mp-header,
  .tev-mp-hero-band,
  .tev-seo-landing__header {
    position: sticky;
    top: 0;
    z-index: 50;
  }

  /* News ticker: keep marquee track from expanding page width */
  .news-ticker-section {
    width: 100%;
    max-width: 100%;
    overflow: hidden;
  }

  .news-track,
  #news-ticker-track {
    max-width: none;
  }

  /* Product detail nav — actions drop to second row on narrow screens */
  body.tev-product-detail-page .tev-mp-nav,
  body.tev-product-detail-page .tev-pd-nav {
    flex-wrap: wrap;
    gap: 0.4rem;
    min-width: 0;
    max-width: 100%;
  }

  body.tev-product-detail-page .tev-mp-nav__titles {
    flex: 1 1 auto;
    min-width: 0;
  }

  body.tev-product-detail-page .tev-pd-nav__actions,
  body.tev-product-detail-page .tev-mp-nav__actions {
    flex: 1 1 100%;
    flex-shrink: 1;
    flex-wrap: wrap;
    justify-content: flex-end;
    margin-left: 0;
    max-width: 100%;
    min-width: 0;
    gap: 0.35rem;
    box-sizing: border-box;
  }

  body.tev-product-detail-page .tev-pd-nav-login {
    white-space: nowrap;
    font-size: 0.62rem;
    padding: 0.3rem 0.5rem;
    box-sizing: border-box;
  }

  /* SEO home charger CTAs — fit inside padded column */
  .tev-home-charger-body__ctas {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
    padding-left: 0;
    padding-right: 0;
  }

  .tev-home-charger-body__cta {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .tev-home-charger-body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
  }

  .tev-home-charger-body__inner {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    padding-left: clamp(12px, 4vw, 16px);
    padding-right: clamp(12px, 4vw, 16px);
  }

  .tev-home-charger-body__table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-width: 100%;
  }

  /* Floating widgets — safe area */
  body:has(.tev-floating-comm) main,
  body:has(.tev-floating-comm) .tev-mp-main,
  body:has(.tev-floating-comm) .tev-cart-main {
    padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
  }

  .tev-floating-comm,
  .floating-whatsapp,
  .floating-ai-chat {
    bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
    right: calc(0.75rem + env(safe-area-inset-right, 0px));
  }

  /* Long text */
  h1, h2, h3, h4, p, li, td, th, span, a {
    overflow-wrap: break-word;
  }

  .tev-mp-card__title,
  .tev-pd-title,
  .product-title {
    overflow-wrap: anywhere;
  }

  /* —— Premium product cards: equal height, no stretch —— */
  .tev-mp-grid,
  #productGrid,
  #vendor-grid {
    align-items: stretch;
  }

  .tev-mp-card,
  .tev-mp-card--premium {
    display: flex;
    flex-direction: column;
    height: 100%;
    min-width: 0;
    max-width: 100%;
    box-sizing: border-box;
  }

  .tev-mp-card__body {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
  }

  .tev-mp-card__actions {
    margin-top: auto;
  }

  .tev-mp-card__img,
  .tev-mp-card__gallery,
  .tev-mp-card--premium .tev-mp-card__img {
    width: 100%;
    max-width: 100%;
    aspect-ratio: 4 / 3;
    overflow: hidden;
  }

  .tev-mp-card__img img,
  .tev-mp-card__gallery img,
  .tev-mp-card__slide img,
  .tev-product-img,
  .tev-mp-card--premium .tev-mp-card__img img {
    width: 100%;
    height: 100%;
    max-width: 100%;
    object-fit: contain;
    object-position: center;
  }

  .tev-mp-card__price-block {
    min-width: 0;
  }

  .tev-mp-card__price,
  .tev-mp-card__mrp {
    overflow-wrap: anywhere;
  }

  /* Home marketplace featured cards */
  .tev-hm-card,
  .tev-hm-featured__card,
  .tev-hm-charger-card,
  .tev-hm-vehicle-card {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }

  .tev-hm-card img,
  .tev-hm-featured__card img,
  .tev-hm-charger-card img,
  .tev-hm-vehicle-card img {
    max-width: 100%;
    height: auto;
    object-fit: contain;
  }

  /* Forms — stack & touch */
  form .form-row,
  form .tev-form-row,
  .tev-auth-form .form-group,
  .tev-checkout-details-grid,
  .tev-amz-form-grid,
  .billing-grid,
  .address-grid {
    grid-template-columns: 1fr;
    display: grid;
    gap: 0.75rem;
  }

  label,
  .tev-label {
    font-size: max(0.875rem, 14px);
  }

  /* Dashboard side menus collapse to top stack */
  .tev-admin-shell,
  .tev-assoc-app,
  .tev-cpo-layout {
    grid-template-columns: 1fr;
  }

  .tev-admin-sidebar,
  .tev-assoc-sidebar,
  .sidebar.admin-sidebar {
    width: 100%;
    max-width: 100%;
    position: relative;
  }

  /* Charts / KPI cards */
  .kpi-grid,
  .stats-grid,
  .dashboard-cards,
  .tev-cpo-kpi-grid,
  .tev-assoc-kpi-grid,
  .overview-cards {
    grid-template-columns: 1fr;
    gap: 0.75rem;
  }
}

/* —— Large mobile (481px–767px): 2-col product grids where space allows —— */
@media (min-width: 481px) and (max-width: 767px) {
  .tev-mp-grid,
  #productGrid,
  #vendor-grid,
  .products-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
  }

  .tev-mp-card__actions {
    flex-direction: column;
  }

  body.tev-home-page .card-grid,
  body.tev-home-page .charger-grid,
  .tev-hm-featured__grid,
  .tev-seo-category-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .kpi-grid,
  .tev-cpo-kpi-grid,
  .tev-assoc-kpi-grid,
  .overview-cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* —— Small phones (≤480px): single column, compact chrome —— */
@media (max-width: 480px) {
  .tev-mp-grid,
  #productGrid,
  #vendor-grid,
  .products-grid,
  body.tev-home-page .card-grid,
  body.tev-home-page .charger-grid,
  .tev-hm-featured__grid {
    grid-template-columns: 1fr;
  }

  .tev-mp-nav__titles h1,
  .login-logo,
  .brand {
    font-size: clamp(0.95rem, 4.5vw, 1.15rem);
  }

  .tev-mp-header .tev-mp-btn span:not(.icon),
  .tev-mp-cart-btn .label {
    /* keep icons; labels may wrap via existing marketplace rules */
    max-width: 100%;
  }

  .tev-home-footer__grid,
  .footer-grid,
  .tev-seo-landing__grid {
    grid-template-columns: 1fr;
  }
}
