/* ==========================================================================
   EasyCheck — Componentes base
   Requiere tokens.css. Sin dependencias de JS.
   ========================================================================== */

/* ------------------------------------------------------------------ reset */
*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--ec-bg);
  color: var(--ec-text);
  font-family: var(--ec-font-body);
  font-size: var(--ec-text-md);
  line-height: var(--ec-leading-body);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--ec-accent); text-decoration: none; transition: color var(--ec-duration) var(--ec-ease); }
a:hover { color: var(--ec-accent-hi); }

p { text-wrap: pretty; }

::selection { background: rgba(0, 196, 122, .15); color: var(--ec-text); }

:focus-visible {
  outline: 2px solid var(--ec-accent);
  outline-offset: 2px;
  border-radius: var(--ec-radius-bar);
}

/* Scrollbars tematizadas — sin esto aparece la barra gris del navegador
   sobre la UI oscura, sobre todo en las tablas anchas de Reportes. */
* { scrollbar-color: var(--ec-border-strong) var(--ec-surface); scrollbar-width: thin; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-track { background: var(--ec-surface); }
::-webkit-scrollbar-thumb { background: var(--ec-border-strong); border-radius: 5px; }
::-webkit-scrollbar-thumb:hover { background: #3a5c8f; }

/* ---------------------------------------------------------------- utilidad */
/* Toda cifra que se lea como número o que se alinee en columna. */
.ec-num { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }

.ec-display { font-family: var(--ec-font-display); font-weight: var(--ec-weight-bold); letter-spacing: var(--ec-tracking-title); }

.ec-label {
  font-size: 10.5px;
  font-weight: var(--ec-weight-semibold);
  color: var(--ec-text-soft);
  text-transform: uppercase;
  letter-spacing: var(--ec-tracking-label);
}

.ec-kicker {
  font-size: var(--ec-text-3xs);
  font-weight: var(--ec-weight-bold);
  color: var(--ec-text-soft);
  text-transform: uppercase;
  letter-spacing: var(--ec-tracking-kicker);
}

.ec-note { margin: 0; font-size: var(--ec-text-xs); line-height: 1.55; color: var(--ec-text-soft); max-width: 72ch; }

.ec-hr { height: 1px; border: 0; background: var(--ec-divider); margin: var(--ec-space-9) 0; }

/* ================================================================= BOTONES */
.ec-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 var(--ec-space-7);
  border: 1px solid transparent;
  border-radius: var(--ec-radius-md);
  font-family: inherit;
  font-size: var(--ec-text-sm);
  font-weight: var(--ec-weight-bold);
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--ec-duration) var(--ec-ease),
              border-color var(--ec-duration) var(--ec-ease),
              color var(--ec-duration) var(--ec-ease);
}
.ec-btn:disabled { opacity: .45; cursor: not-allowed; }
.ec-btn i { font-size: 15px; }

/* Primario — el único relleno lleno de la interfaz. Uno por pantalla. */
.ec-btn-primary {
  background: linear-gradient(135deg, var(--ec-accent) 0%, var(--ec-accent-dk) 100%);
  color: var(--ec-accent-ink);
  box-shadow: var(--ec-shadow-accent);
}
.ec-btn-primary:hover:not(:disabled) { background: linear-gradient(135deg, var(--ec-accent-hi) 0%, var(--ec-accent) 100%); }
.ec-btn-primary:active:not(:disabled) { background: var(--ec-accent-dk); box-shadow: none; }

/* Secundario — la acción habitual. */
.ec-btn-secondary {
  background: var(--ec-surface-2);
  border-color: var(--ec-border);
  color: var(--ec-text-muted);
  font-weight: var(--ec-weight-medium);
}
.ec-btn-secondary:hover:not(:disabled) { border-color: var(--ec-border-strong); color: var(--ec-text); }
.ec-btn-secondary:active:not(:disabled) { background: var(--ec-surface-3); }

/* Acento contorneado — acciones afirmativas que no compiten con el primario. */
.ec-btn-outline {
  background: var(--ec-accent-soft);
  border-color: var(--ec-accent-line);
  color: var(--ec-accent);
  font-weight: var(--ec-weight-semibold);
}
.ec-btn-outline:hover:not(:disabled) { border-color: var(--ec-accent); background: rgba(0, 196, 122, .14); }

