/* Bloque Reporting: analítica server-rendered, descarga contextual y preferencias. */

/* Métricas en Grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin: 14px 0 16px;
}
.metric-card {
  padding: 14px 16px;
  border-radius: var(--ui-radius);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  text-decoration: none;
  color: inherit;
  transition: all 0.15s ease;
}
.metric-card:hover {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.metric-card > span {
  font-size: 0.73rem;
  color: var(--muted);
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.metric-card strong {
  font-size: clamp(1.2rem, 2.2vw, 1.8rem);
  line-height: 1.15;
  letter-spacing: -0.03em;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
}
.metric-card small {
  color: var(--muted);
  font-size: 0.71rem;
}

/* Banner de Aprobación */
.approval-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  margin: 0 0 16px;
  border-radius: var(--ui-radius-lg);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.approval-banner h2 {
  font-size: clamp(1.3rem, 2.4vw, 1.75rem);
  margin: 3px 0;
  font-weight: 800;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}
.approval-banner p {
  color: var(--muted);
  font-size: 0.77rem;
  line-height: 1.5;
  margin: 0;
}
.approval-banner > .ui-icon {
  width: 38px;
  height: 38px;
  color: var(--primary);
  opacity: 0.35;
  flex: none;
}

/* Grillas Analíticas */
.analytics-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.95fr);
  gap: 14px;
  margin: 0 0 16px;
}
.analytics-panel {
  padding: 18px 20px;
  border-radius: var(--ui-radius-lg);
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--ui-shadow);
  min-width: 0;
}
.analytics-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.analytics-head h2 {
  font-size: 0.96rem;
  margin: 0 0 3px;
  font-weight: 750;
}
.analytics-head p {
  color: var(--muted);
  font-size: 0.75rem;
  margin: 0;
}

/* Gráfico Mensual */
.monthly-chart {
  height: 180px;
  padding: 12px 0 0;
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  align-items: flex-end;
}
.monthly-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  gap: 6px;
  min-width: 0;
}
.monthly-column strong {
  font-size: 0.75rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.monthly-column small {
  font-size: 0.69rem;
  color: var(--muted);
  white-space: nowrap;
}
.monthly-track {
  flex: 1;
  width: min(100%, 36px);
  display: flex;
  align-items: flex-end;
  border-bottom: 1px solid var(--line);
}
.monthly-svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}
.monthly-svg rect {
  fill: var(--primary);
  opacity: 0.85;
  transition: opacity 0.15s, fill 0.15s;
}
.monthly-column:hover .monthly-svg rect {
  opacity: 1;
  fill: var(--primary-hover);
}

/* Barras de Estado */
.state-bars {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}
.state-bar-entry > div:first-child {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.76rem;
  margin-bottom: 5px;
}
.state-bar-entry strong {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}
.state-progress {
  display: block;
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  width: 100%;
  height: 7px;
  border-radius: var(--radius-full);
  overflow: hidden;
  background: var(--surface-2);
}
.state-progress::-webkit-progress-bar {
  background: var(--surface-2);
  border-radius: var(--radius-full);
}
.state-progress::-webkit-progress-value {
  background: var(--primary);
  border-radius: var(--radius-full);
}
.state-progress::-moz-progress-bar {
  background: var(--primary);
  border-radius: var(--radius-full);
}

/* Panel de Próximos Vencimientos */
.due-panel { margin-top: 0; }
.due-row {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--line-subtle);
  color: inherit;
  text-decoration: none;
  transition: background 0.12s;
}
.due-row:last-child { border-bottom: 0; }
.due-row:hover { background: var(--surface-2); }
.due-row > span:first-child {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-wrap: anywhere;
}
.due-row strong { font-size: 0.82rem; font-weight: 650; }
.due-row small {
  color: var(--muted);
  font-size: 0.72rem;
}
.due-row .status-pill { white-space: nowrap; }

/* Acciones de Exportación */
.export-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 7px;
}
.export-caption {
  font-size: 0.75rem;
  color: var(--muted);
  font-weight: 650;
  margin-right: 2px;
}
.export-button {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  text-decoration: none;
  font-size: 0.76rem;
  padding: 5px 10px;
}
.export-button .ui-icon { width: 14px; height: 14px; }
.list-panel-exports {
  padding: 0 18px 10px;
  display: flex;
  justify-content: flex-end;
}
.detail-export-row {
  display: flex;
  justify-content: flex-end;
  margin: -4px 0 12px;
}

