/* ============================================================
   Panel V3 redesign · Document Extractor IA
   Estilo: Linear / Notion clean + acentos Real Flow AI
   AUTOCONTENIDO · NO depende de _brand/ · puede borrarse sin afectar nada
   ============================================================ */

/* ---------- Tokens RFA (light theme) ---------- */
:root {
  /* Brand RFA */
  --rfa-navy: #0A1628;
  --rfa-orange: #E85D04;
  --rfa-orange-soft: #FCEAD8;
  --rfa-mint: #5DCAA5;
  --rfa-mint-soft: #E1F5EC;
  --rfa-amber: #F0A500;
  --rfa-amber-soft: #FDF1D7;
  --rfa-cyan: #0EAFC0;
  --rfa-cyan-soft: #DAF1F4;
  --rfa-purple: #7B61FF;
  --rfa-purple-soft: #ECE7FF;
  --rfa-coral: #E85D5D;
  --rfa-coral-soft: #FBE3E3;

  /* Neutros · light */
  --bg: #f5f4f0;            /* fondo principal · off-white tibio */
  --surface: #ffffff;       /* cards · panel */
  --surface-hover: #ebe9e2;
  --surface-active: #f5f4f0;
  --surface-2: var(--surface-hover); /* usado por filtros de reports.html · no estaba definido (fix 2026-06-03) */
  --border: #dddbd4;        /* default · hairline tibio */
  --border-strong: #c4c1b8;
  --border-focus: var(--rfa-orange);

  --text: #1a1a1a;          /* casi negro azulado */
  --text-muted: #888888;
  --text-dim: #bbbbbb;
  --text-on-dark: #F5F5F4;

  /* Tipografía */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --font-display: 'Inter', sans-serif;

  /* Espaciado · grid 4px */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 20px;
  --sp-6: 24px;
  --sp-7: 32px;
  --sp-8: 40px;
  --sp-10: 56px;

  /* Radii */
  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;
  --r-pill: 999px;

  /* Sombras · sutiles tipo Linear */
  --sh-1: 0 1px 2px rgba(10, 22, 40, 0.04);
  --sh-2: 0 1px 3px rgba(10, 22, 40, 0.06), 0 1px 2px rgba(10, 22, 40, 0.04);
  --sh-3: 0 4px 12px rgba(10, 22, 40, 0.06), 0 1px 3px rgba(10, 22, 40, 0.04);
  --sh-4: 0 10px 28px rgba(10, 22, 40, 0.08), 0 4px 8px rgba(10, 22, 40, 0.04);

  /* Transitions */
  --t-fast: 120ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-base: 180ms cubic-bezier(0.4, 0, 0.2, 1);
  --t-slow: 280ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Tamaños */
  --sidebar-w: 232px;
  --sidebar-w-collapsed: 56px;
  --topbar-h: 56px;

  color-scheme: light;
}

/* ---------- Tokens · DARK THEME ---------- */
[data-theme="dark"] {
  /* Brand RFA · variantes soft un poco más saturadas para dark */
  --rfa-orange-soft: rgba(255, 107, 44, 0.16);
  --rfa-mint-soft:   rgba(46, 204, 113, 0.14);
  --rfa-amber-soft:  rgba(240, 165, 0, 0.16);
  --rfa-cyan-soft:   rgba(14, 175, 192, 0.14);
  --rfa-purple-soft: rgba(123, 97, 255, 0.18);
  --rfa-coral-soft:  rgba(255, 68, 68, 0.16);

  /* Neutros · dark deep navy (alineado a la marca panel · 2026-06-01) */
  --bg: #0A1628;
  --surface: #131F2E;
  --surface-hover: #1B2838;
  --surface-active: #1B2838;
  --surface-2: var(--surface-hover);
  --border: #1F2D3D;
  --border-strong: #2D3D52;
  --border-focus: var(--rfa-orange);

  --text: #e0e0e0;
  --text-muted: #888888;
  --text-dim: #555555;
  --text-on-dark: #ffffff;

  /* Sombras · más fuertes para destacar elevación en dark */
  --sh-1: 0 1px 2px rgba(0, 0, 0, 0.30);
  --sh-2: 0 1px 3px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.20);
  --sh-3: 0 4px 12px rgba(0, 0, 0, 0.35), 0 1px 3px rgba(0, 0, 0, 0.20);
  --sh-4: 0 10px 28px rgba(0, 0, 0, 0.40), 0 4px 8px rgba(0, 0, 0, 0.20);

  color-scheme: dark;
}

