/**
 * Thunder EV — Global responsive layout (13" laptop + mobile)
 * Load last on key pages. Prevents horizontal page scroll.
 */

html,
body {
  max-width: 100%;
  overflow-x: hidden;
  margin: 0;
  padding: 0;
}

/* 100vw includes scrollbar width and can bleed past the viewport */
#bg-canvas,
.modal-overlay {
  width: 100%;
  max-width: 100%;
}

/* —— Layout shells —— */
body.tev-home-page,
body.tev-marketplace-page,
body.tev-cart-page,
body.tev-customer-portal,
body.associate-portal-page,
body.tev-admin-body {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

.marketplace-layout,
.products-column,
.tab-panels,
.tev-mp-main,
.tev-cart-main,
.tev-cpo-main,
.tev-assoc-app,
.tev-assoc-main,
.tev-assoc-content,
.tev-admin-shell,
.tev-admin-workspace,
.tev-admin-main,
.main-content.tev-admin-main {
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

/* —— Pinned marketplace sidebar: fit content in remaining viewport —— */
body.tev-sidebar-pinned {
  --tev-sidebar-w: min(280px, 88vw);
  overflow-x: hidden;
}

body.tev-sidebar-pinned .tev-mp-header,
body.tev-sidebar-pinned .tev-mp-main,
body.tev-sidebar-pinned #tev-shared-footer,
body.tev-sidebar-pinned .tev-mp-search-dock,
body.tev-sidebar-pinned .tev-cpo-demo-banner,
body.tev-sidebar-pinned .tev-cpo-loading {
  margin-left: var(--tev-sidebar-w);
  width: calc(100% - var(--tev-sidebar-w));
  max-width: calc(100% - var(--tev-sidebar-w));
  min-width: 0;
  box-sizing: border-box;
}

/* Homepage: sidebar in grid, not pinned offset */
body.tev-home-page .marketplace-layout {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  overflow-x: hidden;
}

body.tev-home-page .products-column,
body.tev-home-page .sidebar-column {
  min-width: 0;
}

@media (max-width: 850px) {
  body.tev-home-page .marketplace-layout {
    grid-template-columns: 1fr;
  }
}

/* —— Homepage header / hero —— */
body.tev-home-page .hero {
  overflow-x: hidden;
  max-width: 100%;
}

body.tev-home-page .hero .nav {
  flex-wrap: wrap;
  min-width: 0;
}

body.tev-home-page .hero-text h1.tev-tagline-blue,
body.tev-home-page .hero-text h1#tev-hero-heading {
  margin-top: 0 !important;
}

body.tev-home-page .tev-ticker-strip,
body.tev-home-page .partners-ticker {
  overflow: hidden;
  max-width: 100%;
  min-width: 0;
}

body.tev-home-page .ticker-track {
  max-width: none;
}

body.tev-home-page .tickers-container.tev-tickers-full {
  overflow: hidden;
  max-width: min(650px, 100%);
}

/* —— Marketplace nav —— */
body.tev-marketplace-page .tev-mp-nav {
  flex-wrap: wrap;
  min-width: 0;
}

body.tev-marketplace-page .tev-mp-nav__titles {
  flex-wrap: wrap;
}

@media (max-width: 1280px) {
  body.tev-marketplace-page .tev-mp-nav__titles h1,
  body.tev-marketplace-page .tev-mp-nav__titles p {
    white-space: normal;
  }
}

/* —— Homepage footer (4-col min widths overflow on ~1280px laptops) —— */
@media (max-width: 1366px) {
  body.tev-home-page .tev-home-footer__grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
    gap: 28px clamp(16px, 2.5vw, 32px);
  }

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

/* —— Tables scroll inside their container, not the page —— */
.tev-table-scroll,
.table-scroll,
.table-container,
.tev-responsive-table-wrap,
.tev-assoc-products-table-wrap,
.tev-cpo-table-wrap,
.tev-scroll-x {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

.tev-table-scroll table,
.table-scroll table,
.table-container table,
.tev-responsive-table-wrap table {
  width: 100%;
  min-width: min(100%, 640px);
}

/* Admin / portal panels: contain wide tables */
.tev-admin-main :is(section, .panel, .card, .dashboard-card, .tev-admin-section, .tev-assoc-card):not(.no-table-scroll) {
  max-width: 100%;
}

.tev-admin-main section:has(> table),
.tev-assoc-card:has(> table),
.tev-assoc-card:has(> .tev-assoc-orders-table),
.tev-cpo-card:has(table) {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
}

/* —— Admin toolbars / filter rows —— */
.tev-admin-topbar .tev-dash-toolbar,
.tev-dash-toolbar,
.tev-admin-toolbar,
.tev-filter-row,
.tev-assoc-toolbar {
  flex-wrap: wrap;
}

.tev-admin-topbar .tev-dash-toolbar {
  min-width: 0;
  flex: 1 1 auto;
}

.tev-admin-main input.form-control[style*="min-width"],
.tev-admin-main select.form-control[style*="min-width"],
.tev-admin-main .form-group[style*="min-width"] {
  min-width: 0 !important;
  max-width: 100%;
  flex: 1 1 140px;
}

/* —— Cart page —— */
body.tev-cart-page .tev-subnav,
body.tev-cart-page .tev-cart-main {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body.tev-cart-page .tev-cart-nav-title {
  min-width: 0;
}

/* —— Customer portal —— */
body.tev-customer-portal .tev-cpo-panel,
body.tev-customer-portal .tev-cpo-card {
  max-width: 100%;
  min-width: 0;
}

/* —— Associate portal —— */
html.associate-portal-page {
  max-width: 100%;
  overflow-x: hidden;
}

.tev-assoc-app {
  max-width: 100%;
  overflow-x: hidden;
}

@media (max-width: 1024px) {
  .tev-admin-shell,
  .tev-admin-workspace,
  .tev-admin-main,
  .tev-admin-content,
  .view-tab,
  .glass-panel {
    max-width: 100%;
    min-width: 0;
    overflow-x: hidden;
  }

  .tev-admin-main .table-container,
  .glass-panel .table-container {
    max-width: 100%;
  }

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

  .tev-admin-main [style*="grid-template-columns: 1fr 1fr 1fr"],
  .tev-admin-main [style*="grid-template-columns:1fr 1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  .tev-admin-main [style*="grid-template-columns: 1fr 1fr"],
  .tev-admin-main [style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }
}

/* Customer + associate hamburger visibility @ tablet */
@media (max-width: 1024px) {
  .tev-cpo-menu-btn,
  .tev-assoc-menu-btn,
  .tev-admin-menu-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }
}

/* —— Responsive grids —— */
.tev-admin-main .stats-grid,
.tev-biz-kpi-grid,
.tev-assoc-kpi-grid {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 140px), 1fr));
}

