/* =========================================
   Layout & responsive grid
   ========================================= */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background: rgba(255, 255, 255, 0.96);
  -webkit-backdrop-filter: saturate(180%) blur(18px);
  backdrop-filter: saturate(180%) blur(18px);
  border-bottom: 1px solid var(--color-border);
}

@supports ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .site-header { background: rgba(255, 255, 255, 0.76); }
}

.drawer-backdrop {
  z-index: 90;
}

.cart-backdrop {
  z-index: 110;
}

.cart-panel {
  z-index: 120;
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 100%;
}

.header-leading {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: var(--space-sm);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex: 0 0 auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-weight: 700;
  font-size: 1.125rem;
  letter-spacing: -0.02em;
  min-width: 0;
  white-space: nowrap;
}

.brand-logo {
  width: auto;
  height: 40px;
  object-fit: contain;
}

.main {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-xl);
  padding-top: var(--space-xl);
  padding-bottom: var(--space-2xl);
}

.config-stage {
  min-width: 0;
}

body[data-selection-view="none"] .main {
  grid-template-columns: minmax(0, 1fr);
}

body[data-selection-view^="catalog:"] .config-stage,
body[data-selection-view="none"] .config-stage {
  max-width: none;
}

body:not([data-selection-view="device"]) [data-device-content] {
  display: none !important;
}

.stage-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-lg);
  margin-bottom: var(--space-xl);
}

.stage-heading { min-width: 0; }
body[data-purchase-mode="kits"] :is(#preview-area, .device-overview, #color-section, #motor-section, #voltage-section, #channel-section, #config-section, #summary-panel, #summary-toggle) { display: none !important; }
body:not([data-purchase-mode="kits"]) #standalone-kit-section,
body:not([data-purchase-mode="kits"]) #kit-summary-panel { display: none !important; }
body:not([data-selection-view="device"]) #kit-summary-panel { display: none !important; }
#kit-summary-panel { display: none; }
body[data-purchase-mode="kits"] #kit-summary-panel { display: block; }
@media (max-width: 1023px) {
  body[data-purchase-mode="kits"] #kit-summary-panel:not(.open) { display: none !important; }
}
@media (max-width: 600px) { .stage-header { flex-direction: column-reverse; align-items: stretch; } }
.stage-catalog-toggle { flex: 0 0 auto; margin-top: 2px; white-space: nowrap; }

.page-title {
  font-size: clamp(1.75rem, 4vw, 2.5rem);
  font-weight: 800;
  line-height: 1.2;
  margin-bottom: var(--space-sm);
}

.page-subtitle {
  color: var(--color-text-secondary);
  font-size: 1rem;
}

@media (max-width: 640px) {
  .stage-header { gap: var(--space-md); }
  .stage-catalog-toggle { padding-inline: var(--space-sm); }
}

.preview-area {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-xl);
  background: linear-gradient(135deg, #eef0f4 0%, #e2e6ec 100%);
  margin-bottom: var(--space-xl);
  aspect-ratio: 16 / 9;
  max-height: 520px;
}

.gallery-viewport {
  position: relative;
  width: 100%;
  height: 100%;
  touch-action: pan-y;
}

.gallery-viewport:focus-visible { outline: 3px solid #111827; outline-offset: -5px; box-shadow: inset 0 0 0 7px #fff; }

.gallery-track {
  display: flex;
  height: 100%;
  transition: transform var(--transition-base);
}

.gallery-slide {
  flex: 0 0 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.gallery-slide img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.gallery-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.9);
  border: none;
  color: var(--color-text);
  font-size: 1.75rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 10;
  opacity: 0;
  transition: opacity var(--transition-fast), background var(--transition-fast);
  padding-bottom: 4px;
}

.preview-area:hover .gallery-nav,
.gallery-viewport:focus-within .gallery-nav {
  opacity: 1;
}

.gallery-nav:hover {
  background: #fff;
}

.gallery-prev { left: var(--space-md); }
.gallery-next { right: var(--space-md); }

.gallery-dots {
  position: absolute;
  bottom: var(--space-md);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: var(--space-sm);
  z-index: 10;
}

.gallery-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.6);
  cursor: pointer;
  transition: transform var(--transition-fast), background var(--transition-fast);
}

.gallery-dot.active {
  background: #fff;
  transform: scale(1.25);
}

