/* ==========================================================================
   Fiscalit-SP · Design system 2026
   Requiere tokens.css. Ver design-system/GUIA.md.

   Índice
     1. Reset y base
     2. Layout: shell autenticado (sidebar, topbar, main)
     3. Layout: no autenticado
     4. Botones
     5. Page header / toggles
     6. Bento grid + card
     7. KPI / hero / sparkline
     8. Chips y badges de estado
     9. Sello Verifactu
    10. Acciones rápidas (tiles)
    11. Tablas
    12. Buscador, filtros, segmented
    13. Listas (actividad, calendario, clientes)
    14. Modelos / totales / help
    15. IA: insight, FAB y panel
    16. Formularios
    17. Feedback: flash, toast, empty state, skeleton, modal, paginación
    18. Utilidades mínimas
    19. Responsive
   ========================================================================== */

/* ============================ 1. RESET Y BASE ============================ */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; padding: 0; }

html, body {
  font-family: var(--font-display);
  color: var(--text-strong);
  background: var(--background-neutral);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: 'ss01', 'cv11';
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
img { max-width: 100%; }
table { border-collapse: collapse; width: 100%; }
[hidden] { display: none !important; }

::selection { background: rgba(95, 184, 138, 0.25); }

:focus-visible {
  outline: 2px solid var(--ledger-blue-mid);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  /* Reducir movimiento ≠ congelarlo todo. Se van los bucles decorativos y el
     desplazamiento espacial; se conservan opacidad, color y el cambio de estado
     —incluido el spinner de carga, que es feedback esencial—. */

  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.12s !important;
    scroll-behavior: auto !important;
  }

  /* Bucles puramente decorativos: fuera */
  .hero-badge .dot,
  .ai-avatar::after { animation: none !important; }
  .skeleton { animation: none !important; background: rgba(201, 214, 229, 0.3) !important; }
  /* Las barras aparecen ya a su altura, sin crecer ni retardo */
  .bar { animation: none !important; }

  /* El indicador de carga SÍ debe seguir girando */
  .spinner { animation: spin 0.8s linear infinite !important; }

  /* Entradas y microdesplazamientos: sin movimiento, el estado sigue siendo visible */
  .view { animation: none !important; }
  .btn:hover, .btn-primary:hover, .btn-success:hover, .btn-danger:hover,
  .action-tile:hover, .model-card:hover, .cal-row:hover,
  .ai-fab:hover, .ai-send:hover { transform: none !important; }
  .ai-panel, .ai-panel.is-open { transform: none !important; }
}

/* ==================== 2. LAYOUT: SHELL AUTENTICADO ==================== */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  z-index: 50;
  width: var(--sidebar-w);
  background: var(--surface);
  border-inline-end: 1px solid var(--ledger-accent);
  display: flex;
  flex-direction: column;
  padding: var(--space-5) var(--space-4);
  gap: var(--space-2);
  overflow: hidden;
  /* Solo el deslizamiento del drawer (transform, compositado). El colapso de
     escritorio cambia `width` de golpe: es un toggle manual y puntual, no
     merece animar una propiedad de layout fotograma a fotograma. */
  transition: transform 0.3s var(--ease-smooth);
}

.brand { display: flex; align-items: center; gap: var(--space-3); padding: 6px 8px 14px; min-width: 0; }
.brand-logo { height: 40px; width: auto; }
.brand-logo--icon { display: none; height: 34px; }
.brand-sub {
  font-size: 11px; color: var(--text-meta); margin-top: 4px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.user-card {
  display: flex; align-items: center; gap: var(--space-3);
  background: var(--background-neutral);
  border-radius: var(--radius-md);
  padding: var(--space-3);
  margin-bottom: var(--space-3);
  position: relative;
  min-width: 0;
}
.user-avatar {
  width: 38px; height: 38px; flex-shrink: 0;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary-stability), var(--ledger-blue-mid));
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-mail { font-size: 11px; color: var(--text-meta); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.verifactu-dot {
  width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0;
  background: var(--status-success);
  box-shadow: 0 0 0 3px rgba(95, 184, 138, 0.2);
}

.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 11px 14px;
  border-radius: 12px;
  font-size: 14px; font-weight: 500;
  color: var(--text-muted);
  transition: background 0.2s var(--ease-smooth), color 0.2s var(--ease-smooth);
  position: relative;
  white-space: nowrap;
}
.nav-item svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-item:hover { background: var(--background-neutral); color: var(--primary-stability); }
.nav-item.is-active {
  background: var(--primary-stability);
  color: #fff; font-weight: 600;
  box-shadow: var(--shadow-soft);
}
.nav-item.is-active::before {
  content: '';
  position: absolute; inset-inline-start: -14px; inset-block: 12px;
  width: 3px; border-radius: 0 3px 3px 0;
  background: var(--status-success);
}

.sidebar-footer {
  display: flex; flex-direction: column; gap: 4px;
  padding-top: var(--space-3);
  border-top: 1px solid var(--ledger-accent);
}
.btn-ghost {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13px;
  color: var(--text-meta);
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
  width: 100%;
}
.btn-ghost svg { width: 18px; height: 18px; flex-shrink: 0; }
.btn-ghost:hover { background: var(--background-neutral); color: var(--primary-stability); }
.btn-ghost--logout:hover { color: var(--earth-warn); background: rgba(166, 90, 50, 0.07); }

/* Sidebar colapsado (desktop) — el estado se refleja en <html class="sb-collapsed"> */
@media (min-width: 900px) {
  .sb-collapsed .sidebar { width: var(--sidebar-w-collapsed); }
  .sb-collapsed .brand-text,
  .sb-collapsed .brand-logo--full,
  .sb-collapsed .user-info,
  .sb-collapsed .verifactu-dot,
  .sb-collapsed .nav-item span,
  .sb-collapsed .btn-ghost span { display: none; }
  .sb-collapsed .brand-logo--icon { display: block; }
  .sb-collapsed .brand,
  .sb-collapsed .user-card { justify-content: center; }
  .sb-collapsed .nav-item,
  .sb-collapsed .btn-ghost { justify-content: center; padding-inline: 12px; }
  .sb-collapsed .main { margin-inline-start: var(--sidebar-w-collapsed); }
}

.main {
  flex: 1;
  min-width: 0;
  margin-inline-start: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  /* El margen sigue al ancho del sidebar sin transición: ambos cambian juntos
     y de golpe en el colapso manual (ver nota en .sidebar). */
}

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4) var(--space-10);
  background: var(--surface);
  border-bottom: 1px solid var(--ledger-accent);
  position: sticky; top: 0; z-index: 20;
}
.topbar-title { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.topbar-meta { font-size: 12px; color: var(--text-meta); }
.topbar-burger { display: none; padding: 8px; border-radius: 10px; color: var(--text-muted); }
.topbar-burger:hover { background: var(--background-neutral); }
.topbar-burger svg { width: 22px; height: 22px; }

.main-content { padding: var(--space-7) var(--space-10) 120px; max-width: var(--main-max); width: 100%; }

/* Backdrop del drawer móvil */
.sidebar-backdrop {
  position: fixed; inset: 0; z-index: 40;
  background: rgba(11, 31, 59, 0.45);
  backdrop-filter: blur(2px);
}

/* ==================== 3. LAYOUT: NO AUTENTICADO ==================== */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: var(--space-8) var(--space-4);
  background:
    radial-gradient(circle at 15% 10%, rgba(95, 184, 138, 0.10), transparent 40%),
    radial-gradient(circle at 85% 90%, rgba(18, 58, 99, 0.08), transparent 45%),
    var(--background-neutral);
}
.auth-card {
  width: 100%;
  max-width: 400px;
}
.auth-brand { text-align: center; margin-bottom: var(--space-7); }
.auth-brand img { height: 52px; width: auto; }
.auth-brand p { font-size: 13px; color: var(--text-soft); margin-top: var(--space-3); }
.auth-panel {
  background: var(--surface);
  border: 1px solid var(--ledger-accent);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-soft);
  padding: var(--space-8);
}
.auth-panel h1 {
  font-size: 22px; font-weight: 800; letter-spacing: -0.02em;
  margin-bottom: var(--space-6);
}
.auth-panel h1 em { font-family: var(--font-serif); font-style: italic; font-weight: 400; color: var(--ledger-blue-mid); }
.auth-alt { text-align: center; font-size: 13px; color: var(--text-soft); margin-top: var(--space-5); }
.auth-alt a { color: var(--ledger-blue-mid); font-weight: 600; }
.auth-alt a:hover { text-decoration: underline; }