/* Fantasma y de icono. */
.ec-btn-ghost { background: transparent; border-color: var(--ec-border); color: var(--ec-text-muted); font-weight: var(--ec-weight-medium); }
.ec-btn-ghost:hover:not(:disabled) { border-color: var(--ec-border-strong); color: var(--ec-text); }

.ec-btn-icon { width: 36px; height: 36px; padding: 0; background: transparent; border-color: var(--ec-border); color: var(--ec-text-soft); }
.ec-btn-icon:hover:not(:disabled) { border-color: var(--ec-border-strong); color: var(--ec-text); }
.ec-btn-icon-sm { width: 32px; height: 32px; border-radius: var(--ec-radius-sm); }
.ec-btn-icon-sm i { font-size: 14px; }

/* Acción dentro de una fila de tabla. */
.ec-btn-row {
  height: auto;
  padding: 6px 11px;
  border-radius: var(--ec-radius-sm);
  border-color: var(--ec-accent-line);
  background: var(--ec-accent-soft);
  color: var(--ec-accent);
  font-size: var(--ec-text-xs);
  font-weight: var(--ec-weight-semibold);
}
.ec-btn-row:hover { border-color: var(--ec-accent); }

/* Link con forma de botón. */
.ec-btn-link {
  height: auto;
  padding: 8px 0;
  background: none;
  border: 0;
  color: var(--ec-accent);
  font-size: 12.5px;
  font-weight: var(--ec-weight-semibold);
}
.ec-btn-link:hover { color: var(--ec-accent-hi); }

.ec-btn-lg { height: 50px; padding: 0 var(--ec-space-11); font-size: var(--ec-text-lg); border-radius: var(--ec-radius-lg); }
.ec-btn-block { width: 100%; height: 44px; font-size: 14.5px; }

/* ==================================================================== CHIP */
/* Selector de un solo valor: presets de período, unidades, filtros. */
.ec-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 13px;
  border: 1px solid var(--ec-border);
  border-radius: var(--ec-radius-pill);
  background: transparent;
  color: var(--ec-text-soft);
  font-family: inherit;
  font-size: var(--ec-text-xs);
  font-weight: var(--ec-weight-regular);
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--ec-duration) var(--ec-ease);
}
.ec-chip:hover { color: var(--ec-text); border-color: var(--ec-border-strong); }
.ec-chip.is-active {
  background: var(--ec-accent-soft);
  border-color: var(--ec-accent-line);
  color: var(--ec-accent);
  font-weight: var(--ec-weight-semibold);
}

/* =================================================================== CARD */
.ec-card {
  background: var(--ec-surface);
  border: 1px solid var(--ec-border);
  border-radius: var(--ec-radius-xl);
  padding: var(--ec-space-9);
  box-shadow: var(--ec-shadow-sm);
}
.ec-card + .ec-card { margin-top: var(--ec-space-6); }

.ec-card-title {
  font-size: var(--ec-text-2xs);
  font-weight: var(--ec-weight-bold);
  color: var(--ec-text-soft);
  text-transform: uppercase;
  letter-spacing: var(--ec-tracking-kicker);
  margin-bottom: var(--ec-space-6);
}
.ec-card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--ec-space-5);
  flex-wrap: wrap;
  margin-bottom: var(--ec-space-1);
}
.ec-card-meta { font-size: var(--ec-text-2xs); color: var(--ec-text-soft); }

/* Variante destacada: una sola por pantalla. */
.ec-card-accent {
  border-color: var(--ec-accent-line);
  background: linear-gradient(135deg, rgba(0, 196, 122, .07) 0%, rgba(15, 31, 56, 0) 65%), var(--ec-surface);
}
.ec-card-warn {
  border-color: var(--ec-warn-line);
  background: linear-gradient(135deg, rgba(245, 166, 35, .06) 0%, rgba(15, 31, 56, 0) 60%), var(--ec-surface);
}

