/* ============================================================
   FACTURAE Premium Module — Estilos específicos
   Basado en variables de iEntop.css (design system ERP)
   ============================================================ */

/* ── Module Shell ── */
.fae-shell {
  display: flex;
  width: 100%;
  height: 100vh;
  background: var(--color-bg-primary);
  color: var(--color-text-primary);
  overflow: hidden;
  font-family: 'Inter', 'Segoe UI', system-ui, sans-serif;
}

/* ── Sidebar ── */
.fae-sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--color-bg-sidebar);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease, min-width 0.3s ease;
  z-index: 30;
  overflow: hidden;
}

.fae-sidebar.collapsed {
  width: 64px;
  min-width: 64px;
}

.fae-sidebar-brand {
  padding: 1.25rem 1rem;
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.fae-sidebar-logo {
  width: 40px;
  height: 40px;
  border-radius: 0.75rem;
  background: linear-gradient(135deg, var(--color-accent), color-mix(in srgb, var(--color-accent) 70%, #fff));
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 4px 12px color-mix(in srgb, var(--color-accent) 30%, transparent);
}

.fae-sidebar-logo svg { color: #fff; }

.fae-sidebar-title {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.fae-sidebar-title h1 {
  font-size: 1.0625rem;
  font-weight: 700;
  color: var(--color-text-primary);
  letter-spacing: -0.02em;
  white-space: nowrap;
  margin: 0;
}

.fae-sidebar-title span {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.fae-sidebar.collapsed .fae-sidebar-title { display: none; }

/* Nav items */
.fae-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.fae-nav-section {
  padding: 0.75rem 0.75rem 0.25rem;
  font-size: 0.625rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-text-muted);
}

.fae-sidebar.collapsed .fae-nav-section { display: none; }

.fae-nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: 0.5rem;
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.8125rem;
  font-weight: 500;
  user-select: none;
  white-space: nowrap;
  border: 1px solid transparent;
}

.fae-nav-item:hover {
  background: var(--color-bg-hover);
  color: var(--color-text-primary);
}

.fae-nav-item.active {
  background: var(--color-accent-subtle);
  color: var(--color-text-accent);
  border-color: color-mix(in srgb, var(--color-accent) 30%, transparent);
  font-weight: 600;
}

.fae-nav-item .fae-nav-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  opacity: 0.7;
}

.fae-nav-item.active .fae-nav-icon { opacity: 1; }

.fae-nav-item .fae-nav-label { flex: 1; }

.fae-sidebar.collapsed .fae-nav-label { display: none; }

.fae-nav-badge {
  font-size: 0.625rem;
  font-weight: 700;
  padding: 0.125rem 0.4375rem;
  border-radius: 9999px;
  background: var(--color-accent);
  color: #fff;
  min-width: 18px;
  text-align: center;
}

.fae-sidebar.collapsed .fae-nav-badge { display: none; }

/* Sidebar footer */
.fae-sidebar-footer {
  padding: 0.75rem;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}

.fae-sidebar-footer .fae-status-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  background: rgba(34, 197, 94, 0.08);
  border: 1px solid rgba(34, 197, 94, 0.2);
  border-radius: 0.5rem;
  font-size: 0.75rem;
  color: var(--color-success);
}

.fae-sidebar.collapsed .fae-status-chip span { display: none; }

.fae-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-success);
  flex-shrink: 0;
  animation: fae-pulse 2s ease-in-out infinite;
}

@keyframes fae-pulse {
  0%, 100% { opacity: 1; box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.4); }
  50% { opacity: 0.7; box-shadow: 0 0 0 6px rgba(34, 197, 94, 0); }
}

/* ── Main Content ── */
.fae-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

/* Top bar */
.fae-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  background: var(--color-bg-card);
  border-bottom: 1px solid var(--color-border);
  flex-shrink: 0;
  gap: 1rem;
  min-height: 56px;
}

