/**
 * Thunder EV — Phase 1 Mobile Responsive
 * Desktop (1025px+): no rules in this file — existing layout unchanged.
 * Tablet: max-width 1024px — spacing/grid adjustments only.
 * Mobile: max-width 767px — single column, touch-friendly controls.
 */

/* —— Tablet (768px–1024px) —— */
@media (max-width: 1024px) {
  html,
  body {
    max-width: 100%;
    overflow-x: hidden;
  }

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

  /* Product grids */
  .tev-mp-grid,
  .products-grid,
  #productGrid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
    gap: clamp(0.65rem, 2vw, 1rem);
  }

  /* Cart / checkout */
  .tev-cart-grid,
  .tev-amz-checkout,
  body.tev-checkout-active .tev-cart-grid {
    grid-template-columns: 1fr !important;
  }

  .checkout-panel {
    position: static !important;
    top: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }

  .tev-checkout-details-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tev-amz-main,
  .tev-amz-layout {
    grid-template-columns: 1fr !important;
  }

  .tev-amz-sticky {
    position: static;
  }

  /* Dashboard tables */
  .table-responsive,
  .tev-table-scroll,
  .table-scroll,
  .table-container,
  .tev-responsive-table-wrap,
  .tev-assoc-products-table-wrap,
  .tev-cpo-table-wrap {
    display: block;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
  }

  .glass-panel:has(table),
  .tev-assoc-card:has(table),
  .tev-cpo-card:has(table) {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* SEO landing headers */
  .tev-seo-landing__header-inner {
    flex-wrap: wrap;
    gap: 0.65rem;
  }

  .tev-seo-landing__nav {
    width: 100%;
    justify-content: flex-start;
  }

  .tev-seo-landing__grid,
  .tev-seo-landing__grid--split {
    grid-template-columns: 1fr !important;
    gap: 1.25rem;
  }

  /* Planner wizard */
  #planner-panel.tev-planner-wizard-panel,
  .tev-planner-wizard-body {
    max-width: 100%;
    overflow-x: hidden;
  }

  .tev-planner-wizard-header {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  /* Product detail */
  .tev-detail-split {
    grid-template-columns: 1fr;
  }

  .tev-detail-split__media {
    border-right: none;
    border-bottom: 1px solid #e2e8f0;
  }

  /* Modals */
  .modal-overlay .modal-content,
  .modal-box,
  .tev-payment-limit-modal__box,
  .tev-vendor-order-modal__panel {
    max-width: min(96vw, 560px);
    max-height: min(92vh, 720px);
    overflow-y: auto;
  }
}

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

  img,
  video,
  iframe,
  svg:not(.logo-icon svg):not([data-tev-logo] svg) {
    max-width: 100%;
    height: auto;
  }

  /* Touch-friendly controls */
  button,
  .tev-btn,
  .cta-small,
  .tev-mp-cart-btn,
  .tev-cart-checkout-btn,
  .tev-cart-auth-btn,
  input[type="submit"],
  input[type="button"],
  .tev-seo-landing__btn {
    min-height: 44px;
  }

  input,
  select,
  textarea,
  .form-control {
    font-size: 16px; /* avoid iOS zoom on focus */
  }

  .checkout-panel input,
  .checkout-panel select,
  .checkout-panel textarea,
  .tev-form input,
  .tev-form select,
  .tev-form textarea,
  .tev-onboard input,
  .tev-onboard select,
  .tev-onboard textarea,
  .tev-auth-card input,
  .tev-auth-card select,
  .tev-auth-card textarea,
  .tev-seo-landing input,
  .tev-seo-landing select,
  .tev-seo-landing textarea,
  .tev-cart-promo input {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
  }

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

  body.tev-home-page .tab-panels,
  body.tev-home-page .products-column {
    padding-left: clamp(0.5rem, 3vw, 1rem);
    padding-right: clamp(0.5rem, 3vw, 1rem);
  }

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

  body.tev-home-page .footer-grid:not(.tev-home-footer__grid) {
    grid-template-columns: 1fr;
  }

  /* Category shortcut tiles (2-col override in responsive-mobile @ 481–767) */
  .tev-seo-category-cards {
    grid-template-columns: 1fr;
    gap: 0.35rem;
    margin-left: 0;
    margin-right: 0;
  }

  .tev-subpage-category-tiles {
    width: calc(100% - 1rem);
    margin-left: auto;
    margin-right: auto;
  }

  .tev-seo-category-card__title {
    font-size: 0.72rem;
  }

  .tev-seo-category-card__sub {
    font-size: 0.58rem;
  }

  /* Product list — leave cascade open for large-mobile 2-col in responsive-mobile.css */
  .tev-mp-grid,
  .products-grid,
  #productGrid {
    grid-template-columns: 1fr;
  }

  body.tev-marketplace-page .tev-mp-toolbar,
  body.tev-marketplace-page .tev-mp-filters {
    flex-direction: column;
    align-items: stretch;
  }

  body.tev-marketplace-page .tev-mp-search-dock {
    left: 0 !important;
    right: 0 !important;
    width: 100% !important;
    max-width: 100% !important;
  }

  /* Product detail */
  .tev-detail-split__info,
  .tev-pd-section {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
  }

  .tev-detail-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .tev-detail-actions .tev-mp-btn-cart,
  .tev-detail-actions .tev-pd-checkout-btn,
  .tev-detail-actions .tev-btn {
    width: 100%;
    flex: 1 1 auto;
    min-width: 0;
  }

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

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

  /* Cart */
  body.tev-cart-page .tev-subnav {
    flex-wrap: wrap;
    gap: 0.35rem;
    padding-left: 0.65rem;
    padding-right: 0.65rem;
  }

  body.tev-cart-page .tev-subnav__center {
    order: 3;
    flex: 1 1 100%;
    justify-content: flex-start;
    padding-left: 0;
  }

  body.tev-cart-page .tev-cart-nav-title__sub {
    display: none;
  }

  .tev-cart-grid {
    gap: 0;
  }

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

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

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

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

  .tev-cart-promo__row input,
  .tev-cart-promo__row button {
    width: 100%;
  }

  /* Checkout: stack Delivery, Billing, Contact, GST */
  .tev-checkout-details-grid {
    grid-template-columns: 1fr !important;
  }

  .tev-checkout-form-grid,
  .tev-form-row,
  .checkout-panel .form-row-2,
  .checkout-panel .form-row-3,
  .addr-grid,
  .addr-grid-3 {
    grid-template-columns: 1fr !important;
  }

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

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

  .cart-item {
    grid-template-columns: 64px 1fr;
  }

  .cart-item__aside {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
  }

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

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

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

  /* Vendor / associate portal (sidebar drawer handled in associate-portal.css) */
  .tev-assoc-kpi-grid {
    grid-template-columns: 1fr !important;
  }

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

  /* Admin dashboard (sidebar drawer handled in admin-layout.css) */
  .tev-admin-topbar {
    flex-wrap: wrap;
    gap: 0.5rem;
    padding-left: 0.65rem;
    padding-right: 0.65rem;
  }

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

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

  /* Login / onboarding */
  .tev-onboard__grid {
    grid-template-columns: 1fr !important;
  }

  .tev-onboard-hero {
    min-height: auto;
    padding: 1.5rem 1rem;
  }

  .tev-auth-panel,
  .tev-auth-card {
    max-width: 100%;
    padding-left: 1rem;
    padding-right: 1rem;
  }

  /* SEO landing pages */
  .tev-seo-landing__hero {
    padding: 1.5rem 1rem 1rem;
  }

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

  .tev-seo-landing__hero-actions .tev-seo-landing__btn {
    width: 100%;
    text-align: center;
    box-sizing: border-box;
  }

  .tev-seo-landing__nav {
    font-size: 0.72rem;
    gap: 0.25rem 0.5rem;
  }

  /* AI planner */
  .tev-planner-wizard-title h2 {
    font-size: 1.25rem;
  }

  .tev-planner-wizard-body {
    padding: 0.85rem;
  }

  .tev-planner-wizard-header__actions {
    width: 100%;
    justify-content: flex-start;
  }

  /* Modals & popups */
  .modal-overlay {
    padding: 0.75rem;
    align-items: flex-end;
  }

  .modal-overlay .modal-content,
  .modal-box,
  .tev-payment-limit-modal__box {
    width: 100%;
    max-width: 100%;
    margin: 0;
    border-radius: 12px 12px 0 0;
  }

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

  /* Sticky elements — avoid overlapping main content */
  .tev-subnav,
  .tev-mp-nav,
  .tev-seo-landing__header {
    position: sticky;
    top: 0;
    z-index: 50;
  }

  body:has(.tev-floating-comm) main,
  body:has(.tev-floating-comm) .tev-mp-main,
  body:has(.tev-floating-comm) .tev-cart-main,
  body:has(.tev-floating-comm) .tev-cpo-main {
    padding-bottom: calc(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));
  }

  /* PDF / proposal preview toolbar */
  .tpr-preview-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

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

  .tpr-preview-status {
    margin-left: 0;
    text-align: center;
  }

  #tprFrame {
    height: calc(100vh - 120px);
  }

  /* Compliance / legal */
  .tev-compliance,
  .tev-compliance article {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

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

/* Desktop lock: ensure hamburger hidden at 1025px+ (mobile-nav.css defaults) */
@media (min-width: 1025px) {
  .tev-nav-menu-btn,
  .tev-cpo-menu-btn,
  .tev-assoc-menu-btn,
  .tev-admin-menu-toggle {
    display: none !important;
  }
}