/* Opciones del popup nativo de <select> legibles en ambos temas (fix 2026-06-03):
   el popup puede pintarse claro por el OS mientras las options heredan texto claro del tema dark */
select option { background-color: var(--surface); color: var(--text); }

/* Smooth transition al cambiar de tema */
html { transition: background-color var(--t-base), color var(--t-base); }
body, .sidebar, .topbar, .kpi, .card, .table-card, .viewer, .btn, .tab, .tabs, .search-box {
  transition: background-color var(--t-base), border-color var(--t-base), color var(--t-base), box-shadow var(--t-base);
}

/* ---------- Banner mockup · sólo visible en este redesign V3 (no productivo) ---------- */
.mockup-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 9999;
  background: repeating-linear-gradient(
    45deg,
    #E85D5D,
    #E85D5D 12px,
    #B73B3B 12px,
    #B73B3B 24px
  );
  color: white;
  padding: 8px 16px;
  text-align: center;
  font-family: 'Inter', sans-serif;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.mockup-banner a { color: white; text-decoration: underline; }
body.has-mockup-banner { padding-top: 38px; }

/* ---------- Reset ligero ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: 0; background: transparent; }
table { border-collapse: collapse; width: 100%; }

/* ---------- App layout ---------- */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
.app[data-sidebar="collapsed"] { grid-template-columns: var(--sidebar-w-collapsed) 1fr; }

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: var(--sp-4) 0;
  overflow-y: auto;
  overflow-x: hidden;
}
/* Custom scrollbar discreto en sidebar (fix 2026-05-17) */
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 0 var(--sp-4) var(--sp-5);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--sp-4);
}
.sidebar__mark {
  width: 32px; height: 32px;
  background: var(--rfa-orange);
  color: white;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 16px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-md);
  flex-shrink: 0;
  box-shadow: var(--sh-1);
}
.sidebar__name {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  letter-spacing: -0.01em;
  white-space: nowrap;
}
.sidebar__name small {
  display: block;
  font-weight: 400;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  margin-top: 2px;
}

.sidebar__group {
  padding: 0 var(--sp-3);
  margin-bottom: var(--sp-5);
}
.sidebar__label {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  padding: 0 var(--sp-3) var(--sp-2);
}

.sidebar__nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar__item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--t-fast);
  cursor: pointer;
  position: relative;
}
.sidebar__item:hover { background: var(--surface-hover); color: var(--text); }
.sidebar__item.is-active {
  background: var(--rfa-orange-soft);
  color: var(--rfa-orange);
  font-weight: 600;
}
.sidebar__item.is-active::before {
  content: '';
  position: absolute;
  left: -var(--sp-3);
  top: 6px; bottom: 6px;
  width: 3px;
  background: var(--rfa-orange);
  border-radius: 0 2px 2px 0;
}
.sidebar__icon {
  width: 16px; height: 16px;
  flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px;
}
.sidebar__count {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg);
  padding: 1px 6px;
  border-radius: var(--r-pill);
  font-weight: 500;
}
.sidebar__item.is-active .sidebar__count {
  background: white;
  color: var(--rfa-orange);
}

