/* ==========================================================================
   VALRI CASTILLO STONE · SISTEMA DE DISEÑO ERP MODERNO (FASE 1 - 4)
   Inspiración: BankDash / Modernize + Claridad B2B ERP
   ========================================================================== */

:root {
  --erp-bg: #f4f6f9;
  --erp-surface: #ffffff;
  --erp-surface-subtle: #f8fafc;
  --erp-border: #e2e8f0;
  --erp-border-strong: #cbd5e1;
  --erp-ink: #0f172a;
  --erp-ink-secondary: #334155;
  --erp-muted: #64748b;
  --erp-brand: #c8102e;
  --erp-brand-hover: #a50d26;
  --erp-brand-soft: #fff1f2;
  --erp-navy: #1e293b;
  --erp-emerald: #059669;
  --erp-emerald-soft: #ecfdf5;
  --erp-amber: #d97706;
  --erp-amber-soft: #fffbeb;
  --erp-blue: #2563eb;
  --erp-blue-soft: #eff6ff;
  --erp-purple: #7c3aed;
  --erp-purple-soft: #f5f3ff;
  --erp-radius-lg: 14px;
  --erp-radius-md: 10px;
  --erp-radius-sm: 6px;
  --erp-shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.05), 0 1px 2px rgba(15, 23, 42, 0.03);
  --erp-shadow-md: 0 4px 12px rgba(15, 23, 42, 0.06);
}

/* Optimización de renderizado diferido para secciones pesadas (modern-web-guidance: defer-rendering-heavy-content) */
/* Sólo secciones de lista opcionales: nunca todas las tablas, dialogs o impresos. */
@media screen {
.erp-lazy-section:not(.table-wrap) {
  content-visibility: auto;
  contain-intrinsic-size: auto 360px;
}
}

/* --- JERARQUÍA DEL SIDEBAR ERP --- */
#sidebar .sidebar-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #94a3b8;
  padding: 0.85rem 0.85rem 0.3rem;
  margin: 0;
}

#sidebar .sidebar-section-label:not(:first-of-type) {
  border-top: 1px solid rgba(148, 163, 184, 0.14);
  margin-top: 0.35rem;
}

/* --- ENCABEZADOS DE VISTA Y KPIS EJECUTIVOS --- */
.erp-view-shell {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.erp-header-card {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  background: var(--erp-surface);
  border: 1px solid var(--erp-border);
  border-radius: var(--erp-radius-lg);
  padding: 1.25rem 1.5rem;
  box-shadow: var(--erp-shadow-sm);
}

.erp-header-card h2 {
  margin: 0.15rem 0 0.25rem;
  font-size: 1.35rem;
  font-weight: 800;
  color: var(--erp-ink);
  letter-spacing: -0.02em;
}

.erp-eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--erp-brand);
}

.erp-header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.erp-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
  gap: 1rem;
}

.erp-kpi-card {
  background: var(--erp-surface);
  border: 1px solid var(--erp-border);
  border-radius: var(--erp-radius-md);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--erp-shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  position: relative;
  overflow: hidden;
}

.erp-kpi-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
  background: var(--erp-brand);
}

.erp-kpi-card.is-emerald::before { background: var(--erp-emerald); }
.erp-kpi-card.is-blue::before { background: var(--erp-blue); }
.erp-kpi-card.is-amber::before { background: var(--erp-amber); }
.erp-kpi-card.is-purple::before { background: var(--erp-purple); }
.erp-kpi-card.is-navy::before { background: var(--erp-navy); }

.erp-kpi-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.erp-kpi-label {
  font-size: 0.76rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--erp-muted);
}

.erp-kpi-value {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--erp-ink);
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}

.erp-kpi-sub {
  font-size: 0.8rem;
  color: var(--erp-muted);
  font-variant-numeric: tabular-nums;
}

/* --- PESTAÑAS INTERACTIVAS EN MODALES Y VISTAS ERP --- */
.erp-dialog-tabs,
.erp-subview-tabs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem;
  background: var(--erp-surface-subtle);
  border: 1px solid var(--erp-border);
  border-radius: var(--erp-radius-md);
  margin-bottom: 1rem;
}

.erp-tab-btn {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--erp-ink-secondary);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.48rem 0.9rem;
  border-radius: var(--erp-radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}

.erp-tab-btn:hover {
  background: rgba(15, 23, 42, 0.04);
  color: var(--erp-ink);
}

.erp-tab-btn.active,
.erp-tab-btn[aria-selected="true"] {
  background: var(--erp-surface);
  color: var(--erp-brand);
  border-color: var(--erp-border);
  box-shadow: var(--erp-shadow-sm);
  font-weight: 700;
}

.erp-tab-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.25rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: rgba(15, 23, 42, 0.07);
  color: var(--erp-ink-secondary);
}

.erp-tab-btn.active .erp-tab-count {
  background: var(--erp-brand-soft);
  color: var(--erp-brand);
}

.erp-tab-hidden {
  display: none !important;
}

/* --- BARRA DE FILTROS Y CONTROLES ERP --- */
.erp-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  background: var(--erp-surface);
  border: 1px solid var(--erp-border);
  border-radius: var(--erp-radius-md);
  padding: 0.85rem 1.1rem;
}

.erp-toolbar-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.erp-toolbar select,
.erp-toolbar input[type="search"],
.erp-toolbar input[type="text"],
.erp-toolbar input[type="date"] {
  margin: 0;
  height: 2.35rem;
  padding: 0 0.75rem;
  font-size: 0.85rem;
  border-radius: var(--erp-radius-sm);
  border: 1px solid var(--erp-border-strong);
  background: var(--erp-surface);
}

/* --- TABLERO KANBAN CRM (EMBUDO DE OPORTUNIDADES) --- */
.crm-pipeline-board {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 0.9rem;
  align-items: start;
}

.crm-stage-col {
  background: #f1f5f9;
  border: 1px solid var(--erp-border);
  border-radius: var(--erp-radius-md);
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  min-height: 280px;
}

.crm-stage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--erp-border-strong);
}

