/* ============================================
   CORDFIEND ERP - Industrial Design System
   ============================================ */

/* -- Reset & Base -- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Core palette */
  --slate-950: #020617; --slate-900: #0f172a; --slate-800: #1e293b;
  --slate-700: #334155; --slate-600: #475569; --slate-500: #64748b;
  --slate-400: #94a3b8; --slate-300: #cbd5e1; --slate-200: #e2e8f0;
  --slate-100: #f1f5f9; --slate-50: #f8fafc;
  --blue-600: #2563eb; --blue-500: #3b82f6; --blue-400: #60a5fa;
  --blue-300: #93c5fd; --blue-100: #dbeafe; --blue-50: #eff6ff;
  --green-600: #16a34a; --green-500: #22c55e; --green-100: #dcfce7;
  --red-600: #dc2626; --red-500: #ef4444; --red-100: #fee2e2;
  --amber-600: #d97706; --amber-500: #f59e0b; --amber-100: #fef3c7;
  --cyan-500: #06b6d4; --cyan-100: #cffafe;

  /* Semantic */
  --brand-green-900: #064e3b; --brand-green-600: #059669; --brand-green-500: #10b981;
  --brand-green-100: #d1fae5; --brand-green-50: #ecfdf5;

  --bg-app: #f8fafc; --bg-card: #ffffff; --bg-sidebar: #ffffff;
  --text-primary: var(--slate-800); --text-secondary: var(--slate-500);
  --text-muted: var(--slate-400); --border-color: var(--slate-200);
  --accent: var(--brand-green-600); --accent-hover: var(--brand-green-900);

  /* Layout */
  --sidebar-width: 260px; --topbar-height: 60px;
  --radius-sm: 6px; --radius-md: 8px; --radius-lg: 12px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.05); --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 12px 40px rgba(0,0,0,.12); --shadow-xl: 0 20px 60px rgba(0,0,0,.18);

  /* Transitions */
  --ease: cubic-bezier(.4,0,.2,1); --dur: .2s;
}

html { font-size: 14px; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-app); color: var(--text-primary);
  display: flex; min-height: 100vh; overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* -- Sidebar -- */
.sidebar {
  width: var(--sidebar-width); min-height: 100vh; background: var(--bg-sidebar);
  display: flex; flex-direction: column; position: fixed; left: 0; top: 0; bottom: 0;
  z-index: 100; transition: transform var(--dur) var(--ease), width var(--dur) var(--ease);
  border-right: 1px solid var(--border-color);
}

/* Sidebar colapsado: solo iconos (60px). Toggle vía botón ☰ del topbar.
   Recupera ~200px para el contenido, útil en notebooks 1280-1366px. */
.sidebar.collapsed { width: 60px; }
.sidebar.collapsed .nav-section-label,
.sidebar.collapsed .nav-item > span:not(.nav-badge),
.sidebar.collapsed .nav-badge,
.sidebar.collapsed .sidebar-footer-info,
.sidebar.collapsed .logo-mark img {
  display: none;
}
.sidebar.collapsed .nav-item { justify-content: center; padding: 12px 8px; }
.sidebar.collapsed .nav-item svg { margin: 0; }
.sidebar.collapsed .sidebar-header { padding: 14px 8px; justify-content: center; }
.sidebar.collapsed .logo-mark::after {
  /* Iconito mini Cordfiend cuando está colapsado (las iniciales) */
  content: 'C'; font-weight: 800; color: var(--brand-green-600);
  font-size: 1.5rem; font-family: 'JetBrains Mono', monospace;
}
.main-content.sidebar-collapsed { margin-left: 60px; }
.sidebar-header {
  padding: 20px 20px 16px; display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--border-color);
}
.logo-mark svg { width: 34px; height: 34px; }
.logo-title { color: var(--brand-green-900); font-weight: 800; font-size: 1rem; letter-spacing: .5px; display: block; }
.logo-subtitle { color: var(--brand-green-600); font-size: .7rem; font-weight: 500; letter-spacing: 1.5px; text-transform: uppercase; display: block; }