/* Tarjeta de métrica: label · valor · variación · nota. */
.ec-metric { display: flex; flex-direction: column; padding: var(--ec-space-8) var(--ec-space-9); }
.ec-metric-value {
  font-family: var(--ec-font-display);
  font-size: 27px;
  font-weight: var(--ec-weight-bold);
  letter-spacing: var(--ec-tracking-hero);
  line-height: var(--ec-leading-tight);
  margin-top: var(--ec-space-4);
  color: var(--ec-text);
}
.ec-metric-value-hero { font-size: var(--ec-text-4xl); color: var(--ec-accent); }
.ec-metric-value.is-warn   { color: var(--ec-warn); }
.ec-metric-value.is-danger { color: var(--ec-danger); }
.ec-metric-sub { font-size: 11.5px; line-height: 1.45; color: var(--ec-text-soft); margin-top: var(--ec-space-3); }

/* Pill de variación contra el período anterior. */
.ec-delta {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  align-self: flex-start;
  margin-top: var(--ec-space-4);
  padding: 2px 8px;
  border-radius: var(--ec-radius-pill);
  font-size: 11.5px;
  font-weight: var(--ec-weight-bold);
}
.ec-delta i { font-size: var(--ec-text-xs); }
.ec-delta-up      { color: var(--ec-accent); background: var(--ec-accent-soft); }
.ec-delta-warn    { color: var(--ec-warn);   background: var(--ec-warn-soft); }
.ec-delta-down    { color: var(--ec-danger); background: var(--ec-danger-soft); }
.ec-delta-neutral { color: var(--ec-text-muted); background: var(--ec-surface-2); }

/* Grillas de tarjetas. */
.ec-grid        { display: grid; gap: var(--ec-space-5); }
.ec-grid-metrics { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.ec-grid-cards   { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: var(--ec-space-6); }
.ec-grid-thirds  { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }

/* ================================================================== TABLA */
.ec-table-wrap {
  background: var(--ec-surface);
  border: 1px solid var(--ec-border);
  border-radius: var(--ec-radius-xl);
  box-shadow: var(--ec-shadow-sm);
  overflow-x: auto;
  margin-bottom: var(--ec-space-6);
}
.ec-table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--ec-space-5);
  flex-wrap: wrap;
  padding: var(--ec-space-4) var(--ec-space-6);
  border-bottom: 1px solid var(--ec-border);
  font-size: var(--ec-text-2xs);
  font-weight: var(--ec-weight-bold);
  color: var(--ec-text-soft);
  text-transform: uppercase;
  letter-spacing: var(--ec-tracking-kicker);
}

