/* =========================================================
   Gerar Relatório — modal de seleção de tipo de relatório
   ========================================================= */

:root {
  --rep-ink: #0F1B2D;
  --rep-ink-2: #2A3447;
  --rep-muted: #5A6478;
  --rep-muted-2: #8A93A6;
  --rep-line: #E6EAF1;
  --rep-line-2: #EEF1F5;
  --rep-surface: #FFFFFF;
  --rep-surface-2: #FAFBFD;
  --rep-navy: #0B2545;
  --rep-navy-2: #112E54;
  --rep-accent: #E08B2A;
  --rep-accent-soft: #FBE7CB;
  --rep-ok: #22A06B;
  --rep-info: #2B6CB0;
  --rep-shadow-lg: 0 24px 60px rgba(15,27,45,.18), 0 2px 6px rgba(15,27,45,.08);
}

body { font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }

/* ====== Backdrop ====== */
.report-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, .35);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid; place-items: center;
  z-index: 50;
  animation: rep-fadeIn .25s ease;
}
.report-backdrop[hidden] { display: none; }

@keyframes rep-fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes rep-slideUp {
  from { opacity: 0; transform: translateY(12px) scale(.985); }
  to   { opacity: 1; transform: none; }
}

/* ====== Modal box ====== */
.report-modal {
  width: 560px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 32px);
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--rep-shadow-lg);
  overflow: hidden;
  animation: rep-slideUp .3s cubic-bezier(.2,.8,.2,1);
  border: 1px solid rgba(255,255,255,.4);
  color: var(--rep-ink);
  box-sizing: border-box;
  transition: width 0.18s ease;
}
.report-modal.is-preview {
  width: 920px;
}
.report-modal *, .report-modal *::before, .report-modal *::after { box-sizing: border-box; }
.report-head, .report-foot { flex: 0 0 auto; }
.report-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; }