.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-section-label {
  font-size: .65rem; font-weight: 700; color: var(--slate-400);
  letter-spacing: 1.5px; padding: 16px 12px 6px; text-transform: uppercase;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px;
  color: var(--slate-600); text-decoration: none; border-radius: var(--radius-sm);
  font-weight: 500; font-size: .875rem; transition: all var(--dur) var(--ease);
  margin-bottom: 2px; position: relative;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.nav-item:hover { color: var(--brand-green-900); background: var(--brand-green-50); }
.nav-item.active {
  color: var(--brand-green-900); background: var(--brand-green-100);
}
.nav-item.active::before {
  content: ''; position: absolute; left: 0; top: 50%; transform: translateY(-50%);
  width: 3px; height: 20px; background: var(--accent); border-radius: 0 3px 3px 0;
}
.nav-badge {
  margin-left: auto; background: var(--brand-green-100); color: var(--brand-green-900);
  font-size: .7rem; font-weight: 700; padding: 2px 7px; border-radius: 10px;
  min-width: 22px; text-align: center;
}
.sidebar-footer {
  padding: 16px 20px; border-top: 1px solid var(--border-color);
}
.sidebar-footer-info { display: flex; align-items: center; gap: 8px; }
.version-tag {
  background: var(--brand-green-100); color: var(--brand-green-900); font-size: .65rem;
  font-weight: 700; padding: 2px 8px; border-radius: 4px; font-family: 'JetBrains Mono', monospace;
}
.footer-text { color: var(--slate-500); font-size: .75rem; }

/* -- Main Content --
   min-width: 0 — sin esto, en un flex container un child con contenido ancho
   (ej. tabla con 9 columnas) crece más allá del viewport, rompiendo el layout.
   El min-width: 0 le dice a flex que puede contraerse aunque su contenido lo pida.
   overflow-x: hidden en main-content — el desbordamiento de contenido (ej. tablas)
   debe scrollear dentro de .table-wrapper, NO en toda la página. */
.main-content {
  margin-left: var(--sidebar-width); flex: 1; display: flex; flex-direction: column;
  min-height: 100vh; min-width: 0; overflow-x: hidden;
  transition: margin-left var(--dur) var(--ease);
}

/* -- Top Bar -- */
.topbar {
  height: var(--topbar-height); background: var(--bg-card);
  border-bottom: 1px solid var(--border-color); display: flex;
  align-items: center; padding: 0 24px; gap: 16px; position: sticky; top: 0; z-index: 50;
  box-shadow: var(--shadow-sm);
}
.menu-toggle {
  display: none; background: none; border: none; cursor: pointer;
  color: var(--text-secondary); padding: 6px;
}
.menu-toggle svg { width: 22px; height: 22px; }
.page-title { font-size: 1.15rem; font-weight: 700; color: var(--text-primary); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }

/* -- Indicador de Sincronización -- */
.sync-status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  user-select: none;
}
.sync-status-indicator:hover {
  background: var(--bg-tertiary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.sync-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #888;
  display: inline-block;
  transition: background var(--dur) var(--ease);
}
.sync-dot.sync-ok { background: #10b981; box-shadow: 0 0 6px rgba(16,185,129,0.6); }
.sync-dot.sync-syncing { background: #f59e0b; animation: sync-pulse 1.2s ease-in-out infinite; }
.sync-dot.sync-error { background: #ef4444; box-shadow: 0 0 6px rgba(239,68,68,0.6); }
/* Conflictos: sync funciona pero el servidor descartó cambios (Excel más nuevo).
   Naranja distinto del amber del "syncing" — pulso suave pero sin animación. */
.sync-dot.sync-warning { background: #f97316; box-shadow: 0 0 6px rgba(249,115,22,0.6); }

/* Fetch en curso AHORA: anillo azul girando alrededor del dot. Se superpone
   sobre cualquier color de estado (verde/rojo/naranja) — el dot mantiene su
   color y el anillo indica "estoy intentando algo ahora mismo". */
.sync-dot.sync-fetching {
  position: relative;
}
.sync-dot.sync-fetching::after {
  content: '';
  position: absolute;
  top: -4px; left: -4px;
  width: calc(100% + 8px); height: calc(100% + 8px);
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: #3b82f6;
  animation: sync-spin 0.8s linear infinite;
  pointer-events: none;
}
@keyframes sync-spin {
  to { transform: rotate(360deg); }
}

/* Indicador BNA cuando el TC cayó a valores por defecto (API caída).
   Aviso visible: borde rojo + fondo rosado pálido para que sobresalga del topbar. */
.bna-rate-indicator.bna-default-fallback {
  background: #fee2e2;
  border: 1px solid #ef4444;
  color: #991b1b;
  position: relative;
}
.bna-rate-indicator.bna-default-fallback::after {
  content: '⚠';
  margin-left: 6px;
  font-size: 0.85rem;
}
@keyframes sync-pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.3); }
}
.sync-label {
  color: var(--text-secondary);
}

/* -- Exchange Rate & Currency Toggle -- */
.bna-rate-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--brand-green-50);
  border: 1px solid var(--brand-green-100);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--brand-green-900);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
  user-select: none;
}
.bna-rate-indicator:hover {
  background: var(--brand-green-100);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.bna-icon {
  font-size: 0.95rem;
}
.bna-label {
  color: var(--brand-green-600);
  font-weight: 600;
}
.bna-val {
  font-family: 'JetBrains Mono', monospace;
  font-weight: 700;
}

.currency-selector {
  display: flex;
  background: var(--slate-100);
  border: 1px solid var(--slate-200);
  padding: 2px;
  border-radius: var(--radius-sm);
  gap: 2px;
}
.curr-btn {
  background: transparent;
  border: none;
  color: var(--slate-600);
  padding: 5px 12px;
  font-size: 0.78rem;
  font-weight: 700;
  border-radius: calc(var(--radius-sm) - 2px);
  cursor: pointer;
  transition: all var(--dur) var(--ease);
}
.curr-btn:hover {
  color: var(--slate-900);
}
.curr-btn.active {
  background: var(--slate-800);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* -- Buttons -- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px;
  border-radius: var(--radius-sm); font-weight: 600; font-size: .8rem;
  cursor: pointer; border: none; transition: all var(--dur) var(--ease);
  font-family: inherit; white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(5,150,105,.3); }
.btn-success { background: var(--green-600); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-danger { background: var(--red-600); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border-color); }
.btn-ghost:hover { background: var(--slate-100); color: var(--text-primary); }
.btn-sm { padding: 5px 10px; font-size: .75rem; }
.btn-icon { padding: 6px; border-radius: var(--radius-sm); background: none; border: none; cursor: pointer; color: var(--text-secondary); transition: all var(--dur); }
.btn-icon:hover { background: var(--slate-100); color: var(--text-primary); }
.btn-icon svg { width: 16px; height: 16px; }
/* Variantes semánticas de btn-icon (acciones de Órdenes de Producción).
   El color se aplica en estado activo; deshabilitado siempre gris. */
.btn-icon-primary { color: var(--brand-green-600); }
.btn-icon-primary:hover { background: var(--brand-green-50); color: var(--brand-green-900); }
.btn-icon-success { color: var(--brand-green-600); }
.btn-icon-success:hover { background: var(--brand-green-50); color: var(--brand-green-900); }
.btn-icon-danger  { color: var(--red-600); }
.btn-icon-danger:hover  { background: var(--red-100); color: var(--red-600); }
/* Estado deshabilitado para todas las variantes:
   - opacidad fuerte para que sea visualmente claro
   - cursor not-allowed
   - hover no hace nada (override de los hover de las variantes) */
.btn-icon:disabled,
.btn-icon[disabled],
.btn-icon[aria-disabled="true"] {
  opacity: 0.35;
  cursor: not-allowed;
  color: var(--text-muted);
}
.btn-icon:disabled:hover,
.btn-icon[disabled]:hover,
.btn-icon[aria-disabled="true"]:hover {
  background: none;
  color: var(--text-muted);
}

/* -- View Container --
   min-width: 0 evita que contenido ancho rompa el flex parent.
   Las tablas dentro de cada view tienen su propio .table-wrapper con scroll. */
.view-container { padding: 24px; flex: 1; min-width: 0; }
.view { display: none; animation: fadeIn .3s var(--ease); min-width: 0; }
.view.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* -- Cards -- */
.card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-header {
  padding: 16px 20px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border-color); gap: 12px; flex-wrap: wrap;
}
.card-header-left { display: flex; align-items: center; gap: 10px; }
.card-header h3 { font-size: .95rem; font-weight: 700; }
.card-body { padding: 20px; }

/* -- Stats Grid -- */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: var(--radius-lg); padding: 20px; display: flex; align-items: flex-start;
  gap: 16px; transition: all var(--dur) var(--ease); box-shadow: var(--shadow-sm);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.stat-icon {
  width: 44px; height: 44px; border-radius: var(--radius-md); display: flex;
  align-items: center; justify-content: center; flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; }
.stat-icon.blue { background: var(--blue-100); color: var(--blue-600); }
.stat-icon.green { background: var(--green-100); color: var(--green-600); }
.stat-icon.amber { background: var(--amber-100); color: var(--amber-600); }
.stat-icon.cyan { background: var(--cyan-100); color: var(--cyan-500); }
.stat-value { font-size: 1.75rem; font-weight: 800; line-height: 1; margin-bottom: 4px; }
.stat-label { font-size: .78rem; color: var(--text-secondary); font-weight: 500; }

/* -- Dashboard [1.9.0] --
   KPI plano (label uppercase + valor grande) — mismo lenguaje visual que las
   cards de valorización de Inventario, para que ambas vistas se sientan
   parte del mismo sistema. */
.dash-kpi-label { font-size: .72rem; font-weight: 700; color: var(--text-muted); letter-spacing: .05em; }
.dash-kpi-value { font-size: 1.5rem; font-weight: 800; margin-top: 4px; }
.dash-kpi-sub { font-size: .75rem; color: var(--text-secondary); margin-top: 8px; line-height: 1.6; }
.dash-range-label { font-size: .78rem; color: var(--text-secondary); font-weight: 500; }
.dash-delta { font-size: .75rem; font-weight: 700; }
.dash-delta-up { color: var(--brand-green-600); }
.dash-delta-down { color: var(--red-600); }
.dash-delta-flat { color: var(--text-muted); }