@media (max-width: 900px) {
  .footer-grid:not(.tev-home-footer__grid) {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 148px), 1fr));
    flex-wrap: unset;
    overflow-x: hidden;
  }
}

/* —— Product grids with pinned sidebar —— */
@media (max-width: 1280px) {
  body.tev-sidebar-pinned .tev-mp-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 220px), 1fr));
  }

  body.tev-sidebar-pinned .tev-quote-layout {
    grid-template-columns: 1fr;
  }

  body.tev-sidebar-pinned .tev-quote-col + .tev-quote-col {
    border-left: none;
    border-top: 1px solid #e2e8f0;
  }
}

/* —— Mobile —— */
@media (max-width: 768px) {
  body.tev-sidebar-pinned .tev-mp-header,
  body.tev-sidebar-pinned .tev-mp-main,
  body.tev-sidebar-pinned #tev-shared-footer,
  body.tev-sidebar-pinned .tev-mp-search-dock,
  body.tev-sidebar-pinned .tev-cpo-demo-banner,
  body.tev-sidebar-pinned .tev-cpo-loading {
    margin-left: 0;
    width: 100%;
    max-width: 100%;
  }

  body.tev-marketplace-page .tev-mp-nav__actions {
    flex-wrap: wrap;
  }
}

@media (max-width: 520px) {
  body.tev-home-page .nav-ctas-right {
    flex-wrap: wrap;
  }

  .tev-assoc-greeting {
    display: none;
  }
}

/* —— Media / embeds —— */
img,
video,
iframe,
svg:not(.logo-icon svg) {
  max-width: 100%;
  height: auto;
}

/* —— 13" laptop (1280–1440px): nav + layout —— */
@media (max-width: 1440px) {
  body.tev-home-page .tev-home-footer__links-grid,
  body.tev-home-page .tev-home-footer__legal-grid {
    grid-template-columns: 1fr;
  }

  body.tev-home-page .tev-home-footer .footer-links a,
  body.tev-home-page .tev-home-footer .footer-links li {
    white-space: normal;
  }
}