/* ====== Head ====== */
.report-head {
  position: relative;
  padding: 22px 26px 18px;
  background: linear-gradient(180deg, #FAFBFD 0%, #FFFFFF 100%);
  border-bottom: 1px solid var(--rep-line-2);
}
.report-eyebrow {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px;
  letter-spacing: 0.18em;
  color: var(--rep-accent);
  font-weight: 600;
  margin-bottom: 6px;
  display: flex; align-items: center; gap: 8px;
}
.report-eyebrow::before {
  content: ""; width: 14px; height: 1px; background: var(--rep-accent);
}
.report-title {
  font-size: 22px; font-weight: 600; letter-spacing: -0.015em;
  margin: 0;
}
.report-sub {
  margin: 4px 0 0;
  font-size: 13px; color: var(--rep-muted);
}
.report-close {
  position: absolute; top: 18px; right: 18px;
  width: 32px; height: 32px;
  border: 0; background: transparent;
  border-radius: 8px;
  color: var(--rep-muted);
  cursor: pointer;
  display: grid; place-items: center;
}
.report-close:hover { background: var(--rep-line-2); color: var(--rep-ink); }

/* ====== Body ====== */
.report-body { padding: 18px 26px 22px; }

.report-group { margin-top: 14px; }
.report-group:first-child { margin-top: 0; }

.report-group-label {
  display: flex; align-items: center; gap: 10px;
  font-family: "JetBrains Mono", monospace;
  font-size: 10.5px; letter-spacing: 0.14em;
  color: var(--rep-muted); text-transform: uppercase;
  font-weight: 600;
  margin-bottom: 8px;
}
.report-group-label::after {
  content: ""; flex: 1; height: 1px; background: var(--rep-line);
}
.report-pill {
  font-family: "Inter", sans-serif;
  font-size: 10.5px;
  background: var(--rep-accent-soft);
  color: var(--rep-accent);
  padding: 2px 8px;
  border-radius: 999px;
  letter-spacing: 0;
  font-weight: 600;
  text-transform: none;
}
.report-pill.is-info { background: #E8F0F8; color: var(--rep-info); }

/* ====== Options grid ====== */
.report-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.report-options.is-full { grid-template-columns: 1fr; }

/* ====== Option card ====== */
.report-opt {
  --rep-ring: var(--rep-info);
  position: relative;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  background: #fff;
  border: 1.5px solid var(--rep-line);
  border-radius: 10px;
  cursor: pointer;
  transition: all .15s ease;
  text-align: left;
}
.report-opt input { position: absolute; opacity: 0; pointer-events: none; }
.report-opt:hover {
  border-color: var(--rep-ring);
  background: var(--rep-surface-2);
}
.report-opt.is-selected {
  border-color: var(--rep-ring);
  background: rgba(43,108,176,.05);
  box-shadow: 0 0 0 4px rgba(43,108,176,.08);
}
.report-opt.is-disabled {
  cursor: not-allowed;
  opacity: 0.55;
  pointer-events: none;
}

.report-thumb {
  flex-shrink: 0;
  width: 44px; height: 56px;
  background: var(--rep-surface-2);
  border: 1px solid var(--rep-line);
  border-radius: 4px;
  display: grid; place-items: center;
  position: relative; overflow: hidden;
}
.report-thumb svg { width: 100%; height: 100%; display: block; }

.report-opt-text { flex: 1; min-width: 0; }
.report-opt-title {
  font-size: 13.5px; font-weight: 600; color: var(--rep-ink);
  display: flex; align-items: center; gap: 6px;
}
.report-badge {
  font-family: "JetBrains Mono", monospace;
  font-size: 9.5px; font-weight: 600;
  background: var(--rep-line-2); color: var(--rep-muted);
  padding: 2px 5px; border-radius: 3px; letter-spacing: 0.05em;
}
.report-badge.is-xls { background: rgba(34,160,107,.12); color: var(--rep-ok); }
.report-opt-desc {
  font-size: 12px; color: var(--rep-muted);
  margin-top: 2px; line-height: 1.4;
}

.report-radio {
  flex-shrink: 0;
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 2px solid var(--rep-line);
  display: grid; place-items: center;
  transition: all .15s;
}
.report-opt.is-selected .report-radio { border-color: var(--rep-ring); }
.report-opt.is-selected .report-radio::after {
  content: "";
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--rep-ring);
}

/* ====== Picker de graficos para o PDF (max 6) ====== */
.report-graficos-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.report-grafico-opt {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 8px;
  row-gap: 2px;
  align-items: center;
  padding: 8px 10px;
  border: 1.5px solid var(--rep-line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  transition: border-color .15s, background .15s, opacity .15s;
  user-select: none;
  min-width: 0;
}
.report-grafico-opt:hover { border-color: var(--rep-info); background: var(--rep-surface-2); }
.report-grafico-opt.is-on {
  border-color: var(--rep-info);
  background: rgba(43, 108, 176, .06);
}
.report-grafico-opt.is-disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
.report-grafico-opt input {
  width: 14px; height: 14px;
  accent-color: var(--rep-info);
  flex-shrink: 0;
  grid-row: 1 / span 2;
  grid-column: 1;
  align-self: center;
}
.report-grafico-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px; font-weight: 700;
  color: var(--rep-ink);
  letter-spacing: 0.04em;
  grid-column: 2;
  grid-row: 1;
  min-width: 0;
}
.report-grafico-desc {
  font-size: 10.5px; color: var(--rep-muted);
  line-height: 1.25;
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Strip "Ordem no PDF": chips arrastaveis com numero e handle */
.report-ordem {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px dashed var(--rep-line);
}
.report-ordem-titulo {
  font-size: 11px;
  font-weight: 600;
  color: var(--rep-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.report-ordem-hint {
  font-size: 10.5px;
  font-weight: 500;
  color: var(--rep-muted);
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.7;
}
.report-ordem-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 36px;
}
.report-ordem-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 6px 6px;
  background: rgba(43, 108, 176, .08);
  border: 1.5px solid var(--rep-info);
  border-radius: 18px;
  cursor: grab;
  user-select: none;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.report-ordem-chip:hover { background: rgba(43, 108, 176, .14); }
.report-ordem-chip:active { cursor: grabbing; }
.report-ordem-chip.is-drop-target {
  transform: translateX(2px);
  box-shadow: -3px 0 0 0 var(--rep-info);
  background: rgba(43, 108, 176, .18);
}
.report-ordem-num {
  display: inline-grid;
  place-items: center;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--rep-info);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
}
.report-ordem-handle {
  color: var(--rep-info);
  font-size: 11px;
  letter-spacing: -2px;
  opacity: 0.7;
}
.report-ordem-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--rep-ink);
  letter-spacing: 0.04em;
}