/* Ranking Top 5 (proveedores/clientes): fila con posición + barra + monto.
   El ancho de la barra es relativo al máximo del propio Top 5 (no global). */
.dash-rank-item { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border-color); }
.dash-rank-item:last-child { border-bottom: none; padding-bottom: 0; }
.dash-rank-item:first-child { padding-top: 0; }
.dash-rank-pos { width: 20px; flex-shrink: 0; font-size: .78rem; font-weight: 800; color: var(--text-muted); text-align: center; }
.dash-rank-body { flex: 1; min-width: 0; }
.dash-rank-name { font-size: .84rem; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-rank-bar-track { height: 6px; background: var(--slate-100); border-radius: 3px; overflow: hidden; margin-top: 5px; }
.dash-rank-bar-fill { height: 100%; border-radius: 3px; background: var(--accent); }
.dash-rank-value { flex-shrink: 0; font-size: .84rem; font-weight: 700; text-align: right; white-space: nowrap; }
.dash-rank-empty { font-size: .82rem; color: var(--text-muted); padding: 8px 0; }

/* Alertas y excepciones [1.9.1]: fila con punto de severidad + título + detalle.
   Rojo (danger) = vencido / requiere acción; ámbar (warning) = próximo a vencer. */
.dash-alert-empty { font-size: .85rem; color: var(--text-muted); padding: 4px 0; }
.dash-alert-row { display: flex; align-items: flex-start; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border-color); }
.dash-alert-row:last-child { border-bottom: none; padding-bottom: 0; }
.dash-alert-row:first-child { padding-top: 0; }
.dash-alert-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.dash-alert-danger .dash-alert-dot { background: var(--red-600); }
.dash-alert-warning .dash-alert-dot { background: var(--amber-500); }
.dash-alert-body { flex: 1; min-width: 0; }
.dash-alert-title { font-size: .84rem; font-weight: 700; color: var(--text-primary); }
.dash-alert-detail { font-size: .78rem; color: var(--text-secondary); margin-top: 2px; }

/* -- Data Tables --
   Si la tabla excede el ancho disponible, scrollea horizontalmente DENTRO
   del wrapper. max-width: 100% asegura que el wrapper no crezca con el contenido. */
.table-wrapper { overflow-x: auto; max-width: 100%; }

/* ── Tabla PT: indicadores de estado en la fila ──
   El estado se mostraba en una columna dedicada (ahora removida). En su lugar:
   - Bloqueado: borde rojo izquierdo + ícono SVG warning junto al código
   - No vigente: opacity reducido (look "archivado")
   Rojo (no naranja) porque el naranja ya está ocupado por sync-syncing/insumos
   y la separación semántica Error (rojo) vs Warning (naranja) sigue SAP Fiori. */