.sidebar__footer {
  margin-top: auto;
  padding: var(--sp-3);
  border-top: 1px solid var(--border);
}
.sidebar__user {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background var(--t-fast);
}
.sidebar__user:hover { background: var(--surface-hover); }
.sidebar__avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--rfa-cyan), var(--rfa-mint));
  color: white;
  font-weight: 600;
  font-size: 12px;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar__user-info { flex: 1; min-width: 0; overflow: hidden; }
.sidebar__user-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar__user-role {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------- Main column ---------- */
.main { display: flex; flex-direction: column; min-width: 0; }

/* ---------- Topbar ---------- */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 var(--sp-7);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-4);
  position: sticky; top: 0; z-index: 50;
  backdrop-filter: blur(8px);
}
:root             .topbar { background: rgba(255, 255, 255, 0.92); }
[data-theme="dark"] .topbar { background: rgba(10, 22, 40, 0.92); }
.topbar__title {
  display: flex; align-items: center; gap: var(--sp-3);
  font-weight: 600;
  font-size: 15px;
  color: var(--text);
  letter-spacing: -0.01em;
}
.topbar__crumbs {
  color: var(--text-dim);
  font-weight: 400;
}
.topbar__crumbs::after { content: '/'; margin: 0 var(--sp-2); color: var(--text-dim); }

.topbar__actions { display: flex; align-items: center; gap: var(--sp-3); }

.live-pill {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: 4px 10px;
  background: var(--rfa-mint-soft);
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 600;
  color: #2C8264;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
[data-theme="dark"] .live-pill { color: var(--rfa-mint); }
.live-pill::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--rfa-mint);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.1); }
}

.btn {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--surface);
  transition: all var(--t-fast);
}
.btn:hover { border-color: var(--border-strong); color: var(--text); background: var(--surface-hover); }
.btn--primary {
  background: var(--rfa-orange);
  border-color: var(--rfa-orange);
  color: white;
  font-weight: 600;
  box-shadow: var(--sh-1);
}
.btn--primary:hover {
  background: #d44e02;
  border-color: #d44e02;
  color: white;
  box-shadow: var(--sh-2);
}
.btn--ghost { border-color: transparent; }

/* ---------- Content area ---------- */
.content {
  padding: var(--sp-7) var(--sp-7) var(--sp-10);
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

.page-header {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: var(--sp-5);
  margin-bottom: var(--sp-7);
}
.page-header__title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  margin: 0 0 4px;
}
.page-header__subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin: 0;
}

/* ---------- KPI cards ---------- */
.kpis {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-7);
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  position: relative;
  overflow: hidden;
  transition: all var(--t-base);
}
.kpi:hover {
  border-color: var(--border-strong);
  box-shadow: var(--sh-3);
  transform: translateY(-1px);
}
.kpi::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px; height: 100%;
  background: var(--accent, var(--rfa-orange));
}
.kpi--review   { --accent: var(--rfa-amber); }
.kpi--approved { --accent: var(--rfa-mint); }
.kpi--exported { --accent: var(--rfa-cyan); }
.kpi--auto     { --accent: var(--rfa-orange); }

.kpi__label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: var(--sp-2);
  display: flex; align-items: center; gap: var(--sp-2);
}
.kpi__label-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent, var(--rfa-orange));
  flex-shrink: 0;
}
.kpi__value {
  font-size: 32px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.025em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.kpi__value--pct::after {
  content: '%';
  font-size: 16px;
  font-weight: 600;
  color: var(--text-muted);
  margin-left: 2px;
}
.kpi__delta {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: var(--sp-2);
  font-family: var(--font-mono);
}
.kpi__delta--up { color: var(--rfa-mint); }
.kpi__delta--up::before { content: '▲ '; }
.kpi__delta--down { color: var(--rfa-coral); }
.kpi__delta--down::before { content: '▼ '; }

/* ---------- Toolbar ---------- */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-4);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}
.tabs {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 3px;
  gap: 2px;
}
.tab {
  padding: 6px 12px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--t-fast);
  display: inline-flex; align-items: center; gap: var(--sp-2);
}
.tab:hover { color: var(--text); background: var(--surface-hover); }
.tab.is-active {
  background: var(--rfa-navy);
  color: white;
  box-shadow: var(--sh-1);
}
[data-theme="dark"] .tab.is-active {
  background: var(--rfa-orange);
  color: white;
}
.tab__count {
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 6px;
  background: var(--bg);
  color: var(--text-muted);
  border-radius: var(--r-pill);
  font-weight: 500;
}
.tab.is-active .tab__count {
  background: rgba(255,255,255,0.2);
  color: white;
}