/* Previsualización de exportaciones */
.export-preview-modal {
  width: min(1100px, calc(100vw - 32px));
  max-width: none;
  height: min(860px, calc(100dvh - 32px));
  max-height: none;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--ui-radius-lg);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 24px 80px rgb(0 0 0 / 0.32);
  overflow: hidden;
}
.export-preview-modal::backdrop { background: rgb(5 12 26 / 0.7); backdrop-filter: blur(3px); }
.export-preview-modal-frame { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; height: 100%; min-width: 0; }
.export-preview-modal-header,
.export-preview-modal-footer {
  position: sticky;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.export-preview-modal-header { top: 0; }
.export-preview-modal-header h2 { margin: 2px 0 0; font-size: 1.15rem; }
.export-preview-modal-footer { bottom: 0; justify-content: flex-end; border: 0; border-top: 1px solid var(--line); }
.export-preview-modal-body { min-width: 0; overflow: auto; padding: 18px; background: var(--surface-2); }
.export-preview-state { min-height: 180px; display: grid; place-content: center; justify-items: center; gap: 12px; color: var(--muted); text-align: center; }
.export-preview-state[hidden] { display: none; }
.export-preview-spinner { width: 30px; height: 30px; border: 3px solid var(--line); border-top-color: var(--primary); border-radius: 50%; animation: export-preview-spin .8s linear infinite; }
@keyframes export-preview-spin { to { transform: rotate(360deg); } }
.export-preview-error { color: var(--danger); }
.export-preview-document { min-width: 0; }
.export-preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-bottom: 14px; }
.export-preview-toolbar > div { display: flex; flex-direction: column; min-width: 0; }
.export-preview-format { color: var(--primary); font-size: .72rem; font-weight: 800; letter-spacing: .08em; }
.export-preview-filename { color: var(--muted); font-size: .75rem; overflow-wrap: anywhere; }
.export-preview-pdf { min-height: min(70dvh, 760px); overflow: hidden; background: #525659; border: 1px solid var(--line); border-radius: var(--ui-radius); }
.export-preview-pdf > p { min-height: inherit; display: grid; place-content: center; margin: 0; color: #fff; }
.export-preview-pdf-frame { display: block; width: 100%; height: min(70dvh, 760px); border: 0; background: #525659; }
.export-preview-native-notice { min-height: 260px; padding: 24px; }
.export-preview-native-notice strong { color: var(--text); font-size: 1rem; }
.export-preview-page { max-width: 1100px; margin: 0 auto; }

@media (prefers-reduced-motion: reduce) { .export-preview-spinner { animation: none; } }

.settings-panel { max-width: 680px; }

@media(max-width: 1120px) {
  .metrics-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .analytics-grid { grid-template-columns: minmax(0, 1fr); }
}
@media(max-width: 580px) {
  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }
  .metric-card { padding: 12px; }
  .metric-card strong { font-size: 1.25rem; }
  .approval-banner { padding: 14px 16px; }
  .analytics-panel { padding: 14px 16px; }
  .monthly-chart { gap: 6px; height: 150px; }
  .monthly-column small { font-size: 0.6rem; }
  .due-row {
    align-items: flex-start;
    flex-direction: column;
    gap: 6px;
  }
  .list-panel-exports {
    justify-content: flex-start;
    padding: 6px 14px;
  }
  .detail-export-row {
    justify-content: flex-start;
    margin: 0 0 12px;
  }
  .export-actions { gap: 5px; }
  .export-preview-modal { width: calc(100vw - 16px); height: calc(100dvh - 16px); }
  .export-preview-modal-body { padding: 10px; }
  .export-preview-toolbar { align-items: stretch; flex-direction: column; }
  .export-preview-toolbar .button { justify-content: center; }
  .export-preview-pdf,
  .export-preview-pdf-frame { height: calc(100dvh - 240px); min-height: 340px; }
}