tbody tr.pt-row-blocked > td:first-child {
  border-left: 3px solid var(--red-600);
}
tbody tr.pt-row-blocked > td { background: var(--red-100); background: #fef2f2; }
tbody tr.pt-row-blocked:hover > td { background: var(--red-100); }
.pt-blocked-icon {
  color: #b91c1c; cursor: help;
  display: inline-flex; align-items: center; margin-right: 4px;
  vertical-align: middle;
}
.pt-blocked-icon svg { width: 14px; height: 14px; }
tbody tr.pt-row-inactive { opacity: 0.55; }
tbody tr.pt-row-inactive:hover { opacity: 0.85; }
/* [1.9.2] Borrador: borde ámbar (en diseño, no operativo). Ámbar y no rojo
   porque no es un error — es un estado de trabajo intencional. */
tbody tr.pt-row-draft > td:first-child {
  border-left: 3px solid #d97706;
}
tbody tr.pt-row-draft > td { background: #fffbeb; }
tbody tr.pt-row-draft:hover > td { background: #fef3c7; }

/* Clientes / Proveedores: bloqueado (rojo) e inactivo (archivado) */
tbody tr.maestro-row-blocked > td:first-child {
  border-left: 3px solid var(--red-600);
}
tbody tr.maestro-row-blocked > td { background: #fef2f2; }
tbody tr.maestro-row-blocked:hover > td { background: var(--red-100); }
tbody tr.maestro-row-inactive { opacity: 0.55; }
tbody tr.maestro-row-inactive:hover { opacity: 0.85; }

/* Banner de PTs bloqueados — solo se muestra si hay al menos 1. */
.pt-blocked-banner {
  display: flex; gap: 12px; align-items: center;
  margin: 0 24px 16px; padding: 12px 16px;
  background: #fef2f2; border-left: 4px solid var(--red-600);
  border-radius: var(--radius-sm); font-size: .82rem;
  color: #7f1d1d;
}
.pt-blocked-banner-icon {
  color: #b91c1c; flex-shrink: 0;
  display: flex; align-items: center;
}
.pt-blocked-banner-icon svg { width: 20px; height: 20px; }
.pt-blocked-banner-text { flex: 1; line-height: 1.4; }
.pt-blocked-banner-text strong { color: #991b1b; }
.pt-blocked-banner .btn { flex-shrink: 0; }
/* Botón X para cerrar el banner. Solo dismiss visual (no persiste): al
   re-navegar a la vista PT, si sigue habiendo bloqueados, vuelve a aparecer. */
.pt-blocked-banner-close {
  background: transparent; border: none; cursor: pointer;
  color: #b91c1c; font-size: 1.3rem; line-height: 1;
  padding: 2px 8px; margin-left: 4px; border-radius: 4px;
  font-weight: 700; flex-shrink: 0;
  transition: background var(--dur);
}
.pt-blocked-banner-close:hover { background: #fee2e2; }

/* ── Filter chips (PT, MP) ──
   Reemplazo del checkbox "Ver inactivos" con un grupo de chips mutuamente
   excluyentes. Patrón estándar SAP Fiori / Odoo / Dynamics. Cada chip puede
   llevar contador; el chip "Bloqueados" usa color rojo para llamar atención. */
.filter-chips {
  display: inline-flex; gap: 4px; flex-wrap: wrap;
  padding: 2px; background: var(--slate-100); border-radius: 8px;
}
.filter-chip {
  background: transparent; border: none; padding: 6px 12px;
  font: inherit; font-size: .78rem; font-weight: 600; cursor: pointer;
  color: var(--text-secondary); border-radius: 6px;
  transition: background var(--dur), color var(--dur);
  display: inline-flex; align-items: center; gap: 6px;
}
.filter-chip:hover { color: var(--text-primary); background: rgba(255,255,255,.5); }
.filter-chip.active {
  background: white; color: var(--text-primary);
  box-shadow: 0 1px 2px rgba(0,0,0,.05), 0 0 0 1px var(--border-color);
}
.filter-chip-count {
  display: inline-block; padding: 1px 7px;
  background: var(--slate-200); color: var(--text-secondary);
  border-radius: 10px; font-size: .65rem; font-weight: 700;
}
.filter-chip.active .filter-chip-count { background: var(--brand-green-100); color: var(--brand-green-900); }
/* Variante "alert": chip con contador rojo para Bloqueados cuando hay > 0 */
.filter-chip.has-alert .filter-chip-count {
  background: #fee2e2; color: #b91c1c;
}
.filter-chip.active.has-alert .filter-chip-count {
  background: var(--red-600); color: white;
}

/* Badge inline para info del header (ej. "1 bloqueado") junto al contador. */
.header-alert-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; margin-left: 8px;
  background: #fee2e2; color: #991b1b;
  border-radius: 10px; font-size: .7rem; font-weight: 700;
}
.header-alert-badge svg { width: 12px; height: 12px; }

/* Los inputs/selects de filtro dentro de los <th> deben respetar el ancho
   del header (no empujarlo). Sin esto, los anchos width:Xpx en <th> quedaban
   como suggestion y el contenido los excedía. */
.table-wrapper thead th input.form-input,
.table-wrapper thead th select.form-select {
  width: 100%; box-sizing: border-box; min-width: 0;
}
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
thead th {
  background: var(--slate-50); color: var(--text-secondary); font-weight: 600;
  text-align: left; padding: 10px 14px; border-bottom: 2px solid var(--border-color);
  font-size: .75rem; text-transform: uppercase; letter-spacing: .5px;
  white-space: nowrap; position: sticky; top: 0;
}
tbody td {
  padding: 10px 14px; border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}
tbody tr { transition: background var(--dur); }
tbody tr:hover { background: var(--brand-green-50); }
tbody tr:last-child td { border-bottom: none; }

.code-cell {
  font-family: 'JetBrains Mono', monospace; font-weight: 600; font-size: .82rem;
  color: var(--brand-green-900); background: var(--brand-green-50); padding: 3px 8px;
  border-radius: 4px; display: inline-block; letter-spacing: .5px;
  vertical-align: middle;
}
/* Badge de estado junto al código (MP, Clientes, Proveedores) */
.code-cell + .badge { margin-left: 4px; vertical-align: middle; }
.badge {
  display: inline-flex; align-items: center; padding: 2px 8px; border-radius: 10px;
  font-size: .7rem; font-weight: 600; white-space: nowrap;
}
.badge-blue { background: var(--blue-100); color: var(--blue-600); }
.badge-green { background: var(--green-100); color: var(--green-600); }
.badge-amber { background: var(--amber-100); color: var(--amber-600); }
.badge-red { background: var(--red-100); color: var(--red-600); }
.badge-orange { background: #ffedd5; color: #c2410c; }
.badge-slate { background: var(--slate-100); color: var(--slate-600); }

/* Empty state component: icon + message for empty tables/lists */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 48px 24px; color: var(--text-muted); text-align: center;
}
.empty-state svg { width: 48px; height: 48px; color: var(--slate-300); }
.empty-state-title { font-size: .9rem; font-weight: 600; color: var(--text-secondary); }
.empty-state-hint { font-size: .78rem; color: var(--text-muted); max-width: 320px; line-height: 1.5; }

.table-actions { display: flex; gap: 4px; }

/* -- Search & Filters -- */
.search-bar {
  display: flex; align-items: center; gap: 8px; background: var(--slate-50);
  border: 1px solid var(--border-color); border-radius: var(--radius-sm);
  padding: 0 12px; transition: border-color var(--dur);
}
.search-bar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(5,150,105,.1); }
.search-bar svg { width: 16px; height: 16px; color: var(--text-muted); flex-shrink: 0; }
.search-bar input {
  border: none; background: none; padding: 8px 4px; font-size: .82rem;
  color: var(--text-primary); outline: none; width: 200px; font-family: inherit;
}

/* -- Forms -- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group.full-width { grid-column: 1 / -1; }
.form-label {
  font-size: .75rem; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .5px;
}
.form-input, .form-select {
  padding: 9px 12px; border: 1px solid var(--border-color); border-radius: var(--radius-sm);
  font-size: .85rem; color: var(--text-primary); background: #fff; font-family: inherit;
  transition: border-color var(--dur), box-shadow var(--dur); outline: none;
}
.form-input:focus, .form-select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px rgba(5,150,105,.1);
}
.form-input::placeholder { color: var(--text-muted); }
.form-select { cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%2394a3b8' viewBox='0 0 16 16'%3E%3Cpath d='M4.5 6l3.5 4 3.5-4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
  padding-right: 32px;
}
.form-hint { font-size: .7rem; color: var(--text-muted); }

/* -- Code Builder Visual -- */
.code-builder {
  background: var(--slate-900); border-radius: var(--radius-md); padding: 30px;
  display: flex; align-items: center; justify-content: center; gap: 4px;
  margin-bottom: 20px;
}
.code-char {
  width: 46px; height: 56px; display: flex; align-items: center; justify-content: center;
  font-family: 'JetBrains Mono', monospace; font-size: 1.5rem; font-weight: 700;
  border-radius: 6px; transition: all .3s var(--ease); position: relative;
}
.code-char.filled { background: var(--brand-green-600); color: #fff; box-shadow: 0 0 20px rgba(5,150,105,.3); }
.code-char.empty { background: var(--slate-700); color: var(--slate-500); border: 2px dashed var(--slate-600); }
.code-char-label {
  position: absolute; bottom: -20px; font-size: .55rem; color: var(--slate-400);
  white-space: nowrap; font-weight: 600; text-transform: uppercase; letter-spacing: .5px;
}
.code-separator { width: 8px; }

/* -- BOM Grid -- */
.bom-grid { width: 100%; }
.bom-grid .bom-row {
  display: grid; grid-template-columns: 1fr 120px 80px 100px 100px 50px;
  gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border-color);
}
.bom-grid .bom-row.bom-header {
  font-size: .72rem; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .5px; border-bottom: 2px solid var(--border-color);
  padding-bottom: 10px;
}
.bom-total-row {
  display: grid; grid-template-columns: 1fr 120px 80px 100px 100px 50px;
  gap: 8px; padding: 12px 0; font-weight: 700; border-top: 2px solid var(--slate-800);
  margin-top: 8px;
}

/* -- Modal -- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.6);
  backdrop-filter: blur(4px); z-index: 200; display: none;
  align-items: center; justify-content: center; padding: 20px;
  animation: fadeIn .2s;
}
.modal-overlay.active { display: flex; }
.modal {
  background: var(--bg-card); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl); width: 100%; max-width: 720px;
  max-height: 92vh; overflow-y: auto; animation: slideUp .3s var(--ease);
}
@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } }
.modal-header {
  padding: 20px 24px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border-color); position: sticky; top: 0;
  background: var(--bg-card); z-index: 1;
}
.modal-title { font-size: 1.05rem; font-weight: 700; }
.modal-close {
  background: none; border: none; cursor: pointer; color: var(--text-muted);
  padding: 4px; border-radius: var(--radius-sm); transition: all var(--dur);
}
.modal-close:hover { background: var(--slate-100); color: var(--text-primary); }
.modal-close svg { width: 20px; height: 20px; }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: 8px; }

/* -- Toast -- */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--slate-900); color: #fff; padding: 12px 20px;
  border-radius: var(--radius-md); font-size: .82rem; font-weight: 500;
  box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 10px;
  animation: toastIn .3s var(--ease); min-width: 280px;
}
.toast.success { border-left: 4px solid var(--green-500); }
.toast.error { border-left: 4px solid var(--red-500); }
.toast.info { border-left: 4px solid var(--blue-500); }
.toast.warning { border-left: 4px solid var(--amber-500); }

/* ── Tabs del modal de Producto Terminado (5.2) ──
   El modal antes era un scroll vertical de 90vh con 4 secciones encadenadas.
   Ahora cada sección es un tab; el usuario salta sin perder contexto. */
.pt-form-shell { display: flex; flex-direction: column; max-height: 82vh; }

/* [1.6.1e] Scroll ÚNICO en modales con form-shell: el modal no scrollea — header,
   tabs y footer (.pt-actions) quedan fijos y SOLO scrollea .pt-tab-content. Elimina
   el "scroll dentro del scroll". Requiere :has() (Chromium/Edge modernos); si no,
   degrada al comportamiento anterior sin romperse. */
.modal:has(.pt-form-shell) { overflow: hidden; display: flex; flex-direction: column; }
.modal:has(.pt-form-shell) .modal-body {
  flex: 1 1 auto; min-height: 0; overflow: hidden;
  display: flex; flex-direction: column; padding-top: 4px; padding-bottom: 14px;
}
.modal:has(.pt-form-shell) .pt-form-shell { max-height: none; flex: 1 1 auto; min-height: 0; }
.pt-tabs-nav {
  display: flex; gap: 4px; border-bottom: 1px solid var(--border-color);
  padding: 0 4px; flex-wrap: wrap; flex-shrink: 0;
}
.pt-tabs-nav button {
  background: transparent; border: none; padding: 10px 16px;
  font: inherit; font-size: .85rem; font-weight: 600; cursor: pointer;
  color: var(--text-secondary); border-bottom: 2px solid transparent;
  transition: color var(--dur), border-color var(--dur);
  position: relative;
}
.pt-tabs-nav button:hover { color: var(--text-primary); }
.pt-tabs-nav button.active {
  color: var(--accent); border-bottom-color: var(--accent);
}
/* Badge contador en el tab — usado para BOM (cantidad de items) y Anexos (cant archivos) */
.pt-tabs-nav button .tab-count {
  display: inline-block; margin-left: 6px; padding: 1px 7px;
  background: var(--slate-100); color: var(--text-secondary);
  border-radius: 10px; font-size: .65rem; font-weight: 700;
  vertical-align: middle;
}
.pt-tabs-nav button.active .tab-count {
  background: var(--brand-green-100); color: var(--brand-green-900);
}
/* Badge de error si la tab tiene campos inválidos */
.pt-tabs-nav button.has-error { color: var(--red-600); }
.pt-tabs-nav button.has-error::after {
  content: ''; position: absolute; top: 6px; right: 6px;
  width: 6px; height: 6px; background: var(--red-500); border-radius: 50%;
}

.pt-tab-content { flex: 1; overflow-y: auto; padding: 16px 4px 0; }
.pt-tab-pane { display: none; }
.pt-tab-pane.active { display: block; }

.pt-actions {
  flex-shrink: 0; display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 0 0; border-top: 1px solid var(--border-color);
  margin-top: 12px; background: white;
}
@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } }
.toast.removing { animation: toastOut .3s var(--ease) forwards; }
@keyframes toastOut { to { opacity: 0; transform: translateX(40px); } }

