/* Variables y tipografías corporativas */
:root {
  --font-main: 'Inter', system-ui, -apple-system, sans-serif;
  --font-heading: 'Outfit', 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  /* Tema oscuro por defecto */
  --bg-primary: #0b0f17;
  --bg-card: #131b26;
  --bg-card-hover: #1a2433;
  --bg-input: #1a2433;
  --border-color: rgba(255, 255, 255, 0.08);
  --border-focus: #3b82f6;

  --text-main: #f3f4f6;
  --text-muted: #9ca3af;
  --text-dim: #6b7280;

  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --accent-light: rgba(59, 130, 246, 0.15);

  --success: #10b981;
  --success-bg: rgba(16, 185, 129, 0.12);
  --warning: #f59e0b;
  --warning-bg: rgba(245, 158, 11, 0.15);
  --danger: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.15);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

[data-theme="light"] {
  --bg-primary: #f8fafc;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f5f9;
  --bg-input: #f8fafc;
  --border-color: #e2e8f0;
  --border-focus: #2563eb;

  --text-main: #0f172a;
  --text-muted: #475569;
  --text-dim: #94a3b8;

  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-light: rgba(37, 99, 235, 0.1);
}

/* Regla estricta: sólo box-sizing en * */
*, *::before, *::after {
  box-sizing: border-box;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-primary);
  color: var(--text-main);
  margin: 0;
  padding: 0;
  overflow-x: clip;
  width: 100%;
  max-width: 100%;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.tool-layout {
  max-width: 1380px;
  margin: 1.25rem auto 3rem;
  padding: 0 1rem;
  width: 100%;
}

.closet-container {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
  margin-bottom: 2rem;
}

/* Barra superior */
.closet-topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.view-switch-group {
  display: flex;
  background: var(--bg-primary);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  gap: 4px;
}

.btn-mode {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0.55rem 1.1rem;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-heading);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 40px;
}

.btn-mode.active {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.35);
}

.closet-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.btn-action-outline,
.btn-action-solid {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.5rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
  min-height: 40px;
}

.btn-action-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-action-outline:hover {
  background: var(--bg-card-hover);
  border-color: var(--text-muted);
}

.btn-action-solid {
  background: var(--accent);
  border: 1px solid var(--accent);
  color: #ffffff;
}

.btn-action-solid:hover {
  background: var(--accent-hover);
}

/* Banner de métricas */
.closet-stats-banner {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  padding: 0.85rem 0;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 1rem;
}

.stat-pill {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-label {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.stat-val {
  font-family: var(--font-mono);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-main);
}

.ergo-ok {
  color: var(--success);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.86rem;
}

.ergo-warning {
  color: var(--warning);
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.86rem;
}

/* Espacio de trabajo dual: Barra lateral + Visor */
.closet-workspace {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1rem;
  min-height: 620px;
}

@media (max-width: 992px) {
  .closet-workspace {
    grid-template-columns: 1fr;
  }
}

/* Barra lateral */
.closet-sidebar {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  max-height: 720px;
  overflow-y: auto;
}

.sidebar-tabs {
  display: flex;
  background: var(--bg-card);
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  gap: 3px;
}

.tab-btn {
  flex: 1;
  padding: 0.45rem 0.2rem;
  border-radius: var(--radius-sm);
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s ease;
  min-height: 36px;
}

.tab-btn.active {
  background: var(--accent);
  color: #ffffff;
}

.tab-pane {
  display: none;
  flex-direction: column;
  gap: 0.85rem;
}

.tab-pane.active {
  display: flex;
}

.pane-header {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.pane-title {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-main);
}

.pane-help {
  font-size: 0.78rem;
  color: var(--text-muted);
}

/* Form fields y selects canónicos */
select {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  white-space: nowrap;
  overflow: hidden;
  height: 42px;
  padding: 0 40px 0 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-input);
  color: var(--text-main);
  font-family: var(--font-main);
  font-size: 0.88rem;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%239ca3af' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
}

select option {
  background: var(--bg-card);
  color: var(--text-main);
}

.form-group-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group-field label {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
}

.input-with-unit {
  display: flex;
  align-items: center;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  height: 42px;
}