/* ====== Preview do PDF ====== */
.report-preview-body {
  padding: 14px 18px 18px;
  display: flex;
  min-height: 0;
}
.report-preview-frame {
  flex: 1;
  width: 100%;
  height: 70vh;
  min-height: 460px;
  border: 1px solid var(--rep-line);
  border-radius: 6px;
  background: #525659;
}

/* Synthesis (XLS) variant — green ring */
.report-opt.is-synthesis { --rep-ring: var(--rep-ok); }
.report-opt.is-synthesis .report-thumb {
  background: #fff;
  border-color: #C8D0DC;
}
.report-opt.is-synthesis.is-selected {
  background: rgba(34,160,107,.05);
  box-shadow: 0 0 0 4px rgba(34,160,107,.10);
}

/* ====== Footer ====== */
.report-foot {
  padding: 16px 26px;
  background: var(--rep-surface-2);
  border-top: 1px solid var(--rep-line-2);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.report-foot-info {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--rep-muted);
  /* Permite a info encolher (e nao empurrar o botao Gerar pra quebrar
     em duas linhas) quando o hint for longo. */
  min-width: 0; flex: 1 1 auto;
}
.report-foot-info svg { color: var(--rep-info); flex-shrink: 0; }
.report-foot-info span {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0;
}
.report-foot-actions {
  display: flex; gap: 10px;
  flex: 0 0 auto;   /* nao deixa os botoes encolherem */
}

/* ====== Buttons (escopados ao modal para nao colidir com .btn-ghost/.btn-primary
   ja usados em outras telas do dashboard) ====== */
.report-backdrop .btn {
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 13px; font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
  display: inline-flex; align-items: center; gap: 8px;
  white-space: nowrap;   /* nunca quebra "Gerar Relatorio" em 2 linhas */
  flex-shrink: 0;
}
.report-backdrop .btn-ghost {
  background: #fff;
  border-color: var(--rep-line);
  color: var(--rep-ink-2);
}
.report-backdrop .btn-ghost:hover { background: var(--rep-line-2); }
.report-backdrop .btn-primary {
  background: var(--rep-navy);
  color: #fff;
}
.report-backdrop .btn-primary:hover { background: var(--rep-navy-2); }
.report-backdrop .btn-primary:disabled { opacity: .5; cursor: not-allowed; }

/* Seletor de formato (PDF / XLSX) que aparece quando "Relatorio de Sintese"
   eh selecionado. Toggle de dois botoes lado a lado. */
.report-formato {
  display: flex; align-items: center; gap: 10px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--rep-muted);
}
.report-formato-label {
  font-family: "JetBrains Mono", monospace;
  font-size: 10.5px; letter-spacing: 0.14em;
  text-transform: uppercase; font-weight: 600;
}
.report-formato-toggle {
  display: inline-flex;
  border: 1.5px solid var(--rep-line);
  border-radius: 8px;
  overflow: hidden;
}
.report-formato-btn {
  background: #fff;
  border: 0;
  padding: 6px 14px;
  font-family: "JetBrains Mono", monospace;
  font-size: 11.5px; font-weight: 700;
  color: var(--rep-muted);
  cursor: pointer;
  letter-spacing: 0.04em;
}
.report-formato-btn + .report-formato-btn { border-left: 1.5px solid var(--rep-line); }
.report-formato-btn:hover:not(:disabled) {
  background: var(--rep-surface-2);
  color: var(--rep-ink);
}
.report-formato-btn.is-on {
  background: var(--rep-ok);
  color: #fff;
}
.report-formato-btn:disabled { opacity: .5; cursor: not-allowed; }

/* ====== Filtro de Periodo (range de inicio_perf) ======
   Aparece nos modos all-1, all-4 e synthesis. Toggle no header do grupo
   liga/desliga; quando ligado, expande dois date inputs + chips de preset
   (Hoje, 7 dias, 30 dias, mes atual). */
.report-periodo-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  margin-left: auto;
  font-family: "Inter", sans-serif;
  font-size: 11.5px; font-weight: 600;
  color: var(--rep-muted);
  text-transform: none; letter-spacing: 0;
  cursor: pointer;
  user-select: none;
}
.report-periodo-toggle input[type="checkbox"] {
  width: 14px; height: 14px;
  accent-color: var(--rep-navy);
  cursor: pointer;
  margin: 0;
}
.report-periodo-toggle:has(input:checked) {
  color: var(--rep-ink);
}