/* ============================ 4. BOTONES ============================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 11px 20px;
  border-radius: var(--radius-pill);
  font-size: 13px; font-weight: 600;
  transition: transform 0.25s var(--ease-elastic), box-shadow 0.25s var(--ease-smooth), background 0.2s, border-color 0.2s;
  white-space: nowrap;
}
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--primary-stability); color: #fff; box-shadow: var(--shadow-soft); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.btn-secondary { background: var(--surface); border: 1px solid var(--ledger-accent); color: var(--primary-stability); }
.btn-secondary:hover { border-color: var(--primary-stability); }
.btn-success { background: var(--status-success-2); color: #fff; box-shadow: var(--shadow-soft); }
.btn-success:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.btn-danger { background: var(--earth-warn); color: #fff; }
.btn-danger:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.btn-sm { padding: 7px 13px; font-size: 12px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ==================== 5. PAGE HEADER / TOGGLES ==================== */
.page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--space-6);
  margin-bottom: var(--space-7);
  flex-wrap: wrap;
}
.page-title { font-size: 32px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.1; }
.page-title em { font-family: var(--font-serif); font-style: italic; font-weight: 400; color: var(--ledger-blue-mid); }
.page-sub { font-size: 14px; color: var(--text-soft); margin-top: 6px; }
.page-actions { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; }

.mode-toggle, .segmented {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--ledger-accent);
  border-radius: var(--radius-pill);
  padding: 4px;
}
.mode-toggle button, .segmented button,
.mode-toggle a, .segmented a {
  display: inline-flex; align-items: center;
  padding: 7px 16px;
  border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 600;
  color: var(--text-soft);
  transition: background 0.3s var(--ease-elastic), color 0.2s;
}
.mode-toggle button.is-active, .segmented button.is-active,
.mode-toggle a.is-active, .segmented a.is-active {
  background: var(--primary-stability); color: #fff;
}
.segmented a:hover:not(.is-active) { color: var(--primary-stability); }

/* Fila-selector de año (cuentas anuales) — el botón de la 1ª celda es el control real */
tr.year-row:hover td,
tr.year-row:focus-within td { background: rgba(201, 214, 229, 0.18); }
tr.is-selected td { background: rgba(18, 58, 99, 0.07); }
tr.is-selected td:first-child { box-shadow: inset 3px 0 0 var(--status-success); }
.year-btn {
  display: block; width: 100%;
  font: inherit; color: inherit; text-align: start;
  margin: -16px -18px; padding: 16px 18px;
  box-sizing: content-box;
}
.year-btn[aria-pressed="true"] strong { color: var(--ledger-blue-mid); }

/* Contenedor de gráfico */
.chart-box { position: relative; width: 100%; height: 280px; }
.chart-box--sm { height: 170px; }

/* --- Modelos fiscales: banner de resultado --- */
.result-banner {
  border-radius: var(--radius-lg);
  border: 1px solid;
  padding: var(--space-6);
  margin-bottom: var(--space-5);
}
.result-banner--earth   { background: rgba(166, 90, 50, 0.09); border-color: rgba(166, 90, 50, 0.32); }
.result-banner--success { background: rgba(95, 184, 138, 0.10); border-color: rgba(95, 184, 138, 0.35); }
.result-banner--neutral { background: var(--background-neutral); border-color: var(--ledger-accent); }
.result-banner-label { font-size: 13px; font-weight: 700; }
.result-banner--earth .result-banner-label { color: var(--earth-warn); }
.result-banner--success .result-banner-label { color: var(--status-success-2); }
.result-banner--neutral .result-banner-label { color: var(--text-soft); }
.result-banner-value {
  font-size: 42px; font-weight: 800; letter-spacing: -0.03em; line-height: 1;
  margin-top: 6px; font-variant-numeric: tabular-nums;
}
.result-banner--earth .result-banner-value { color: var(--earth-warn); }
.result-banner--success .result-banner-value { color: var(--status-success-2); }
.result-banner--neutral .result-banner-value { color: var(--primary-stability); }
.result-banner-hint { font-size: 12px; color: var(--text-meta); margin-top: 8px; }

/* Tablas de casillas */
.casilla-num { font-size: 11px; color: var(--text-faint); width: 44px; font-variant-numeric: tabular-nums; }
tr.casilla-total td { background: var(--background-neutral); font-weight: 700; }
tr.casilla-total td strong { color: var(--primary-stability); }

/* Rejilla de modelos (índice) */
.modelo-tiles { display: grid; grid-template-columns: repeat(6, 1fr); gap: var(--space-3); }
.modelo-tile {
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--ledger-accent);
  border-radius: var(--radius-md);
}
.modelo-tile.is-off { border-style: dashed; opacity: 0.55; }
.modelo-tile .n { font-family: var(--font-serif); font-size: 28px; line-height: 1; color: var(--primary-stability); }
.modelo-tile .d { font-size: 11px; color: var(--text-meta); margin-top: 4px; }
@media (max-width: 900px) { .modelo-tiles { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 560px) { .modelo-tiles { grid-template-columns: repeat(2, 1fr); } }

/* --- Calendario fiscal --- */
.cal-layout { display: grid; grid-template-columns: 1fr 420px; gap: var(--space-6); align-items: start; }
@media (max-width: 1200px) { .cal-layout { grid-template-columns: 1fr; } .cal-grid-col { display: none; } }

.timeline { position: relative; padding-inline-start: 92px; }
.timeline::before { content: ''; position: absolute; inset-inline-start: 84px; top: 6px; bottom: 6px; width: 1px; background: var(--ledger-accent); }
.tl-item { position: relative; margin-bottom: var(--space-4); }
.tl-date { position: absolute; inset-inline-start: -92px; top: 14px; width: 76px; text-align: end; font-size: 11px; font-weight: 700; color: var(--text-soft); }
.tl-date small { display: block; color: var(--text-faint); font-weight: 500; }
.tl-dot { position: absolute; inset-inline-start: -12px; top: 16px; width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--surface); z-index: 1; }
.tl-dot--green { background: var(--status-success); }
.tl-dot--amber { background: var(--amber-alert); }
.tl-dot--red { background: var(--deadline-critical); }
.tl-dot--blue { background: var(--ledger-accent); }

.tl-card { border: 1px solid var(--ledger-accent); border-radius: var(--radius-md); overflow: hidden; background: var(--surface); }
.tl-card--green { border-color: rgba(95, 184, 138, 0.4); }
.tl-card--amber { border-color: rgba(192, 138, 46, 0.4); }
.tl-card--red { border-color: var(--deadline-critical-soft); }
.tl-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: 10px 16px; border-bottom: 1px solid var(--ledger-accent); }
.tl-head h2, .tl-head h3 { font-size: 13px; font-weight: 700; }
.tl-head .when { font-size: 11px; font-weight: 700; }
.tl-card--green .tl-head { background: rgba(95, 184, 138, 0.10); } .tl-card--green .when { color: var(--status-success-2); }
.tl-card--amber .tl-head { background: rgba(192, 138, 46, 0.10); } .tl-card--amber .when { color: var(--amber-text); }
.tl-card--red .tl-head { background: var(--deadline-critical-soft); } .tl-card--red .when { color: var(--deadline-critical); }
.tl-ob { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: 10px 16px; font-size: 13px; }
.tl-ob + .tl-ob { border-top: 1px solid var(--ledger-accent); }
.tl-ob .m { font-family: var(--font-serif); font-size: 15px; color: var(--text-muted); width: 34px; flex-shrink: 0; }
.tl-ob .lbl { flex: 1; min-width: 0; color: var(--text-body); }

