/* components/reportes/reportes.css
   Módulo de Reportería. Misma estética que el analizador; vars de tema. */

.rep-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.rep-empresa {
  display: inline-flex; align-items: center; gap: 0.375rem;
  font-size: 0.8125rem; color: var(--muted);
  background: var(--surface); border: 0.5px solid var(--border);
  padding: 0.375rem 0.75rem; border-radius: 999px;
}
.rep-empresa i { font-size: 0.9375rem; }

/* ── Landing: grupos + tarjetas ─────────────────────────────── */
.rep-grupo { margin-bottom: 1.5rem; }
.rep-grupo-titulo {
  font-size: 0.6875rem; font-weight: 600; letter-spacing: .06em; text-transform: uppercase;
  color: var(--muted); margin-bottom: 0.625rem;
}
.rep-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(17rem, 1fr)); gap: 0.75rem; }
.rep-card {
  display: flex; align-items: center; gap: 0.875rem; text-align: left;
  background: var(--surface); border: 0.5px solid var(--border);
  border-radius: 0.75rem; padding: 1rem 1.125rem; cursor: pointer; width: 100%;
  transition: transform .15s cubic-bezier(.16,1,.3,1), box-shadow .15s, border-color .15s;
}
.rep-card:hover { transform: translateY(-2px); box-shadow: 0 8px 22px rgba(0,0,0,.1); border-color: var(--border-md); }
.rep-card:active { transform: translateY(0); }
.rep-card-icon {
  flex-shrink: 0; width: 2.5rem; height: 2.5rem; border-radius: 0.625rem;
  background: var(--accent-bg); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.rep-card-icon i { font-size: 1.25rem; }
.rep-card-body { display: flex; flex-direction: column; gap: 0.1875rem; flex: 1; min-width: 0; }
.rep-card-titulo { font-size: 0.875rem; font-weight: 600; color: var(--text); }
.rep-card-desc { font-size: 0.75rem; color: var(--muted); line-height: 1.4; }
.rep-card-chevron { color: var(--muted); display: flex; }
.rep-card-chevron i { font-size: 1.125rem; }

/* ── Barra de filtros ───────────────────────────────────────── */
.rep-filtros {
  display: flex; align-items: flex-end; gap: 0.75rem; flex-wrap: wrap;
  background: var(--surface); border: 0.5px solid var(--border);
  border-radius: 0.75rem; padding: 1rem 1.125rem; margin-bottom: 1.125rem;
}
.rep-filtro { display: flex; flex-direction: column; gap: 0.3125rem; }
.rep-filtro label { font-size: 0.75rem; font-weight: 500; color: var(--text); }
.rep-filtro .crud-input { min-width: 9rem; }
.rep-filtro-ancho { flex: 1; min-width: 14rem; }
.rep-btn-consultar { align-self: flex-end; }

/* ── Contenido / estados ────────────────────────────────────── */
.rep-contenido { min-height: 6rem; }
.rep-vacio { padding: 2.5rem 1rem; text-align: center; color: var(--muted); font-size: 0.8125rem; }
.rep-error { color: var(--danger); }
.rep-loading { display: flex; align-items: center; justify-content: center; padding: 2.5rem; }
.rep-filtro-nota { font-size: 0.75rem; color: var(--muted); align-self: center; }
.rep-ok {
  display: flex; flex-direction: column; align-items: center; gap: 0.625rem;
  padding: 2.5rem 1rem; text-align: center; color: #059669;
  background: var(--success-bg, #ECFDF5); border: 0.5px solid #10B981; border-radius: 0.75rem;
}
.rep-ok i { font-size: 2rem; }
.rep-ok p { font-size: 0.8125rem; color: var(--text); }
[data-theme="dark"] .rep-ok { background: #064E3B; color: #6EE7B7; }
@media (prefers-color-scheme: dark) { .rep-ok { background: #064E3B; color: #6EE7B7; } }

/* ── KPIs ───────────────────────────────────────────────────── */
.rep-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(10rem, 1fr)); gap: 0.75rem; margin-bottom: 1.125rem; }
.rep-kpi {
  background: var(--surface); border: 0.5px solid var(--border);
  border-radius: 0.75rem; padding: 1rem 1.125rem;
}
.rep-kpi-destacar { border-color: var(--accent); background: var(--accent-bg); }
.rep-kpi-valor { font-size: 1.5rem; font-weight: 700; color: var(--text); line-height: 1.1; }
.rep-kpi-destacar .rep-kpi-valor { color: var(--accent); }
.rep-kpi-label { font-size: 0.75rem; color: var(--muted); margin-top: 0.25rem; }

.rep-viz {
  background: var(--surface); border: 0.5px solid var(--border);
  border-radius: 0.75rem; padding: 1.125rem 1.25rem; margin-bottom: 1.125rem;
}
.rep-mini { display: flex; gap: 1.25rem; font-size: 0.75rem; color: var(--muted); margin-bottom: 1.125rem; }

/* ── Timeline (trazabilidad) ────────────────────────────────── */
.rep-timeline { position: relative; padding-left: 1.5rem; }
.rep-tl-item { position: relative; padding-bottom: 1rem; }
.rep-tl-item::before {
  content: ''; position: absolute; left: -1.03rem; top: 1.1rem; bottom: -0.1rem;
  width: 2px; background: var(--border-md);
}
.rep-tl-last::before { display: none; }
.rep-tl-dot {
  position: absolute; left: -1.5rem; top: 0.9rem; width: 0.75rem; height: 0.75rem;
  border-radius: 50%; background: var(--accent); border: 2px solid var(--bg); z-index: 1;
}
.rep-tl-card {
  background: var(--surface); border: 0.5px solid var(--border);
  border-radius: 0.75rem; padding: 0.875rem 1rem;
}
.rep-tl-top { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.rep-tl-etapa { font-size: 0.75rem; font-weight: 700; letter-spacing: .04em; color: var(--accent); }
.rep-tl-folio { font-size: 0.875rem; font-weight: 600; color: var(--text); margin-top: 0.25rem; }
.rep-tl-meta { display: flex; flex-wrap: wrap; gap: 0.875rem; margin-top: 0.375rem; font-size: 0.75rem; color: var(--muted); align-items: center; }
.rep-tl-meta i { font-size: 0.8125rem; vertical-align: -1px; }
.rep-tl-monto { color: var(--text); font-weight: 600; }

/* ── Tablas ─────────────────────────────────────────────────── */
.rep-tabla-wrap { overflow-x: auto; border: 0.5px solid var(--border); border-radius: 0.75rem; }
.rep-tabla { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
.rep-tabla th {
  background: var(--bg); padding: 0.625rem 0.875rem; text-align: left; white-space: nowrap;
  font-weight: 600; font-size: 0.6875rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em;
  border-bottom: 0.5px solid var(--border);
}
.rep-tabla td { padding: 0.625rem 0.875rem; border-bottom: 0.5px solid var(--border); color: var(--text); white-space: nowrap; }
.rep-tabla tr:last-child td { border-bottom: none; }
.rep-tabla tbody tr:hover td { background: var(--bg); }
.rep-num { text-align: right; font-variant-numeric: tabular-nums; }
.rep-pos { color: #10B981; font-weight: 600; }
.rep-neg { color: var(--danger); font-weight: 600; }
.rep-cambio { display: flex; align-items: center; gap: 0.375rem; }
.rep-cambio i { font-size: 0.8125rem; color: var(--muted); }

/* ── Badges de estatus ──────────────────────────────────────── */
.rep-badge {
  display: inline-block; font-size: 0.6875rem; font-weight: 500;
  padding: 0.125rem 0.5rem; border-radius: 999px; white-space: nowrap; text-transform: capitalize;
  background: var(--bg); color: var(--muted);
}
.rep-badge-ok { background: var(--success-bg, #ECFDF5); color: #059669; }
.rep-badge-warn { background: #FEF3C7; color: #B45309; }
.rep-badge-bad { background: var(--danger-bg); color: var(--danger); }
.rep-badge-neutral { background: var(--bg); color: var(--muted); }
@media (prefers-color-scheme: dark) {
  .rep-badge-ok { background: #064E3B; color: #6EE7B7; }
  .rep-badge-warn { background: #451A03; color: #FCD34D; }
}
[data-theme="dark"] .rep-badge-ok { background: #064E3B; color: #6EE7B7; }
[data-theme="dark"] .rep-badge-warn { background: #451A03; color: #FCD34D; }

/* ── viz.js: barras ─────────────────────────────────────────── */
.rep-barras { display: flex; flex-direction: column; gap: 0.625rem; }
.rep-barra-row { display: grid; grid-template-columns: 10rem 1fr auto; align-items: center; gap: 0.75rem; }
.rep-barra-label { font-size: 0.75rem; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rep-barra-track { background: var(--bg); border-radius: 999px; height: 0.75rem; overflow: hidden; }
.rep-barra-fill { height: 100%; width: var(--w); background: var(--c); border-radius: 999px; }
.rep-barra-fill.rep-anim { animation: rep-grow .6s cubic-bezier(.16,1,.3,1) both; animation-delay: var(--d); }
@keyframes rep-grow { from { width: 0; } to { width: var(--w); } }
.rep-barra-valor { font-size: 0.75rem; font-weight: 600; color: var(--text); font-variant-numeric: tabular-nums; white-space: nowrap; }
.rep-barra-sub { color: var(--muted); font-weight: 400; }
@media (max-width: 40rem) { .rep-barra-row { grid-template-columns: 6rem 1fr auto; } }

/* ── viz.js: donut ──────────────────────────────────────────── */
.rep-donut-wrap { display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap; }
.rep-donut { width: 9rem; height: 9rem; flex-shrink: 0; }
.rep-donut-arc { transform-origin: center; }
.rep-donut-anim { opacity: 0; animation: rep-fade .5s ease-out forwards; }
@keyframes rep-fade { to { opacity: 1; } }
.rep-donut-centro-val { font-size: 15px; font-weight: 700; fill: var(--text); }
.rep-donut-centro-lbl { font-size: 8px; fill: var(--muted); }
.rep-leyenda { display: flex; flex-direction: column; gap: 0.5rem; flex: 1; min-width: 12rem; }
.rep-leyenda-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.8125rem; }
.rep-leyenda-dot { width: 0.625rem; height: 0.625rem; border-radius: 50%; flex-shrink: 0; }
.rep-leyenda-label { color: var(--text); flex: 1; }
.rep-leyenda-val { color: var(--muted); font-variant-numeric: tabular-nums; }

@media (prefers-reduced-motion: reduce) {
  .rep-barra-fill.rep-anim, .rep-donut-anim { animation: none; opacity: 1; }
}

/* ══ Consolidado ══════════════════════════════════════════════ */
.rep-head-acciones { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }

/* ── Tarjeta destacada con contorno dorado animado ──────────── */
.rep-grupo-destacado { margin-bottom: 1.75rem; }
.rep-card-consolidado {
  position: relative; border: none; isolation: isolate;
  background: var(--surface);
}
/* Anillo dorado: gradiente que fluye lentamente alrededor del borde. El
   fondo opaco de la tarjeta (::after) tapa el centro y deja solo el marco. */
.rep-card-consolidado::before {
  content: ''; position: absolute; inset: 0; z-index: -2; border-radius: 0.75rem;
  padding: 1.5px;
  background: linear-gradient(115deg, #bf953f, #fcf6ba, #b38728, #fbf5b7, #aa771c, #fcf6ba, #bf953f);
  background-size: 300% 300%;
  animation: rep-gold-flow 7s ease-in-out infinite;
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor; mask-composite: exclude;
}
.rep-card-consolidado::after {
  content: ''; position: absolute; inset: 1.5px; z-index: -1; border-radius: 0.65rem;
  background: var(--surface);
}
.rep-card-consolidado:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 26px rgba(191, 149, 63, 0.22);
}
@keyframes rep-gold-flow {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}
.rep-card-icon-gold {
  background: linear-gradient(135deg, #fdf3c4, #e8c766);
  color: #8a6a1a;
}
.rep-card-badge-gold {
  display: inline-block; margin-left: 0.5rem; vertical-align: 1px;
  font-size: 0.625rem; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: #8a6a1a; background: linear-gradient(135deg, #fdf3c4, #f0d688);
  border: 0.5px solid #d9b85a; border-radius: 999px; padding: 0.0625rem 0.5rem;
}
[data-theme="dark"] .rep-card-badge-gold { color: #fdf3c4; background: rgba(191,149,63,.18); border-color: #8a6a1a; }
@media (prefers-color-scheme: dark) {
  .rep-card-badge-gold { color: #fdf3c4; background: rgba(191,149,63,.18); border-color: #8a6a1a; }
}
@media (prefers-reduced-motion: reduce) {
  .rep-card-consolidado::before { animation: none; }
}

/* Selector de periodo (segmentado + campos según el modo) */
.rep-cons-filtros {
  background: var(--surface); border: 0.5px solid var(--border);
  border-radius: 0.75rem; padding: 1rem 1.125rem; margin-bottom: 1.125rem;
  display: flex; flex-direction: column; gap: 0.875rem;
}
.rep-seg {
  display: inline-flex; background: var(--bg); border: 0.5px solid var(--border);
  border-radius: 0.625rem; padding: 0.1875rem; gap: 0.1875rem; flex-wrap: wrap; align-self: flex-start;
}
.rep-seg-btn {
  display: inline-flex; align-items: center; gap: 0.375rem; cursor: pointer;
  border: none; background: transparent; color: var(--muted);
  font-size: 0.8125rem; font-weight: 500; padding: 0.4375rem 0.875rem; border-radius: 0.5rem;
  transition: background .15s, color .15s;
}
.rep-seg-btn i { font-size: 0.9375rem; }
.rep-seg-btn:hover { color: var(--text); }
.rep-seg-activo { background: var(--surface); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.rep-cons-campos { display: flex; align-items: flex-end; gap: 0.75rem; flex-wrap: wrap; }
.rep-cons-campo { display: flex; align-items: flex-end; gap: 0.75rem; flex-wrap: wrap; }
.rep-cons-campo[hidden] { display: none; }
.rep-cons-hint { font-size: 0.8125rem; color: var(--muted); align-self: center; }

/* Barra de exportación (fuera de la hoja, no se imprime) */
.rep-cons-toolbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  flex-wrap: wrap; margin-bottom: 1rem;
}
.rep-cons-toolbar-info { font-size: 0.8125rem; color: var(--muted); }
.rep-cons-toolbar-info strong { color: var(--text); }
.rep-cons-toolbar-btns { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.rep-cons-toolbar-btns .crud-btn { display: inline-flex; align-items: center; gap: 0.375rem; }
.rep-cons-toolbar-btns i { font-size: 0.9375rem; }

/* La "hoja" del reporte — se ve como un documento tipo PDF/Tableau */
.rep-cons-page {
  background: #ffffff; color: #1a1a1a;
  border: 0.5px solid var(--border); border-radius: 0.5rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.12);
  padding: 2rem 2.25rem; overflow: hidden;
}
[data-theme="dark"] .rep-cons-page { background: #f7f7f8; }

.rep-cons-confidencial {
  text-align: right; font-size: 0.625rem; font-weight: 700; letter-spacing: .09em;
  text-transform: uppercase; color: #9a7b2e; margin-bottom: 0.5rem;
}
.rep-cons-report-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1.5rem;
  border-bottom: 2px solid #e5e7eb; padding-bottom: 1.25rem; margin-bottom: 1.25rem; flex-wrap: wrap;
}
.rep-cons-report-empresa {
  font-size: 0.75rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: #6b7280;
}
.rep-cons-report-titulo { font-size: 1.5rem; font-weight: 700; color: #111827; margin: 0.25rem 0 0; }
.rep-cons-report-meta { display: flex; gap: 1.5rem; flex-wrap: wrap; text-align: right; }
.rep-cons-report-meta > div { font-size: 0.875rem; color: #111827; font-weight: 600; }
.rep-cons-report-meta span { display: block; font-size: 0.6875rem; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: #9ca3af; margin-bottom: 0.125rem; }

.rep-cons-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: 0.75rem; margin-bottom: 1.5rem; }
.rep-cons-kpi { background: #f9fafb; border: 1px solid #e5e7eb; border-radius: 0.5rem; padding: 0.875rem 1rem; }
.rep-cons-kpi-destacar { background: #eff6ff; border-color: #bfdbfe; }
.rep-cons-kpi-valor { font-size: 1.25rem; font-weight: 700; color: #111827; line-height: 1.15; font-variant-numeric: tabular-nums; }
.rep-cons-kpi-destacar .rep-cons-kpi-valor { color: #1d4ed8; }
.rep-cons-kpi-label { font-size: 0.6875rem; color: #6b7280; margin-top: 0.25rem; text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }

.rep-cons-tabla-wrap { overflow-x: auto; border: 1px solid #e5e7eb; border-radius: 0.5rem; }
.rep-cons-tabla { width: 100%; border-collapse: collapse; font-size: 0.75rem; color: #1f2937; }
.rep-cons-tabla th {
  background: #f3f4f6; padding: 0.5rem 0.625rem; text-align: left; white-space: nowrap;
  font-weight: 700; font-size: 0.625rem; color: #374151; text-transform: uppercase; letter-spacing: .02em;
  border-bottom: 1px solid #d1d5db; position: sticky; top: 0;
}
.rep-cons-tabla td { padding: 0.5rem 0.625rem; border-bottom: 1px solid #eceef1; white-space: nowrap; vertical-align: top; }
.rep-cons-tabla tbody tr:nth-child(even) td { background: #fafbfc; }
.rep-cons-tabla .rep-num { text-align: right; font-variant-numeric: tabular-nums; }
.rep-cons-tabla .rep-pos { color: #059669; font-weight: 600; }
.rep-cons-tabla .rep-neg { color: #dc2626; font-weight: 600; }
.rep-cons-tabla td.rep-cons-desc { white-space: normal; min-width: 15rem; max-width: 22rem; }
.rep-cons-tabla td.rep-cons-obs { white-space: normal; min-width: 8rem; max-width: 14rem; }
.rep-cons-totales td { background: #f3f4f6 !important; font-weight: 700; color: #111827; border-top: 2px solid #d1d5db; border-bottom: none; }

/* ── Impresión: documento oficial, todas las columnas en una hoja ── */
@media print {
  body.rep-print-consolidado * { visibility: hidden; }
  body.rep-print-consolidado .rep-cons-page,
  body.rep-print-consolidado .rep-cons-page * { visibility: visible; }
  body.rep-print-consolidado .rep-cons-page {
    position: absolute; left: 0; top: 0; width: 100%;
    box-shadow: none; border: none; border-radius: 0; padding: 0;
    background: #fff !important; color: #111 !important;
  }
  /* La barra de exportación nunca se imprime. */
  body.rep-print-consolidado .rep-cons-toolbar { display: none !important; }

  /* Encabezado más compacto (aire de documento formal). */
  body.rep-print-consolidado .rep-cons-confidencial { font-size: 7pt; margin-bottom: 4pt; }
  body.rep-print-consolidado .rep-cons-report-head { padding-bottom: 8pt; margin-bottom: 8pt; }
  body.rep-print-consolidado .rep-cons-report-titulo { font-size: 14pt; }
  body.rep-print-consolidado .rep-cons-report-meta > div { font-size: 8pt; }
  body.rep-print-consolidado .rep-cons-kpis { gap: 6pt; margin-bottom: 8pt; }
  body.rep-print-consolidado .rep-cons-kpi { padding: 5pt 7pt; }
  body.rep-print-consolidado .rep-cons-kpi-valor { font-size: 11pt; }
  body.rep-print-consolidado .rep-cons-kpi-label { font-size: 6pt; }

  /* Tabla a escala reducida y fija para que las 15 columnas quepan a lo
     ancho de una sola hoja horizontal; el texto largo se envuelve. */
  body.rep-print-consolidado .rep-cons-tabla-wrap { overflow: visible; border: none; }
  body.rep-print-consolidado .rep-cons-tabla {
    table-layout: fixed; width: 100%; font-size: 6pt;
  }
  body.rep-print-consolidado .rep-cons-tabla th,
  body.rep-print-consolidado .rep-cons-tabla td {
    padding: 1.5pt 2pt; white-space: normal !important; word-break: break-word;
    overflow-wrap: anywhere; max-width: none; min-width: 0;
  }
  body.rep-print-consolidado .rep-cons-tabla th { position: static; font-size: 5.5pt; }
  body.rep-print-consolidado .rep-cons-tabla tbody tr { page-break-inside: avoid; }
  body.rep-print-consolidado .rep-cons-tabla thead { display: table-header-group; }

  @page { size: A4 landscape; margin: 8mm; }
}
