/* ============================================================
   FinSight — Trace Modal (Composição/Rastreabilidade) v9.13.24
   ============================================================
   Modal universal de transparência financeira:
   • Nível 1 — Composição Resumida (parcelas + fórmula + validação)
   • Nível 2 — Detalhamento Analítico (delegado ao DrillDown)
   • Responsivo: desktop, tablet, celular
   ============================================================ */

.trace-modal {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 9999;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.trace-modal.active {
  display: flex;
  animation: fs-trace-in .18s ease-out;
}

.trace-modal-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

.trace-modal-content {
  position: relative;
  width: 100%;
  max-width: 920px;
  max-height: 92vh;
  background: #fff;
  border-radius: 14px;
  box-shadow: 0 25px 60px rgba(15, 23, 42, .35), 0 0 0 1px rgba(138, 92, 255, .15);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.trace-modal-header {
  padding: 18px 22px 14px;
  background: linear-gradient(180deg, #faf7ff 0%, #fff 100%);
  border-bottom: 1px solid #f0edf7;
  flex-shrink: 0;
}

.trace-modal-body {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 22px;
  -webkit-overflow-scrolling: touch;
}

.trace-modal-footer {
  padding: 12px 22px 16px;
  background: #fafbfc;
  border-top: 1px solid #f0edf7;
  flex-shrink: 0;
}

/* Scrollbar do body */
.trace-modal-body::-webkit-scrollbar { width: 8px; }
.trace-modal-body::-webkit-scrollbar-track {
  background: rgba(138, 92, 255, .04);
  border-radius: 4px;
}
.trace-modal-body::-webkit-scrollbar-thumb {
  background: linear-gradient(180deg, #8a5cff, #5c32c2);
  border-radius: 4px;
}

/* Botão fechar */
.btn-close-trace {
  background: transparent;
  border: none;
  font-size: 22px;
  color: #9ca3af;
  cursor: pointer;
  line-height: 1;
  padding: 4px 10px;
  border-radius: 6px;
  transition: background .15s;
}
.btn-close-trace:hover {
  background: #f3f4f6;
  color: #374151;
}

/* Linhas de parcela (cards clicáveis) */
.trace-rows .trace-row {
  -webkit-tap-highlight-color: rgba(138, 92, 255, .15);
}

.trace-row:active {
  transform: scale(.99);
}

/* Badge de consistência */
.trace-cons-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  white-space: nowrap;
}

/* ───────── RESPONSIVO ───────── */
@media (max-width: 900px) {
  .trace-modal-content { max-width: 100%; max-height: 95vh; }
  .trace-modal-header,
  .trace-modal-body,
  .trace-modal-footer { padding-left: 16px; padding-right: 16px; }
}

@media (max-width: 640px) {
  .trace-modal { padding: 8px; }
  .trace-modal-content { border-radius: 12px; max-height: 96vh; }
  .trace-modal-header { padding: 14px 14px 10px; }
  .trace-modal-body { padding: 12px 14px; }
  .trace-modal-footer { padding: 10px 14px 12px; }

  .trace-row {
    padding: 10px 12px !important;
  }
  .trace-row > div:first-child {
    flex-wrap: wrap !important;
    row-gap: 4px !important;
  }
}

@media (max-width: 480px) {
  .trace-modal-content { max-height: 98vh; }
  .btn-trace-detail {
    width: 100%;
    text-align: center;
  }
}

/* Animação de entrada */
@keyframes fs-trace-in {
  from { opacity: 0; transform: scale(.96); }
  to   { opacity: 1; transform: scale(1); }
}

.trace-modal.active .trace-modal-content {
  animation: fs-trace-content-in .25s cubic-bezier(.16, 1, .3, 1);
}

@keyframes fs-trace-content-in {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Indicador visual de elementos clicáveis (cursor + hint sutil) */
[data-trace-spec],
[data-trace-tipo] {
  cursor: pointer;
  position: relative;
  transition: background-color .12s;
}

[data-trace-spec]:hover,
[data-trace-tipo]:hover {
  background-color: rgba(138, 92, 255, .04);
}

/* Pequeno ícone de lupa que aparece em elementos rastreáveis no hover */
.trace-hint {
  display: inline-block;
  font-size: 9px;
  color: #c4b5fd;
  margin-left: 4px;
  opacity: 0;
  transition: opacity .15s;
}

[data-trace-spec]:hover .trace-hint,
[data-trace-tipo]:hover .trace-hint {
  opacity: 1;
}

/* Print: oculta o modal */
@media print {
  .trace-modal { display: none !important; }
}