.preview-info {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: var(--space-xl);
  background: linear-gradient(to top, rgba(0, 0, 0, 0.65), transparent);
  color: #fff;
}

.preview-info h2 {
  font-size: clamp(1.5rem, 3vw, 2rem);
  font-weight: 700;
  margin-bottom: var(--space-xs);
}

.preview-info p {
  opacity: 0.9;
  max-width: 600px;
}

.category-tabs .tab-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.category-tabs .category-selected-count {
  flex-shrink: 0;
  margin-left: 0;
}

.category-tabs .category-selected-count.is-empty {
  background: var(--color-text-secondary);
}

.category-tabs {
  position: static;
  top: auto;
  z-index: 80;
  display: flex;
  gap: var(--space-sm);
  margin-bottom: 0;
  overflow-x: auto;
  padding: 0 0 var(--space-sm);
  border-bottom: 1px solid var(--color-border);
  background: var(--color-bg);
  overscroll-behavior-x: contain;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border-strong) transparent;
}

.category-tabs::-webkit-scrollbar {
  height: 7px;
}

.category-tabs::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: var(--color-border-strong);
}

.config-section {
  position: relative;
}

.config-sticky-header {
  position: sticky;
  top: var(--header-height);
  z-index: 80;
  background: var(--color-bg);
  padding-top: var(--space-sm);
}

.config-sticky-header .spec-chips {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height 0.2s ease, opacity 0.2s ease, margin 0.2s ease;
  margin-bottom: 0;
}

.config-sticky-header.is-sticky .spec-chips {
  max-height: 64px;
  opacity: 1;
  flex-wrap: nowrap;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: thin;
  padding: 2px 0 4px;
  margin-bottom: var(--space-sm);
}
.config-sticky-header.is-sticky .spec-chip { flex: 0 0 auto; }

.options-panel {
  min-height: 200px;
  padding-top: var(--space-sm);
}

.summary-panel {
  position: relative;
}

.catalog-summary-panel {
  position: relative;
  min-width: 0;
}

.catalog-summary-panel[hidden] {
  display: none !important;
}

.summary-sticky {
  position: sticky;
  top: calc(var(--header-height) + var(--space-lg));
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  box-shadow: var(--shadow-md);
  border: 1px solid var(--color-border);
}