/* -- Pagination -- */
.pagination { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; border-top: 1px solid var(--border-color); }
.pagination-info { font-size: .78rem; color: var(--text-secondary); }
.pagination-btns { display: flex; gap: 4px; }
.pagination-btns button { padding: 5px 10px; }

/* -- Empty State -- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); }
.empty-state svg { width: 64px; height: 64px; margin-bottom: 16px; opacity: .3; }
.empty-state h4 { font-size: 1rem; margin-bottom: 6px; color: var(--text-secondary); }
.empty-state p { font-size: .82rem; }

/* -- Cost Impact Card -- */
.cost-impact {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 16px; align-items: center;
  padding: 16px; background: var(--slate-50); border-radius: var(--radius-md); margin-top: 16px;
}
.cost-impact .arrow-col { color: var(--text-muted); }
.cost-impact .arrow-col svg { width: 24px; height: 24px; }
.cost-val { font-family: 'JetBrains Mono', monospace; font-size: 1.25rem; font-weight: 700; }
.cost-label { font-size: .72rem; color: var(--text-secondary); font-weight: 500; }

/* -- Tab Bar -- */
.tab-bar { display: flex; gap: 0; border-bottom: 2px solid var(--border-color); margin-bottom: 20px; }
.tab-btn {
  padding: 10px 20px; font-size: .82rem; font-weight: 600; color: var(--text-secondary);
  background: none; border: none; cursor: pointer; position: relative;
  transition: color var(--dur);
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--accent); }
.tab-btn.active::after {
  content: ''; position: absolute; bottom: -2px; left: 0; right: 0;
  height: 2px; background: var(--accent);
}

/* -- Responsive -- */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-xl); }
  .main-content { margin-left: 0; }
  .menu-toggle { display: flex; }
  .form-grid { grid-template-columns: 1fr; }
  .bom-grid .bom-row { grid-template-columns: 1fr 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
  .search-bar input { width: 140px; }
  .topbar-actions .btn span { display: none; }
}

/* -- Scrollbar -- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--slate-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--slate-400); }
.sidebar::-webkit-scrollbar-thumb { background: var(--slate-700); }

/* -- Misc Utilities -- */
.text-mono { font-family: 'JetBrains Mono', monospace; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.mb-24 { margin-bottom: 24px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }
.inline-flex { display: inline-flex; align-items: center; }

/* highlight row on update */
@keyframes rowHighlight {
  0% { background: var(--amber-100); }
  100% { background: transparent; }
}
.row-updated { animation: rowHighlight 1.5s var(--ease); }

/* ═══════════════════════════════════════════════════════
   MÓDULO PRODUCCIÓN
   ═══════════════════════════════════════════════════════ */

/* Stats cards clickables */
.prod-stats-grid { margin-bottom: 16px; cursor: pointer; }
.prod-stat { transition: transform 0.12s var(--ease), box-shadow 0.12s var(--ease); }
.prod-stat:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0,0,0,0.10); }

/* Número de orden */
.prod-orden-num {
  font-family: 'JetBrains Mono', monospace;
  font-size: 12px; font-weight: 700;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  padding: 2px 8px; border-radius: 4px;
}