.input-with-unit input {
  flex: 1 1 0%;
  width: 0;
  min-width: 0;
  height: 100%;
  padding: 0 0.75rem;
  border: none;
  background: transparent;
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.95rem;
  font-weight: 600;
}

.input-with-unit input:focus {
  outline: none;
}

.unit-tag {
  padding: 0 0.75rem;
  font-size: 0.8rem;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

/* Columnas de configuración modular */
.columns-config-container {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.column-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.65rem;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.column-card-title {
  font-family: var(--font-heading);
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  justify-content: space-between;
}

.column-card-title span {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--accent);
}

.maletero-toggle-row {
  margin-top: 0.4rem;
  padding: 0.5rem;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
}

.switch-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.82rem;
  color: var(--text-main);
  cursor: pointer;
}

.switch-label input {
  width: 18px;
  height: 18px;
  cursor: pointer;
}

/* Panel ergonómico */
.closet-ergo-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.65rem;
  margin-top: auto;
}

.ergo-title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.4rem;
}

.ergo-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.ergo-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--success-bg);
  color: var(--success);
}

.ergo-badge.warn {
  background: var(--warning-bg);
  color: var(--warning);
}

.ergo-tips-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.76rem;
  color: var(--text-muted);
}

.ergo-tip-item {
  padding: 4px 6px;
  border-radius: 4px;
  background: var(--bg-primary);
  border-left: 3px solid var(--accent);
}

.ergo-tip-item.warn {
  border-left-color: var(--warning);
  color: #fed7aa;
}

/* Área de Viewport (3D y 2D) */
.closet-viewport-area {
  position: relative;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  min-height: 620px;
  display: flex;
  flex-direction: column;
}

.view-panel {
  display: none;
  width: 100%;
  height: 100%;
  min-height: 620px;
  position: relative;
}

.view-panel.active {
  display: flex;
  flex-direction: column;
}

.three-floating-controls,
.canvas-floating-controls {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  z-index: 10;
  pointer-events: none;
}

.three-floating-controls > *,
.canvas-floating-controls > * {
  pointer-events: auto;
}

.btn-canvas-ctrl {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0.45rem 0.8rem;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(8px);
  min-height: 36px;
}

.btn-canvas-ctrl:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

.three-tip,
.canvas-scale-indicator {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-dim);
  background: var(--bg-card);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  font-family: var(--font-mono);
}

.three-container {
  width: 100%;
  height: 100%;
  min-height: 620px;
  flex: 1;
  background: #0b0f17;
}

.canvas-wrapper {
  width: 100%;
  height: 100%;
  min-height: 620px;
  flex: 1;
}

#closet-canvas-2d {
  display: block;
  width: 100%;
  height: 100%;
}

/* Sección de Despiece Técnico (BOM) */
.bom-section {
  margin-top: 1.75rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

.bom-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.bom-subtitle {
  font-size: 0.84rem;
  color: var(--text-muted);
  margin: 0.25rem 0 0 0;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

.bom-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
  margin-top: 0.5rem;
}

.bom-table th {
  text-align: left;
  padding: 0.65rem 0.8rem;
  background: var(--bg-primary);
  color: var(--text-muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--border-color);
}

.bom-table td {
  padding: 0.7rem 0.8rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  font-family: var(--font-mono);
  font-size: 0.84rem;
}

.bom-table td:first-child,
.bom-table td:nth-child(6),
.bom-table td:nth-child(7) {
  font-family: var(--font-main);
}

.bom-table tr:hover td {
  background: var(--bg-card-hover);
}

/* Herrajes */
.hardware-box {
  margin-top: 1.5rem;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
}

.hardware-title {
  font-family: var(--font-heading);
  font-size: 0.95rem;
  font-weight: 700;
  margin: 0 0 0.85rem 0;
  color: var(--text-main);
}

.hardware-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.75rem;
}

.hardware-item {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.65rem 0.85rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.hardware-item-name {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
}

.hardware-item-qty {
  font-family: var(--font-mono);
  font-size: 0.86rem;
  font-weight: 700;
  color: var(--accent);
}

/* Títulos acotados */
.tool-layout h1,
.tool-layout h2,
.tool-layout h3,
.tool-layout h4 {
  font-family: var(--font-heading);
}

.section-title {
  font-size: 1.15rem;
  font-weight: 700;
  margin: 0;
  color: var(--text-main);
}