@media (max-width: 1280px) {
  body.tev-home-page .hero .nav {
    flex-wrap: wrap;
    row-gap: 0.65rem;
  }

  body.tev-home-page .nav-ctas-right {
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 0.45rem;
    margin-left: auto;
  }

  body.tev-home-page .marketplace-layout {
    grid-template-columns: minmax(0, 200px) minmax(0, 1fr);
  }

  body.tev-marketplace-page .tev-mp-nav__titles h1 {
    font-size: clamp(1rem, 2.5vw, 1.35rem);
  }

  .stats-row {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)) !important;
    gap: clamp(0.75rem, 2vw, 1.5rem);
  }

  .glass-panel {
    padding: clamp(1rem, 2vw, 2.2rem);
  }
}

@media (max-width: 1024px) {
  body.tev-home-page .marketplace-layout {
    grid-template-columns: 1fr;
  }

  body.tev-home-page .sidebar-column {
    max-width: 100%;
  }
}

/* —— Admin dashboard: contain panels + filters —— */
.tev-admin-workspace,
.tev-admin-content,
.tev-admin-main .view-tab {
  max-width: 100%;
  min-width: 0;
  overflow-x: hidden;
}

.tev-admin-main .glass-panel,
.tev-admin-main .tev-catalog-import {
  max-width: 100%;
  box-sizing: border-box;
}

.tev-admin-topbar {
  max-width: 100%;
  min-width: 0;
}

.tev-admin-topbar-actions {
  flex-wrap: wrap;
}

.tev-crm-filters {
  max-width: 100%;
}

.tev-crm-filters > div {
  flex: 1 1 120px;
  min-width: 0;
  max-width: 100%;
}

.tev-crm-filters input.form-control,
.tev-crm-filters select.form-control,
.tev-admin-main [style*="min-width"] input.form-control,
.tev-admin-main [style*="min-width"] select.form-control {
  width: 100%;
  min-width: 0 !important;
  max-width: 100%;
  box-sizing: border-box;
}

.tev-admin-main .form-group[style*="min-width"],
.tev-admin-main div[style*="min-width"] > .form-control {
  min-width: 0 !important;
  max-width: 100%;
}

.tev-dash-search {
  min-width: 0;
  flex: 1 1 140px;
  max-width: 100%;
}

/* Off-screen drawers/modals must not widen the page (100vw includes scrollbar) */
.tev-crm-drawer:not(.open),
.tev-mp-filter-drawer:not(.open) {
  pointer-events: none;
  visibility: hidden;
}

.tev-crm-drawer,
.tev-crm-drawer.open {
  max-width: 100%;
}

/* Bare tables inside panels → scroll in place */
.glass-panel:not(.no-table-scroll):has(> table),
.view-tab.active .glass-panel:not(.no-table-scroll):has(table) {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-x: contain;
  max-width: 100%;
}

.glass-panel:not(.no-table-scroll) > table,
.view-tab.active .glass-panel table {
  width: 100%;
  min-width: min(100%, 640px);
}

/* —— Cart / checkout —— */
body.tev-cart-page .tev-cart-layout,
body.tev-cart-page .tev-cart-grid,
body.tev-cart-page .tev-checkout-layout {
  max-width: 100%;
  min-width: 0;
}

body.tev-cart-page .tev-subnav .brand {
  flex-wrap: wrap;
  min-width: 0;
}

/* —— Customer portal panels —— */
body.tev-customer-portal .tev-cpo-layout,
body.tev-customer-portal .tev-cpo-grid {
  max-width: 100%;
  min-width: 0;
}

/* —— Associate portal tables —— */
.tev-assoc-main .tev-assoc-card {
  max-width: 100%;
  min-width: 0;
}

/* —— Product list filter / quote bars —— */
body.tev-marketplace-page .tev-mp-filters,
body.tev-marketplace-page .tev-mp-toolbar,
body.tev-marketplace-page .tev-quote-layout {
  max-width: 100%;
  min-width: 0;
}