.search-box {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  flex: 1;
  max-width: 320px;
  transition: border-color var(--t-fast);
}
.search-box:focus-within { border-color: var(--rfa-orange); }
.search-box input {
  flex: 1;
  border: 0;
  outline: 0;
  font-family: inherit;
  font-size: 13px;
  background: transparent;
  color: var(--text);
}
.search-box input::placeholder { color: var(--text-dim); }

/* ---------- Table ---------- */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--sh-1);
}
.table {
  width: 100%;
  font-size: 13px;
}
.table thead th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--sp-3) var(--sp-5);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  white-space: nowrap;
}
.table tbody tr {
  cursor: pointer;
  transition: background var(--t-fast);
}
.table tbody tr:hover { background: var(--surface-hover); }
.table tbody tr + tr td { border-top: 1px solid var(--border); }
.table td {
  padding: var(--sp-3) var(--sp-5);
  vertical-align: middle;
  white-space: nowrap;
}

.cell-file {
  display: flex; align-items: center; gap: var(--sp-3);
  min-width: 0;
}
.cell-file__icon {
  width: 32px; height: 32px;
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  font-size: 14px;
}
.cell-file__name {
  font-weight: 500;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  overflow: hidden; text-overflow: ellipsis;
  max-width: 280px;
}
.cell-file__sub {
  font-size: 11px;
  color: var(--text-dim);
}