.mini-cals { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3); }
.mini-cal { border: 1px solid var(--ledger-accent); border-radius: var(--radius-md); padding: 10px; background: var(--surface); }
.mini-cal-name { display: block; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; text-align: center; color: var(--text-soft); margin-bottom: 6px; }
.mini-cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.mini-cal-grid .h { font-size: 9px; font-weight: 700; color: var(--text-faint); text-align: center; padding: 2px 0; }
.mini-cal-grid .d { font-size: 10px; text-align: center; padding: 4px 0; border-radius: 6px; color: var(--text-soft); font-variant-numeric: tabular-nums; }
.mini-cal-grid .d.mark { color: #fff; font-weight: 700; }
.mini-cal-grid .d.mark--green { background: var(--status-success-2); }
.mini-cal-grid .d.mark--amber { background: var(--amber-text); }
.mini-cal-grid .d.mark--red { background: var(--deadline-critical); }
.mini-cal-grid .d.mark--blue { background: var(--ledger-blue-mid); }
.mini-cal-grid .d.today { box-shadow: inset 0 0 0 1.5px var(--primary-stability); font-weight: 800; }

.cal-year-nav { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-4); }
.cal-year-nav .y { font-size: 18px; font-weight: 800; letter-spacing: 0.02em; }
.cal-year-nav a { width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--ledger-accent); border-radius: var(--radius-sm); color: var(--text-muted); }
.cal-year-nav a:hover { border-color: var(--ledger-blue-mid); }

/* ==================== 6. BENTO GRID + CARD ==================== */
.bento { display: grid; grid-template-columns: repeat(12, 1fr); gap: var(--space-5); align-items: start; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; }
.span-9 { grid-column: span 9; }
.span-12 { grid-column: span 12; }

.card {
  background: var(--surface);
  border: 1px solid var(--ledger-accent);
  border-radius: var(--radius-lg);
  padding: var(--space-6);
  box-shadow: var(--shadow-soft);
  transition: box-shadow 0.4s var(--ease-smooth);
  position: relative;
  overflow: hidden;
}
.card:hover { box-shadow: var(--shadow-hover); }
.card--flush { padding: 0; }

.card-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.card-label { font-size: 11px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; color: var(--text-meta); }
.card-title { font-size: 18px; font-weight: 700; letter-spacing: -0.02em; }
.card-title em { font-family: var(--font-serif); font-style: italic; font-weight: 400; color: var(--ledger-blue-mid); }

/* ==================== 7. KPI / HERO / SPARKLINE ==================== */
.hero-kpi {
  background: linear-gradient(135deg, #0B1F3B 0%, #123A63 100%);
  color: #fff;
  border: none;
}
.hero-kpi::before {
  content: ''; position: absolute; top: -80px; right: -80px;
  width: 260px; height: 260px; border-radius: 50%;
  background: radial-gradient(circle, rgba(95, 184, 138, 0.25), transparent 70%);
}
.hero-kpi::after {
  content: ''; position: absolute; bottom: -60px; left: -60px;
  width: 200px; height: 200px; border-radius: 50%;
  background: radial-gradient(circle, rgba(201, 167, 90, 0.15), transparent 70%);
}
.hero-kpi .card-label { color: rgba(255, 255, 255, 0.6); }
.hero-value { font-size: 56px; font-weight: 800; letter-spacing: -0.04em; line-height: 1; font-variant-numeric: tabular-nums; }
.hero-value em { font-family: var(--font-serif); font-style: italic; font-weight: 400; color: #FFD970; }
.hero-sub { margin-top: 10px; font-size: 13px; color: rgba(255, 255, 255, 0.65); }
.hero-badge {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 18px; padding: 6px 12px;
  background: rgba(95, 184, 138, 0.2);
  border: 1px solid rgba(95, 184, 138, 0.4);
  border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 600; color: #A6E0BC;
}
.hero-badge .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--status-success); animation: pulse 2s infinite; }

@keyframes pulse { 0%, 100% { opacity: 1; transform: scale(1); } 50% { opacity: 0.5; transform: scale(1.3); } }

.kpi-value { font-size: 42px; font-weight: 800; letter-spacing: -0.03em; line-height: 1; font-variant-numeric: tabular-nums; }
.kpi-value span { font-size: 22px; }
.kpi-value--success { color: var(--status-success-2); }
.kpi-value--amber { color: var(--amber-text); }
.kpi-delta {
  display: inline-flex; align-items: center; gap: 4px;
  margin-top: 12px; padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 600;
  background: rgba(95, 184, 138, 0.12); color: var(--status-success-2);
}
.kpi-delta--down { background: var(--earth-warn-soft); color: var(--earth-warn); }
.kpi-sub { margin-top: 8px; font-size: 12px; color: var(--text-meta); }
.spark { width: 100%; height: 60px; margin-top: 10px; }

/* Mini bar chart (ingresos/gastos por trimestre) */
.tax-chart {
  display: flex; align-items: flex-end; gap: 12px;
  height: 148px; margin-top: 20px; padding-top: 4px;
  border-bottom: 1px dashed rgba(255, 255, 255, 0.25);
}
.card:not(.hero-kpi) .tax-chart { border-bottom-color: var(--ledger-accent); }
.bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; }
.bar-stack { width: 100%; flex: 1; display: flex; align-items: flex-end; gap: 4px; padding-top: 6px; }
/* La altura la fija el servidor (style inline). El crecimiento de entrada va por
   transform: scaleY —compositado— no por transición de `height`. */
.bar {
  flex: 1; min-height: 2px; max-height: 100%; border-radius: 5px 5px 0 0;
  transform-origin: bottom;
  animation: barGrow 0.5s var(--ease-smooth) both;
}
.bar-group:nth-child(2) .bar { animation-delay: 0.06s; }
.bar-group:nth-child(3) .bar { animation-delay: 0.12s; }
.bar-group:nth-child(4) .bar { animation-delay: 0.18s; }
@keyframes barGrow { from { transform: scaleY(0); } to { transform: scaleY(1); } }
.bar--ing { background: linear-gradient(180deg, var(--status-success), var(--status-success-2)); }
.bar--gas { background: linear-gradient(180deg, #E8B667, var(--amber-alert)); }
.bar-label { font-size: 11px; font-weight: 600; color: var(--text-meta); }
.hero-kpi .bar-label { color: rgba(255, 255, 255, 0.7); }

.legend { display: flex; gap: 16px; margin-top: 12px; font-size: 12px; }
.legend-item { display: inline-flex; align-items: center; gap: 6px; color: var(--text-soft); }
.hero-kpi .legend-item { color: rgba(255, 255, 255, 0.7); }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

.activity { display: flex; flex-direction: column; }
.activity--cols { display: grid; grid-template-columns: 1fr 1fr; column-gap: var(--space-8); }
@media (max-width: 900px) { .activity--cols { grid-template-columns: 1fr; } }

/* ==================== 8. CHIPS Y BADGES ==================== */
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px; font-weight: 700;
  white-space: nowrap;
}
.chip--verifactu { background: rgba(95, 184, 138, 0.16); color: var(--status-success-2); }
.chip--verifactu::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: var(--status-success); }
.chip--green   { background: rgba(95, 184, 138, 0.16); color: var(--status-success-2); }
.chip--amber   { background: rgba(192, 138, 46, 0.16); color: var(--amber-text); }
.chip--blue    { background: rgba(18, 58, 99, 0.10); color: var(--ledger-blue-mid); }
.chip--red     { background: var(--deadline-critical-soft); color: var(--deadline-critical); }
.chip--neutral { background: var(--background-neutral); color: var(--text-soft); }