.ec-table { width: 100%; border-collapse: collapse; font-size: var(--ec-text-sm); }
.ec-table th {
  padding: 11px var(--ec-space-6);
  text-align: left;
  background: var(--ec-surface-2);
  border-bottom: 1px solid var(--ec-border);
  font-size: var(--ec-text-3xs);
  font-weight: var(--ec-weight-bold);
  color: var(--ec-text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
.ec-table td {
  padding: var(--ec-space-5) var(--ec-space-6);
  border-bottom: 1px solid var(--ec-divider);
  color: var(--ec-text);
  white-space: nowrap;
}
.ec-table tbody tr:last-child td { border-bottom: 0; }
.ec-table tbody tr:hover td { background: rgba(22, 37, 64, .45); }

/* Toda columna numérica: derecha + tabular. Nunca centrada. */
.ec-table .num,
.ec-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum';
  font-weight: var(--ec-weight-semibold);
}
.ec-table td.num.is-soft   { color: var(--ec-text-muted); font-weight: var(--ec-weight-regular); }
.ec-table td.num.is-accent { color: var(--ec-accent); font-weight: var(--ec-weight-bold); }
.ec-table td.num.is-warn   { color: var(--ec-warn);   font-weight: var(--ec-weight-bold); }
.ec-table td.num.is-danger { color: var(--ec-danger); font-weight: var(--ec-weight-bold); }
.ec-table td.is-strong { font-weight: var(--ec-weight-semibold); }
.ec-table .cell-sub { display: block; font-size: var(--ec-text-2xs); color: var(--ec-text-soft); margin-top: 2px; }

/* ============================================================ FORMULARIOS */
.ec-field { display: block; }
.ec-field > label,
.ec-field-label {
  display: block;
  margin-bottom: var(--ec-space-2);
  font-size: 10.5px;
  font-weight: var(--ec-weight-semibold);
  color: var(--ec-text-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.ec-input,
.ec-select,
.ec-textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--ec-surface-2);
  border: 1px solid var(--ec-border);
  border-radius: var(--ec-radius-md);
  color: var(--ec-text);
  font-family: inherit;
  font-size: var(--ec-text-sm);
  outline: none;
  transition: border-color var(--ec-duration) var(--ec-ease);
}
.ec-input:hover, .ec-select:hover { border-color: var(--ec-border-strong); }
.ec-input:focus, .ec-select:focus, .ec-textarea:focus { border-color: var(--ec-accent); outline: none; }
.ec-input::placeholder { color: var(--ec-text-faint); }
.ec-input:disabled, .ec-select:disabled { opacity: .45; cursor: not-allowed; }
.ec-input.num { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }

.ec-select { cursor: pointer; }
.ec-input-auto { width: auto; }
.ec-input-flex { flex: 1; min-width: 200px; }

.ec-filter-bar { display: flex; align-items: center; gap: var(--ec-space-3); flex-wrap: wrap; margin-bottom: var(--ec-space-8); }
.ec-filter-bar .spacer { flex: 1; }

/* ============================================================ BADGE / PILL */
.ec-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border: 1px solid transparent;
  border-radius: var(--ec-radius-pill);
  font-size: var(--ec-text-2xs);
  font-weight: var(--ec-weight-semibold);
  white-space: nowrap;
}
.ec-badge i { font-size: var(--ec-text-3xs); }
.ec-badge-ok      { background: var(--ec-accent-soft); border-color: var(--ec-accent-line); color: var(--ec-accent); }
.ec-badge-warn    { background: var(--ec-warn-soft);   border-color: var(--ec-warn-line);   color: var(--ec-warn); }
.ec-badge-danger  { background: var(--ec-danger-soft); border-color: var(--ec-danger-line); color: var(--ec-danger); }
.ec-badge-info    { background: var(--ec-info-soft);   border-color: var(--ec-info-line);   color: var(--ec-info); }
.ec-badge-neutral { background: var(--ec-surface-2);   border-color: var(--ec-border);      color: var(--ec-text-muted); }
/* Advertencia honesta: el dato se muestra igual, marcado como no verificado. */
.ec-badge-unverified { background: var(--ec-surface-2); border: 1px dashed var(--ec-border-strong); color: var(--ec-text-muted); font-size: var(--ec-text-3xs); font-weight: var(--ec-weight-bold); }

/* Etiqueta de tipo de comprobante (A / B / C / NC). */
.ec-doc-tag {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: var(--ec-radius-pill);
  font-size: var(--ec-text-3xs);
  font-weight: var(--ec-weight-bold);
  vertical-align: middle;
}
.ec-doc-a  { background: var(--ec-info-soft);   color: var(--ec-info); }
.ec-doc-b  { background: rgba(167, 139, 250, .10); color: var(--ec-data-3); }
.ec-doc-c  { background: var(--ec-accent-soft); color: var(--ec-accent); }
.ec-doc-nc { background: var(--ec-warn-soft);   color: var(--ec-warn); }

/* Badge de posición en un ranking. */
.ec-rank {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: var(--ec-radius-full);
  background: var(--ec-surface-3);
  color: var(--ec-text-soft);
  font-size: var(--ec-text-2xs);
  font-weight: var(--ec-weight-bold);
}
.ec-rank-1 { background: rgba(245, 166, 35, .15); color: var(--ec-warn); }

/* ================================================================= ALERTA */
.ec-alert {
  display: flex;
  align-items: flex-start;
  gap: var(--ec-space-4);
  padding: var(--ec-space-5) var(--ec-space-6);
  border: 1px solid transparent;
  border-radius: var(--ec-radius-lg);
  font-size: 12.5px;
  line-height: 1.55;
}
.ec-alert i { font-size: var(--ec-text-lg); flex-shrink: 0; }
.ec-alert-ok     { background: var(--ec-accent-soft); border-color: var(--ec-accent-line); color: var(--ec-text); }
.ec-alert-warn   { background: rgba(245, 166, 35, .07); border-color: var(--ec-warn-line);   color: var(--ec-warn-text); }
.ec-alert-danger { background: var(--ec-danger-soft);   border-color: var(--ec-danger-line); color: var(--ec-danger-text); }
.ec-alert-info   { background: var(--ec-info-soft);     border-color: var(--ec-info-line);   color: var(--ec-text-muted); }