.tag {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.tag--factura  { background: var(--rfa-cyan-soft); color: #08727F; }
.tag--recibo   { background: var(--rfa-mint-soft); color: #2C8264; }
.tag--contrato { background: var(--rfa-amber-soft); color: #8A5C00; }
.tag--id       { background: var(--rfa-purple-soft); color: #4A39A3; }
.tag--otro     { background: var(--surface-hover); color: var(--text-muted); }
/* Dark · texto más claro sobre fondos soft con alpha */
[data-theme="dark"] .tag--factura  { color: var(--rfa-cyan); }
[data-theme="dark"] .tag--recibo   { color: var(--rfa-mint); }
[data-theme="dark"] .tag--contrato { color: var(--rfa-amber); }
[data-theme="dark"] .tag--id       { color: var(--rfa-purple); }

.conf {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}
.conf::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
}
.conf--high::before { background: var(--rfa-mint); }
.conf--mid::before  { background: var(--rfa-amber); }
.conf--low::before  { background: var(--rfa-coral); }
.conf--high { color: #2C8264; }
.conf--mid  { color: #8A5C00; }
.conf--low  { color: #B73B3B; }
[data-theme="dark"] .conf--high { color: var(--rfa-mint); }
[data-theme="dark"] .conf--mid  { color: var(--rfa-amber); }
[data-theme="dark"] .conf--low  { color: var(--rfa-coral); }

.status {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px;
  border-radius: var(--r-pill);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.status--review_pending { background: var(--rfa-amber-soft); color: #8A5C00; }
.status--auto_approved  { background: var(--rfa-mint-soft); color: #2C8264; }
.status--exported       { background: var(--rfa-cyan-soft); color: #08727F; }
.status--error          { background: var(--rfa-coral-soft); color: #B73B3B; }
.status--processing     { background: var(--rfa-purple-soft); color: #4A39A3; }
[data-theme="dark"] .status--review_pending { color: var(--rfa-amber); }
[data-theme="dark"] .status--auto_approved  { color: var(--rfa-mint); }
[data-theme="dark"] .status--exported       { color: var(--rfa-cyan); }
[data-theme="dark"] .status--error          { color: var(--rfa-coral); }
[data-theme="dark"] .status--processing     { color: var(--rfa-purple); }

.priority {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.priority--high   { color: var(--rfa-coral); }
.priority--normal { color: var(--text-muted); }
.priority--low    { color: var(--text-dim); }

.ts {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

/* ---------- Empty state ---------- */
.empty {
  text-align: center;
  padding: var(--sp-10) var(--sp-6);
  color: var(--text-muted);
}
.empty__icon {
  font-size: 32px;
  margin-bottom: var(--sp-3);
  opacity: 0.4;
}
.empty__title { font-size: 15px; font-weight: 600; color: var(--text); margin: 0 0 4px; }
.empty__sub   { font-size: 13px; color: var(--text-muted); margin: 0; }

/* ---------- Detail page ---------- */
.detail {
  display: grid;
  grid-template-columns: 1fr 360px;
  gap: var(--sp-5);
  margin-top: var(--sp-4);
}
@media (max-width: 1024px) {
  .detail { grid-template-columns: 1fr; }
}

.viewer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--sh-2);
  height: 760px;
  display: flex;
  flex-direction: column;
}
.viewer__head {
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3);
}
.viewer__filename {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  overflow: hidden; text-overflow: ellipsis;
}
.viewer__body {
  flex: 1;
  background: #2C2F3A;
  position: relative;
}
[data-theme="dark"] .viewer__body { background: #0A0D14; }
.viewer__placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: rgba(255, 255, 255, 0.4);
  font-size: 13px;
  gap: var(--sp-3);
}
.viewer__placeholder-icon { font-size: 48px; opacity: 0.5; }

.aside { display: flex; flex-direction: column; gap: var(--sp-4); }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--sh-1);
}
.card__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
}
.card__title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text);
  margin: 0;
}
.card__sub {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.field-list { display: flex; flex-direction: column; gap: var(--sp-3); }
.field {
  display: grid;
  grid-template-columns: 110px 1fr;
  align-items: baseline;
  gap: var(--sp-3);
  padding-bottom: var(--sp-3);
  border-bottom: 1px dashed var(--border);
}
.field:last-child { border-bottom: 0; padding-bottom: 0; }
.field__label {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.field__value {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  word-break: break-word;
}
.field__value--money {
  font-size: 14px;
  font-weight: 700;
  color: var(--rfa-orange);
}
.field__value--editable {
  border: 1px solid transparent;
  padding: 4px 6px;
  border-radius: 4px;
  cursor: text;
  transition: all var(--t-fast);
}
.field__value--editable:hover { background: var(--surface-hover); border-color: var(--border); }

.actions-row {
  display: flex; gap: var(--sp-2);
  padding-top: var(--sp-4);
  margin-top: var(--sp-4);
  border-top: 1px solid var(--border);
}
.actions-row .btn { flex: 1; justify-content: center; }
.btn--success {
  background: var(--rfa-mint);
  border-color: var(--rfa-mint);
  color: white;
  font-weight: 600;
}
.btn--success:hover {
  background: #4eb594;
  border-color: #4eb594;
  color: white;
}
.btn--danger {
  background: var(--surface);
  border-color: var(--rfa-coral);
  color: var(--rfa-coral);
  font-weight: 600;
}
.btn--danger:hover {
  background: var(--rfa-coral);
  color: white;
}

/* ---------- Theme toggle ---------- */
.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--t-fast);
  font-size: 14px;
}
.theme-toggle:hover {
  border-color: var(--border-strong);
  color: var(--text);
  background: var(--surface-hover);
}
.theme-toggle__sun { display: inline; }
.theme-toggle__moon { display: none; }
[data-theme="dark"] .theme-toggle__sun { display: none; }
[data-theme="dark"] .theme-toggle__moon { display: inline; }

/* ---------- Confidence bar ---------- */
.conf-bar {
  display: flex; align-items: center; gap: var(--sp-3);
  margin-top: var(--sp-3);
}
.conf-bar__track {
  flex: 1;
  height: 6px;
  background: var(--surface-hover);
  border-radius: var(--r-pill);
  overflow: hidden;
}
.conf-bar__fill {
  height: 100%;
  background: linear-gradient(90deg, var(--rfa-orange), var(--rfa-mint));
  border-radius: var(--r-pill);
  transition: width var(--t-slow);
}
.conf-bar__value {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  min-width: 56px;
  text-align: right;
}

/* ---------- Validation list ---------- */
.validations { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--sp-2); }
.validations li {
  display: flex; align-items: flex-start; gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: var(--r-md);
  font-size: 12px;
}
.validations li.ok    { background: var(--rfa-mint-soft);  color: #2C8264; }
.validations li.warn  { background: var(--rfa-amber-soft); color: #8A5C00; }
.validations li.error { background: var(--rfa-coral-soft); color: #B73B3B; }
[data-theme="dark"] .validations li.ok    { color: var(--rfa-mint); }
[data-theme="dark"] .validations li.warn  { color: var(--rfa-amber); }
[data-theme="dark"] .validations li.error { color: var(--rfa-coral); }
.validations li::before {
  content: '';
  width: 14px; height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
  margin-top: 1px;
}
.validations li.ok::before    { background: var(--rfa-mint); }
.validations li.warn::before  { background: var(--rfa-amber); }
.validations li.error::before { background: var(--rfa-coral); }

/* ---------- Source badge ---------- */
.source-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: var(--font-mono);
}
.source--email     { background: #DBEAFE; color: #1E40AF; }
.source--upload    { background: var(--rfa-purple-soft); color: #4A39A3; }
.source--whatsapp  { background: var(--rfa-mint-soft); color: #2C8264; }
.source--gdrive    { background: var(--rfa-amber-soft); color: #8A5C00; }
.source--api       { background: var(--rfa-coral-soft); color: #B73B3B; }
[data-theme="dark"] .source--email     { background: rgba(96, 165, 250, 0.18); color: #93C5FD; }
[data-theme="dark"] .source--upload    { color: var(--rfa-purple); }
[data-theme="dark"] .source--whatsapp  { color: var(--rfa-mint); }
[data-theme="dark"] .source--gdrive    { color: var(--rfa-amber); }
[data-theme="dark"] .source--api       { color: var(--rfa-coral); }

/* ---------- Loader ---------- */
.loading {
  display: inline-flex; align-items: center; gap: var(--sp-2);
  font-size: 13px; color: var(--text-muted);
  padding: var(--sp-6);
}
.loading::before {
  content: '';
  width: 12px; height: 12px;
  border: 2px solid var(--border);
  border-top-color: var(--rfa-orange);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .content { padding: var(--sp-4); }
  .topbar { padding: 0 var(--sp-4); }
}

/* ---------- Upload page ---------- */
.dropzone {
  border: 2px dashed var(--border-strong);
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: var(--sp-10) var(--sp-7);
  text-align: center;
  transition: all var(--t-base);
  cursor: pointer;
}
.dropzone:hover, .dropzone.is-active {
  border-color: var(--rfa-orange);
  background: var(--rfa-orange-soft);
}
.dropzone__icon {
  font-size: 56px;
  margin-bottom: var(--sp-4);
  color: var(--rfa-orange);
  opacity: 0.7;
}
.dropzone__title { font-size: 18px; font-weight: 700; color: var(--text); margin: 0 0 var(--sp-2); }
.dropzone__sub { font-size: 13px; color: var(--text-muted); margin: 0 0 var(--sp-5); }
.dropzone__btn { display: inline-block; }
.dropzone__formats {
  margin-top: var(--sp-5);
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.section-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin: var(--sp-7) 0 var(--sp-3);
  letter-spacing: -0.01em;
}
.section-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin: 0 0 var(--sp-4);
}

.channel-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--sp-3);
}
.channel-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  transition: all var(--t-fast);
}
.channel-card:hover { border-color: var(--border-strong); box-shadow: var(--sh-2); }
.channel-card.is-active {
  border-color: var(--rfa-mint);
  background: linear-gradient(180deg, var(--rfa-mint-soft) 0%, var(--surface) 30%);
}
.channel-card.is-locked {
  opacity: 0.55;
  border-style: dashed;
}
.channel-card__head { display: flex; align-items: center; justify-content: space-between; }
.channel-card__icon { font-size: 18px; }
.channel-card__name { font-size: 13px; font-weight: 600; color: var(--text); }
.channel-card__status {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-family: var(--font-mono);
}
.channel-card__status--on { color: var(--rfa-mint); }
.channel-card__status--off { color: var(--text-dim); }
.channel-card__sub { font-size: 11px; color: var(--text-muted); font-family: var(--font-mono); }

/* ---------- Reports page ---------- */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-5);
}
.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-4) var(--sp-5);
}
.metric__label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: var(--sp-2);
}
.metric__value {
  font-size: 24px;
  font-weight: 700;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  line-height: 1;
}
.metric__trend {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  margin-top: var(--sp-2);
}
.metric__trend--up   { color: var(--rfa-mint); }
.metric__trend--down { color: var(--rfa-coral); }

.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  margin-bottom: var(--sp-4);
}
.chart-placeholder {
  background: linear-gradient(135deg, var(--surface-hover) 0%, var(--surface-active) 100%);
  border: 1px dashed var(--border);
  border-radius: var(--r-md);
  padding: var(--sp-7);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-2);
  min-height: 200px;
  color: var(--text-dim);
  font-size: 12px;
}
.chart-placeholder__icon { font-size: 32px; opacity: 0.5; }
.chart-placeholder__bars {
  display: flex; align-items: flex-end; gap: 8px;
  height: 100px;
}
.chart-placeholder__bar {
  width: 28px;
  background: linear-gradient(180deg, var(--rfa-orange), var(--rfa-amber));
  border-radius: 3px 3px 0 0;
  opacity: 0.85;
}

/* ---------- Settings page ---------- */
.settings {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: var(--sp-7);
  margin-top: var(--sp-4);
}
@media (max-width: 880px) {
  .settings { grid-template-columns: 1fr; }
}

.settings-nav { display: flex; flex-direction: column; gap: 2px; position: sticky; top: calc(var(--topbar-h) + var(--sp-4)); align-self: start; }
.settings-nav__item {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--r-sm);
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--t-fast);
}
.settings-nav__item:hover { background: var(--surface-hover); color: var(--text); }
.settings-nav__item.is-active {
  background: var(--rfa-orange-soft);
  color: var(--rfa-orange);
  font-weight: 600;
}

.form-group { margin-bottom: var(--sp-5); }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}
.form-help {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  font-family: var(--font-mono);
}
.input, .select {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-family: inherit;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--t-fast);
}
.input:focus, .select:focus { outline: 0; border-color: var(--rfa-orange); }
.input--mono { font-family: var(--font-mono); font-size: 12px; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-3);
  cursor: pointer;
}
.toggle__track {
  width: 36px; height: 20px;
  background: var(--border-strong);
  border-radius: var(--r-pill);
  position: relative;
  transition: background var(--t-fast);
}
.toggle__track::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  top: 2px; left: 2px;
  background: white;
  border-radius: 50%;
  box-shadow: var(--sh-1);
  transition: transform var(--t-fast);
}
.toggle.is-on .toggle__track { background: var(--rfa-orange); }
.toggle.is-on .toggle__track::after { transform: translateX(16px); }
.toggle__label { font-size: 13px; color: var(--text); }