/* ==================== 9. SELLO VERIFACTU ==================== */
.seal { display: flex; flex-direction: column; align-items: center; padding: 12px 0; }
.seal-ring {
  width: 128px; height: 128px; border-radius: 50%;
  background: conic-gradient(from -90deg, var(--status-success) 0%, var(--status-success) var(--seal-pct, 92%), var(--ledger-accent) var(--seal-pct, 92%));
  display: grid; place-items: center; position: relative;
}
.seal-ring::after { content: ''; position: absolute; inset: 8px; border-radius: 50%; background: var(--surface); }
.seal-inner {
  position: relative; z-index: 2;
  width: 88px; height: 88px; border-radius: 50%;
  background: linear-gradient(135deg, #5FB88A, #3F9E70);
  color: #fff; display: grid; place-items: center;
  box-shadow: 0 8px 24px rgba(95, 184, 138, 0.4);
}
.seal-inner svg { width: 38px; height: 38px; }
.seal-caption { margin-top: 14px; text-align: center; font-size: 13px; font-weight: 700; }
.seal-caption small { display: block; font-weight: 500; color: var(--text-meta); margin-top: 4px; font-size: 11px; }

/* ==================== 10. ACCIONES RÁPIDAS ==================== */
.actions-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-3); }
.action-tile {
  display: flex; flex-direction: column; gap: var(--space-3);
  padding: 18px;
  background: var(--background-neutral);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  transition: transform 0.3s var(--ease-elastic), background 0.2s, border-color 0.2s, box-shadow 0.2s;
  text-align: start;
}
.action-tile:hover {
  transform: translateY(-3px);
  background: var(--surface);
  border-color: var(--ledger-accent);
  box-shadow: var(--shadow-soft);
}
.action-icon {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center;
  background: rgba(18, 58, 99, 0.08); color: var(--ledger-blue-mid);
}
.action-icon svg { width: 20px; height: 20px; }
.action-icon--green { background: rgba(95, 184, 138, 0.15); color: var(--status-success-2); }
.action-icon--amber { background: rgba(192, 138, 46, 0.12); color: var(--amber-text); }
.action-icon--navy  { background: rgba(11, 31, 59, 0.08); color: var(--primary-stability); }
.action-title { display: block; font-size: 14px; font-weight: 700; }
.action-sub { display: block; font-size: 12px; color: var(--text-meta); margin-top: 2px; }

/* ============================ 11. TABLAS ============================ */
.table-wrap { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--ledger-accent); }
.table-wrap table { min-width: 620px; }
.table-wrap.fit { overflow: visible; }
.table-wrap.fit table { min-width: 0; }
.table-wrap.fit th, .table-wrap.fit td { padding: 10px 12px; white-space: normal; }
.table-wrap.fit td.num, .table-wrap.fit th.num { white-space: nowrap; }
thead th {
  text-align: start; padding: 14px 18px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--text-meta);
  background: var(--background-neutral);
  border-bottom: 1px solid var(--ledger-accent);
  white-space: nowrap;
}
tbody td { padding: 16px 18px; font-size: 13px; border-bottom: 1px solid var(--ledger-accent); color: var(--text-body); white-space: nowrap; }
tbody td.wrap { white-space: normal; }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.15s; }
tbody tr:hover { background: rgba(201, 214, 229, 0.15); }
td.num, th.num { text-align: end; font-variant-numeric: tabular-nums; font-weight: 600; }
td strong { color: var(--primary-stability); font-weight: 700; }
code, .mono { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); }

/* ==================== 12. BUSCADOR / FILTROS ==================== */
.search-input {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 12px 18px;
  background: var(--surface);
  border: 1px solid var(--ledger-accent);
  border-radius: var(--radius-pill);
  transition: border-color 0.2s, box-shadow 0.2s;
  flex: 1; max-width: 480px;
}
.search-input:focus-within { border-color: var(--ledger-blue-mid); box-shadow: 0 0 0 4px rgba(18, 58, 99, 0.08); }
.search-input svg { width: 18px; height: 18px; color: var(--text-meta); flex-shrink: 0; }
.search-input input { flex: 1; border: none; outline: none; font: inherit; font-size: 14px; background: transparent; }

.filters { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; margin-bottom: var(--space-5); }
.filter-select {
  padding: 10px 16px;
  background: var(--surface);
  border: 1px solid var(--ledger-accent);
  border-radius: var(--radius-pill);
  font: inherit; font-size: 13px; font-weight: 500;
  color: var(--primary-stability);
  cursor: pointer;
  transition: border-color 0.2s;
}
.filter-select:hover { border-color: var(--ledger-blue-mid); }

/* ==================== 13. LISTAS ==================== */
.activity-row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 14px 0;
  border-bottom: 1px solid var(--ledger-accent);
}
.activity-row:last-child { border-bottom: none; }
.act-avatar {
  width: 36px; height: 36px; border-radius: 12px; flex-shrink: 0;
  display: grid; place-items: center;
  background: var(--background-neutral); color: var(--ledger-blue-mid);
}
.act-avatar svg { width: 18px; height: 18px; }
.act-body { flex: 1; min-width: 0; }
.act-title { font-size: 13px; font-weight: 600; }
.act-sub { font-size: 11px; color: var(--text-meta); margin-top: 2px; }
.act-amount { font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.act-amount--pos { color: var(--status-success-2); }
.act-amount--neg { color: var(--earth-warn); }

.cal-list { display: flex; flex-direction: column; gap: var(--space-3); }
.cal-row {
  display: flex; align-items: center; gap: var(--space-3);
  padding: 12px;
  background: var(--background-neutral);
  border-radius: var(--radius-md);
  transition: transform 0.3s var(--ease-elastic);
}
.cal-row:hover { transform: translateX(4px); }
.cal-date { min-width: 52px; text-align: center; padding: 6px; background: var(--surface); border-radius: 10px; border: 1px solid var(--ledger-accent); }
.cal-day { font-size: 20px; font-weight: 800; line-height: 1; letter-spacing: -0.02em; }
.cal-mon { font-size: 10px; color: var(--text-meta); font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; margin-top: 2px; }
.cal-info { flex: 1; min-width: 0; }
.cal-title { font-size: 13px; font-weight: 700; }
.cal-sub {
  font-size: 11px; color: var(--text-meta); margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.client-row {
  display: grid;
  grid-template-columns: 40px 2fr 1fr 2fr 1fr auto;
  align-items: center; gap: var(--space-4);
  padding: 16px 20px;
  border-bottom: 1px solid var(--ledger-accent);
  transition: background 0.15s;
}
.client-row:hover { background: rgba(201, 214, 229, 0.15); }
.client-row:last-child { border-bottom: none; }
.client-avatar {
  width: 40px; height: 40px; border-radius: 12px;
  background: linear-gradient(135deg, var(--ledger-accent), #E4EBF3);
  color: var(--primary-stability);
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.client-name { font-weight: 700; font-size: 14px; }
.client-sub { font-size: 12px; color: var(--text-meta); margin-top: 2px; }

/* ==================== 14. MODELOS / TOTALES / HELP ==================== */
.totals-strip { display: grid; grid-template-columns: repeat(5, 1fr); gap: var(--space-5); margin-bottom: var(--space-6); }
/* Variantes de nº de columnas — respetan los breakpoints de abajo (a `.totals-strip`).
   Nunca fijar las columnas con style inline: rompe el colapso responsive. */
.totals-strip--3 { grid-template-columns: repeat(3, 1fr); }
.totals-strip--4 { grid-template-columns: repeat(4, 1fr); }
.total-tile { padding: 20px; }
.total-label { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--text-meta); }
.total-value { font-size: 28px; font-weight: 800; letter-spacing: -0.03em; margin-top: 10px; font-variant-numeric: tabular-nums; }

.model-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4); }
.model-card {
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--ledger-accent);
  border-radius: var(--radius-md);
  transition: transform 0.3s var(--ease-elastic), box-shadow 0.3s, border-color 0.2s;
  position: relative; overflow: hidden;
}
.model-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-hover); border-color: var(--ledger-blue-mid); }
.model-card.is-locked { opacity: 0.55; }
.model-number { font-family: var(--font-serif); font-size: 48px; font-weight: 400; line-height: 1; letter-spacing: -0.03em; color: var(--primary-stability); }
.model-name { font-size: 13px; font-weight: 700; margin-top: 6px; }
.model-desc { font-size: 11px; color: var(--text-meta); margin-top: 4px; }