.report-periodo {
  display: flex; flex-direction: column; gap: 10px;
  padding: 12px;
  border: 1px solid var(--rep-line);
  border-radius: 10px;
  background: var(--rep-surface-2);
}
.report-periodo-row {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px;
}
.report-periodo-field {
  display: flex; flex-direction: column; gap: 4px;
}
.report-periodo-lbl {
  font-family: "JetBrains Mono", monospace;
  font-size: 10px; letter-spacing: 0.14em;
  text-transform: uppercase; font-weight: 600;
  color: var(--rep-muted);
}
.report-periodo-field input[type="date"] {
  font-family: "Inter", sans-serif;
  font-size: 13px;
  color: var(--rep-ink);
  background: #fff;
  border: 1.5px solid var(--rep-line);
  border-radius: 8px;
  padding: 7px 10px;
  outline: none;
  min-width: 150px;
  transition: border-color .15s, box-shadow .15s;
}
.report-periodo-field input[type="date"]:hover:not(:disabled) {
  border-color: var(--rep-muted-2);
}
.report-periodo-field input[type="date"]:focus {
  border-color: var(--rep-navy);
  box-shadow: 0 0 0 3px rgba(11,37,69,.10);
}
.report-periodo-field input[type="date"]:disabled {
  opacity: .55; cursor: not-allowed;
}
.report-periodo-clear {
  align-self: stretch;
  background: transparent;
  border: 1.5px solid var(--rep-line);
  border-radius: 8px;
  padding: 7px 12px;
  font-family: "Inter", sans-serif;
  font-size: 12px; font-weight: 600;
  color: var(--rep-muted);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.report-periodo-clear:hover:not(:disabled) {
  background: #fff;
  color: var(--rep-ink);
  border-color: var(--rep-muted-2);
}
.report-periodo-clear:disabled { opacity: .5; cursor: not-allowed; }

.report-periodo-presets {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.report-periodo-chip {
  background: #fff;
  border: 1px solid var(--rep-line);
  border-radius: 999px;
  padding: 5px 11px;
  font-family: "Inter", sans-serif;
  font-size: 11.5px; font-weight: 600;
  color: var(--rep-muted);
  cursor: pointer;
  transition: background .15s, color .15s, border-color .15s;
}
.report-periodo-chip:hover:not(:disabled) {
  background: var(--rep-accent-soft);
  color: var(--rep-accent);
  border-color: var(--rep-accent-soft);
}
.report-periodo-chip:disabled { opacity: .5; cursor: not-allowed; }

/* Spinner do botao "Gerando..." — gira em loop continuo. */
.report-spinner { animation: rep-spin 0.85s linear infinite; transform-origin: 50% 50%; }
@keyframes rep-spin { to { transform: rotate(360deg); } }

/* ====== Tela de progresso (durante geracao do PDF da pasta) ====== */
.report-progress { display: flex; flex-direction: column; gap: 12px; }
.report-progress-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px;
}
.report-progress-title {
  font-size: 15px; font-weight: 600; color: var(--rep-ink);
}
.report-progress-count {
  font-family: "JetBrains Mono", monospace;
  font-size: 12px; font-weight: 600;
  color: var(--rep-info);
}
.report-progress-bar {
  height: 6px; background: var(--rep-line-2); border-radius: 999px;
  overflow: hidden; position: relative;
}
.report-progress-bar-fill {
  height: 100%;
  background: var(--rep-info);
  transition: width 200ms ease;
}
.report-progress-current {
  font-size: 12.5px; color: var(--rep-muted);
  display: flex; align-items: center; gap: 6px;
}
.report-progress-current::before {
  content: "";
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--rep-info);
  animation: rep-pulse 1.2s ease-in-out infinite;
}
.report-progress-current strong {
  color: var(--rep-ink); font-weight: 600;
  font-family: "JetBrains Mono", monospace; font-size: 12px;
}
@keyframes rep-pulse {
  0%, 100% { opacity: .35; transform: scale(.85); }
  50%      { opacity: 1;   transform: scale(1.1); }
}
.report-progress-list {
  margin: 0; padding: 8px 0;
  list-style: none;
  max-height: 240px; min-height: 120px;
  overflow-y: auto;
  border: 1px solid var(--rep-line);
  border-radius: 8px;
  background: var(--rep-surface-2);
}
.report-progress-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 6px 12px;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  color: var(--rep-ink-2);
}
.report-progress-list li.is-ok .report-progress-icon {
  color: var(--rep-ok);
}
.report-progress-list li.is-fail {
  color: #A82828;
}
.report-progress-list li.is-fail .report-progress-icon {
  color: #A82828;
}
.report-progress-icon {
  font-weight: 700; flex-shrink: 0; width: 14px; text-align: center;
}
.report-progress-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.report-progress-motivo {
  font-size: 11px; color: var(--rep-muted);
  font-family: "Inter", sans-serif;
}
.report-progress-empty {
  font-style: italic; color: var(--rep-muted-2);
  font-family: "Inter", sans-serif;
}