/* Barra de progreso inline en la tabla */
.prod-progress-wrap { display: flex; align-items: center; gap: 8px; justify-content: flex-end; }
.prod-progress-bar { width: 60px; height: 5px; background: var(--bg-tertiary); border-radius: 3px; overflow: hidden; flex-shrink: 0; }
.prod-progress-fill { height: 100%; background: #22c55e; border-radius: 3px; transition: width 0.3s; }

/* Columnas de cantidad en el listado de Órdenes de Producción.
   Ancho fijo igual entre Requeridas/Realizadas (70px) — alcanza para 5 dígitos
   con separador de miles (ej. 99.999). Números alineados a la derecha. */
.th-qty, .td-qty {
  width: 70px;
  min-width: 70px;
  max-width: 70px;
  text-align: right;
  vertical-align: middle;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;  /* alineación vertical de dígitos */
}
.th-qty { vertical-align: bottom; }
/* Wrap para "Realizadas": barra de progreso + número, INLINE en una sola línea
   para que el número quede en el mismo baseline que las demás celdas (fix del
   "0" que aparecía desfasado verticalmente). La barra queda chica (24px) a la
   izquierda del número. */
.prod-qty-wrap {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  vertical-align: middle;
  line-height: 1;
}
.prod-qty-wrap .prod-progress-bar {
  width: 24px; height: 4px;
  display: inline-block;
  background: var(--bg-tertiary);
  border-radius: 2px; overflow: hidden;
}
.prod-qty-wrap .prod-progress-fill {
  display: block; height: 100%;
  background: var(--green-500, #22c55e);
  border-radius: 2px;
}
.prod-qty-num { font-variant-numeric: tabular-nums; }

/* Badges de estado de producción (estilo Linear/Stripe: pill + dot indicador).
   Mismo lenguaje visual que el listado del Cotizador. */
.badge-estado {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap;
  border: 1px solid transparent;
  line-height: 1.4;
}
.badge-estado-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor; flex-shrink: 0;
  box-shadow: 0 0 0 2px rgba(255,255,255,0.6);
}
/* Pendiente → amber (en cola, pendiente de arranque) */
.badge-estado-pendiente {
  background: var(--amber-100); color: var(--amber-600);
  border-color: rgba(217,119,6,0.18);
}
/* En Proceso → blue (en marcha) */
.badge-estado-enproceso {
  background: var(--blue-100); color: var(--blue-600);
  border-color: rgba(37,99,235,0.18);
}
/* Finalizada → green (terminal exitoso) */
.badge-estado-finalizada {
  background: var(--green-100); color: var(--green-600);
  border-color: rgba(22,163,74,0.20);
}
/* Cancelada → red (terminal cortado) */
.badge-estado-cancelada {
  background: var(--red-100); color: var(--red-600);
  border-color: rgba(220,38,38,0.18);
}

/* Tabla de detalles de extremo en el modal */
.prod-extremo-table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.prod-extremo-table th { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-secondary); padding: 6px 8px; text-align: left; border-bottom: 1px solid var(--border); }
.prod-extremo-table td { padding: 6px 4px; border-bottom: 1px solid var(--bg-tertiary); vertical-align: middle; }
.prod-extremo-table td:first-child { font-size: 12px; padding-left: 8px; white-space: nowrap; }

/* [1.6.1c] Tabla de extremos de Especificaciones — estética del BOM: filas
   limpias, SIN cajas por celda. table-layout:fixed para que la descripción
   trunque con ellipsis en vez de ensanchar la columna. */
.specs-ext-table { width: 100%; border-collapse: collapse; margin-top: 4px; table-layout: fixed; }
.specs-ext-table th {
  font-size: .72rem; font-weight: 600; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: .5px; text-align: left;
  padding: 0 8px 10px; border-bottom: 2px solid var(--border-color); line-height: 1.2;
}
.specs-ext-table td {
  padding: 6px 8px; border-bottom: 1px solid var(--border-color);
  vertical-align: middle; font-size: .82rem;
}
.specs-ext-table tr:last-child td { border-bottom: none; }
.specs-ext-table .spec-cond { font-weight: 600; white-space: nowrap; }
.specs-ext-table .input-sm { width: 100%; }

/* [1.6.1d] Terminal/Aislador como fila del BOM: badge de código (chico) a la
   izquierda + descripción a la derecha en 2 líneas. SIN borde: celda clickeable;
   al hover, fondo sutil + lápiz. "Ninguno" se muestra como badge (rojo). */
.spec-pick {
  display: flex; align-items: center; gap: 8px; min-width: 0;
  cursor: pointer; padding: 5px 7px; border-radius: 6px;
  border: 1px solid transparent; min-height: 38px; box-sizing: border-box;
}
.spec-pick:hover, .spec-pick:focus { outline: none; background: var(--bg-secondary); }
.spec-pick.spec-pick-ro { cursor: default; padding-left: 0; }
.spec-pick.spec-pick-ro:hover { background: transparent; }
.spec-pick .code-cell { flex: 0 0 auto; font-size: .7rem; }
.spec-pick-desc {
  flex: 1 1 auto; min-width: 0; color: var(--text-muted); font-size: .74rem; line-height: 1.25;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
/* "Ninguno" como badge rojo (mismo lenguaje que .code-cell) */
.spec-none {
  flex: 0 0 auto; display: inline-block; padding: 2px 8px; border-radius: 5px;
  background: #fef2f2; color: #dc2626; border: 1px solid #fecaca;
  font-size: .7rem; font-weight: 700; font-family: var(--font-mono, monospace); letter-spacing: .3px;
}
.spec-edit-ico { flex: 0 0 auto; color: var(--text-muted); opacity: 0; transition: opacity .12s; }
.spec-pick:hover .spec-edit-ico { opacity: .55; }

/* Input pequeño para tablas dentro del modal */
.input-sm { width: 100%; padding: 5px 7px; border: 1px solid var(--border); border-radius: 5px; font-size: 12px; background: var(--bg-primary); color: var(--text-primary); box-sizing: border-box; }
.input-sm:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px rgba(99,102,241,0.12); }

/* Hint en inputs readonly */
.input-readonly-hint { background: var(--bg-tertiary); color: var(--text-secondary); cursor: default; }
.field-hint { font-size: 11px; color: var(--text-secondary); margin-top: 3px; display: block; }

/* Section titles dentro del modal */
.form-section-title { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.07em; color: var(--text-secondary); margin-bottom: 10px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }

/* Modo solo-lectura del form de Orden de Producción (botón "Ver").
   Campos deshabilitados pero legibles: gris suave de fondo, texto con buen
   contraste (no el opacity 0.4 default del browser que los vuelve ilegibles). */