.help-hero {
  padding: var(--space-10);
  background: linear-gradient(135deg, #0B1F3B, #123A63);
  color: #fff;
  border-radius: var(--radius-lg);
  position: relative; overflow: hidden;
  margin-bottom: var(--space-7);
}
.help-hero h1 { font-size: 38px; font-weight: 800; letter-spacing: -0.03em; line-height: 1.05; }
.help-hero h1 em { font-family: var(--font-serif); font-style: italic; font-weight: 400; color: #FFD970; }
.help-hero p { margin-top: 12px; color: rgba(255, 255, 255, 0.75); max-width: 520px; }
.help-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-5); }
.help-search input { flex: 1; background: transparent; border: none; outline: none; color: #fff; font: inherit; font-size: 14px; }
.help-search input::placeholder { color: rgba(255, 255, 255, 0.5); }
.help-search {
  margin-top: var(--space-5); display: flex; align-items: center; gap: 10px;
  padding: 12px 18px; max-width: 520px;
  background: rgba(255, 255, 255, 0.10); border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: var(--radius-pill); color: rgba(255, 255, 255, 0.6);
  transition: border-color 0.2s, box-shadow 0.2s, background 0.2s;
}
.help-search:focus-within {
  border-color: rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.16);
  box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.14);
}
.help-layout { display: grid; grid-template-columns: 180px 1fr; gap: var(--space-6); align-items: start; }
.help-nav { position: sticky; top: var(--space-5); display: flex; flex-direction: column; gap: 2px; }
.help-nav a { font-size: 13px; color: var(--text-soft); padding: 5px 0; }
.help-nav a:hover { color: var(--primary-stability); }
@media (max-width: 900px) { .help-layout { grid-template-columns: 1fr; } .help-nav { display: none; } }

.help-acc-item { border-top: 1px solid var(--ledger-accent); }
.help-acc-item:first-child { border-top: none; }
.help-acc-item > button {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: 14px 4px; font-size: 14px; font-weight: 600; text-align: start; color: var(--text-body);
}
.help-acc-item > button:hover { color: var(--primary-stability); }
.help-acc-item > button svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--text-meta); transition: transform 0.2s; }
.help-acc-body { padding: 0 4px 16px; font-size: 13px; line-height: 1.6; color: var(--text-soft); }
.help-acc-body code { background: var(--background-neutral); padding: 1px 5px; border-radius: 4px; }

/* ==================== 15. IA: INSIGHT, FAB, PANEL ==================== */
.ai-insight {
  background: linear-gradient(135deg, rgba(255,118,193,0.10), rgba(112,145,255,0.10) 50%, rgba(255,217,112,0.10));
  border: 1px solid var(--ia-border);
}
.ai-insight::before {
  content: ''; position: absolute; top: -50px; right: -50px;
  width: 180px; height: 180px; border-radius: 50%;
  background: var(--ia-mesh); filter: blur(50px); opacity: 0.35;
}
.ai-tag {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  background: var(--ia-mesh); color: #fff;
  border-radius: var(--radius-pill);
  font-size: 10px; font-weight: 800; letter-spacing: 0.1em; text-transform: uppercase;
  margin-bottom: 12px;
  box-shadow: 0 4px 12px rgba(112, 145, 255, 0.3);
}
.ai-text { font-size: 15px; line-height: 1.5; font-weight: 500; color: var(--primary-stability); }
.ai-text strong { font-weight: 700; }
.ai-cta {
  margin-top: 14px;
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  background: var(--surface);
  border: 1px solid rgba(112, 145, 255, 0.3);
  border-radius: var(--radius-pill);
  font-size: 12px; font-weight: 600; color: var(--ledger-blue-mid);
}

.ai-fab {
  position: fixed; bottom: 28px; inset-inline-end: 28px; z-index: 100;
  display: flex; align-items: center; gap: var(--space-3);
  padding: 6px 18px 6px 6px;
  background: var(--surface);
  border: 1px solid var(--ledger-accent);
  border-radius: var(--radius-pill);
  box-shadow: 0 12px 40px rgba(11, 31, 59, 0.18);
  transition: transform 0.3s var(--ease-elastic), box-shadow 0.3s;
}
.ai-fab:hover { transform: translateY(-3px); box-shadow: 0 20px 50px rgba(11, 31, 59, 0.24); }
.ai-fab-inner {
  width: 44px; height: 44px; border-radius: 50%;
  background: var(--ia-mesh); background-size: 200% 200%;
  display: grid; place-items: center;
  box-shadow: 0 8px 20px rgba(255, 118, 193, 0.3);
}
/* El mesh solo se mueve cuando el usuario apunta al FAB — sin bucle en reposo */
.ai-fab:hover .ai-fab-inner,
.ai-fab:focus-visible .ai-fab-inner { animation: meshShift 6s ease infinite; }
.ai-fab-inner svg { width: 22px; height: 22px; }
.ai-fab-label { font-size: 13px; font-weight: 700; color: var(--primary-stability); padding-inline-end: 4px; }
@keyframes meshShift { 0%, 100% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } }

.ai-panel {
  position: fixed; bottom: 100px; inset-inline-end: 28px; z-index: 99;
  width: 400px; max-width: calc(100vw - 56px);
  height: 560px; max-height: calc(100vh - 140px);
  background: rgba(255, 255, 255, 0.78);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.6);
  border-radius: var(--radius-lg);
  box-shadow: 0 30px 70px rgba(11, 31, 59, 0.25);
  display: flex; flex-direction: column;
  overflow: hidden;
  transform: translateY(30px) scale(0.96); opacity: 0; pointer-events: none;
  transition: transform 0.4s var(--ease-elastic), opacity 0.3s;
}
.ai-panel.is-open { transform: translateY(0) scale(1); opacity: 1; pointer-events: auto; }
.ai-header { padding: 14px 16px; background: var(--ia-mesh); color: #fff; display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.ai-header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ai-avatar { width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,0.25); border: 1px solid rgba(255,255,255,0.4); position: relative; flex-shrink: 0; }
.ai-avatar::after { content: ''; position: absolute; inset: 8px; border-radius: 50%; background: #fff; animation: pulse 2s infinite; }
.ai-title { font-size: 14px; font-weight: 700; }
.ai-sub { font-size: 11px; opacity: 0.85; }
.ai-close { width: 28px; height: 28px; border-radius: 50%; background: rgba(255,255,255,0.2); color: #fff; font-size: 17px; display: grid; place-items: center; flex-shrink: 0; }
.ai-tabs { display: flex; gap: var(--space-2); padding: 10px 16px; background: rgba(255,255,255,0.6); border-bottom: 1px solid var(--ledger-accent); }
.ai-tabs button {
  flex: 1; padding: 7px 12px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600; color: var(--text-soft);
  border: 1px solid transparent;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
}
.ai-tabs button.is-active { background: var(--surface); color: var(--ledger-blue-mid); border-color: var(--ledger-accent); box-shadow: var(--shadow-soft); }
.ai-body { flex: 1; padding: 18px; overflow-y: auto; display: flex; flex-direction: column; gap: var(--space-3); background: linear-gradient(to bottom, rgba(255,255,255,0.4), rgba(242,245,248,0.6)); }
.ai-bubble { padding: 12px 15px; font-size: 13px; line-height: 1.5; max-width: 90%; }
.ai-bubble--bot { background: var(--surface); border: 1px solid var(--ledger-accent); border-radius: 16px 16px 16px 4px; box-shadow: var(--shadow-soft); align-self: flex-start; }
.ai-bubble--user { background: var(--primary-stability); color: #fff; border-radius: 16px 16px 4px 16px; align-self: flex-end; }
.ai-quick { display: flex; flex-direction: column; gap: var(--space-2); }
.ai-quick-item {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
  padding: 12px; border: 1px solid var(--ledger-accent); border-radius: var(--radius-md);
  background: var(--surface); text-align: start;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.ai-quick-item:hover { border-color: var(--ledger-blue-mid); box-shadow: var(--shadow-soft); }
.ai-quick-title { display: block; font-size: 13px; font-weight: 600; }
.ai-quick-item p { font-size: 11px; color: var(--text-meta); margin-top: 2px; }
.ai-footer { padding: 12px 14px; background: var(--surface); border-top: 1px solid var(--ledger-accent); }
.ai-input { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 16px; background: var(--background-neutral); border: 1px solid var(--ledger-accent); border-radius: var(--radius-pill); transition: border-color 0.2s, box-shadow 0.2s; }
.ai-input:focus-within { border-color: var(--ledger-blue-mid); box-shadow: 0 0 0 4px rgba(18, 58, 99, 0.08); }
.ai-input input { flex: 1; border: none; outline: none; font: inherit; font-size: 13px; background: transparent; }
.ai-send { width: 34px; height: 34px; border-radius: 50%; background: var(--ia-mesh); display: grid; place-items: center; transition: transform 0.3s var(--ease-elastic); }
.ai-send:hover { transform: rotate(-15deg) scale(1.05); }
.ai-send svg { width: 15px; height: 15px; }

/* Markdown dentro de las respuestas del chat */
.chat-md h1, .chat-md h2, .chat-md h3 { font-weight: 700; margin: 8px 0 4px; }
.chat-md h2 { font-size: 0.95rem; } .chat-md h3 { font-size: 0.88rem; }
.chat-md p { margin: 4px 0; }
.chat-md ul, .chat-md ol { padding-inline-start: 1.2rem; margin: 4px 0; }
.chat-md li { margin: 2px 0; }
.chat-md table { width: 100%; font-size: 0.75rem; margin: 6px 0; }
.chat-md th { background: var(--primary-stability); color: #fff; padding: 4px 6px; text-align: start; }
.chat-md td { padding: 3px 6px; border-bottom: 1px solid var(--ledger-accent); }
.chat-md code { background: var(--background-neutral); border-radius: 3px; padding: 1px 4px; font-size: 0.8rem; }
.chat-md pre { background: var(--background-neutral); border-radius: 6px; padding: 8px; overflow-x: auto; margin: 6px 0; }
.chat-md pre code { background: none; padding: 0; }
.chat-md blockquote { border-inline-start: 3px solid var(--ledger-blue-mid); padding-inline-start: 8px; color: var(--text-soft); margin: 6px 0; }
.chat-md hr { border: none; border-top: 1px solid var(--ledger-accent); margin: 8px 0; }

/* ============================ 16. FORMULARIOS ============================ */
.form-grid { display: flex; flex-direction: column; gap: var(--space-5); }
.form-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-4); }
/* 3 columnas — colapsa a 1 en móvil vía la media query de `.form-row`.
   No fijar las columnas con style inline: rompe ese colapso. */
.form-row--3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 899px) { .form-row--3 { grid-template-columns: repeat(2, 1fr); } }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field-legend { font-size: 13px; font-weight: 600; color: var(--text-muted); }
.field-hint { font-size: 12px; color: var(--text-meta); }
.field-error { font-size: 12px; color: var(--earth-warn); font-weight: 500; }

.input, .textarea, .select {
  width: 100%;
  padding: 11px 14px;
  background: var(--surface);
  border: 1px solid var(--ledger-accent);
  border-radius: var(--radius-sm);
  font: inherit; font-size: 14px;
  color: var(--text-strong);
  transition: border-color 0.2s var(--ease-smooth), box-shadow 0.2s;
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--ledger-blue-mid);
  box-shadow: 0 0 0 4px rgba(18, 58, 99, 0.08);
}
.input:user-invalid, .field.has-error .input { border-color: var(--earth-warn); }
.input:user-valid { border-color: var(--status-success); }
.textarea { min-height: 96px; resize: vertical; }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%23556372' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-inline-end: 38px; }

.check { display: flex; align-items: flex-start; gap: 10px; font-size: 14px; color: var(--text-body); cursor: pointer; }
.check input { width: 18px; height: 18px; margin-top: 1px; accent-color: var(--ledger-blue-mid); flex-shrink: 0; }

/* Toggle (interruptor) */
.toggle {
  display: inline-flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 600; color: var(--text-meta);
  padding: 5px 10px; border-radius: var(--radius-pill);
  background: var(--background-neutral);
  transition: background 0.2s, color 0.2s;
  user-select: none;
}
.toggle.is-on { background: var(--amber-soft); color: var(--amber-text); }
.toggle-track {
  position: relative; width: 30px; height: 17px; flex-shrink: 0;
  border-radius: var(--radius-pill); background: var(--ledger-accent);
  transition: background 0.2s;
}
.toggle.is-on .toggle-track { background: var(--amber-alert); }
.toggle-track::after {
  content: ''; position: absolute; top: 2px; inset-inline-start: 2px;
  width: 13px; height: 13px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.2s var(--ease-elastic);
}
.toggle.is-on .toggle-track::after { transform: translateX(13px); }

/* Fila de autocompletado (CNAE, etc.) */
.ac-row:hover, .ac-row.is-active { background: var(--primary-stability); color: #fff; }
.ac-row:hover .mono, .ac-row.is-active .mono { color: rgba(255, 255, 255, 0.75); }

/* Avatar de iniciales genérico */
.avatar {
  width: 38px; height: 38px; border-radius: 12px; flex-shrink: 0;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--ledger-accent), #E4EBF3);
  color: var(--primary-stability); font-weight: 700; font-size: 13px;
}

/* Tarjetas de opción (radio) */
.radio-cards { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--space-3); }
.radio-card {
  display: flex; flex-direction: column; gap: 4px;
  padding: 14px;
  border: 2px solid var(--ledger-accent);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.radio-card:hover { border-color: var(--ledger-blue-mid); }
.radio-card:has(input:checked) { border-color: var(--primary-stability); background: rgba(18, 58, 99, 0.04); }
.radio-card input { position: absolute; opacity: 0; pointer-events: none; }
.radio-card-title { display: block; font-size: 14px; font-weight: 700; }
.radio-card p { font-size: 12px; color: var(--text-meta); line-height: 1.45; }

/* Zona de arrastre de archivos */
.dropzone {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; text-align: center;
  min-height: 160px;
  padding: var(--space-6);
  border: 2px dashed var(--ledger-accent);
  border-radius: var(--radius-md);
  background: var(--background-neutral);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.dropzone:hover, .dropzone.is-dragging { border-color: var(--ledger-blue-mid); background: rgba(18, 58, 99, 0.05); }
.dropzone svg { width: 34px; height: 34px; color: var(--text-meta); }
.dropzone-main { font-size: 14px; color: var(--text-muted); }
.dropzone-main b { color: var(--ledger-blue-mid); }
.dropzone-hint { font-size: 12px; color: var(--text-faint); }
.dropzone-file { font-size: 14px; font-weight: 600; color: var(--ledger-blue-mid); word-break: break-all; }

/* Bloque informativo */
.note {
  padding: var(--space-4) var(--space-5);
  background: rgba(18, 58, 99, 0.06);
  border: 1px solid var(--ledger-accent);
  border-radius: var(--radius-md);
  font-size: 13px; color: var(--text-muted);
}
.note h2, .note h4 { font-size: 13px; font-weight: 700; margin-bottom: 6px; color: var(--text-strong); }
.note ol { list-style: decimal; padding-inline-start: 1.3rem; display: flex; flex-direction: column; gap: 4px; }
.note ul { list-style: disc; padding-inline-start: 1.3rem; display: flex; flex-direction: column; gap: 4px; }
.note li { padding-inline-start: 4px; }

@keyframes spin { to { transform: rotate(360deg); } }
.spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,0.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; }

/* --- Revisión de apuntes (documents/review) --- */
.review-legend { display: flex; flex-wrap: wrap; gap: var(--space-4); margin-bottom: var(--space-4); font-size: 12px; color: var(--text-soft); }
.review-legend span { display: inline-flex; align-items: center; gap: 6px; }
.review-swatch { width: 12px; height: 12px; border-radius: 4px; border: 1px solid; flex-shrink: 0; }
.review-swatch--missing { background: rgba(166, 90, 50, 0.11); border-color: var(--earth-warn); }
.review-swatch--lowconf { background: rgba(192, 138, 46, 0.12); border-color: var(--amber-alert); }
.review-swatch--ok { background: var(--surface); border-color: var(--ledger-accent); }

.review-entry {
  border-inline-start: 4px solid var(--ledger-accent);
  margin-bottom: var(--space-4);
}
.review-entry--missing { border-inline-start-color: var(--earth-warn); }
.review-entry--lowconf { border-inline-start-color: var(--amber-alert); }
.review-entry--ok { border-inline-start-color: var(--status-success); }

.review-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-2); margin-bottom: var(--space-4); }
.review-head .btn { margin-inline-start: auto; }
.review-head .btn + .btn { margin-inline-start: 0; }