.crm-stage-col[data-stage="NEW"] .crm-stage-header { border-bottom-color: #64748b; }
.crm-stage-col[data-stage="VISITED"] .crm-stage-header { border-bottom-color: #2563eb; }
.crm-stage-col[data-stage="QUOTING"] .crm-stage-header { border-bottom-color: #7c3aed; }
.crm-stage-col[data-stage="NEGOTIATION"] .crm-stage-header { border-bottom-color: #d97706; }
.crm-stage-col[data-stage="WON"] .crm-stage-header { border-bottom-color: #059669; }
.crm-stage-col[data-stage="LOST"] .crm-stage-header { border-bottom-color: #dc2626; }

.crm-stage-title {
  font-size: 0.8rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--erp-ink);
}

.crm-lead-card {
  background: var(--erp-surface);
  border: 1px solid var(--erp-border);
  border-radius: var(--erp-radius-sm);
  padding: 0.85rem;
  box-shadow: var(--erp-shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.crm-lead-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--erp-shadow-md);
}

.crm-lead-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.4rem;
}

.crm-lead-code {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--erp-muted);
  font-variant-numeric: tabular-nums;
}

.crm-lead-title {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--erp-ink);
  margin: 0;
}

.crm-lead-meta {
  font-size: 0.8rem;
  color: var(--erp-ink-secondary);
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.crm-lead-amount {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--erp-navy);
  font-variant-numeric: tabular-nums;
}

.crm-lead-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding-top: 0.45rem;
  border-top: 1px dashed var(--erp-border);
}

.crm-lead-actions button {
  font-size: 0.74rem;
  padding: 0.28rem 0.55rem;
}

/* --- BADGES SEMÁNTICOS ERP (SEGMENTOS, ESTADOS Y CONTABILIDAD) --- */
.erp-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size:12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.erp-badge.segment-architect { background: var(--erp-purple-soft); color: var(--erp-purple); }
.erp-badge.segment-contractor { background: var(--erp-blue-soft); color: var(--erp-blue); }
.erp-badge.segment-fabricator { background: var(--erp-amber-soft); color: var(--erp-amber); }
.erp-badge.segment-end_client { background: #f1f5f9; color: #334155; }
.erp-badge.segment-distributor { background: var(--erp-emerald-soft); color: var(--erp-emerald); }

.erp-badge.status-paid,
.erp-badge.status-accepted,
.erp-badge.status-won,
.erp-badge.status-completed {
  background: var(--erp-emerald-soft);
  color: var(--erp-emerald);
}

.erp-badge.status-pending,
.erp-badge.status-partial,
.erp-badge.status-quoting,
.erp-badge.status-negotiation {
  background: var(--erp-amber-soft);
  color: var(--erp-amber);
}

.erp-badge.status-overdue,
.erp-badge.status-cancelled,
.erp-badge.status-voided,
.erp-badge.status-lost {
  background: var(--erp-brand-soft);
  color: var(--erp-brand);
}

.erp-badge.status-info {
  background: var(--erp-blue-soft);
  color: var(--erp-blue);
}

/* --- CONTABILIDAD Y CUENTAS FINANCIERAS --- */
.acc-grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  gap: 1rem;
}

.acc-card {
  background: var(--erp-surface);
  border: 1px solid var(--erp-border);
  border-radius: var(--erp-radius-md);
  padding: 1.25rem;
  box-shadow: var(--erp-shadow-sm);
}

.acc-card h3 {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 800;
  color: var(--erp-ink);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.acc-account-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 0.85rem;
}

.acc-account-item {
  border: 1px solid var(--erp-border);
  border-radius: var(--erp-radius-sm);
  padding: 0.9rem 1rem;
  background: var(--erp-surface-subtle);
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.acc-account-item strong {
  font-size: 0.92rem;
  color: var(--erp-ink);
}

.acc-cost-pill-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  font-size: 0.74rem;
  color: var(--erp-muted);
}

.acc-cost-pill {
  background: #f1f5f9;
  border-radius: 4px;
  padding: 0.1rem 0.4rem;
  font-variant-numeric: tabular-nums;
}

/* --- FORMULARIOS EN MODALES ERP --- */
.erp-form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.85rem;
}

.erp-client-segment-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--erp-surface-subtle);
  border: 1px solid var(--erp-border);
  border-radius: var(--erp-radius-md);
  margin-bottom: 1rem;
}

.erp-client-segment-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.erp-client-segment-controls select {
  margin: 0;
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
}

@media (max-width: 768px) {
  .erp-header-card {
    padding: 1rem;
  }
  .crm-pipeline-board {
    grid-template-columns: 1fr;
  }
}

/* Espacio de trabajo operativo: una jerarquía común, no otra capa de tarjetas.
   Sólo pantalla; documentos A4/A5 y reglas de impresión quedan independientes. */