.checkbox-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: var(--sp-2) 0;
  border-bottom: 1px solid var(--border);
}
.checkbox-row:last-child { border-bottom: 0; }
.checkbox-row label { flex: 1; font-size: 13px; cursor: pointer; }

/* ---------- Scrollbar minimal ---------- */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: var(--r-pill); border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ============================================================
   Feature flags engine · oculta items según tier contratado
   ============================================================ */
.feature-locked { display: none !important; }

/* Role-based · oculta items que el rol del user no debe ver */
.role-locked { display: none !important; }

/* Viewer mode · readonly indicators · CSS hint solo */
[data-readonly="true"] input:not([type="search"]):not(.theme-toggle),
[data-readonly="true"] textarea,
[data-readonly="true"] select { opacity: 0.6; pointer-events: none; }
[data-readonly="true"] .btn--primary { opacity: 0.4; pointer-events: none; }

/* Si en algún caso quieres mostrar grayed-out con upsell tooltip,
   reemplazar el display:none arriba por:

   .feature-locked {
     opacity: 0.42;
     pointer-events: none;
     cursor: not-allowed;
     position: relative;
   }
   .feature-locked::after {
     content: '🔒';
     font-size: 11px;
     margin-left: 6px;
     opacity: 0.7;
   }
*/

/* ---------- Tier badge en sidebar footer ---------- */
.tier-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: var(--r-pill);
  font-family: var(--font-sans);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: var(--surface-active);
  color: var(--text-muted);
  border: 1px solid var(--border);
  vertical-align: middle;
}
.tier-badge[data-tier="starter"]    { background: var(--rfa-cyan-soft);    color: var(--rfa-cyan);   border-color: transparent; }
.tier-badge[data-tier="pro"]        { background: var(--rfa-mint-soft);    color: var(--rfa-mint);   border-color: transparent; }
.tier-badge[data-tier="enterprise"] { background: var(--rfa-purple-soft);  color: var(--rfa-purple); border-color: transparent; }