.review-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-3); }
.review-grid .field.col-2 { grid-column: span 2; }
.field--missing, .field--lowconf { border-radius: var(--radius-sm); padding: 6px; margin: -6px; }
.field--missing { background: rgba(166, 90, 50, 0.14); }
.field--missing > label { color: var(--earth-warn); font-weight: 700; }
.field--missing .input, .field--missing .select { border-color: var(--earth-warn); }
.field--lowconf { background: rgba(192, 138, 46, 0.18); }
.field--lowconf > label { color: var(--amber-text); font-weight: 700; }

.review-ocr { margin-top: var(--space-3); }
.review-ocr summary { font-size: 12px; color: var(--text-meta); cursor: pointer; }
.review-ocr summary:hover { color: var(--text-strong); }
.review-ocr p {
  margin-top: 6px; padding: 10px 12px;
  background: var(--background-neutral); border-radius: var(--radius-sm);
  font-family: var(--font-mono); font-size: 12px; color: var(--text-soft);
  white-space: pre-wrap; word-break: break-word;
}

/* --- Resumen de totales (factura, modelo) --- */
.doc-totals { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; font-size: 14px; }
.doc-totals > div { display: flex; gap: var(--space-8); align-items: baseline; }
.doc-totals .lbl { color: var(--text-soft); }
.doc-totals .val { min-width: 120px; text-align: end; font-weight: 600; font-variant-numeric: tabular-nums; }
.doc-totals .total-row { border-top: 1px solid var(--ledger-accent); padding-top: 8px; margin-top: 4px; }
.doc-totals .total-row .lbl { color: var(--text-strong); font-weight: 700; }
.doc-totals .total-row .val { font-size: 20px; font-weight: 800; color: var(--primary-stability); }

/* --- Ficha de datos (pares clave/valor) --- */
.data-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--space-4) var(--space-6); }
.data-grid .k { font-size: 11px; color: var(--text-meta); text-transform: uppercase; letter-spacing: 0.06em; }
.data-grid .v { font-size: 14px; font-weight: 500; margin-top: 3px; }
@media (max-width: 640px) { .data-grid { grid-template-columns: repeat(2, 1fr); } }

/* --- Panel plegable (detalle de factura: cambiar estado, enviar email) --- */
.panel-row { display: flex; align-items: center; justify-content: space-between; gap: var(--space-4); }
.panel-row h2, .panel-row h3 { font-size: 14px; font-weight: 700; }
.panel-row p { font-size: 12px; color: var(--text-meta); margin-top: 2px; }
.panel-body { margin-top: var(--space-5); padding-top: var(--space-5); border-top: 1px solid var(--ledger-accent); }

/* --- Editor de líneas de factura --- */
.linea-head, .linea-row {
  display: grid;
  grid-template-columns: 1fr 90px 110px 90px 32px;
  gap: var(--space-2);
  align-items: center;
}
.linea-head { padding: 0 4px 6px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-meta); }
.linea-head span:not(:first-child) { text-align: center; }
.linea-row { margin-bottom: var(--space-2); }
.linea-row .input, .linea-row .select { padding: 9px 10px; font-size: 13px; }
.linea-sub { grid-column: 1 / -1; text-align: end; font-size: 11px; color: var(--text-meta); padding-inline-end: 40px; margin-top: -2px; }
.linea-del { border: none; background: none; color: var(--text-faint); display: grid; place-items: center; }
.linea-del:hover { color: var(--earth-warn); }
.linea-del svg { width: 16px; height: 16px; }
@media (max-width: 640px) {
  .linea-head { display: none; }
  .linea-row { grid-template-columns: 1fr 1fr 40px; }
  .linea-row > :nth-child(1) { grid-column: 1 / -1; }
}

@media (max-width: 900px) {
  .review-grid { grid-template-columns: repeat(2, 1fr); }
  .review-grid .field.col-2 { grid-column: span 2; }
}
@media (max-width: 560px) {
  .review-grid { grid-template-columns: 1fr; }
  .review-grid .field.col-2 { grid-column: span 1; }
}

/* ============ 17. FEEDBACK ============ */
.flash-stack { display: flex; flex-direction: column; gap: var(--space-3); margin-bottom: var(--space-5); }
.flash {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 13px; font-weight: 500;
  border: 1px solid;
}
.flash span { flex: 1; }
.flash button { opacity: 0.5; font-size: 16px; line-height: 1; padding: 2px; }
.flash button:hover { opacity: 1; }
.flash--success { background: rgba(95, 184, 138, 0.12); border-color: rgba(95, 184, 138, 0.35); color: var(--status-success-2); }
.flash--error   { background: var(--earth-warn-soft); border-color: rgba(166, 90, 50, 0.36); color: var(--earth-warn); }
.flash--warning { background: rgba(192, 138, 46, 0.14); border-color: rgba(192, 138, 46, 0.38); color: var(--amber-text); }
.flash--info    { background: rgba(18, 58, 99, 0.08); border-color: var(--ledger-accent); color: var(--ledger-blue-mid); }

.empty-state {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: var(--space-3);
  padding: var(--space-16) var(--space-6);
  color: var(--text-soft);
}
.empty-state svg { width: 48px; height: 48px; color: var(--text-faint); }
.empty-state h1, .empty-state h2, .empty-state h3 { font-size: 16px; font-weight: 700; color: var(--text-strong); }
.empty-state p { font-size: 13px; max-width: 360px; }

.skeleton {
  background: linear-gradient(90deg, rgba(201, 214, 229, 0.15), rgba(201, 214, 229, 0.4), rgba(201, 214, 229, 0.15));
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.modal-backdrop {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(11, 31, 59, 0.4);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  padding: var(--space-4);
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lift);
  max-width: 420px; width: 100%;
  padding: var(--space-7);
}
.modal h2, .modal h3 { font-size: 18px; font-weight: 700; }
.modal p { font-size: 13px; color: var(--text-soft); margin-top: var(--space-3); }
.modal-actions { display: flex; gap: var(--space-3); justify-content: flex-end; margin-top: var(--space-6); }