@media screen {
  #app { font-size:14px; }
  #app .topbar { height:64px; min-height:64px; margin-bottom:0; padding-inline:24px; backdrop-filter:none; }
  #app #main { max-width:1540px; padding:24px 24px 52px; }
  #app .workspace-location { min-width:0; margin-right:auto; line-height:1.4; }
  #app .workspace-location span { display:block; color:var(--muted); font-size:12px; }
  #app .workspace-location strong { font-size:13px; font-weight:600; }
  #app .workspace-location strong { display:block; max-width:40ch; overflow-wrap:anywhere; }
  #app .topbar-actions { gap:16px; }
  #app .warehouse-context { min-width:170px; }
  #app .warehouse-context select { min-height:34px; }
  #app .role-info strong { font-size:13px; font-weight:600; }
  #app .role-avatar { width:34px; height:34px; font-size:13px; }
  #sidebar .sidebar-top { margin-bottom:14px; }
  #sidebar .sidebar-primary { margin-bottom:10px; box-shadow:none; }
  #sidebar .sidebar-section-label { font-size:10px; letter-spacing:.055em; padding:12px 10px 5px; }
  #nav .nav-parent-btn { min-height:42px; padding-block:9px; font-weight:550; }
  #nav .nav-sub-item { min-height:40px; padding-block:9px; font-size:12px; font-weight:500; }
  #sidebar .help-card { display:none; }
  #sidebar .sidebar-bottom { padding-top:6px; }
  #sidebar .prototype-label { margin-top:2px; padding-block:4px; }
  #app .view-header { gap:12px; margin:0 0 20px; padding:0; align-items:center; }
  #app .view-header > div { min-width:0; }
  #app .view-header h2 { font-size:23px; line-height:1.3; font-weight:650; letter-spacing:-.4px; margin:0 0 5px; }
  #app .view-header p { margin:0; font-size:13px; line-height:1.55; max-width:75ch; }
  #app .view-subtitle { font-size:11px; font-weight:550; letter-spacing:0; }
  #app .primary, #app .secondary, #app .table-button { box-shadow:none; font-size:13px; font-weight:600; min-height:38px; padding:8px 13px; border-radius:7px; }
  #app .primary:hover, #app .secondary:hover { transform:none; }
  #app .icon-button { min-width:38px; min-height:38px; }
  #app h3 { font-weight:600; }
  #app .toolbar { gap:12px; margin-bottom:16px; align-items:end; flex-wrap:wrap; }
  #app .toolbar label { font-size:12px; min-width:0; text-align:left; }
  #app input:not([type="checkbox"]):not([type="radio"]):not([type="file"]), #app select { font-size:14px; }
  #app .card { border-radius:10px; box-shadow:none; }
  #app .table-wrap { box-shadow:none; border-radius:8px; max-width:100%; min-width:0; overflow-x:auto; }
  #app table th { font-size:12px; font-weight:600; letter-spacing:.03em; padding:10px 13px; }
  #app table td { font-size:13px; padding:12px 13px; }
  #app .table-wrap .table-button { padding:6px 10px; }
  #app .kpi-grid { gap:12px; }
  #app .kpi-card { padding:16px; border-radius:9px; box-shadow:none; min-width:0; }
  #app .kpi-value { font-size:25px; font-weight:650; }
  #app .kpi-title, #app .kpi-label { font-size:11px; font-weight:600; }
  #app .kpi-card:hover { transform:none; box-shadow:none; }
  #app .finance-kpi-row { gap:12px; }
  #app .stat-card-premium { padding:16px; min-width:0; box-shadow:none; border-radius:9px; }
  #app .stat-card-premium:hover { transform:none; box-shadow:none; }
  #app .stat-card-value { font-size:25px; font-weight:650; overflow-wrap:anywhere; }
  #app .stat-card-sub { font-size:12px; }
  #app .chart-card { min-width:0; padding:18px; box-shadow:none; border-radius:9px; }
  #app .empty { padding:28px 20px; border-radius:9px; }
  #app .empty h2 { font-size:18px; font-weight:600; }
  #app .empty p { font-size:13px; }
  #app .empty-icon-wrap { width:44px; height:44px; margin-bottom:12px; }
  #app .inventory-scope-note { background:transparent; border:0; border-radius:0; border-left:2px solid var(--line); font-size:12px; padding:4px 10px; margin-bottom:12px; }
  #app .inventory-modern-product > summary { min-height:78px; }
  #home-dashboard { padding-top:0; }
  #home-dashboard h1 { font-size:27px; font-weight:650; }
  #home-dashboard .home-intro { margin-bottom:18px; }
  #home-dashboard .home-action { min-height:70px; padding-block:12px; }
  #home-dashboard .home-panel-head { padding-top:18px; padding-bottom:14px; }
  #home-dashboard .home-columns { gap:18px; }
  #home-dashboard .home-task { padding-block:13px; }
  #home-dashboard .home-task-copy strong, #home-dashboard .home-task-end strong { font-weight:600; }
  #home-dashboard h2 { font-size:19px; font-weight:600; }
  .erp-view-shell { gap:16px; min-width:0; }
  .erp-header-card { padding:0; border:0; background:none; box-shadow:none; gap:12px; }
  .erp-header-card > div:first-child { flex:1 1 320px; min-width:0; }
  .erp-header-card h2 { font-size:23px; font-weight:650; margin:0 0 5px; line-height:1.3; }
  .erp-header-card p { margin:0; font-size:13px; line-height:1.5; }
  .erp-eyebrow { color:var(--erp-muted); font-size:11px; font-weight:550; letter-spacing:0; text-transform:none; }
  .erp-header-actions { gap:8px; }
  .erp-kpi-grid { grid-template-columns:repeat(4,minmax(0,1fr)); gap:0; border:1px solid var(--line); border-radius:9px; background:white; overflow:hidden; }
  .erp-kpi-card { min-width:0; background:none; border:0; border-right:1px solid var(--line); border-radius:0; box-shadow:none; padding:14px 16px; gap:5px; }
  .erp-kpi-card:last-child { border-right:0; }
  .erp-kpi-card::before { display:none; }
  .erp-kpi-label { font-size:12px; font-weight:500; text-transform:none; letter-spacing:0; }
  .erp-kpi-value { font-size:23px; font-weight:650; }
  .erp-kpi-sub { font-size:11px; line-height:1.5; }
  .erp-toolbar { border:0; border-bottom:1px solid var(--line); border-radius:0; padding:0 0 12px; background:none; gap:10px; }
  .erp-toolbar-group { gap:8px; min-width:0; }
  .erp-toolbar-group:has(input[type="search"]) { flex:1 1 280px; }
  .erp-toolbar-group input { max-width:100%; }
  .erp-toolbar select { max-width:100%; width:auto; }
  .erp-toolbar .view-switcher-group { flex-shrink:0; }
  .crm-pipeline-board { grid-template-columns:repeat(6,minmax(220px,1fr)); overflow-x:auto; padding-bottom:8px; }
  .crm-stage-col { min-height:180px; }
  .crm-stage-title { font-size:12px; font-weight:600; text-transform:none; letter-spacing:0; }
  .acc-grid-2 { grid-template-columns:repeat(2,minmax(0,1fr)); gap:16px; }
  .acc-card { padding:16px; min-width:0; box-shadow:none; }
  .acc-card h3 { font-size:15px; font-weight:600; flex-wrap:wrap; gap:6px; }
  #app .acc-grid-2 table { min-width:0; table-layout:fixed; }
  #app .acc-grid-2 td:first-child { width:66%; }
  #app .acc-grid-2 td:last-child { width:34%; text-align:right; overflow-wrap:anywhere; }
  .acc-account-list { grid-template-columns:repeat(auto-fit,minmax(min(100%,220px),1fr)); }
  .acc-account-item { min-width:0; }
  .erp-review-note { margin:0 0 12px; padding:8px 12px; border-left:2px solid var(--warn); background:var(--warn-soft); color:#76500b; font-size:12px; line-height:1.5; }
  #detail-dialog .dialog-head { padding:18px 22px; }
  #detail-dialog .dialog-head h2 { font-size:21px; font-weight:650; }
  #detail-dialog #dialog-body { padding:20px 22px; }
  #detail-dialog .facts { grid-template-columns:repeat(4,minmax(0,1fr)); gap:0; border:1px solid var(--line); border-radius:9px; overflow:hidden; margin-bottom:18px; }
  #detail-dialog .fact { padding:12px; border:0; border-bottom:1px solid var(--line); border-right:1px solid var(--line); border-radius:0; background:#fafbfd; box-shadow:none; min-width:0; }
  #detail-dialog .fact small { font-size:12px; font-weight:500; text-transform:none; letter-spacing:0; }
  #detail-dialog .fact strong { font-size:13px; font-weight:600; overflow-wrap:anywhere; }
  .erp-dialog-tabs { background:white; border:0; border-bottom:1px solid var(--line); border-radius:0; padding:0; margin-bottom:16px; flex-wrap:nowrap; overflow-x:auto; gap:16px; }
  .erp-dialog-tabs .erp-tab-btn { min-height:44px; padding:9px 2px; flex:0 0 auto; border:0; border-bottom:2px solid transparent; border-radius:0; box-shadow:none; font-size:13px; font-weight:550; }
  .erp-dialog-tabs .erp-tab-btn.active { color:var(--red); border-bottom-color:var(--red); box-shadow:none; }
  .erp-tab-btn:focus-visible { outline:2px solid var(--red); outline-offset:-2px; }
  [data-erp-panel] { min-width:0; }
  .sale-document-actions { display:flex; align-items:center; flex-wrap:wrap; justify-content:space-between; gap:8px; margin-bottom:12px; }
  .erp-form-grid { grid-template-columns:repeat(auto-fit,minmax(min(100%,210px),1fr)); }
  /* Filtros comparables en listas; no alcanza formularios ni documentos. */
  #view .filter-bar > label { min-width:0; margin:0; font-size:12px; gap:6px; flex:1 1 160px; }
  #view .filter-bar > .inventory-search-field { flex:2 1 280px; }
  #view .filter-bar > label input:not([type="checkbox"]):not([type="radio"]), #view .filter-bar > label select { width:100%; min-width:0; margin:0; }
  #view .list-search-field { flex:1 1 240px; width:min(100%,480px); max-width:480px; margin:0; font-size:12px; gap:6px; }
  #view [data-ui-style="u248"] > [data-ui-style="u250"] { flex:1 1 360px; justify-content:flex-end; min-width:0; }
  #view [data-ui-style="u250"] > .search-input-wrap { flex:1 1 240px; max-width:440px; min-width:0; }
  #view .search-input-wrap input { min-width:0; }
  /* El texto empieza después de la lupa (otras reglas dejaban el relleno en 12 px y la lupa tapaba la primera letra). */
  #app #view .search-input-wrap input[type="search"] { padding-left:38px; }
  #view .kpi-card [data-ui-style="u224"] { display:none; }
  #view .kpi-title, #view .stat-label, #view .stat-card-head small { text-transform:none; letter-spacing:0; }
  #view .kpi-value, #view .stat-value, #view .erp-kpi-value, #view td { font-variant-numeric:tabular-nums; }
  #view :is(.view-header,.erp-header-card) p { text-wrap:pretty; }
  #view input::placeholder, #view textarea::placeholder { color:var(--erp-muted); opacity:1; }
  #app input, #app textarea { caret-color:var(--erp-brand); }
  #view ::selection { background:var(--erp-brand-soft); color:var(--erp-ink); }
  #view .table-wrap { scrollbar-color:var(--erp-border-strong) var(--erp-surface-subtle); scrollbar-width:thin; }
  #view .table-wrap:focus-visible { outline:2px solid var(--erp-brand); outline-offset:2px; }
  #view .clients-directory-table { min-width:920px; }
  #view .clients-directory-table td[data-label="Documento"],
  #view .clients-directory-table td[data-label="Contacto"] .tabular-nums,
  #view .clients-directory-table .badge-dni, #view .clients-directory-table .badge-ruc { white-space:nowrap; overflow-wrap:normal; flex-shrink:0; }
  #view .table-wrap[data-scrollable-table]::before { content:'Desplázate para ver todas las columnas'; display:block; position:sticky; left:0; width:fit-content; max-width:100%; padding:8px 12px; color:var(--erp-muted); font-size:12px; line-height:1.5; }
  #view a { text-underline-offset:3px; }
  .view-location { display:none; }
  #view { animation:none; }

  /* Pantalla de acceso · Opción C Esencial (centrada, sin panel fotográfico dividido) */
  .access.access-essential {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 36px 20px;
    background: #f1f2f4;
    grid-template-columns: none;
  }
  .access.access-essential .access-card {
    width: min(440px, 100%);
    min-height: 540px;
    margin: 0;
    padding: 34px 38px 24px;
    background: #ffffff;
    border: 0;
    border-radius: 14px;
    box-shadow: 0 14px 42px rgba(25, 38, 49, 0.06);
    display: flex;
    flex-direction: column;
  }
  .access.access-essential .access-essential-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 11px;
    margin: 0 0 30px;
    color: #20292d;
  }
  .access.access-essential .access-essential-brand img {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
  }
  .access.access-essential .access-essential-brand strong {
    display: block;
    font-size: 23px;
    font-weight: 700;
    letter-spacing: 0.04em;
    line-height: 1.05;
  }
  .access.access-essential .access-essential-brand small {
    display: block;
    font-size: 9px;
    font-weight: 600;
    letter-spacing: 0.12em;
    color: #49565a;
    margin-top: 3px;
  }
  .access.access-essential .access-essential-body {
    width: 100%;
    max-width: 372px;
    margin: 0 auto 26px;
  }
  .access.access-essential h1 {
    font-size: 27px;
    font-weight: 650;
    letter-spacing: -0.03em;
    line-height: 1.2;
    margin: 0 0 10px;
    text-align: center;
    color: #20292d;
    text-wrap: balance;
  }
  .access.access-essential .access-intro {
    text-align: center;
    font-size: 14px;
    line-height: 1.5;
    color: #5a666d;
    margin: 0 0 28px;
  }
  .access.access-essential form label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: #20292d;
    margin: 0 0 8px;
  }
  .access.access-essential .access-input-wrap {
    height: 50px;
    border: 1px solid #d6dce0;
    border-radius: 9px;
    display: flex;
    align-items: center;
    gap: 11px;
    padding: 0 14px;
    margin-bottom: 20px;
    background: #ffffff;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
  }
  .access.access-essential .access-input-wrap:has(+ .access-field-hint) {
    margin-bottom: 6px;
  }
  .access.access-essential .access-field-hint {
    display: block;
    margin: 0 0 18px;
    font-size: 12px;
    color: #5a666d;
  }
  .access.access-essential .access-input-wrap > svg {
    width: 19px;
    height: 19px;
    color: #5d6b73;
    flex-shrink: 0;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  .access.access-essential .access-input-wrap:focus-within {
    border-color: var(--red);
    box-shadow: 0 3px 10px rgba(200, 16, 46, 0.08);
  }
  .access.access-essential .access-input-wrap input {
    border: 0;
    outline: 0;
    box-shadow: none;
    padding: 0;
    margin: 0;
    width: 100%;
    min-width: 0;
    height: 100%;
    background: transparent;
    font-size: 15px;
    color: #20292d;
    caret-color: var(--red);
  }
  .access.access-essential .access-input-wrap input::placeholder {
    color: #637079;
    opacity: 1;
  }
  .access.access-essential .access-input-password {
    padding-right: 3px;
  }
  .access.access-essential .access-password-toggle {
    border: 0;
    background: transparent;
    color: #526069;
    min-width: 44px;
    height: 44px;
    padding: 0;
    border-radius: 7px;
    cursor: pointer;
    display: grid;
    place-items: center;
    flex-shrink: 0;
  }
  .access.access-essential .access-password-toggle:hover {
    background: #f2f4f5;
    color: #20292d;
  }
  .access.access-essential .access-password-toggle:focus-visible {
    outline: 2px solid var(--red);
    outline-offset: 2px;
  }
  .access.access-essential .access-password-toggle svg {
    width: 19px;
    height: 19px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.75;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  .access.access-essential .access-password-toggle .icon-eye-hide {
    display: none;
  }
  .access.access-essential .access-password-toggle.is-visible .icon-eye-show {
    display: none;
  }
  .access.access-essential .access-password-toggle.is-visible .icon-eye-hide {
    display: block;
  }
  .access.access-essential .access-submit {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
    width: 100%;
    min-height: 50px;
    margin-top: 6px;
    border: 0;
    border-radius: 9px;
    background: var(--red);
    color: #ffffff;
    font-size: 14px;
    font-weight: 600;
    box-shadow: 0 5px 12px rgba(200, 16, 46, 0.12);
    transition: background-color 0.15s ease;
  }
  .access.access-essential .access-submit:hover:not(:disabled) {
    background: #a70d27;
    transform: none;
  }
  .access.access-essential .access-submit svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.85;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  .access.access-essential .access-account-help {
    font-size: 12px;
    color: #5a666d;
    margin: 18px 0 0;
    text-align: center;
    line-height: 1.55;
  }
  .access.access-essential .access-essential-footer {
    margin-top: auto;
    padding-top: 12px;
    text-align: center;
    font-size: 11px;
    color: #59666e;
    line-height: 1.5;
  }
  .access.access-essential .access-essential-footer span {
    margin: 0 6px;
  }

  /* Fase 2.1 — Refinamiento selectivo de Inventario real (Stock, Retazos, Caballetes, Catálogos y Ficha) */
  .num-tabular {
    font-variant-numeric: tabular-nums;
  }
  #app .inventory-kpi-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #ffffff;
    margin-bottom: 16px;
    overflow: hidden;
  }
  #app .inventory-kpi-cell {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    padding: 13px 16px;
    border-right: 1px solid var(--line);
  }
  #app .inventory-kpi-cell:last-child {
    border-right: 0;
  }
  #app .inventory-kpi-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    line-height: 1.35;
  }
  #app .inventory-kpi-value {
    font-size: 22px;
    font-weight: 650;
    color: var(--ink);
    line-height: 1.2;
    letter-spacing: -0.02em;
  }
  #app .inventory-kpi-sub {
    font-size: 11px;
    color: var(--muted);
    line-height: 1.4;
  }

  #app .stock-alert-banner {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-left: 3px solid #d97706;
    border-radius: 9px;
    padding: 12px 16px;
    margin-bottom: 16px;
    box-shadow: none;
  }
  #app .stock-alert-layout {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
  }
  #app .stock-alert-copy {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-width: 0;
  }
  #app .stock-alert-icon {
    width: 20px;
    height: 20px;
    color: #b45309;
    flex-shrink: 0;
    margin-top: 1px;
  }
  #app .stock-alert-icon svg {
    width: 20px;
    height: 20px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.85;
    stroke-linecap: round;
    stroke-linejoin: round;
  }
  #app .stock-alert-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
  }
  #app .stock-crit-chip {
    min-height: 36px;
    padding: 5px 10px;
    border-radius: 999px;
    border: 1px solid #fcd34d;
    background: #ffffff;
    color: #78350f;
    font-size: 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    box-shadow: none;
  }
  #app .stock-crit-chip:hover {
    transform: none;
    background: #fef3c7;
    border-color: #f59e0b;
    box-shadow: none;
  }

  #app .inventory-workspace-card {
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 0;
    overflow: hidden;
    background: #ffffff;
  }
  #app .inventory-workspace-card > .filter-bar {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr);
    gap: 12px;
    padding: 16px 18px 12px;
    margin: 0;
    align-items: end;
  }
  #app .inventory-workspace-card > .filter-bar label {
    margin: 0;
    font-size: 12px;
    font-weight: 600;
    color: var(--ink);
  }
  #app .inventory-workspace-card > .filter-bar input[type="search"],
  #app .inventory-workspace-card > .filter-bar select {
    width: 100%;
    min-width: 0;
    min-height: 40px;
    margin-top: 5px;
  }
  #app .inventory-workspace-card .inventory-group-control {
    grid-column: 1 / -1;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: fit-content;
    font-size: 12px;
    font-weight: 500;
    color: #334155;
    padding-top: 2px;
    cursor: pointer;
  }
  #app .inventory-workspace-card .inventory-group-control input[type="checkbox"] {
    width: 16px;
    height: 16px;
    margin: 0;
    accent-color: var(--red);
  }
  #app .inventory-workspace-card > .inventory-result-count {
    padding: 0 18px 12px;
    margin: 0;
    font-size: 12px;
    color: var(--muted);
    border-bottom: 1px solid var(--line);
  }
  #app .inventory-remnants-card .inventory-groups {
    padding: 12px 18px 18px;
    display: grid;
    gap: 10px;
  }
  #app .inventory-remnants-card > #inv-result > .inventory-stock-table-wrap,
  #app .inventory-modern-stock > #inv-result > .inventory-stock-table-wrap {
    border: 0;
    border-radius: 0;
  }
  #app .inventory-unit-code {
    letter-spacing: 0.01em;
    font-variant-numeric: tabular-nums;
  }
  #app .inventory-status-stack {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
  }
  :is(#app, dialog) .status.status-storage {
    background: #f1f5f9;
    color: #334155;
    border: 1px solid #cbd5e1;
  }
  :is(#app, dialog) .status.status-danger {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
  }
  #app .inventory-irregular-note {
    display: block;
    margin-top: 4px;
  }
  #app .inventory-stock-table td button[data-item-id] {
    min-height: 36px;
    padding: 6px 12px;
    font-size: 12px;
    font-weight: 600;
  }

  #app .caballetes-workspace-card {
    padding: 18px 20px 20px;
  }
  #app .caballete-grid {
    gap: 14px;
    margin-top: 14px;
  }
  #app .caballete-zone-group { margin-top: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
  #app .caballete-zone-group:first-of-type { margin-top: 6px; }
  #app .caballete-zone-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    min-height: 56px;
    padding: 10px 16px;
    border: 0;
    border-radius: 10px;
    background: #f8fafc;
    color: var(--ink);
    text-align: left;
    cursor: pointer;
  }
  #app .caballete-zone-toggle:hover { background: #f1f5f9; }
  #app .caballete-zone-toggle:focus-visible { outline: 2px solid var(--red); outline-offset: -2px; }
  #app .caballete-zone-toggle[aria-expanded="true"] { border-bottom-left-radius: 0; border-bottom-right-radius: 0; border-bottom: 1px solid var(--line); }
  #app .caballete-zone-info { display: grid; gap: 2px; min-width: 0; }
  #app .caballete-zone-meta { font-size: 12px; font-weight: 500; color: var(--muted); }
  #app .caballete-zone-body { padding: 4px 16px 16px; }
  #app .caballete-remove { color: var(--muted); margin-left: 12px; }
  #app .caballete-zone-heading {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: var(--ink);
  }
  #app .caballete-zone-heading svg {
    width: 15px;
    height: 15px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
    color: var(--muted);
  }
  #app .caballete-zone-heading small {
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
  }
  #app .caballete-card {
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 16px;
    gap: 14px;
    box-shadow: none;
    transition: border-color 0.15s ease;
  }
  #app .caballete-card:hover {
    transform: none;
    border-color: #94a3b8;
    box-shadow: none;
  }
  #app .caballete-zone {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 0.02em;
    text-transform: none;
    margin-bottom: 3px;
  }
  #app .caballete-zone svg {
    width: 13px;
    height: 13px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
    flex-shrink: 0;
  }
  #app .caballete-title {
    font-size: 17px;
    font-weight: 650;
  }
  #app .caballete-stats {
    padding: 12px 14px;
    border-radius: 8px;
    gap: 10px 14px;
  }
  #app .caballete-stat-item small {
    font-size:12px;
    font-weight: 500;
    text-transform: none;
    letter-spacing: 0;
  }
  #app .caballete-stat-item strong {
    font-size: 15px;
    font-weight: 650;
  }
  #app .caballete-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: auto;
  }
  #app .caballete-actions .btn-filter-by-loc {
    flex: 1 1 180px;
    width: auto;
    margin-top: 0;
    min-height: 38px;
    font-size: 13px;
    font-weight: 600;
  }
  #app .caballete-actions .inventory-catalog-edit {
    position: static;
    margin: 0;
    min-height: 38px;
    padding: 6px 10px;
    font-size: 12px;
  }

  #app .inventory-catalog-section .inventory-catalog-list li {
    position: static;
    padding: 11px 12px;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }
  #app .inventory-catalog-section .inventory-catalog-edit {
    position: static;
    margin-top: 2px;
    min-height: 34px;
    padding: 4px 8px;
    font-size: 12px;
  }
  #app .inventory-catalog-section .inventory-lot-label-action {
    margin-top: 4px;
    width: 100%;
    justify-content: center;
  }

  dialog .inventory-item-sheet {
    display: grid;
    gap: 16px;
  }
  dialog .inventory-sheet-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--line);
  }
  dialog .inventory-item-sheet .inventory-item-provenance {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
    font-size: 13px;
    color: #334155;
  }
  dialog .inventory-item-sheet .inventory-photo-link {
    margin-left: auto;
    font-weight: 600;
    color: var(--red);
    text-underline-offset: 3px;
  }
  dialog .inventory-item-sheet .inventory-qr-card {
    margin-top: 0;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #ffffff;
    text-align: left;
    box-shadow: none;
  }

  /* Fase 2.2 & 2.3 — Mostrador comercial, franja económica #detail-dialog y banner de resiliencia Wi-Fi */
  #app .connection-status-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px 14px;
    padding: 10px 24px;
    background: #fffbeb;
    border-bottom: 1px solid #fcd34d;
    color: #78350f;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.45;
  }
  #app .connection-status-banner[hidden] {
    display: none !important;
  }
  #app .connection-status-banner[data-status-mode="session-expired"] {
    background: #fef2f2;
    border-bottom-color: #fecaca;
    color: #991b1b;
  }
  #app .connection-status-banner .compact-btn {
    min-height: 34px;
    padding: 5px 11px;
    font-size: 12px;
    font-weight: 600;
    background: #ffffff;
  }

  #app .commercial-workspace-card {
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 9px;
    overflow: hidden;
    background: #ffffff;
  }
  #app .commercial-workspace-card > .toolbar {
    padding: 16px 18px;
    margin: 0;
    border-bottom: 1px solid var(--line);
    align-items: end;
  }
  #app .commercial-workspace-card > #sales-result > .table-wrap {
    border: 0;
    border-radius: 0;
  }

  #detail-dialog .sale-economic-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #f8fafc;
    margin-bottom: 16px;
    overflow: hidden;
  }
  #detail-dialog .sale-econ-cell {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    padding: 12px 14px;
    border-right: 1px solid var(--line);
    background: #ffffff;
  }
  #detail-dialog .sale-econ-cell:last-child {
    border-right: 0;
  }
  #detail-dialog .sale-econ-cell > small:first-child {
    font-size:12px;
    font-weight: 600;
    color: var(--muted);
    line-height: 1.3;
  }
  #detail-dialog .sale-econ-cell > strong {
    font-size: 17px;
    font-weight: 650;
    color: var(--ink);
    line-height: 1.25;
    overflow-wrap: anywhere;
  }
  #detail-dialog .sale-econ-cell.is-due > strong {
    color: #9a3412;
  }
  #detail-dialog .sale-econ-cell.is-settled > strong {
    color: #166534;
  }
  #detail-dialog .sale-context-facts {
    margin-bottom: 14px;
  }
  #detail-dialog .sale-document-actions,
  #detail-dialog .dialog-actions-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
  }
  #detail-dialog .sale-physical-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8fafc;
  }

  /* Rediseño Clientes estilo Backstage: Franja de métricas, tarjeta de trabajo y directorio */
  #app .client-view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
  }
  #app .client-kpi-strip {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    border: 1px solid var(--line);
    border-radius: 9px;
    background: #ffffff;
    margin-bottom: 16px;
    overflow: hidden;
  }
  #app .client-kpi-cell {
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
    padding: 13px 16px;
    border-right: 1px solid var(--line);
    border-radius: 0;
    border-top: 0;
    border-bottom: 0;
    border-left: 0;
    background: transparent;
  }
  #app .client-kpi-cell:last-child {
    border-right: 0;
  }
  #app .client-kpi-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    line-height: 1.35;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }
  #app .client-kpi-value {
    font-size: 22px;
    font-weight: 650;
    color: var(--ink);
    line-height: 1.2;
    letter-spacing: -0.02em;
  }
  #app .client-kpi-sub {
    font-size: 11px;
    color: var(--muted);
    line-height: 1.4;
  }

  #app .client-workspace-card {
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 9px;
    overflow: hidden;
    background: #ffffff;
    margin-bottom: 24px;
  }
  #app .client-workspace-toolbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px 16px;
    padding: 16px 18px;
    margin: 0;
    border-bottom: 1px solid var(--line);
    background: #fafbfc;
  }
  #app .client-search-field {
    flex: 1 1 280px;
    min-width: 0;
  }
  #app .client-search-field label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0;
  }
  #app .client-search-field input[type="search"] {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #ffffff;
    font-size: 13px;
  }
  #app .client-filter-field {
    flex: 0 1 240px;
    min-width: 180px;
  }
  #app .client-filter-field label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin: 0;
  }
  #app .client-filter-field select {
    width: 100%;
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: #ffffff;
    font-size: 13px;
  }
  #app .client-workspace-card > #clients-table-result > .table-wrap {
    border: 0;
    border-radius: 0;
  }

  #app .client-cell-layout {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
  }
  #app .client-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
    flex-shrink: 0;
    user-select: none;
  }
  #app .client-avatar.is-company {
    background: #f1f5f9;
    color: #1e293b;
    border: 1px solid #cbd5e1;
  }
  #app .client-avatar.is-person {
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
  }
  #app .client-identity-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
  }
  #app .client-legal-name {
    font-weight: 650;
    color: var(--ink);
    line-height: 1.3;
    overflow-wrap: anywhere;
  }
  #app .client-trade-name {
    font-size: 12px;
    color: var(--muted);
    line-height: 1.3;
    overflow-wrap: anywhere;
  }
  #app .client-contact-name {
    font-size: 11px;
    color: #64748b;
    line-height: 1.3;
    overflow-wrap: anywhere;
  }
  #app .client-contact-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    font-size: 13px;
  }
  #app .client-phone {
    font-weight: 600;
    color: var(--ink);
  }
  #app .client-email {
    font-size: 12px;
    color: var(--muted);
    overflow-wrap: anywhere;
  }
  #app .client-action-buttons {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
  }
  #app .client-action-buttons .btn-view-profile {
    background: #f8fafc;
    border: 1px solid #cbd5e1;
    color: #0f172a;
    font-weight: 600;
  }
  #app .client-action-buttons .btn-view-profile:hover {
    background: #ffffff;
    border-color: #94a3b8;
  }
  #app .client-debt-badge {
    margin-top: 3px;
    display: inline-block;
  }

  /* Expediente 360 (#detail-dialog) */
  #detail-dialog .dossier-hero-title {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
  }
  #detail-dialog .dossier-identity-text {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
  }
  #detail-dialog .dossier-name-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
  }
  #detail-dialog .dossier-legal-name {
    font-size: 18px;
    font-weight: 700;
    color: var(--ink);
  }
  #detail-dialog .dossier-trade-subtitle {
    margin-bottom: 12px;
    font-size: 13px;
    color: var(--muted);
  }
  #detail-dialog .dossier-meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px 16px;
    padding: 14px 16px;
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 9px;
    margin-bottom: 14px;
  }
  #detail-dialog .dossier-meta-cell {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
  }
  #detail-dialog .dossier-meta-cell strong {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  #detail-dialog .dossier-meta-cell span {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink);
    overflow-wrap: anywhere;
  }
  #detail-dialog .dossier-stat-strip {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
  }
  #detail-dialog .dossier-stat-cell {
    padding: 12px 14px;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    gap: 2px;
  }
  #detail-dialog .dossier-stat-cell .client-stat-title {
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }
  #detail-dialog .dossier-stat-cell .client-stat-value {
    font-size: 18px;
    font-weight: 700;
    color: var(--ink);
  }
}
@media screen and (max-width:980px) {
  #app .topbar { padding-inline:16px; }
  #app .workspace-location { display:none; }
  #app .view-location { display:block; margin:0 0 12px; color:var(--erp-muted); font-size:12px; line-height:1.5; overflow-wrap:anywhere; }
  #app #main { padding:20px 20px calc(100px + env(safe-area-inset-bottom,0px)); }
  #app .primary, #app .secondary, #app .table-button, #app .icon-button { min-height:44px; }
  #nav .nav-parent-btn, #nav .nav-sub-item { min-height:44px; }
  .erp-header-actions { flex-wrap:wrap; }
  .erp-kpi-grid { grid-template-columns:repeat(2,minmax(0,1fr)); }
  .erp-kpi-card { border-bottom:1px solid var(--line); }
  .erp-kpi-card:nth-child(even) { border-right:0; }
  .erp-kpi-card:nth-last-child(-n+2) { border-bottom:0; }
  #app .inventory-kpi-strip { grid-template-columns:repeat(2,minmax(0,1fr)); }
  #app .inventory-kpi-cell { border-bottom:1px solid var(--line); }
  #app .inventory-kpi-cell:nth-child(even) { border-right:0; }
  #app .inventory-kpi-cell:nth-last-child(-n+2) { border-bottom:0; }
  #app .client-kpi-strip { grid-template-columns:repeat(2,minmax(0,1fr)); }
  #app .client-kpi-cell { border-bottom:1px solid var(--line); }
  #app .client-kpi-cell:nth-child(even) { border-right:0; }
  #app .client-kpi-cell:nth-last-child(-n+2) { border-bottom:0; }
  #detail-dialog .dossier-stat-strip { grid-template-columns:repeat(2,minmax(0,1fr)); }
  #app .stock-crit-chip, #app .caballete-actions .btn-filter-by-loc, #app .caballete-actions .inventory-catalog-edit, #app .inventory-catalog-section .inventory-catalog-edit, #app .connection-status-banner .compact-btn { min-height:44px; }
  #app .connection-status-banner { padding-inline:16px; }
  #detail-dialog .sale-economic-strip { grid-template-columns:repeat(2,minmax(0,1fr)); }
  #detail-dialog .sale-econ-cell { border-bottom:1px solid var(--line); }
  #detail-dialog .sale-econ-cell:nth-child(even) { border-right:0; }
  #detail-dialog .sale-econ-cell:nth-last-child(-n+2) { border-bottom:0; }
  .acc-grid-2 { grid-template-columns:minmax(0,1fr); }
}
@media screen and (max-width:600px) {
  #app .topbar { padding-inline:12px; gap:10px; }
  #app .topbar-actions { gap:8px; flex:1; justify-content:flex-end; }
  #app .warehouse-context { min-width:0; flex:1; max-width:180px; }
  #app .role-avatar { display:none; }
  #app #main { padding:18px 14px calc(100px + env(safe-area-inset-bottom,0px)); }
  #app .view-header { align-items:flex-start; gap:12px; margin-bottom:16px; }
  #app .view-header h2, .erp-header-card h2 { font-size:21px; }
  #app .kpi-grid { grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; }
  #app .kpi-card { padding:12px; }
  #app .kpi-value { font-size:21px; }
  #app .finance-kpi-row { grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; }
  #app .stat-card-premium { padding:12px; }
  #app .stat-card-value { font-size:21px; }
  #app .stat-card-head small { font-size:12px; }
  #app .stat-card-icon { display:none; }
  #app .chart-card { padding:14px; max-width:100%; min-width:0; overflow:hidden; }
  #app .chart-bars-wrap { max-width:100%; min-width:0; overflow-x:auto; -webkit-overflow-scrolling:touch; scrollbar-width:thin; }
  #app .ranking-row { grid-template-columns:36px minmax(0, 1fr); gap:10px; padding:10px 12px; }
  #app .ranking-body { min-width:0; }
  #app .ranking-meta { gap:6px; flex-direction:column; overflow-wrap:anywhere; }
  #app .ranking-stat { grid-column:1 / -1; align-items:flex-start; text-align:left; flex-direction:row; justify-content:space-between; width:100%; border-top:1px solid var(--line); padding-top:8px; }
  /* El toolbar es columna: flex-basis en px se convertiría en altura. */
  #app .toolbar { align-items:stretch; }
  #app .toolbar label { min-width:0; flex:0 1 auto; width:100%; }
  #app .view-actions, #app .toolbar { flex-wrap:wrap; }
  .erp-header-card > div:first-child { flex-basis:100%; }
  .erp-header-actions { width:100%; }
  .erp-header-actions button { flex:1 1 auto; }
  .erp-kpi-card { padding:12px; }
  .erp-kpi-value { font-size:21px; }
  .erp-toolbar { align-items:stretch; }
  .erp-toolbar-group { flex:1 1 100%; }
  .erp-toolbar-group > input, .erp-toolbar-group > select { width:100%; }
  #view .filter-bar > label { flex:1 1 100%; }
  #app .inventory-modern-stock .inventory-search-field,
  #app .inventory-workspace-card > .filter-bar .inventory-search-field { grid-column:1 / -1; }
  #app .inventory-workspace-card > .filter-bar { padding:12px; grid-template-columns:minmax(0,1fr) minmax(0,1fr); gap:10px; }
  #app .inventory-workspace-card > .inventory-result-count { padding:0 12px 10px; }
  #app .inventory-remnants-card .inventory-groups { padding:10px 12px 14px; }
  #app .inventory-kpi-cell { padding:11px 12px; }
  #app .inventory-kpi-value { font-size:19px; }
  #app .caballetes-workspace-card { padding:14px; }
  dialog .inventory-item-sheet .inventory-photo-link { margin-left:0; }
  #view [data-ui-style="u248"] > [data-ui-style="u250"] { justify-content:flex-start; }
  #view [data-ui-style="u250"] > .search-input-wrap { max-width:none; }
  #view input:not([type="checkbox"]):not([type="radio"]), #view select, #view textarea,
  dialog:not(.print-preview) input:not([type="checkbox"]):not([type="radio"]), dialog:not(.print-preview) select, dialog:not(.print-preview) textarea { font-size:16px; }
  .erp-toolbar select, .erp-toolbar input { min-height:44px; }
  #detail-dialog .dialog-head { padding:14px 16px; }
  #detail-dialog #dialog-body { padding:16px; }
  #detail-dialog .facts { grid-template-columns:repeat(2,minmax(0,1fr)); }
  #detail-dialog .sale-econ-cell { padding:10px 12px; }
  #detail-dialog .sale-econ-cell > strong { font-size:15px; }
  #app .client-workspace-toolbar { padding:12px; }
  #app .client-search-field, #app .client-filter-field { flex-basis:100%; width:100%; min-width:0; }
  #detail-dialog .dossier-meta-grid { grid-template-columns:minmax(0,1fr); padding:12px; }
  #detail-dialog .dossier-stat-strip { grid-template-columns:minmax(0,1fr); }
  #app .commercial-workspace-card > .toolbar { padding:12px; }
  #app .connection-status-banner { padding:10px 12px; }
  .erp-dialog-tabs { gap:12px; }
  .access.access-essential { padding:20px 14px; }
  .access.access-essential .access-card { width:100%; max-width:430px; min-height:0; padding:26px 22px 20px; border-radius:14px; box-shadow:0 12px 32px rgba(25,38,49,0.06); }
  .access.access-essential .access-essential-brand { margin-bottom:22px; }
  .access.access-essential h1 { font-size:24px; }
  .access.access-essential .access-intro { margin-bottom:22px; }
  .access.access-essential .access-input-wrap input { font-size:16px; }
}
.nav-stage-label { min-width:0; flex:1; }
#nav .nav-module-status { display:block; margin-top:3px; color:#bfcbd7; font-size:11px; font-weight:400; line-height:1.35; }
#nav .nav-stage-lock { width:15px; height:15px; flex-shrink:0; color:#bfcbd7; }
#nav .nav-parent-btn[data-module-stage] .nav-chevron { margin-left:0; order:3; }
#nav .nav-sub-item[data-module-stage] { color:#bcc8d4; cursor:not-allowed; }
#nav .nav-sub-item[data-module-stage] .nav-stage-lock { margin-left:auto; width:13px; height:13px; }
#nav .nav-sub-item[data-module-stage]:hover { background:rgba(255,255,255,.04); }
@media print {
  .erp-dialog-tabs, .workspace-location, .view-location, #route-status, #connection-status-banner { display:none!important; }
  [data-erp-panel][hidden] { display:block!important; }
  .erp-lazy-section, .table-wrap { content-visibility:visible; contain-intrinsic-size:none; }
}

