/* Fase 7.5 — Reportes y Auditoría como mesa analítica SaaS. */
#reportes.phase5-reports-audit {
  --reports-canvas: var(--color-canvas);
  --reports-surface: var(--color-surface);
  --reports-raised: var(--color-surface-raised);
  --reports-ink: var(--color-text);
  --reports-muted: var(--color-text-muted);
  --reports-border: var(--color-border);
  --reports-primary: var(--tenant-primary);
  --reports-primary-subtle: var(--tenant-primary-subtle);
  --reports-primary-border: var(--tenant-primary-border);
  --reports-focus: var(--color-focus);
  --reports-success: var(--color-success);
  --reports-warning: var(--color-warning);
  --reports-error: var(--color-error);
  --reports-info: var(--color-info);
  gap: var(--space-6);
  color: var(--reports-ink);
}

/* Apertura editorial: contexto, pregunta y cantidad consultada. */
#reportes .phase5-report-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: var(--space-6);
  margin: 0;
  padding: var(--space-6) 0 var(--space-5);
  overflow: visible;
  border: 0;
  border-bottom: 1px solid var(--reports-border);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

#reportes.phase5-audit-mode .phase5-report-hero {
  box-shadow: none;
}

#reportes .phase5-report-hero > div:first-child {
  max-width: 74ch;
}

#reportes .phase5-report-hero .eyebrow {
  margin: 0 0 var(--space-2);
  color: var(--reports-muted);
  font-size: var(--type-xs);
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#reportes .phase5-report-hero h2 {
  max-width: 22ch;
  margin: 0 0 var(--space-2);
  color: var(--reports-ink);
  font-size: clamp(var(--type-2xl), 3vw, var(--type-3xl));
  line-height: 1.15;
  letter-spacing: -0.025em;
}

#reportes .phase5-hero-description {
  max-width: 72ch;
  margin: 0;
  color: var(--reports-muted);
  font-size: var(--type-md);
  line-height: 1.55;
}

#reportes .phase5-report-count {
  align-self: center;
  min-width: 9rem;
  min-height: auto;
  padding: var(--space-3) 0 var(--space-3) var(--space-5);
  border: 0;
  border-left: 1px solid var(--reports-border);
  border-radius: 0;
  background: transparent;
  color: var(--reports-ink);
  font-size: var(--type-sm);
  text-align: right;
}

/* Catálogo: selector de preguntas en filas, no tarjetas promocionales. */
#reportes .phase5-report-catalog {
  margin: 0;
  border: 0;
  border-top: 1px solid var(--reports-border);
  border-bottom: 1px solid var(--reports-border);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

#reportes .phase5-report-catalog > summary {
  min-height: auto;
  padding: var(--space-4) 0;
  border-bottom: 1px solid transparent;
  color: var(--reports-ink);
}

#reportes .phase5-report-catalog[open] > summary {
  border-bottom-color: var(--reports-border);
}

#reportes .phase5-report-catalog > summary span:first-child {
  display: flex;
  align-items: baseline;
  gap: var(--space-3);
}

#reportes .phase5-report-catalog > summary strong {
  font-size: var(--type-lg);
}

#reportes .phase5-report-catalog > summary small {
  color: var(--reports-muted);
  font-size: var(--type-sm);
}

#reportes .phase5-catalog-count {
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--reports-muted);
  font-size: var(--type-xs);
  font-weight: 700;
}

#reportes .report-grid {
  counter-reset: report-view;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  margin: 0;
  padding: 0;
}

#reportes .report-card {
  counter-increment: report-view;
  position: relative;
  display: grid;
  grid-template-columns: 2.25rem minmax(0, 1fr);
  align-content: center;
  column-gap: var(--space-3);
  min-height: 7rem;
  padding: var(--space-4) var(--space-5);
  overflow: visible;
  border: 0;
  border-bottom: 1px solid var(--reports-border);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  color: var(--reports-ink);
  transform: none;
  transition:
    background-color var(--duration-fast) var(--ease-standard),
    color var(--duration-fast) var(--ease-standard);
}

#reportes .report-card:nth-child(odd) {
  border-right: 1px solid var(--reports-border);
}