/* ---------- Sidebar logout button ---------- */
.sidebar__logout {
  margin-top: 12px;
  width: 100%;
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 8px 12px;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--t-fast);
}
.sidebar__logout:hover {
  background: var(--rfa-coral-soft);
  color: var(--rfa-coral);
  border-color: var(--rfa-coral);
}
.sidebar__logout:active { transform: scale(0.98); }

/* ============================================================
   Print friendly · PDF export via window.print()
   ============================================================ */
@media print {
  @page { size: A4; margin: 14mm 12mm; }
  body { background: #fff !important; color: #111 !important; }
  .sidebar, .topbar__actions, .toolbar, .btn, .theme-toggle, .live-pill, button { display: none !important; }
  .topbar { padding: 0 !important; border: 0 !important; margin-bottom: 8mm; }
  .topbar__title { padding: 0 !important; font-size: 18pt !important; }
  .app { display: block !important; grid-template-columns: 1fr !important; }
  .main { margin: 0 !important; padding: 0 !important; max-width: 100% !important; }
  .content { padding: 0 !important; }
  .page-header { margin-bottom: 8mm; }
  .page-header__title { font-size: 22pt !important; color: #000 !important; }
  .page-header__subtitle { color: #555 !important; }
  .metric-grid, .kpis { page-break-inside: avoid; }
  .metric, .kpi, .v3-card, .chart-card, .card { box-shadow: none !important; border: 1px solid #ccc !important; page-break-inside: avoid; }
  canvas { max-width: 100% !important; height: auto !important; page-break-inside: avoid; }
  table { page-break-inside: auto; }
  tr { page-break-inside: avoid; page-break-after: auto; }
  thead { display: table-header-group; }
  /* Footer print con marca · agregado por JS al imprimir */
  .print-footer { display: block !important; margin-top: 10mm; padding-top: 4mm; border-top: 1px solid #ccc; font-size: 9pt; color: #666; text-align: center; }
  .mockup-banner, #notif-wrap, .feature-locked, .role-locked { display: none !important; }
}
.print-footer { display: none; }