.fae-topbar-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.fae-topbar-left h2 {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--color-text-primary);
  margin: 0;
}

.fae-topbar-left .fae-breadcrumb {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.fae-topbar-right {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.fae-topbar-btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.4375rem 0.875rem;
  font-size: 0.8125rem;
  font-weight: 500;
  border: 1px solid var(--color-border);
  border-radius: 0.5rem;
  background: var(--color-bg-input);
  color: var(--color-text-secondary);
  cursor: pointer;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.fae-topbar-btn:hover {
  border-color: var(--color-accent);
  color: var(--color-text-accent);
  background: var(--color-accent-subtle);
}

.fae-topbar-btn.primary {
  background: var(--color-accent);
  color: #fff;
  border-color: var(--color-accent);
}

.fae-topbar-btn.primary:hover {
  background: var(--color-accent-hover);
  box-shadow: 0 4px 12px color-mix(in srgb, var(--color-accent) 30%, transparent);
  transform: translateY(-1px);
}

/* ── Content Area ── */
.fae-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1.5rem;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

/* View panels — only active is visible */
.fae-view { display: none; }
.fae-view.active { display: block; animation: fae-fadeIn 0.3s ease; }

@keyframes fae-fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ============================================================
   DASHBOARD
   ============================================================ */

/* KPI Cards */
.fae-kpi-grid {
  display: grid;
  /* auto-fit y no un número fijo: eran 4 tarjetas y al pasar a 6 (se añadieron
     "Firmadas sin enviar" y "Con error") un repeat(4,1fr) dejaba las dos
     últimas descolgadas en una segunda fila. Así se reparten solas y además
     aguantan anchos estrechos. */
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.fae-kpi {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 0.75rem;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: relative;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.fae-kpi:hover {
  border-color: color-mix(in srgb, var(--color-accent) 40%, transparent);
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

.fae-kpi::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--color-accent), color-mix(in srgb, var(--color-accent) 40%, transparent));
  opacity: 0;
  transition: opacity 0.3s;
}

.fae-kpi:hover::after { opacity: 1; }

.fae-kpi-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.fae-kpi-icon {
  width: 40px;
  height: 40px;
  border-radius: 0.625rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.fae-kpi-icon.blue { background: rgba(59, 130, 246, 0.12); color: #3b82f6; }
.fae-kpi-icon.amber { background: rgba(245, 158, 11, 0.12); color: #f59e0b; }
.fae-kpi-icon.green { background: rgba(34, 197, 94, 0.12); color: #22c55e; }
.fae-kpi-icon.purple { background: rgba(139, 92, 246, 0.12); color: #8b5cf6; }
/* Añadidos con los KPIs "Firmadas sin enviar" y "Con error": el dashboard pasó
   de 4 a 6 tarjetas y estos dos colores no estaban definidos. */
.fae-kpi-icon.cyan { background: rgba(6, 182, 212, 0.12); color: #06b6d4; }
.fae-kpi-icon.red { background: rgba(239, 68, 68, 0.12); color: #ef4444; }

.fae-kpi-trend {
  font-size: 0.6875rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.125rem 0.375rem;
  border-radius: 9999px;
}

.fae-kpi-trend.up { background: rgba(34,197,94,0.1); color: #22c55e; }
.fae-kpi-trend.down { background: rgba(239,68,68,0.1); color: #ef4444; }

.fae-kpi-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--color-text-primary);
  letter-spacing: -0.02em;
  line-height: 1;
}

.fae-kpi-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-weight: 500;
}

/* Dashboard grid — chart + activity */
.fae-dash-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1rem;
}

/* Chart card */
.fae-chart-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 0.75rem;
  padding: 1.25rem;
}

.fae-chart-card h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text-primary);
  margin: 0 0 1rem 0;
}

/* CSS-only bar chart */
.fae-bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 0.75rem;
  height: 180px;
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--color-border);
}

.fae-bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  height: 100%;
  justify-content: flex-end;
}

.fae-bar {
  width: 100%;
  max-width: 40px;
  border-radius: 0.375rem 0.375rem 0 0;
  background: linear-gradient(180deg, var(--color-accent), color-mix(in srgb, var(--color-accent) 60%, transparent));
  transition: height 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
  position: relative;
  min-height: 4px;
}

.fae-bar:hover {
  filter: brightness(1.2);
  box-shadow: 0 0 12px color-mix(in srgb, var(--color-accent) 40%, transparent);
}

.fae-bar-label {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  font-weight: 500;
}

.fae-bar-value {
  font-size: 0.625rem;
  font-weight: 700;
  color: var(--color-text-accent);
}

/* Activity timeline */
.fae-activity-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 0.75rem;
  padding: 1.25rem;
}