#reportes .report-card:nth-last-child(-n + 2) {
  border-bottom: 0;
}

#reportes .report-card::before {
  grid-row: 1 / span 3;
  align-self: start;
  color: var(--reports-muted);
  font-family: var(--font-data);
  font-size: var(--type-sm);
  font-weight: 700;
  content: counter(report-view, decimal-leading-zero);
}

#reportes .report-card:hover {
  border-color: var(--reports-border);
  background: color-mix(in srgb, var(--reports-primary-subtle) 56%, transparent);
  box-shadow: none;
  transform: none;
}

#reportes .report-card.active {
  border-color: var(--reports-border);
  background: var(--reports-primary-subtle);
  box-shadow: none;
}

#reportes .report-card.active::before {
  color: var(--reports-primary);
}

#reportes .report-card strong {
  grid-column: 2;
  margin: var(--space-1) 0;
  color: var(--reports-ink);
  font-size: var(--type-lg);
  line-height: 1.35;
}

#reportes .report-card span:not(.phase5-report-category) {
  grid-column: 2;
  max-width: 48ch;
  color: var(--reports-muted);
  font-size: var(--type-sm);
  line-height: 1.5;
}

#reportes .phase5-report-category {
  grid-column: 2;
  justify-self: start;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--reports-muted);
  font-size: var(--type-xs);
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

/* Periodos y filtros: una barra de consulta continua. */
#reportes .phase5-periods {
  align-items: end;
  gap: var(--space-6);
  padding: var(--space-5) 0 var(--space-4);
  border: 0;
  border-bottom: 1px solid var(--reports-border);
  border-radius: 0;
  background: transparent;
}

#reportes .phase5-period-copy {
  gap: var(--space-1);
  max-width: 34ch;
}

#reportes .phase5-period-copy strong {
  color: var(--reports-ink);
  font-size: var(--type-lg);
}

#reportes .phase5-period-copy span {
  color: var(--reports-muted);
  font-size: var(--type-sm);
}

#reportes .phase5-period-actions {
  gap: var(--space-4);
}

#reportes .phase5-period-button,
#reportes .phase5-density-button {
  min-height: 2.5rem;
  padding: var(--space-2) 0;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--reports-muted);
  font-size: var(--type-sm);
  font-weight: 700;
  box-shadow: none;
}

#reportes .phase5-period-button:hover,
#reportes .phase5-density-button:hover {
  color: var(--reports-ink);
  background: transparent;
}

#reportes .phase5-period-button.active {
  border-bottom-color: var(--reports-primary);
  background: transparent;
  color: var(--reports-ink);
}

#reportes .report-filters {
  grid-template-columns: repeat(4, minmax(9.5rem, 1fr));
  gap: var(--space-4);
  margin: 0;
  padding: var(--space-5) 0;
  border: 0;
  border-bottom: 1px solid var(--reports-border);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

#reportes .phase5-filter-title {
  grid-column: 1 / span 1;
  align-content: start;
  gap: var(--space-1);
  padding: 0 var(--space-5) 0 0;
  border: 0;
  border-right: 1px solid var(--reports-border);
}

#reportes .phase5-filter-title strong {
  color: var(--reports-ink);
  font-size: var(--type-lg);
}

#reportes .phase5-filter-title span {
  color: var(--reports-muted);
  font-size: var(--type-sm);
  line-height: 1.45;
}

#reportes .report-filters label {
  gap: var(--space-2);
  color: var(--reports-muted);
  font-size: var(--type-xs);
  font-weight: 700;
  letter-spacing: 0.03em;
}

#reportes .report-filters input {
  min-width: 0;
  min-height: 2.5rem;
  border-radius: var(--radius-control);
}

#reportes .report-actions {
  grid-column: 2 / -1;
  display: flex;
  justify-content: flex-end;
  gap: var(--space-3);
  padding-top: 0;
}

#reportes .phase5-filter-summary {
  min-height: auto;
  gap: var(--space-3);
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--reports-border);
  color: var(--reports-muted);
  font-size: var(--type-xs);
}

#reportes .phase5-filter-summary-label {
  color: var(--reports-ink);
}