.form-readonly input:disabled,
.form-readonly select:disabled,
.form-readonly textarea:disabled {
  background: var(--bg-app, #f8fafc);
  color: var(--text-primary);
  -webkit-text-fill-color: var(--text-primary);  /* Safari/Chrome: anula el gris de disabled */
  opacity: 1;
  cursor: default;
}

/* Celdas clickeables (Código / Descripción) que abren el visor del PT congelado.
   Affordance: cursor pointer + color de marca en hover + subrayado sutil. */
.op-pt-link { cursor: pointer; transition: color var(--dur); }
.op-pt-link:hover { color: var(--brand-green-700); text-decoration: underline; }
td.td-desc.op-pt-link:hover { text-decoration: underline; }

/* Column widths de tabla producción */
.td-desc  { max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.td-cant  { text-align: right; font-variant-numeric: tabular-nums; }
.td-actions { white-space: nowrap; }

/* ──────────────────────────────────────────────────────────
   Date picker custom (filtro de Fecha en Órdenes de Producción)
   ────────────────────────────────────────────────────────── */

/* Botón trigger: parece un input pero es un <button>. Sin ícono de calendario
   (más limpio); al click abre el popover. Si tiene valor seleccionado, se
   resalta levemente para que el usuario sepa que el filtro está activo. */
.cal-trigger {
  display: inline-flex; align-items: center;
  border: 1px solid var(--border-color);
  border-radius: 5px;
  font-family: inherit;
  color: var(--text-primary);
  transition: border-color var(--dur), box-shadow var(--dur);
}
.cal-trigger:hover  { border-color: var(--brand-green-500); }
.cal-trigger:focus  { outline: none; border-color: var(--brand-green-600);
                      box-shadow: 0 0 0 2px rgba(16,185,129,0.15); }
.cal-trigger.has-value {
  border-color: var(--brand-green-500);
  background: var(--brand-green-50) !important;
  color: var(--brand-green-900);
  font-weight: 600;
}

/* Popover: posicionado absoluto (top/left calculados en JS desde el rect del
   trigger). z-index alto para que pase por encima de la tabla y el sidebar.
   IMPORTANTE: fondo SÓLIDO (#fff vía --bg-card). El token --bg-primary NO existe
   en este proyecto — usarlo dejaba el popover transparente. */
.cal-popover {
  position: absolute;
  z-index: 10000;
  background: var(--bg-card, #ffffff);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(15,23,42,0.20), 0 3px 10px rgba(15,23,42,0.10);
  padding: 12px;
  width: 260px;
  font-family: inherit;
  color: var(--text-primary);
  user-select: none;
  /* Entrada sutil (≈160ms, ease-out) — respeta el rango 150–300ms de microinteracciones */
  animation: calPopIn 0.16s ease-out;
}
@keyframes calPopIn {
  from { opacity: 0; transform: translateY(-4px); }
  to   { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .cal-popover { animation: none; }
}

/* Header: título (mes/año o año o rango) + flechas de navegación */
.cal-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 4px;
  margin-bottom: 8px;
}
.cal-title {
  font-size: 13.5px; font-weight: 700;
  color: var(--text-primary);
  text-transform: capitalize;
  letter-spacing: 0.01em;
}
/* Título clickable (días → meses → años). Affordance: hover de fondo + caret. */
.cal-title-btn {
  display: inline-flex; align-items: center; gap: 4px;
  background: none; border: none; cursor: pointer;
  padding: 4px 8px; border-radius: 7px;
  font-family: inherit;
  transition: background var(--dur), color var(--dur);
}
.cal-title-btn:hover { background: var(--brand-green-50); color: var(--brand-green-900); }
.cal-title-static { padding: 4px 8px; }   /* vista años: el rango no es clickable */
.cal-title-caret { width: 14px; height: 14px; opacity: 0.7; }

.cal-nav {
  background: none; border: none; cursor: pointer;
  color: var(--text-secondary);
  width: 28px; height: 28px;
  border-radius: 7px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: background var(--dur), color var(--dur);
}
.cal-nav:hover { background: var(--brand-green-50); color: var(--brand-green-900); }
.cal-chev { width: 16px; height: 16px; display: block; }

/* Grilla: 7 columnas en días, 3 en meses/años */
.cal-grid { display: grid; gap: 4px; }
.cal-grid-7 { grid-template-columns: repeat(7, 1fr); }
.cal-grid-3 { grid-template-columns: repeat(3, 1fr); }
.cal-grid-headers { gap: 2px; margin-bottom: 2px; }
.cal-grid-cells { margin-top: 2px; }

.cal-cell {
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 12.5px;
  border-radius: 8px;
  background: none; border: none;
  color: var(--text-primary);
  font-family: inherit;
}
/* Días: celdas cuadradas chicas */
.cal-grid-7 .cal-cell { height: 30px; }
/* Meses/años: celdas más altas (menos densidad, mejor target) */
.cal-grid-3 .cal-cell { height: 40px; font-size: 13px; }

.cal-header-cell {
  color: var(--text-muted);
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  height: 22px;
  cursor: default;
}
.cal-empty { background: none; cursor: default; }

/* Celdas interactivas (día / mes / año) comparten estilo de hover/estado */
.cal-day, .cal-month, .cal-year {
  cursor: pointer;
  transition: background var(--dur), color var(--dur), box-shadow var(--dur);
}
.cal-day:hover, .cal-month:hover, .cal-year:hover {
  background: var(--brand-green-50); color: var(--brand-green-900);
}
/* "Hoy": anillo verde fino (no compite con seleccionado) */
.cal-day.is-today, .cal-month.is-today, .cal-year.is-today {
  box-shadow: inset 0 0 0 1.5px var(--brand-green-500);
  font-weight: 700;
}
/* "Seleccionado": relleno verde sólido + texto blanco */
.cal-day.is-selected, .cal-month.is-selected, .cal-year.is-selected {
  background: var(--brand-green-600);
  color: #fff;
  font-weight: 700;
  box-shadow: none;
}
.cal-day.is-selected:hover, .cal-month.is-selected:hover, .cal-year.is-selected:hover {
  background: var(--brand-green-900);
  color: #fff;
}

/* Footer: acciones Hoy / Limpiar */
.cal-footer {
  display: flex; justify-content: space-between; gap: 6px;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
}
.cal-action {
  flex: 1;
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 7px;
  padding: 6px 8px;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  font-family: inherit;
  transition: all var(--dur);
}
.cal-action:hover {
  background: var(--brand-green-50);
  border-color: var(--brand-green-500);
  color: var(--brand-green-900);
}
.cal-action-clear:hover {
  background: var(--red-100);
  border-color: var(--red-500);
  color: var(--red-600);
}

/* ── Tab Procesos: chips de estado y acciones de F-PRO ── */
.op-proc-actions { white-space: nowrap; text-align: right; }
.op-proc-actions .btn-icon { margin-left: 2px; }
.op-proc-actions .btn-icon svg { width: 14px; height: 14px; }
.op-proc-chip {
  display: inline-block; padding: 2px 7px; border-radius: 9px;
  font-size: 11px; font-weight: 600; margin-right: 4px; vertical-align: middle;
}
.op-proc-chip-ok      { background: var(--brand-green-50); color: var(--brand-green-900); }
.op-proc-chip-pending { background: var(--slate-100); color: var(--text-secondary); }
.op-proc-chip-na      { background: var(--slate-100); color: var(--text-muted); font-style: italic; }
.op-proc-spinner { animation: op-proc-spin 0.8s linear infinite; }
@keyframes op-proc-spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

/* ── Sub-tabs por letra de sublote (A..Z) dentro de la pestaña Sublotes ──
   Scopeado bajo #op-sublotes-tabs para ganarle en especificidad a
   `.pt-tabs-nav button.active` (que setea color: var(--accent) y nos pisaba
   el color: #fff, dejando la letra invisible cuando --accent ≈ fondo verde).
   También para garantizar el padding compacto frente al `padding: 10px 16px`
   heredado del estilo base de tabs. */
#op-sublotes-tabs .op-sl-tab {
  min-width: 34px; padding: 6px 10px; font-size: .85rem; font-weight: 700;
  border: 1px solid var(--border); background: var(--bg-secondary);
  color: var(--text-secondary); cursor: pointer; border-radius: 6px;
  border-bottom: 1px solid var(--border);  /* override .pt-tabs-nav button */
  transition: background 0.15s, color 0.15s;
  line-height: 1.2;
}
#op-sublotes-tabs .op-sl-tab:hover { color: var(--text-primary); background: var(--slate-100); }
#op-sublotes-tabs .op-sl-tab.active {
  background: var(--brand-green-600, #16a34a);
  color: #fff;
  border-color: transparent;
}
#op-sublotes-tabs .op-sl-tab[disabled] { cursor: not-allowed; opacity: .55; }

/* ── Sub-modal anidado (encima del modal de OP, sin pisarlo) ── */
.op-submodal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000;
}
.op-submodal {
  background: var(--bg-primary); border-radius: 12px;
  max-width: 640px; width: calc(100% - 40px); max-height: 85vh;
  display: flex; flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,0.35);
}
.op-submodal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.op-submodal-head h3 { margin: 0; font-size: 1rem; font-weight: 700; }
.op-submodal-close {
  background: none; border: none; font-size: 24px; line-height: 1;
  color: var(--text-secondary); cursor: pointer; padding: 4px 8px;
}
.op-submodal-close:hover { color: var(--text-primary); }
.op-submodal-body { padding: 20px; overflow-y: auto; }