.site-footer {
  padding: var(--space-2xl) 0 var(--space-lg);
  background: #20262e;
  color: #c3cbd5;
  font-size: 0.875rem;
  text-align: left;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.site-footer p { margin: 0; }
.site-footer-main { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--space-xl); align-items: start; padding-bottom: var(--space-xl); }
.site-footer-brand { display: grid; gap: var(--space-md); min-width: 0; }
.site-footer-logo { display: block; width: 140px; height: auto; filter: brightness(0) invert(1); }
.site-footer .site-footer-company { font-size: 16px; font-weight: 600; color: #f3f5f7; }
.site-footer-sales { display: grid; gap: var(--space-sm); }
#site-footer-contact { font-weight: 700; }
.site-footer-sales > a { color: #f3f5f7; font-size: 16px; }
.site-footer-bottom { display: flex; flex-wrap: wrap; justify-content: space-between; gap: var(--space-sm) var(--space-xl); border-top: 1px solid #46505d; padding-top: var(--space-lg); }
.site-footer a { color: inherit; text-underline-offset: 3px; }
.site-footer a:hover { color: #fff; }
.site-footer a:focus-visible { outline: 2px solid #f3f5f7; outline-offset: 4px; border-radius: 2px; }
@media (max-width: 639px) {
  .site-footer-main { grid-template-columns: minmax(0, 1fr); }
  .site-footer-bottom { flex-direction: column; }
}

@media (max-width: 360px) {
  .site-header .header-inner { padding-inline: 10px; }
  .header-leading, .header-actions { gap: 4px; }
  .site-header .brand-logo { width: 60px; height: auto; flex: 0 0 auto; }
}
@media (max-width: 1023px) {
  body[data-selection-view^="catalog:"] .site-footer,
  body[data-selection-view="device"] .site-footer { padding-bottom: calc(var(--space-lg) + 80px + env(safe-area-inset-bottom)); }
}

/* Desktop layout */
@media (min-width: 1024px) {
  .main {
    grid-template-columns: 1fr var(--summary-width);
    gap: var(--space-2xl);
  }

  .summary-panel {
    order: 2;
  }

  .catalog-summary-panel {
    order: 2;
  }

  .config-stage {
    order: 1;
  }
}

/* Tablet & mobile: account for fixed summary toggle */
@media (max-width: 1023px) {
  .main {
    padding-bottom: calc(var(--space-2xl) + 60px);
  }
}

/* Large screens */
@media (min-width: 1440px) {
  .main {
    grid-template-columns: 1fr 420px;
  }
}

/* Device selector */
.device-selector-bar {
  grid-column: 1 / -1;
  margin-bottom: 0;
  padding-bottom: var(--space-lg);
  border-bottom: 1px solid var(--color-border);
}

.device-selector-bar label {
  flex: 0 0 auto;
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.4;
}

.device-selector-row {
  display: flex;
  align-items: center;
  gap: var(--space-md);
}

@media (max-width: 899px) {
  .header-actions { gap: 6px; }
  .brand-name { display: none; }

  #cart-toggle,
  .account-toggle {
    width: 42px;
    height: 42px;
    padding: 0;
    border-radius: 50%;
  }

  #cart-toggle { position: relative; }
  #cart-toggle .cart-label,
  .account-toggle span { display: none; }
  #cart-toggle .cart-badge { position: absolute; top: -5px; right: -5px; }
}

@media (max-width: 639px) {
  .device-selector-row {
    align-items: stretch;
    flex-direction: column;
    gap: var(--space-sm);
  }
}

/* Spec sections */
.spec-section {
  margin-bottom: var(--space-md);
}

.spec-section-header {
  margin-bottom: var(--space-sm);
}

.spec-section-header h3 {
  font-size: 1.25rem;
  font-weight: 700;
}

.config-section {
  margin-bottom: var(--space-md);
}

.config-section > .spec-section-header {
  margin-bottom: 0;
}

.device-overview {
  margin: 0 0 var(--space-xl);
  padding: var(--space-lg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-surface);
}
.device-overview summary { display:flex; align-items:center; justify-content:space-between; gap:16px; margin:-8px; padding:8px; border-radius:var(--radius-sm); cursor:pointer; list-style:none; }
.device-overview summary:hover { background:var(--color-bg); }
.device-overview summary:focus-visible { outline:3px solid var(--color-accent-dark); outline-offset:3px; }
.device-overview summary::-webkit-details-marker { display:none; }
.overview-toggle-label { flex:0 0 auto; min-width:64px; padding:7px 14px; border:1px solid var(--color-border); border-radius:var(--radius-md); color:var(--color-text-secondary); background:var(--color-surface); font-size:13px; font-weight:600; line-height:1; text-align:center; transition:color var(--transition-fast),border-color var(--transition-fast),background-color var(--transition-fast); }
.device-overview summary:hover .overview-toggle-label { border-color:var(--color-accent-dark); color:var(--color-accent-dark); background:var(--color-accent-light); }
.device-overview .overview-grid { padding-top:16px; }
.device-overview[open] summary { margin-bottom:0; padding-bottom:14px; border-bottom:1px solid var(--color-border); border-radius:var(--radius-lg) var(--radius-lg) 0 0; }
.overview-grid{display:grid;grid-template-columns:minmax(0,1fr) minmax(320px,1fr);gap:24px;align-items:start}.overview-grid h3{font-size:14px;margin:0 0 8px}.overview-specifications table{width:100%;border-collapse:collapse}.overview-specifications th,.overview-specifications td{padding:8px 10px;border-bottom:1px solid var(--line,#e5e7eb);text-align:left;vertical-align:top;overflow-wrap:anywhere}.overview-specifications th{font-weight:600;width:38%}
@media (max-width: 900px){.overview-grid{grid-template-columns:1fr;gap:16px}.overview-specifications{overflow-x:auto;overscroll-behavior:contain}.overview-specifications table{min-width:280px}}
@media (max-width: 639px){.overview-specifications{overflow-x:visible}.overview-specifications table{min-width:0;table-layout:fixed}}

.device-overview h2 {
  margin: 0;
  font-size: 1.125rem;
  line-height: 1.35;
}

.page-desc {
  margin: 0;
  color: var(--color-text-secondary);
  font-size: 1rem;
  line-height: 1.7;
  white-space: pre-line;
  overflow-wrap: anywhere;
}

@media (max-width: 639px) {
  .gallery-nav {
    display: none;
  }
}