#reportes .phase5-filter-chip {
  position: relative;
  gap: var(--space-1);
  padding: 0 0 0 var(--space-3);
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--reports-muted);
}

#reportes .phase5-filter-chip::before {
  position: absolute;
  left: 0;
  color: var(--reports-border);
  content: '·';
}

/* Resumen: franja analítica con divisores, no tarjetas KPI. */
#reportes .phase5-report-summary {
  grid-template-columns: 1.2fr repeat(3, minmax(0, 1fr));
  gap: 0;
  margin-top: var(--space-2);
  border-top: 1px solid var(--reports-border);
  border-bottom: 1px solid var(--reports-border);
  background: var(--reports-surface);
}

#reportes .phase5-summary-card {
  align-content: start;
  gap: var(--space-1);
  min-width: 0;
  min-height: 7.25rem;
  padding: var(--space-5);
  border: 0;
  border-right: 1px solid var(--reports-border);
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

#reportes .phase5-summary-card:last-child {
  border-right: 0;
}

#reportes .phase5-summary-card span {
  color: var(--reports-muted);
  font-size: var(--type-xs);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

#reportes .phase5-summary-card strong {
  color: var(--reports-ink);
  font-family: var(--font-data);
  font-size: var(--type-2xl);
  line-height: 1.15;
}

#reportes .phase5-summary-card small {
  max-width: 34ch;
  color: var(--reports-muted);
  font-size: var(--type-xs);
  line-height: 1.45;
}

#reportes .phase5-summary-card.attention,
#reportes.phase5-audit-mode .phase5-summary-card:first-child {
  background: color-mix(in srgb, var(--reports-warning) 6%, var(--reports-surface));
  box-shadow: none;
}

#reportes.phase5-audit-mode .phase5-summary-card:first-child {
  background: color-mix(in srgb, var(--reports-info) 6%, var(--reports-surface));
}

/* Evidencia: cabecera sobria y tabla dominante. */
#reportes .phase5-table-header {
  align-items: end;
  gap: var(--space-6);
  padding: var(--space-6) 0 var(--space-3);
  border-bottom: 1px solid var(--reports-border);
}

#reportes .phase5-table-header h3 {
  margin: var(--space-1) 0;
  color: var(--reports-ink);
  font-size: var(--type-xl);
}

#reportes .phase5-table-header p {
  color: var(--reports-muted);
  font-size: var(--type-sm);
}

#reportes .phase5-table-eyebrow {
  color: var(--reports-muted);
  font-size: var(--type-xs);
}

#reportes .phase5-table-tools {
  gap: var(--space-4);
}

#reportes .phase5-scroll-hint {
  color: var(--reports-muted);
  font-size: var(--type-xs);
}

#reportes .phase5-report-table-wrap {
  max-height: 66vh;
  border: 0;
  border-bottom: 1px solid var(--reports-border);
  border-radius: 0;
  background: var(--reports-surface);
  box-shadow: none;
}

#reportes .phase5-report-table-wrap.is-loading::after {
  border-radius: 0;
  background: color-mix(in srgb, var(--reports-surface) 92%, transparent);
  color: var(--reports-ink);
}

#reportes .phase5-report-table-wrap th {
  background: color-mix(in srgb, var(--reports-canvas) 68%, var(--reports-surface));
  color: var(--reports-ink);
  border-bottom: 1px solid var(--reports-border);
  font-size: var(--type-xs);
  letter-spacing: 0.025em;
  text-transform: none;
}

#reportes .phase5-report-table-wrap td {
  border-bottom-color: color-mix(in srgb, var(--reports-border) 72%, transparent);
  color: var(--reports-ink);
}

#reportes .phase5-report-table-wrap th:first-child,
#reportes .phase5-report-table-wrap td:first-child {
  box-shadow: 1px 0 0 var(--reports-border);
}

#reportes .phase5-report-table-wrap td:first-child {
  background: var(--reports-surface);
}

#reportes .phase5-report-table-wrap tbody tr:hover td {
  background: color-mix(in srgb, var(--reports-info) 4%, var(--reports-surface));
}

