/* ==========================================================================
   layout.css — App shell, header, sidebar panel, viewport
   MPP Fitment Studio
   ========================================================================== */

/* --------------------------------------------------------------------------
   App Shell
   -------------------------------------------------------------------------- */
.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */
.header {
  height: var(--header-height);
  background: var(--color-surface-1);
  border-bottom: 1px solid var(--color-border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5);
  flex-shrink: 0;
  z-index: 200;
}

.header__logo {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  text-decoration: none;
}

.header__logo:hover {
  text-decoration: none;
}

/* MPP diamond mark */
.logo-mark {
  width: 30px;
  height: 30px;
  background: var(--color-accent);
  clip-path: polygon(50% 0%, 100% 50%, 50% 100%, 0% 50%);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-mark__text {
  font-size: 8px;
  font-weight: 800;
  color: #fff;
  letter-spacing: 0.05em;
  margin-top: 1px;
}

.header__logo-img {
  height: 32px;
  width: auto;
  flex-shrink: 0;
  display: block;
}

.logo-wordmark {
  display: flex;
  flex-direction: column;
  gap: 0px;
}

.logo-wordmark__brand {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--color-text-primary);
  line-height: 1;
}

.logo-wordmark__product {
  font-size: 9px;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--color-accent);
  line-height: 1;
  margin-top: 3px;
}

/* Header right controls */
.header__controls {
  display: flex;
  align-items: center;
  gap: var(--space-2);
}

.header__unit-toggle {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  background: var(--color-surface-2);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  padding: 2px;
}

.unit-btn {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  background: transparent;
  border: none;
  border-radius: 2px;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast);
}

.unit-btn.active {
  background: var(--color-accent);
  color: #fff;
}

.header__admin-btn {
  padding: 6px 14px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--color-text-secondary);
  background: transparent;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}

.header__admin-btn:hover {
  border-color: var(--color-accent);
  color: var(--color-accent);
}

/* --------------------------------------------------------------------------
   Main content area (viewport + panel)
   -------------------------------------------------------------------------- */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* --------------------------------------------------------------------------
   3D Viewport
   -------------------------------------------------------------------------- */
.viewport {
  flex: 1;
  position: relative;
  background: var(--color-bg);
  overflow: hidden;
  cursor: grab;
}

.viewport:active {
  cursor: grabbing;
}

#canvas-3d {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* --- HUD overlays --- */
.viewport__hud {
  position: absolute;
  pointer-events: none;
}

/* Top-right: view controls + camera help */
.viewport__controls {
  top: var(--space-3);
  right: var(--space-3);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
}

.vp-btn-row {
  display: flex;
  gap: 6px;
}

.vp-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  background: rgba(255,255,255,0.75);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-size: 11px;
  font-family: var(--font-ui);
  color: var(--color-text-secondary);
  cursor: pointer;
  backdrop-filter: blur(4px);
  transition: color 0.2s, background 0.2s, opacity 0.2s, border-color 0.2s;
  pointer-events: all;
  opacity: 0.38;
}

.vp-btn svg {
  flex-shrink: 0;
}

.vp-btn--active {
  color: var(--color-text-primary);
  background: rgba(255,255,255,0.82);
  border-color: var(--color-border-strong);
  opacity: 1;
}

.vp-btn:hover {
  opacity: 1;
  background: rgba(255,255,255,0.95);
}

.vp-help {
  background: rgba(255,255,255,0.75);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.vp-help__row {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 10px;
  color: var(--color-text-muted);
  white-space: nowrap;
}

kbd {
  display: inline-block;
  padding: 1px 5px;
  background: var(--color-surface-3);
  border: 1px solid var(--color-border);
  border-radius: 3px;
  font-size: 10px;
  font-family: var(--font-ui);
  color: var(--color-text-secondary);
  line-height: 1.4;
}

.vp-help__mouse {
  font-style: italic;
  color: var(--color-text-secondary);
}
.viewport__view-label {
  top: var(--space-4);
  left: var(--space-5);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

/* Bottom-left: live stats */
.viewport__stats {
  bottom: var(--space-3);
  left: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.hud-stat {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
}

.hud-stat__value {
  color: var(--color-accent);
  font-variant-numeric: tabular-nums;
}

/* Bottom-right: fitment callout badges */
.viewport__fitment {
  bottom: var(--space-3);
  right: var(--space-3);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.fitment-badge {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid var(--color-border);
  border-left: 3px solid var(--color-accent);
  padding: 4px 10px;
  font-size: 11px;
  color: var(--color-text-muted);
  letter-spacing: 0.03em;
  backdrop-filter: blur(4px);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  display: flex;
  align-items: center;
  gap: 4px;
}

.fitment-badge__label {
  font-size: 10px;
  font-weight: 700;
  color: var(--color-text-muted);
  letter-spacing: 0.05em;
}

.fitment-badge__sep {
  color: var(--color-border-strong);
  margin: 0 2px;
}

.fitment-badge__val {
  color: var(--color-text-primary);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

/* Crosshair reticle (subtle, hidden when not useful) */
.viewport__crosshair {
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  opacity: 0.2;
}

.viewport__crosshair::before,
.viewport__crosshair::after {
  content: '';
  position: absolute;
  background: var(--color-accent);
}

.viewport__crosshair::before {
  width: 100%;
  height: 1px;
  top: 50%;
  transform: translateY(-50%);
}

.viewport__crosshair::after {
  height: 100%;
  width: 1px;
  left: 50%;
  transform: translateX(-50%);
}

/* --------------------------------------------------------------------------
   Right Panel
   -------------------------------------------------------------------------- */
.panel {
  width: var(--panel-width);
  background: var(--color-surface-1);
  border-left: 1px solid var(--color-border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  flex-shrink: 0;
}

/* Tab bar */
.panel__tabs {
  display: flex;
  border-bottom: 1px solid var(--color-border-subtle);
  flex-shrink: 0;
}

.panel__tab {
  flex: 1;
  padding: 11px 6px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: color var(--transition-fast), border-color var(--transition-fast);
  text-align: center;
}

.panel__tab:hover:not(.active) {
  color: var(--color-text-secondary);
}

.panel__tab.active {
  color: var(--color-accent);
  border-bottom-color: var(--color-accent);
}

/* Scrollable content area */
.panel__content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-4);
}

/* Tab panels */
.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* --------------------------------------------------------------------------
   Panel Sections
   -------------------------------------------------------------------------- */
.section {
  margin-bottom: var(--space-6);
}

.section__title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-3);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  color: var(--color-text-muted);
}

.section__title::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--color-border-subtle);
}