.fae-activity-card h3 {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--color-text-primary);
  margin: 0 0 1rem 0;
}

.fae-timeline {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.fae-timeline-item {
  display: flex;
  gap: 0.75rem;
  padding: 0.625rem 0;
  border-bottom: 1px solid color-mix(in srgb, var(--color-border) 50%, transparent);
}

.fae-timeline-item:last-child { border-bottom: none; }

.fae-timeline-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 4px;
}

.fae-timeline-dot.green { background: var(--color-success); }
.fae-timeline-dot.amber { background: var(--color-warning); }
.fae-timeline-dot.red { background: var(--color-danger); }
.fae-timeline-dot.blue { background: #3b82f6; }

.fae-timeline-body {
  flex: 1;
  min-width: 0;
}

.fae-timeline-text {
  font-size: 0.8125rem;
  color: var(--color-text-primary);
  line-height: 1.4;
}

.fae-timeline-time {
  font-size: 0.6875rem;
  color: var(--color-text-muted);
  margin-top: 0.125rem;
}

/* ============================================================
   FACTURAS LIST
   ============================================================ */

/* Filters bar */
.fae-filters {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem;
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.fae-filter-group {
  display: flex;
  align-items: center;
  gap: 0.25rem;
}

.fae-filter-label {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  font-weight: 500;
  white-space: nowrap;
}

.fae-filter-select,
.fae-filter-input {
  padding: 0.375rem 0.625rem;
  font-size: 0.8125rem;
  background: var(--color-bg-input);
  border: 1px solid var(--color-border);
  border-radius: 0.375rem;
  color: var(--color-text-primary);
  outline: none;
  transition: border-color 0.2s;
}

.fae-filter-select:focus,
.fae-filter-input:focus {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 2px var(--color-accent-subtle);
}

.fae-search-box {
  flex: 1;
  min-width: 200px;
  position: relative;
}

.fae-search-box input {
  width: 100%;
  padding: 0.375rem 0.625rem 0.375rem 2rem;
  font-size: 0.8125rem;
  background: var(--color-bg-input);
  border: 1px solid var(--color-border);
  border-radius: 0.375rem;
  color: var(--color-text-primary);
  outline: none;
  transition: border-color 0.2s;
}

.fae-search-box input:focus {
  border-color: var(--color-border-focus);
  box-shadow: 0 0 0 2px var(--color-accent-subtle);
}

.fae-search-box svg {
  position: absolute;
  left: 0.625rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
}

/* Table */
.fae-table-wrap {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 0.75rem;
  overflow: hidden;
}

.fae-table {
  width: 100%;
  border-collapse: collapse;
}

.fae-table thead th {
  padding: 0.75rem 1rem;
  font-size: 0.6875rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-muted);
  background: color-mix(in srgb, var(--color-bg-secondary) 80%, var(--color-bg-primary));
  border-bottom: 1px solid var(--color-border);
  text-align: left;
  white-space: nowrap;
}

.fae-table tbody tr {
  transition: background 0.15s;
  cursor: pointer;
}

.fae-table tbody tr:hover {
  background: var(--color-bg-hover);
}

.fae-table tbody td {
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  color: var(--color-text-primary);
  border-bottom: 1px solid color-mix(in srgb, var(--color-border) 50%, transparent);
  white-space: nowrap;
}

.fae-table tbody tr:last-child td { border-bottom: none; }

/* Status badges */
.fae-status {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.1875rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

.fae-status.accepted { background: rgba(34,197,94,0.12); color: #22c55e; }
.fae-status.pending { background: rgba(245,158,11,0.12); color: #f59e0b; }
.fae-status.rejected { background: rgba(239,68,68,0.12); color: #ef4444; }
.fae-status.draft { background: rgba(148,163,184,0.12); color: #94a3b8; }
.fae-status.sent { background: rgba(59,130,246,0.12); color: #3b82f6; }

.fae-type-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.125rem 0.375rem;
  border-radius: 0.25rem;
  font-size: 0.6875rem;
  font-weight: 700;
  background: var(--color-bg-input);
  color: var(--color-text-accent);
  letter-spacing: 0.02em;
}

/* Amount column */
.fae-amount {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

/* Row actions */
/* Acciones de fila.
   Antes estaban a opacity:0 —solo aparecían al pasar el ratón por la fila— y
   eran botones de 28x28 con un icono suelto ("▶", "</>"): ni se veían ni, al
   verse, se entendía cuál era cuál. Ahora están siempre visibles (algo
   atenuadas para no competir con los datos) y llevan etiqueta junto al icono. */
.fae-row-actions {
  display: flex;
  gap: 0.375rem;
  opacity: 0.75;
  transition: opacity 0.2s;
}

.fae-table tbody tr:hover .fae-row-actions { opacity: 1; }

.fae-row-action {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  height: 26px;
  padding: 0 0.5rem;
  font-size: 0.6875rem;
  font-weight: 600;
  border: 1px solid var(--color-border);
  background: var(--color-bg-input);
  color: var(--color-text-secondary);
  border-radius: 0.375rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.2s;
}

.fae-row-action:hover {
  background: var(--color-accent-subtle);
  border-color: var(--color-accent);
  color: var(--color-text-accent);
}

.fae-row-action-ico { font-size: 0.8125rem; line-height: 1; }

/* En estrecho se cae la etiqueta y quedan los iconos, que ahí sí valen porque
   el tooltip sigue estando. */
@media (max-width: 1200px) {
  .fae-row-action-txt { display: none; }
  .fae-row-action { padding: 0 0.4rem; }
}

/* Pagination */
.fae-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--color-border);
}

.fae-pagination-info {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

.fae-pagination-btns {
  display: flex;
  gap: 0.25rem;
}

.fae-page-btn {
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--color-border);
  border-radius: 0.375rem;
  background: var(--color-bg-input);
  color: var(--color-text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.fae-page-btn:hover { border-color: var(--color-accent); color: var(--color-text-accent); }
.fae-page-btn.active { background: var(--color-accent); color: #fff; border-color: var(--color-accent); }

/* ============================================================
   CONFIG PANEL
   ============================================================ */

.fae-config-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

.fae-config-card {
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: 0.75rem;
  padding: 1.25rem;
}

.fae-config-card h3 {
  font-size: 0.875rem;
  font-weight: 700;
  color: var(--color-text-primary);
  margin: 0 0 1rem 0;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.fae-config-card h3 svg { color: var(--color-text-accent); }

.fae-config-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 0;
  border-bottom: 1px solid color-mix(in srgb, var(--color-border) 40%, transparent);
}

.fae-config-row:last-child { border-bottom: none; }

.fae-config-key {
  font-size: 0.8125rem;
  color: var(--color-text-secondary);
}

.fae-config-val {
  font-size: 0.8125rem;
  color: var(--color-text-primary);
  font-weight: 600;
}

/* ============================================================
   IMPORT (Facturas recibidas)
   ============================================================ */

.fae-dropzone {
  border: 2px dashed var(--color-border);
  border-radius: 0.75rem;
  padding: 3rem 2rem;
  text-align: center;
  margin-bottom: 1.5rem;
  transition: all 0.2s;
  cursor: pointer;
  background: color-mix(in srgb, var(--color-bg-card) 50%, transparent);
}

.fae-dropzone:hover {
  border-color: var(--color-accent);
  background: var(--color-accent-subtle);
}

.fae-dropzone-icon {
  width: 56px;
  height: 56px;
  border-radius: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-accent-subtle);
  color: var(--color-text-accent);
  margin: 0 auto 1rem;
}

.fae-dropzone p {
  font-size: 0.875rem;
  color: var(--color-text-secondary);
  margin: 0 0 0.25rem 0;
}

.fae-dropzone .small {
  font-size: 0.75rem;
  color: var(--color-text-muted);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 1200px) {
  .fae-kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .fae-dash-grid { grid-template-columns: 1fr; }
  .fae-config-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .fae-sidebar { width: 64px; min-width: 64px; }
  .fae-sidebar .fae-sidebar-title,
  .fae-sidebar .fae-nav-label,
  .fae-sidebar .fae-nav-section,
  .fae-sidebar .fae-nav-badge { display: none; }
  .fae-kpi-grid { grid-template-columns: 1fr; }
  .fae-content { padding: 1rem; }
}

/* ── ERP Integration Mode (no sidebar) ── */
.fae-erp-mode {
  height: 100%;
  min-height: 0;
}
.fae-erp-mode .fae-sidebar { display: none; }
.fae-erp-mode .fae-main { width: 100%; }
.fae-erp-mode .fae-topbar {
  border-bottom: 1px solid var(--color-border, #2a2a3a);
}
.fae-erp-mode .fae-content {
  height: calc(100% - 52px);
  overflow-y: auto;
}

/* ============================================================================
   SCROLL SOLO DE LAS FILAS  (directiva de UI del ERP)
   ============================================================================
   En una vista con tabla, el scroll vertical lo hace ÚNICAMENTE el bloque de
   filas. Los filtros, la cabecera de columnas y la paginación permanecen fijos.

   Antes scrolleaba .fae-content entera: al bajar por el listado se perdían de
   vista los filtros, el buscador y —lo peor— la fila de cabecera, así que a
   partir de la pantalla 2 no se sabía qué columna era cada una.

   Solo aplica a cola / registro / recibidas, que son las que llevan tabla; el
   dashboard y la configuración siguen scrolleando enteras, que es lo suyo.
   La clase la pone FAE_HTML.render() según la sección.
   ---------------------------------------------------------------------------- */
.fae-erp-mode .fae-content-fixed {
  overflow: hidden;              /* el contenedor NO scrollea */
  display: flex;
  flex-direction: column;
  min-height: 0;
}

/* ⚠ El selector lleva .active a propósito: la regla `.fae-view.active`
   (display:block) de más arriba tiene especificidad 0,2,0 y ganaba a un
   `.fae-view-table` suelto (0,1,0), dejando la vista en display:block. Con
   block no hay contexto flex, así que ni el bloque de filas encogía ni había
   scroll interno: seguía scrolleando la vista entera. Medido en navegador. */
.fae-view.active.fae-view-table {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;                 /* sin esto el hijo no encoge y no hay scroll */
  overflow: hidden;
}

/* Filtros y buscador: altura natural, nunca se encogen ni se van con el scroll */
.fae-view-table > .fae-filters,
.fae-view-table > .fae-dropzone { flex: 0 0 auto; }

/* La caja de la tabla ocupa el resto y reparte: filas (scroll) + paginación */
.fae-view-table > .fae-table-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ⭐ El único elemento con scroll vertical. min-height:0 es imprescindible:
   sin él, en Chrome el hijo de un flex no encoge por debajo de su contenido y
   el scroll se va al ancestro. */
.fae-table-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: auto;              /* en anchos pequeños, scroll horizontal aquí */
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

/* La paginación es el pie del bloque: fija abajo, fuera del área scrolleable */
.fae-view-table > .fae-table-wrap > .fae-pagination { flex: 0 0 auto; }

/* Cabecera de columnas pegada al borde superior del área que scrollea.
   z-index 2 para quedar por encima de las celdas al desplazarse. */
.fae-table-scroll thead th {
  position: sticky;
  top: 0;
  z-index: 2;
}

/* ----------------------------------------------------------------------------
   DASHBOARD — misma regla, aplicada a su propio layout.
   Aquí la "lista" es la actividad reciente: es lo único que debe scrollear.
   Los KPIs y el gráfico de barras se quedan siempre a la vista.
   El selector lleva .active por lo mismo que el de las tablas: `.fae-view.active`
   (display:block) tiene más especificidad que una clase suelta.
   ---------------------------------------------------------------------------- */
.fae-view.active.fae-view-dash {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.fae-view-dash > .fae-kpi-grid { flex: 0 0 auto; }

.fae-view-dash > .fae-dash-grid {
  flex: 1 1 auto;
  min-height: 0;                 /* los items de un grid no encogen sin esto */
}

/* Las dos tarjetas reparten su altura: título fijo + cuerpo que se adapta */
.fae-view-dash .fae-chart-card,
.fae-view-dash .fae-activity-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.fae-view-dash .fae-chart-card > h3,
.fae-view-dash .fae-activity-card > h3 { flex: 0 0 auto; }

/* ⭐ Lo único que scrollea en el dashboard */
.fae-view-dash .fae-timeline {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
}

/* El gráfico tiene alto fijo (180px): que no se deforme si falta sitio */
.fae-view-dash .fae-bar-chart { flex: 0 0 auto; }

/* =================================================================
   TELÉFONO (≤ 760 px) — FacturaE, 10-11-2026
   Cola, Registro y Recibidas en tarjetas con la vista entera desplazándose
   (la paginación queda pegada abajo); KPIs de dos en dos; configuración en
   una columna con los campos a lo ancho.
   ================================================================= */
@media (max-width: 760px) {

  .fae-topbar { padding: 10px 14px; min-height: 52px; gap: 8px; flex-wrap: wrap; }
  .fae-topbar-left { min-width: 0; }
  .fae-topbar-left h2 {
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .fae-topbar-right:empty { display: none; }
  .fae-erp-mode .fae-content { padding: 12px 14px; }

  /* ── Un solo desplazamiento por vista ──────────────────────────────────
     En el escritorio solo se desplazan las filas (filtros y cabecera fijos);
     en el teléfono eso dejaba la lista en una franja: se desplaza la vista
     entera y la paginación se queda pegada abajo. */
  .fae-erp-mode .fae-content-fixed { overflow-y: auto; display: block; }
  .fae-view.active.fae-view-table,
  .fae-view.active.fae-view-dash { display: block; overflow: visible; }
  .fae-view-table > .fae-table-wrap { display: block; overflow: visible; }
  .fae-table-scroll { overflow: visible; }
  .fae-view-table > .fae-table-wrap > .fae-pagination {
    position: sticky;
    bottom: -12px;   /* pegada al borde, por debajo del padding de .fae-content */
    z-index: 3;
    background: var(--color-bg-card);
    padding: 10px 12px;
  }
  .fae-view-dash .fae-timeline { overflow: visible; }

  /* KPIs: de dos en dos */
  .fae-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 12px; }
  .fae-kpi { min-width: 0; padding: 14px; }

  /* Filtros: cada grupo con su rótulo encima, de dos en dos; buscador y
     botones a lo ancho */
  .fae-filters {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    padding: 12px;
  }
  .fae-filter-group { flex-direction: column; align-items: stretch; gap: 3px; min-width: 0; }
  .fae-filter-select,
  .fae-filter-input { width: 100%; min-width: 0; min-height: 40px; box-sizing: border-box; }
  .fae-filters > .fae-search-box { grid-column: 1 / -1; min-width: 0; }
  .fae-search-box input { min-height: 40px; }
  .fae-filters > .fae-topbar-btn { grid-column: 1 / -1; justify-content: center; min-height: 40px; }

  /* ── Tablas en tarjetas ────────────────────────────────────────────── */
  .fae-table:has(> #fae-cola-body),
  .fae-table:has(> #fae-registro-body),
  .fae-table:has(> #fae-recibidas-body) { display: block; min-width: 0; }
  .fae-table:has(> #fae-cola-body) > thead,
  .fae-table:has(> #fae-registro-body) > thead,
  .fae-table:has(> #fae-recibidas-body) > thead { display: none; }
  #fae-cola-body, #fae-registro-body, #fae-recibidas-body { display: block; }
  #fae-cola-body > tr:not(:has(> td[colspan])),
  #fae-registro-body > tr:not(:has(> td[colspan])),
  #fae-recibidas-body > tr:not(:has(> td[colspan])) {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 5px 10px;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
  }
  #fae-cola-body > tr > td,
  #fae-registro-body > tr > td,
  #fae-recibidas-body > tr > td {
    display: block;
    padding: 0;
    border: none;
    min-width: 0;
  }
  #fae-cola-body > tr > td[colspan],
  #fae-registro-body > tr > td[colspan],
  #fae-recibidas-body > tr > td[colspan] { padding: 1.5rem 0.75rem; }
  .fae-view-table .fae-amount { white-space: nowrap; font-size: 0.9375rem; }
  .fae-view-table .fae-row-actions { opacity: 1; flex-wrap: wrap; }
  .fae-view-table .fae-row-action { height: 36px; padding: 0 0.6rem; }
  .fae-view-table .fae-row-action-txt { display: inline; }

  /* Cola: casilla | nº | total; destinatario | estado; NIF | destino;
     fecha | acciones. Celdas: 1 casilla, 2 nº, 3 fecha, 4 destinatario,
     5 NIF, 6 total, 7 destino, 8 estado, 9 acciones. */
  #fae-cola-body > tr:not(:has(> td[colspan])) {
    grid-template-columns: 28px minmax(0, 1fr) auto;
    grid-template-areas:
      "cb num tot"
      "cb des est"
      "cb nif dst"
      "cb fec fec"
      "cb acc acc";
  }
  #fae-cola-body > tr > td:nth-child(1) { grid-area: cb; align-self: start; }
  #fae-cola-body > tr > td:nth-child(1) input { width: 20px; height: 20px; }
  #fae-cola-body > tr > td:nth-child(2) { grid-area: num; }
  #fae-cola-body > tr > td:nth-child(3) { grid-area: fec; font-size: 0.75rem; color: var(--color-text-secondary); }
  #fae-cola-body > tr > td:nth-child(4) { grid-area: des; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #fae-cola-body > tr > td:nth-child(5) { grid-area: nif; font-size: 0.75rem; color: var(--color-text-muted); }
  #fae-cola-body > tr > td:nth-child(6) { grid-area: tot; text-align: right; }
  #fae-cola-body > tr > td:nth-child(7) { grid-area: dst; justify-self: end; font-size: 0.75rem; }
  #fae-cola-body > tr > td:nth-child(8) { grid-area: est; justify-self: end; }
  #fae-cola-body > tr > td:nth-child(9) { grid-area: acc; }

  /* Registro: nº | total; destinatario | estado; destino | envío;
     CSV | último cambio; XML. Celdas: 1 nº, 2 fecha envío,
     3 destinatario, 4 destino, 5 total, 6 estado, 7 CSV, 8 último cambio, 9 XML. */
  #fae-registro-body > tr:not(:has(> td[colspan])) {
    grid-template-areas:
      "num tot"
      "des est"
      "dst fen"
      "csv ult"
      "xml xml";
  }
  #fae-registro-body > tr > td:nth-child(1) { grid-area: num; }
  #fae-registro-body > tr > td:nth-child(2) { grid-area: fen; justify-self: end; font-size: 0.75rem; color: var(--color-text-secondary); }
  #fae-registro-body > tr > td:nth-child(3) { grid-area: des; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #fae-registro-body > tr > td:nth-child(4) { grid-area: dst; font-size: 0.75rem; }
  #fae-registro-body > tr > td:nth-child(5) { grid-area: tot; text-align: right; }
  #fae-registro-body > tr > td:nth-child(6) { grid-area: est; justify-self: end; }
  #fae-registro-body > tr > td:nth-child(7) { grid-area: csv; font-size: 0.6875rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #fae-registro-body > tr > td:nth-child(8) { grid-area: ult; justify-self: end; font-size: 0.75rem; color: var(--color-text-muted); }
  #fae-registro-body > tr > td:nth-child(9) { grid-area: xml; }
  #fae-registro-body > tr > td:nth-child(2)::before { content: 'Envío: '; color: var(--color-text-muted); }

  /* Recibidas: nº | total; emisor | fecha; NIF | base; firma | factura
     de compra; acciones. Celdas: 1 nº, 2 fecha, 3 emisor, 4 NIF,
     5 base, 6 total, 7 firma, 8 factura de compra, 9 acciones. */
  #fae-recibidas-body > tr:not(:has(> td[colspan])) {
    grid-template-areas:
      "num tot"
      "emi fec"
      "nif bas"
      "fir fco"
      "acc acc";
  }
  #fae-recibidas-body > tr > td:nth-child(1) { grid-area: num; }
  #fae-recibidas-body > tr > td:nth-child(2) { grid-area: fec; justify-self: end; font-size: 0.75rem; color: var(--color-text-secondary); }
  #fae-recibidas-body > tr > td:nth-child(3) { grid-area: emi; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  #fae-recibidas-body > tr > td:nth-child(4) { grid-area: nif; font-size: 0.75rem; color: var(--color-text-muted); }
  #fae-recibidas-body > tr > td:nth-child(5) { grid-area: bas; justify-self: end; font-size: 0.75rem; white-space: nowrap; }
  #fae-recibidas-body > tr > td:nth-child(6) { grid-area: tot; text-align: right; }
  #fae-recibidas-body > tr > td:nth-child(7) { grid-area: fir; }
  #fae-recibidas-body > tr > td:nth-child(8) { grid-area: fco; justify-self: end; }
  #fae-recibidas-body > tr > td:nth-child(9) { grid-area: acc; }
  #fae-recibidas-body > tr > td:nth-child(5)::before { content: 'Base '; color: var(--color-text-muted); }
  .fae-dropzone { padding: 1.5rem 1rem; margin-bottom: 12px; }

  /* ── Configuración: una columna; rótulo y valor, y los campos a lo ancho */
  .fae-config-grid { grid-template-columns: minmax(0, 1fr); }
  .fae-config-card { min-width: 0; padding: 14px; }
  .fae-config-row { flex-wrap: wrap; gap: 6px 12px; }
  .fae-config-key { flex: 1 1 auto; min-width: 0; }
  .fae-config-val { min-width: 0; text-align: right; overflow-wrap: anywhere; }
  .fae-config-val:has(select, input, textarea) { flex: 1 1 100%; text-align: left; }
  .fae-config-val select,
  .fae-config-val input,
  .fae-config-val textarea {
    width: 100% !important;   /* el literal legal trae width:280px en línea */
    min-height: 40px;
    box-sizing: border-box;
  }
  #fae-cfg-save { flex: 1; justify-content: center; min-height: 42px; }
}