/* ════════════════════════════════════════════════════════════════════
   GESTIÓN DE ACTIVOS (v1.4.0)
   ════════════════════════════════════════════════════════════════════ */

/* Sub-tabs de tipos de activo (Matrices / Aplicadores / Cuchillas / ...) */
/* Sub-tabs de TIPO de activo: viven en el header del card (junto al título),
   con estilo "tab subrayado" (mismo lenguaje que .pt-tabs-nav). Quedan así
   claramente separadas del filtro de ESTADO (.filter-chips, control
   segmentado en bandeja gris) que va en la fila de abajo, alineado a la derecha. */
.activos-subtabs { background: transparent; }
.activos-tab {
  padding: 8px 14px;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: color .12s ease, border-color .12s ease;
}
.activos-tab:hover { background: transparent; color: var(--text-primary); }
/* Resaltado de la sub-tab activa (verde + subrayado). Antes scopeado a
   #activos-subtabs; generalizado a la clase para que aplique a cualquier
   contenedor de sub-tabs (Gestión de Activos #activos-subtabs e Inventario
   #inv-tabs). Especificidad (0,2,0) > base .activos-tab y > .activos-tab:hover. */
.activos-tab.active {
  background: transparent;
  color: var(--accent, #16a34a);
  border-bottom-color: var(--accent, #16a34a);
}
.activos-tab-soon {
  opacity: .5;
  cursor: not-allowed;
  background: transparent !important;
}
.activos-tab-soon:hover {
  background: transparent !important;
  color: var(--text-secondary) !important;
}
.activos-tab-soon[disabled] { pointer-events: none; }

/* Pill de estado del activo */
.activo-status-pill {
  display: inline-block;
  padding: 2px 10px;
  font-size: .74rem;
  font-weight: 700;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: .02em;
}
.activo-status-ok    { background: #dcfce7; color: #166534; }
.activo-status-warn  { background: #fef3c7; color: #92400e; }
.activo-status-baja  { background: #fee2e2; color: #991b1b; }

/* Empty state de "Próximamente" */
.activo-empty-state {
  text-align: center;
  color: var(--text-muted);
  border: 1px dashed var(--border);
  border-radius: 12px;
  margin: 24px;
}
.activo-empty-state .empty-state-title { font-size: 1.05rem; font-weight: 700; color: var(--text-primary); margin-bottom: 6px; }
.activo-empty-state .empty-state-hint  { font-size: .85rem; line-height: 1.5; }

/* Warning en celda de dropdown ACTIVO del sublote */
.op-proc-noavail {
  font-size: .68rem;
  color: #dc2626;
  margin-top: 2px;
  line-height: 1.2;
}

/* Fila inactiva en tablas (reutiliza para fichas inactivas) */
.row-inactive { background: #fafafa; opacity: .72; }
.row-inactive strong { color: var(--text-muted); font-weight: 600; }

/* Banner amarillo de mantenimiento próximo en la ficha de activo */
.activo-alert-banner {
  background: #fef3c7;
  border-left: 4px solid #f59e0b;
  color: #78350f;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: .85rem;
  margin-bottom: 12px;
}
.activo-alert-banner strong { color: #78350f; }

/* ════════════════════════════════════════════════════════════════════
   INVENTARIO SEGREGADO + CALIDAD (v1.8.0)
   ════════════════════════════════════════════════════════════════════ */
/* Pills de bucket de stock: disponible (verde) / pendiente de revisión
   (naranja) / comprometido (azul) / no conforme (rojo). Se usan en la tabla
   de Inventario, el modal de movimientos y la cola de Calidad. */
.stock-pill {
  display: inline-block;
  min-width: 34px;
  padding: 2px 9px;
  font-size: .78rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: right;
  border-radius: 10px;
  border: 1px solid transparent;
}
.stock-pill-disponible   { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.stock-pill-pendiente    { background: #fef3c7; color: #92400e; border-color: #fde68a; }
.stock-pill-comprometido { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.stock-pill-noconforme   { background: #fee2e2; color: #991b1b; border-color: #fecaca; }

/* ════════════════════════════════════════════════════════════
   [2.0.0] Autenticación: overlay de login + badge de usuario
   ════════════════════════════════════════════════════════════ */
.login-overlay {
  position: fixed; inset: 0; z-index: 4000;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-app);
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: 32px 28px;
}
.login-logo-wrap { display: flex; justify-content: center; margin-bottom: 12px; }
.login-logo { max-width: 120px; width: 100%; height: auto; }
.login-title { text-align: center; margin: 0 0 4px; font-size: 1.25rem; color: var(--text-primary); }
.login-sub { text-align: center; margin: 0 0 20px; font-size: .85rem; color: var(--text-secondary); }
.login-error {
  margin: 4px 0 12px; padding: 8px 10px;
  background: #fee2e2; color: #991b1b; border: 1px solid #fecaca;
  border-radius: var(--radius-sm); font-size: .8rem;
}

.user-badge {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 10px; border-radius: var(--radius-md);
  background: var(--bg-app); border: 1px solid var(--border-color);
  font-size: .8rem;
}
.user-badge-name { font-weight: 600; color: var(--text-primary); }
.user-badge-role {
  font-size: .68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .03em; color: var(--text-muted);
  background: var(--bg-card); border: 1px solid var(--border-color);
  border-radius: 10px; padding: 1px 7px;
}
.user-badge #btn-logout { padding: 3px 10px; font-size: .78rem; }