/* --------------------------------------------------------------------------
   Bottom Stats Bar
   -------------------------------------------------------------------------- */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--color-border-subtle);
  flex-shrink: 0;
}

.stats-bar__item {
  padding: 8px var(--space-3);
  text-align: center;
  border-right: 1px solid var(--color-border-subtle);
}

.stats-bar__item:last-child {
  border-right: none;
}

.stats-bar__value {
  display: block;
  font-size: 15px;
  font-weight: 700;
  color: var(--color-text-primary);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.stats-bar__label {
  display: block;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.stats-bar__value.warn {
  color: var(--color-warning);
}

.stats-bar__value.danger {
  color: var(--color-danger);
}

/* ==========================================================================
   Mobile Layout — stacked viewport + collapsible bottom panel
   ========================================================================== */
@media (hover: none) and (pointer: coarse) {

  .app-body {
    flex-direction: column;
    position: relative;
  }

  /* Viewport fills everything — panel floats over it */
  .viewport {
    flex: 1;
    width: 100%;
    height: calc(100dvh - var(--header-height));
  }

  /* Hide wordmark subtitle */
  .logo-wordmark__product { display: none; }
  .logo-wordmark__brand   { font-size: 11px; }

  /* Panel: fixed to bottom, floats over viewport */
  .panel {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    border-left: none;
    border-top: 1px solid var(--color-border);
    transition: height 0.3s ease;
    height: 52dvh;
    min-height: 0;
    overflow: hidden;
    z-index: 100;
    box-shadow: 0 -4px 20px rgba(0,0,0,0.12);
  }

  .panel--collapsed {
    height: 58px !important;
  }

  /* Hide stats bar — chips replace it */
  .stats-bar { display: none; }

  /* Drag handle */
  .panel__drag-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 22px;
    cursor: pointer;
    flex-shrink: 0;
    background: var(--color-surface-1);
    border-bottom: 1px solid var(--color-border-subtle);
  }
  .panel__drag-handle::before {
    content: '';
    width: 36px;
    height: 4px;
    background: var(--color-border-strong);
    border-radius: 2px;
  }

  /* Tab bar */
  .panel__tabs { height: 36px; }
  .panel__tab  { font-size: 9px; padding: 8px 2px; letter-spacing: 0.06em; }

  /* Scrollable content */
  .panel__content {
    height: calc(100% - 58px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Hide camera help */
  .vp-help { display: none; }

  /* Viewport buttons — icon only */
  .vp-btn span { display: none; }
  .vp-btn { padding: 7px 8px; }

  /* Fitment badges + mobile chips — float above panel + safe area + buffer */
  .viewport__fitment {
    right: var(--space-3);
    bottom: calc(var(--mobile-panel-h, 52dvh) + var(--space-3));
    transition: bottom 0.3s ease;
  }
  .fitment-badge { font-size: 10px; padding: 3px 8px; }

  /* Mobile camber/RH chips — above fitment badges */
  .mobile-chips {
    display: flex !important;
    right: var(--space-3);
    bottom: calc(var(--mobile-panel-h, 52dvh) + var(--space-3) + 70px);
    transition: bottom 0.3s ease;
  }

  /* D-pad — bottom-left, above panel */
  .mobile-pan-btns {
    display: flex !important;
    position: absolute;
    bottom: calc(var(--mobile-panel-h, 52dvh) + var(--space-3));
    left: var(--space-3);
    transition: bottom 0.3s ease;
  }
}

/* Hidden on desktop, shown on mobile via media query */
.mobile-chips {
  display: none;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  position: absolute;
}

/* Hidden on desktop */
.mobile-pan-btns {
  display: none;
  pointer-events: all;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  z-index: 10;
}

.mobile-pan-row {
  display: flex;
  gap: 4px;
}

.mobile-pan-btn {
  width: 42px;
  height: 42px;
  background: rgba(255,255,255,0.82);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--color-text-secondary);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.mobile-pan-btn:active {
  background: rgba(255,255,255,0.98);
  border-color: var(--color-border-strong);
}
/* Dimension legend */
.viewport__dim-legend {
  bottom: var(--space-3);
  left: var(--space-5);
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
}

.viewport__dim-legend.hidden { display: none; }

.dim-legend__item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.dim-legend__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dim-legend__label {
  font-size: 10px;
  color: var(--color-text-secondary);
  font-family: var(--font-ui);
  text-shadow: 0 1px 2px rgba(255,255,255,0.8);
}