/* Ingreso único: preparación, conteo físico y revisión administrativa. */
.receipt-fields { border: 0; padding: 0; margin: 0; min-width: 0; }
.receipt-workspace { display: grid; gap: 16px; min-width: 0; }
.receipt-list { display: grid; gap: 12px; padding: 0; margin: 0; list-style: none; }
.receipt-list > li { display: grid; gap: 8px; padding: 12px; border: 1px solid var(--border, #dfe3e8); border-radius: 10px; min-width: 0; overflow-wrap: anywhere; }
.receipt-list > li > button[data-receipt] { display: grid; gap: 6px; text-align: left; width: 100%; white-space: normal; }
.receipt-unit > div { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.receipt-scan-form { display: grid; gap: 12px; padding: 16px; border: 1px solid var(--border, #dfe3e8); border-radius: 10px; }
.receipt-workspace .dialog-actions { flex-wrap: wrap; }
.receipt-workspace .dialog-actions button { white-space: normal; }
.receipt-workspace input, .receipt-workspace select { min-width: 0; max-width: 100%; }

/* El contenido del encabezado determina su altura: el almacén conserva aire arriba. */
@media screen {
  #app .topbar { height:auto; min-height:84px; padding-block:12px !important; align-items:center; }
  #app .topbar-actions { min-width:0; align-items:center; flex-wrap:wrap; justify-content:flex-end; row-gap:10px; }
  #app .warehouse-context { margin:0; gap:5px; line-height:1.35; align-self:center; flex:0 1 240px; width:clamp(150px,22vw,240px); max-width:240px; }
  #app .warehouse-context #warehouse-indicator { line-height:1.35; max-width:100%; }
  #app .warehouse-context select { margin:0; min-height:38px; }
  #app .topbar .role-switcher { min-width:0; }
  #app .topbar .role-info { min-width:0; max-width:200px; }
  #app .topbar .role-info strong { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
}
@media screen and (max-width:820px) {
  #app .topbar { min-height:84px; padding-block:12px !important; }
  #app .topbar .warehouse-context select { min-height:44px; }
}

@media screen and (max-width:600px) {
  #app .topbar .warehouse-context { flex:1 1 140px; width:auto; min-width:0; max-width:180px; }
}

/* Componentes compartidos: cliente seleccionado y encabezado opaco al desplazar. */
@media screen {
  #app .topbar { background:#fff; backdrop-filter:none; }
  #app .client-selected-badge { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:12px; align-items:start; max-width:100%; }
  #app .client-selected-badge > [data-ui-style="u023"] { display:grid; grid-template-columns:auto minmax(0,1fr); min-width:0; align-items:start; }
  #app .client-selected-badge > [data-ui-style="u023"] > div { min-width:0; }
  #app .client-selected-badge strong, #app .client-selected-badge .muted { overflow-wrap:anywhere; white-space:normal; }
  #app .client-selected-badge [data-ui-style="u026"] { white-space:nowrap; min-height:44px; max-width:100%; }
  #app .client-selected-badge :is(.badge-dni,.badge-ruc) { white-space:nowrap; }
  #app .client-warning-banner { min-width:0; overflow-wrap:anywhere; }
  #app .client-warning-banner svg { flex:none; }
}
@media screen and (max-width:600px) {
  #app .client-selected-badge { grid-template-columns:minmax(0,1fr); padding:14px; gap:10px; }
  #app .client-selected-badge > [data-ui-style="u023"] { grid-template-columns:minmax(0,1fr); gap:8px; }
  #app .client-selected-badge [data-ui-style="u026"] { justify-self:start; }
}

/* Client editor: compact fields without changing document lookup or permissions. */
dialog.client-editor { width:min(640px,calc(100vw - 24px)); max-width:calc(100vw - 24px); }
.client-editor .dialog-content { padding:20px; }
.client-editor h3 { font-size:20px; line-height:1.3; }
.client-editor form { --workflow-control-height:42px; display:flex; flex-direction:column; gap:12px; }
.client-editor label { min-width:0; margin:0; gap:5px; font-size:13px; line-height:1.4; }
.client-editor :is(input,select,textarea) { min-width:0; width:100%; min-height:42px; padding:9px 10px; font-size:14px; line-height:1.4; border-radius:4px; }
.client-editor textarea { min-height:66px; }
.client-editor .field-grid { grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; align-items:start; margin:0; }
.client-editor .client-document-grid { grid-template-columns:150px minmax(0,1fr); }
#new-client-form .client-document-grid > label { font-size:13px !important; line-height:18px !important; gap:6px; }
.client-editor #edit-client-form .client-document-grid { grid-template-columns:minmax(0,1fr); }
.client-editor .doc-search-header { display:contents; }
.client-editor .doc-search-input-group { display:grid; grid-template-columns:minmax(0,1fr) auto; gap:6px; }
.client-editor .btn-doc-lookup { min-height:42px; padding:9px 12px; font-size:13px; border-radius:4px; }
.client-editor .doc-lookup-status { order:1; margin-top:2px; font-weight:500; font-size:12px; }
.client-editor .dialog-actions { margin-top:4px; gap:8px; }
.client-editor .dialog-actions button { min-height:42px; padding:9px 14px; font-size:14px; border-radius:4px; }
@media (max-width:540px) {
  .client-editor form { --workflow-control-height:44px; }
  .client-editor :is(input,select,textarea) { font-size:16px; }
  .client-editor .dialog-content { padding:16px; }
  .client-editor .field-grid,.client-editor .client-document-grid { grid-template-columns:minmax(0,1fr); }
  .client-editor select[name="documentType"] { width:190px; max-width:100%; }
  .client-editor :is(input,select,.btn-doc-lookup),.client-editor .dialog-actions button { min-height:44px; }
}