/* ============================================================
   DARK THEME OVERRIDES (modal de gerar PDF)
   Sobrescreve --rep-* tokens + hardcodes #fff. O preview do PDF
   em si (.report-preview-frame) fica light por design — o PDF
   gerado e' sempre claro e o frame so emula o leitor.
============================================================ */
[data-theme="dark"] {
  --rep-ink: #E8EEF8;
  --rep-ink-2: #B8C2D6;
  --rep-muted: #8A93A6;
  --rep-muted-2: #6E7689;
  --rep-line: #1F2A3D;
  --rep-line-2: #18222F;
  --rep-surface: #121C2B;
  --rep-surface-2: #0F1827;
  --rep-navy: #1A3A66;
  --rep-navy-2: #2A4A78;
  --rep-shadow-lg: 0 24px 60px rgba(0,0,0,.5), 0 2px 6px rgba(0,0,0,.3);
}

[data-theme="dark"] .report-modal { background: var(--rep-surface); border-color: var(--rep-line); }
[data-theme="dark"] .report-head {
  background: linear-gradient(180deg, var(--rep-surface-2) 0%, var(--rep-surface) 100%);
}
[data-theme="dark"] .report-pill.is-info { background: rgba(43,108,176,.18); color: #87B6E8; }
[data-theme="dark"] .report-opt { background: var(--rep-surface); }
[data-theme="dark"] .report-opt:hover { background: var(--rep-surface-2); }
[data-theme="dark"] .report-opt.is-selected { background: rgba(43,108,176,.12); }
[data-theme="dark"] .report-opt.is-synthesis .report-thumb { background: var(--rep-surface); border-color: var(--rep-line); }
[data-theme="dark"] .report-opt.is-synthesis.is-selected { background: rgba(34,160,107,.10); }
[data-theme="dark"] .report-thumb { background: var(--rep-surface-2); }
[data-theme="dark"] .report-grafico-opt { background: var(--rep-surface); }
[data-theme="dark"] .report-grafico-opt:hover { background: var(--rep-surface-2); }
[data-theme="dark"] .report-grafico-opt.is-on { background: rgba(43,108,176,.12); }
[data-theme="dark"] .report-backdrop .btn-ghost { background: var(--rep-surface); color: var(--rep-ink-2); }
[data-theme="dark"] .report-backdrop .btn-ghost:hover { background: var(--rep-surface-2); }
[data-theme="dark"] .report-formato-btn { background: var(--rep-surface); }
[data-theme="dark"] .report-formato-btn:hover:not(:disabled) { background: var(--rep-surface-2); }
[data-theme="dark"] .report-periodo-field input[type="date"] { background: var(--rep-surface); color: var(--rep-ink); }
[data-theme="dark"] .report-periodo-clear:hover:not(:disabled) { background: var(--rep-surface); }
[data-theme="dark"] .report-periodo-chip { background: var(--rep-surface); }
[data-theme="dark"] .report-periodo-chip:hover:not(:disabled) {
  background: rgba(224,139,42,.18); color: var(--rep-accent); border-color: rgba(224,139,42,.30);
}

/* Lista de progresso e barra */
[data-theme="dark"] .report-progress-list { background: var(--rep-surface-2); }
[data-theme="dark"] .report-progress-list li.is-fail { color: #F37771; }
[data-theme="dark"] .report-progress-list li.is-fail .report-progress-icon { color: #F37771; }

/* Backdrop um pouco mais escuro pra dar contraste */
[data-theme="dark"] .report-backdrop { background: rgba(0,0,0,.55); }