#reportes .phase5-report-table-wrap tbody tr.phase5-attention-row td {
  background: color-mix(in srgb, var(--reports-warning) 7%, var(--reports-surface));
}

#reportes.phase5-audit-mode .phase5-report-table-wrap tbody tr td {
  font-family: var(--font-data);
}

#reportes.phase5-audit-mode .phase5-report-table-wrap tbody tr:nth-child(even) td {
  background: color-mix(in srgb, var(--reports-canvas) 44%, var(--reports-surface));
}

#reportes.phase5-density-compact .phase5-report-table-wrap th,
#reportes.phase5-density-compact .phase5-report-table-wrap td {
  font-size: var(--type-xs);
}

#reportes .report-card:focus-visible,
#reportes .phase5-period-button:focus-visible,
#reportes .phase5-density-button:focus-visible,
#reportes .phase5-report-catalog > summary:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--reports-focus) 36%, transparent);
  outline-offset: 2px;
}

@media (max-width: 1100px) {
  #reportes .phase5-report-hero {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  #reportes .report-grid {
    grid-template-columns: 1fr;
  }

  #reportes .report-card:nth-child(odd) {
    border-right: 0;
  }

  #reportes .report-card:nth-last-child(2) {
    border-bottom: 1px solid var(--reports-border);
  }

  #reportes .phase5-periods,
  #reportes .phase5-table-header {
    align-items: flex-start;
  }

  #reportes .report-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #reportes .phase5-filter-title {
    grid-column: 1 / -1;
    padding: 0 0 var(--space-4);
    border-right: 0;
    border-bottom: 1px solid var(--reports-border);
  }

  #reportes .report-actions {
    grid-column: 1 / -1;
  }

  #reportes .phase5-report-summary {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  #reportes .phase5-summary-card:nth-child(2) {
    border-right: 0;
  }

  #reportes .phase5-summary-card:nth-child(-n + 2) {
    border-bottom: 1px solid var(--reports-border);
  }
}

@media (max-width: 680px) {
  #reportes.phase5-reports-audit {
    gap: var(--space-5);
  }

  #reportes .phase5-report-hero {
    grid-template-columns: 1fr;
    gap: var(--space-4);
    padding-top: var(--space-4);
  }

  #reportes .phase5-report-hero h2 {
    font-size: var(--type-2xl);
  }

  #reportes .phase5-report-count {
    justify-self: stretch;
    padding: var(--space-3) 0 0;
    border-top: 1px solid var(--reports-border);
    border-left: 0;
    text-align: left;
  }

  #reportes .phase5-report-catalog > summary {
    align-items: flex-start;
  }

  #reportes .phase5-report-catalog > summary span:first-child {
    display: grid;
    gap: var(--space-1);
  }

  #reportes .report-card {
    min-height: auto;
    padding: var(--space-4) 0;
  }

  #reportes .phase5-periods,
  #reportes .phase5-table-header {
    gap: var(--space-4);
  }

  #reportes .phase5-period-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: var(--space-2) var(--space-4);
  }

  #reportes .phase5-period-button,
  #reportes .phase5-density-button {
    width: auto;
    min-height: 2.75rem;
    text-align: left;
  }

  #reportes .report-filters,
  #reportes .phase5-report-summary {
    grid-template-columns: 1fr;
  }

  #reportes .report-actions {
    justify-content: stretch;
  }

  #reportes .report-actions .btn {
    width: 100%;
  }

  #reportes .phase5-summary-card,
  #reportes .phase5-summary-card:nth-child(2),
  #reportes .phase5-summary-card:last-child {
    min-height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--reports-border);
  }

  #reportes .phase5-summary-card:last-child {
    border-bottom: 0;
  }

  #reportes .phase5-table-tools {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  #reportes .phase5-scroll-hint {
    max-width: none;
    text-align: left;
  }

  #reportes .phase5-report-table-wrap {
    max-height: 62vh;
  }

  #reportes .phase5-report-table-wrap th:first-child,
  #reportes .phase5-report-table-wrap td:first-child {
    position: static;
    min-width: 10.5rem;
    box-shadow: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  #reportes .report-card,
  #reportes .phase5-period-button,
  #reportes .phase5-density-button {
    transition: none;
  }
}