/* —— Mobile admin topbar —— */
@media (max-width: 480px) {
  .tev-admin-topbar {
    padding-left: 0.65rem;
    padding-right: 0.65rem;
    gap: 0.5rem;
  }

  .tev-admin-profile-chip {
    max-width: min(120px, 38vw);
  }

  .tev-admin-page-header h1,
  .dashboard-title-bar h1 {
    font-size: 1.25rem;
    word-break: break-word;
  }

  .glass-panel-header {
    flex-wrap: wrap;
    gap: 0.65rem;
  }
}

/* —— Mobile audit: text wrap + viewport containment —— */
body,
p,
h1, h2, h3, h4, h5, h6,
td, th, li, label, span, a {
  overflow-wrap: break-word;
  word-wrap: break-word;
}

pre, code {
  overflow-x: auto;
  max-width: 100%;
}

/* Product cards: stack on narrow viewports */
@media (max-width: 1024px) {
  .tev-mp-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 240px), 1fr));
  }
}

@media (max-width: 640px) {
  .tev-mp-grid {
    grid-template-columns: 1fr;
  }
}

/* Footer: 2-col tablet, 1-col phone */
@media (max-width: 1024px) {
  body.tev-home-page .tev-home-footer__grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  body.tev-home-page .tev-home-footer__brand {
    grid-column: 1 / -1;
  }
}

@media (max-width: 640px) {
  body.tev-home-page .tev-home-footer__grid {
    grid-template-columns: 1fr;
  }

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

/* Floating comm / AI widgets: safe area + content clearance */
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,
body:has(.tev-floating-comm) .tev-assoc-main,
body:has(#tev-floating-comm) main {
  padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
}

body:has(.floating-ai-search-dock) main,
body:has(.floating-ai-search-dock) .tab-panels {
  padding-bottom: calc(6rem + env(safe-area-inset-bottom, 0px));
}

.tev-floating-comm {
  bottom: var(--tev-floating-safe-bottom, calc(1.25rem + env(safe-area-inset-bottom, 0px)));
  right: calc(1.25rem + env(safe-area-inset-right, 0px));
  pointer-events: none;
}

.tev-floating-comm__item,
.tev-floating-comm__btn {
  pointer-events: auto;
}

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

.floating-ai-search-dock {
  bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
}

@media (max-width: 640px) {
  .tev-floating-comm {
    bottom: calc(0.85rem + env(safe-area-inset-bottom, 0px));
    right: calc(0.85rem + env(safe-area-inset-right, 0px));
  }

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

  .floating-ai-search-dock {
    bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
    right: calc(0.85rem + env(safe-area-inset-right, 0px));
  }
}

/* Associate portal @ tablet */
@media (max-width: 1024px) {
  .tev-assoc-main {
    padding: 0.85rem 1rem 1.5rem;
  }

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

@media (max-width: 640px) {
  .tev-assoc-kpi-grid {
    grid-template-columns: 1fr;
  }
}

/* Customer portal @ tablet */
@media (max-width: 1024px) {
  body.tev-customer-portal .tev-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

@media (max-width: 640px) {
  body.tev-customer-portal .tev-kpi-grid {
    grid-template-columns: 1fr;
  }
}

/* Compliance / legal / product detail / business onboarding */
body.tev-compliance-page,
body.tev-subpage {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body.tev-onboard,
body.tev-onboard--business {
  width: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

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

.tev-compliance,
.tev-compliance article,
.tev-subnav,
#detail {
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

.tev-compliance-nav {
  max-width: 100%;
}

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

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

#detail img,
.tev-prod-hero,
.tev-datasheet-viewer {
  max-width: 100%;
}

.tev-prod-gallery {
  flex-wrap: wrap;
}

.tev-about-carousel-wrap,
.tev-about-carousel {
  max-width: 100%;
  overflow-x: hidden;
}

#tev-shared-footer {
  max-width: 100%;
  overflow-x: hidden;
  box-sizing: border-box;
}

.tev-india-strip {
  overflow-wrap: anywhere;
  word-break: break-word;
  max-width: 100%;
}

.tev-india-strip a {
  overflow-wrap: anywhere;
}

.tev-footer-strip,
.tev-footer-strip__inner {
  max-width: 100%;
  min-width: 0;
}

[data-tev-comm-channels] {
  max-width: 100%;
  min-width: 0;
  overflow-x: hidden;
  box-sizing: border-box;
}

[data-tev-comm-channels] .tev-comm-channels {
  max-width: 100%;
}