/* Estado vacío: explica qué cargar y qué se desbloquea. Nunca un gráfico en cero. */
.ec-empty {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--ec-space-6);
  padding: var(--ec-space-13);
  background: var(--ec-surface);
  border: 1px dashed var(--ec-border-strong);
  border-radius: var(--ec-radius-xl);
}
.ec-empty > i { font-size: 30px; color: var(--ec-text-faint); }
.ec-empty h3 { margin: 0; font-family: var(--ec-font-display); font-size: var(--ec-text-xl); font-weight: var(--ec-weight-bold); letter-spacing: var(--ec-tracking-title); color: var(--ec-text-strong); }
.ec-empty p { margin: 0; max-width: 54ch; font-size: 14.5px; color: var(--ec-text-muted); }

/* Datos insuficientes: lista lo que falta, con acción por ítem. */
.ec-insufficient {
  display: flex;
  flex-direction: column;
  gap: var(--ec-space-6);
  padding: var(--ec-space-11);
  background: var(--ec-surface);
  border: 1px solid rgba(245, 166, 35, .30);
  border-radius: var(--ec-radius-xl);
}
.ec-req-row { display: flex; align-items: center; gap: var(--ec-space-4); font-size: 13.5px; }
.ec-req-row .missing { color: var(--ec-danger); font-size: 15px; }
.ec-req-row .partial { color: var(--ec-warn);   font-size: 15px; }

/* ================================================== BARRA DE PROGRESO/TOPE */
.ec-bar {
  position: relative;
  height: 8px;
  margin-top: var(--ec-space-6);
  border-radius: var(--ec-radius-bar);
  background: var(--ec-divider);
  overflow: hidden;
}
.ec-bar-fill { position: absolute; inset: 0 auto 0 0; border-radius: var(--ec-radius-bar); background: var(--ec-accent); }
.ec-bar-fill.is-warn   { background: var(--ec-warn); }
.ec-bar-fill.is-danger { background: var(--ec-danger); }
/* Excedente: franja rayada a la derecha cuando se pasa el 100%. */
.ec-bar-over {
  position: absolute;
  inset: 0 0 0 auto;
  border-radius: 0 var(--ec-radius-bar) var(--ec-radius-bar) 0;
  background: repeating-linear-gradient(135deg, var(--ec-danger) 0 4px, var(--ec-danger-dk) 4px 8px);
  box-shadow: -1px 0 0 var(--ec-surface);
}
/* Mini barra comparativa dentro de una lista. */
.ec-minibar { position: relative; flex-shrink: 0; width: 84px; height: 6px; border-radius: var(--ec-radius-bar); background: var(--ec-divider); }
.ec-minibar > span { position: absolute; inset: 0 auto 0 0; border-radius: var(--ec-radius-bar); background: var(--ec-info); }
.ec-minibar > span.is-warn   { background: var(--ec-warn); }
.ec-minibar > span.is-danger { background: var(--ec-danger); }

/* ============================================================== LEYENDAS */
.ec-legend { display: flex; flex-direction: column; gap: 9px; flex: 1 1 260px; min-width: 240px; }
.ec-legend-row { display: flex; align-items: center; gap: 9px; }
.ec-legend-swatch { flex-shrink: 0; width: 10px; height: 10px; border-radius: 2px; }
.ec-legend-label { flex: 1; min-width: 0; font-size: 12.5px; color: var(--ec-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ec-legend-pct { font-size: 12.5px; font-weight: var(--ec-weight-bold); color: var(--ec-text); font-feature-settings: 'tnum'; }
.ec-legend-amount { min-width: 80px; text-align: right; font-size: var(--ec-text-2xs); color: var(--ec-text-soft); font-feature-settings: 'tnum'; }

/* Contenedores de gráfico: alto fijo + position relative los exige Chart.js. */
.ec-chart    { position: relative; height: 300px; }
.ec-chart-sm { position: relative; height: 250px; }
.ec-donut    { position: relative; flex-shrink: 0; width: 168px; height: 168px; }
.ec-chart-row { display: flex; align-items: center; gap: var(--ec-space-9); flex-wrap: wrap; }