.pagination { display: flex; align-items: center; justify-content: center; gap: var(--space-2); margin-top: var(--space-6); }
.pagination a, .pagination span {
  min-width: 36px; height: 36px;
  display: grid; place-items: center;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600;
  color: var(--text-muted);
  border: 1px solid var(--ledger-accent);
  background: var(--surface);
}
.pagination a:hover { border-color: var(--ledger-blue-mid); }
.pagination .is-current { background: var(--primary-stability); color: #fff; border-color: var(--primary-stability); }

/* ==================== 18. UTILIDADES MÍNIMAS ==================== */
.view { animation: viewFade 0.4s var(--ease-smooth); }
@keyframes viewFade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
.stack { display: flex; flex-direction: column; gap: var(--space-4); }
.row { display: flex; align-items: center; gap: var(--space-3); }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); }
.muted { color: var(--text-meta); }
.tnum { font-variant-numeric: tabular-nums; }
.text-success { color: var(--status-success-2); }
.text-warn { color: var(--earth-warn); }

/* ============================ 19. RESPONSIVE ============================ */
@media (max-width: 1200px) {
  .span-3 { grid-column: span 6; }
  .span-5, .span-7 { grid-column: span 12; }
  .totals-strip { grid-template-columns: repeat(2, 1fr); }
  .model-grid, .actions-grid, .help-grid { grid-template-columns: repeat(2, 1fr); }
  .main-content { padding-inline: var(--space-6); }
}
@media (max-width: 980px) {
  .span-6, .span-8 { grid-column: span 12; }
  .span-4 { grid-column: span 6; }
}

@media (max-width: 899px) {
  .sidebar {
    transform: translateX(-100%);
    box-shadow: var(--shadow-lift);
  }
  .sb-drawer-open .sidebar { transform: translateX(0); }
  .main { margin-inline-start: 0; }
  .topbar-burger { display: grid; place-items: center; }
  .page-title { font-size: 26px; }
  #sbCollapseBtn { display: none; }          /* el colapso no aplica al drawer */
  .sb-drawer-open .ai-fab { display: none; } /* no tapar el menú abierto */
  .topbar-meta { display: none; }            /* email fuera en móvil */
}

@media (max-width: 720px) {
  .span-4, .span-6, .span-8, .span-9 { grid-column: span 12; }
  .bento { gap: var(--space-3); }
  .main-content { padding: var(--space-5) var(--space-4) 110px; }
  .actions-grid, .totals-strip, .model-grid, .help-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .client-row { grid-template-columns: 40px 1fr auto; }
  .client-row > :nth-child(3), .client-row > :nth-child(4), .client-row > :nth-child(5) { display: none; }
  .ai-panel { inset-inline: 16px; width: auto; }
  .ai-fab { inset-inline-end: 16px; padding: 6px; }
  .ai-fab-label { display: none; }               /* solo el círculo en móvil */
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
}

/* --- Tablas de listado → tarjetas en móvil ---
   `.table-wrap.cards` colapsa la tabla en una tarjeta por fila: la cabecera
   pasa a etiqueta (data-label) delante de cada valor y las acciones caen al
   pie, alcanzables. Solo para listados con columna de acciones; el libro y
   otras vistas tipo hoja de cálculo se quedan con scroll horizontal. */
@media (max-width: 720px) {
  .table-wrap.cards > table,
  .table-wrap.cards > table > tbody,
  .table-wrap.cards > table > tbody > tr,
  .table-wrap.cards > table > tbody > tr > td { display: block; width: 100%; }
  .table-wrap.cards > table { min-width: 0; font-size: 13px; }
  .table-wrap.cards > table > thead { display: none; }

  .table-wrap.cards > table > tbody > tr {
    padding: var(--space-4) var(--space-5);
    border-bottom: 1px solid var(--ledger-accent);
  }
  .table-wrap.cards > table > tbody > tr:last-child { border-bottom: none; }
  .table-wrap.cards > table > tbody > tr:hover { background: none; }

  .table-wrap.cards > table > tbody > tr > td {
    display: flex; align-items: baseline; justify-content: space-between;
    gap: var(--space-4);
    padding: 5px 0; border: none;
    white-space: normal; text-align: end;
  }
  .table-wrap.cards > table > tbody > tr > td::before {
    content: attr(data-label);
    flex: 0 0 auto; text-align: start;
    font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--text-meta);
  }
  /* primera celda = título de la tarjeta */
  .table-wrap.cards > table > tbody > tr > td:first-child {
    font-size: 15px; padding-bottom: var(--space-2); text-align: start;
  }
  .table-wrap.cards > table > tbody > tr > td:first-child::before { display: none; }
  /* celda con contenido rico (avatar+nombre, nombre+concepto): etiqueta arriba, bloque debajo */
  .table-wrap.cards > table > tbody > tr > td.cell-block { display: block; text-align: start; }
  .table-wrap.cards > table > tbody > tr > td.cell-block::before { display: block; margin-bottom: 3px; }
  /* celda de acciones: sin data-label → fila completa, botones repartidos a lo ancho.
     Los envoltorios (<form>, <span x-data> de confirm_action) se hacen flex para
     que su botón interior también se estire. */
  .table-wrap.cards > table > tbody > tr > td:not([data-label]) { padding-top: var(--space-3); }
  .table-wrap.cards > table > tbody > tr > td:not([data-label])::before { display: none; }
  .table-wrap.cards > table > tbody > tr > td:not([data-label]) > .row { width: 100%; flex-wrap: wrap; }
  .table-wrap.cards > table > tbody > tr > td:not([data-label]) > .row > * { flex: 1 1 auto; min-width: 0; }
  .table-wrap.cards > table > tbody > tr > td:not([data-label]) > .row > form,
  .table-wrap.cards > table > tbody > tr > td:not([data-label]) > .row > span { display: flex; }
  .table-wrap.cards > table > tbody > tr > td:not([data-label]) > .row > form > .btn,
  .table-wrap.cards > table > tbody > tr > td:not([data-label]) > .row > span > .btn { flex: 1; }
  /* celdas vacías no ocupan línea */
  .table-wrap.cards > table > tbody > tr > td:empty { display: none; }
}

/* Afordancia de scroll para las tablas que sí siguen en horizontal */
@media (max-width: 720px) {
  .table-wrap:not(.cards):not(.fit) {
    background:
      linear-gradient(to right, var(--surface) 30%, rgba(255,255,255,0)) left / 40px 100% no-repeat,
      linear-gradient(to left, var(--surface) 30%, rgba(255,255,255,0)) right / 40px 100% no-repeat,
      radial-gradient(farthest-side at 0 50%, rgba(11,31,59,0.12), transparent) left / 14px 100% no-repeat,
      radial-gradient(farthest-side at 100% 50%, rgba(11,31,59,0.12), transparent) right / 14px 100% no-repeat;
    background-attachment: local, local, scroll, scroll;
  }
}

/* --- Objetivos táctiles (punteros gruesos: dedo, stylus) ---
   GUIA §0: ningún control por debajo de 44px en contextos de uso rápido. */
@media (pointer: coarse) {
  .btn { min-height: 44px; }
  .btn-sm { min-height: 44px; padding-block: 8px; }
  .topbar-burger { padding: 11px; }
  .filter-select { min-height: 44px; }
  .pagination a, .pagination span { min-width: 44px; height: 44px; }
  .flash button { display: inline-grid; place-items: center; min-width: 36px; min-height: 36px; }
  .segmented button, .segmented a, .mode-toggle button, .mode-toggle a { min-height: 38px; }
  .toggle { min-height: 40px; }
}
