/* ================================================================
   PRECIFIKA — MÓDULO DE RECIBOS FINANCEIROS
   Versão 1.0 — Maio 2026
   Arquivos relacionados: js/receipts.js, js/receipt-pdf.js
   ================================================================ */

/* ── Variáveis do módulo ── */
:root {
  --rec-primary:    #2563eb;
  --rec-success:    #16a34a;
  --rec-warning:    #d97706;
  --rec-danger:     #dc2626;
  --rec-purple:     #7c3aed;
  --rec-gray-50:    #f8fafc;
  --rec-gray-100:   #f1f5f9;
  --rec-gray-200:   #e2e8f0;
  --rec-gray-400:   #94a3b8;
  --rec-gray-600:   #475569;
  --rec-gray-800:   #1e293b;
  --rec-radius:     14px;
  --rec-shadow:     0 4px 20px rgba(0,0,0,.08);
}

/* ================================================================
   1. BOTÃO EMITIR RECIBO — na tabela/card de orçamentos aprovados
   ================================================================ */

/* Badge na listagem indicando recibos emitidos */
.est-receipt-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 700;
  color: var(--rec-success);
  background: #dcfce7;
  border: 1px solid #bbf7d0;
  padding: 2px 7px;
  border-radius: 20px;
  margin-left: 4px;
  white-space: nowrap;
  vertical-align: middle;
}

/* Botão emitir recibo na coluna de ações */
.btn-emit-receipt {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--rec-success);
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
  cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
  white-space: nowrap;
}
.btn-emit-receipt:hover {
  background: #dcfce7;
  border-color: #86efac;
  transform: translateY(-1px);
}
.btn-emit-receipt i { font-size: 11px; }

/* ================================================================
   2. MODAL — EMITIR RECIBO (overlay + box)
   ================================================================ */

.receipt-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(3px);
  z-index: 1100;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.receipt-modal-overlay.active {
  display: flex;
}

.receipt-modal-box {
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  width: 100%;
  max-width: 700px;
  max-height: 92vh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  animation: recModalIn .22s ease;
}

@keyframes recModalIn {
  from { opacity: 0; transform: translateY(24px) scale(.97); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

.receipt-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 26px 18px;
  border-bottom: 1px solid var(--rec-gray-200);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 2;
  border-radius: 20px 20px 0 0;
}

.receipt-modal-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.receipt-modal-title-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #dcfce7, #bbf7d0);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--rec-success);
  flex-shrink: 0;
}

.receipt-modal-title h2 {
  font-size: 17px;
  font-weight: 700;
  color: var(--rec-gray-800);
  margin: 0;
  line-height: 1.2;
}

.receipt-modal-title p {
  font-size: 12px;
  color: var(--rec-gray-400);
  margin: 2px 0 0;
}

.receipt-modal-close {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: var(--rec-gray-100);
  color: var(--rec-gray-600);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background .15s;
  flex-shrink: 0;
}
.receipt-modal-close:hover { background: var(--rec-gray-200); }

.receipt-modal-body {
  padding: 24px 26px;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.receipt-modal-footer {
  padding: 16px 26px 20px;
  border-top: 1px solid var(--rec-gray-200);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  position: sticky;
  bottom: 0;
  background: #fff;
  border-radius: 0 0 20px 20px;
}

/* ================================================================
   3. SEÇÕES INTERNAS DO MODAL DE EMISSÃO
   ================================================================ */

/* Cabeçalho de seção */
.rec-section-title {
  font-size: 12px;
  font-weight: 700;
  color: var(--rec-gray-600);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.rec-section-title i {
  width: 18px;
  text-align: center;
  color: var(--rec-primary);
}

/* Card resumo do orçamento */
.rec-estimate-summary {
  background: var(--rec-gray-50);
  border: 1px solid var(--rec-gray-200);
  border-radius: var(--rec-radius);
  padding: 16px 18px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}

.rec-sum-item {}
.rec-sum-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--rec-gray-400);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 3px;
}
.rec-sum-value {
  font-size: 14px;
  font-weight: 700;
  color: var(--rec-gray-800);
}
.rec-sum-value--big {
  font-size: 18px;
  color: var(--rec-primary);
}
.rec-sum-value--green {
  font-size: 14px;
  color: var(--rec-success);
}

/* Grid de campos do formulário */
.rec-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.rec-form-grid--3 {
  grid-template-columns: 1fr 1fr 1fr;
}
.rec-form-full { grid-column: 1 / -1; }

.rec-form-group {}
.rec-form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--rec-gray-600);
  margin-bottom: 5px;
}
.rec-form-label span { color: var(--rec-danger); }

.rec-form-input,
.rec-form-select,
.rec-form-textarea {
  width: 100%;
  padding: 9px 12px;
  font-size: 13.5px;
  font-family: inherit;
  color: var(--rec-gray-800);
  background: #fff;
  border: 1.5px solid var(--rec-gray-200);
  border-radius: 9px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  box-sizing: border-box;
}
.rec-form-input:focus,
.rec-form-select:focus,
.rec-form-textarea:focus {
  border-color: var(--rec-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
.rec-form-textarea {
  resize: vertical;
  min-height: 70px;
}

/* Campo calculado (somente leitura com destaque) */
.rec-calculated-field {
  display: flex;
  align-items: center;
  gap: 0;
  background: #f0fdf4;
  border: 1.5px solid #bbf7d0;
  border-radius: 9px;
  overflow: hidden;
}
.rec-calculated-prefix {
  padding: 9px 12px;
  font-size: 12px;
  font-weight: 700;
  color: var(--rec-success);
  background: #dcfce7;
  border-right: 1px solid #bbf7d0;
  white-space: nowrap;
}
.rec-calculated-value {
  flex: 1;
  padding: 9px 12px;
  font-size: 16px;
  font-weight: 800;
  color: var(--rec-success);
  background: transparent;
  border: none;
  outline: none;
  cursor: default;
  font-family: inherit;
}

/* Card de progresso do faturamento */
.rec-billing-progress {
  background: var(--rec-gray-50);
  border: 1px solid var(--rec-gray-200);
  border-radius: var(--rec-radius);
  padding: 14px 16px;
}
.rec-billing-progress-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--rec-gray-600);
  margin-bottom: 8px;
}
.rec-billing-progress-bar-wrap {
  height: 8px;
  background: var(--rec-gray-200);
  border-radius: 20px;
  overflow: hidden;
  margin-bottom: 6px;
}
.rec-billing-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #16a34a);
  border-radius: 20px;
  transition: width .4s ease;
}
.rec-billing-progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--rec-gray-400);
}
.rec-billing-progress-meta strong { color: var(--rec-gray-800); }

/* ================================================================
   4. SEÇÃO DE DADOS BANCÁRIOS NO MODAL
   ================================================================ */

.rec-bank-selector {
  display: flex;
  align-items: center;
  gap: 10px;
}
.rec-bank-selector select {
  flex: 1;
}

.btn-rec-add-bank {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--rec-primary);
  background: #eff6ff;
  border: 1.5px solid #bfdbfe;
  border-radius: 9px;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
  font-family: inherit;
}
.btn-rec-add-bank:hover { background: #dbeafe; }

/* Preview card de dados bancários selecionados */
.rec-bank-preview {
  background: var(--rec-gray-50);
  border: 1px solid var(--rec-gray-200);
  border-radius: var(--rec-radius);
  padding: 14px 16px;
  display: none;
}
.rec-bank-preview.visible { display: block; }

.rec-bank-preview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}
.rec-bank-preview-item {}
.rec-bank-preview-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--rec-gray-400);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.rec-bank-preview-value {
  font-size: 13px;
  font-weight: 600;
  color: var(--rec-gray-800);
  margin-top: 1px;
}

/* ================================================================
   5. MODAL DE DADOS BANCÁRIOS (cadastro/edição)
   ================================================================ */

.bank-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.6);
  backdrop-filter: blur(3px);
  z-index: 1200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.bank-modal-overlay.active { display: flex; }

.bank-modal-box {
  background: #fff;
  border-radius: 18px;
  box-shadow: 0 20px 60px rgba(0,0,0,.22);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  animation: recModalIn .2s ease;
}

.bank-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--rec-gray-200);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 2;
  border-radius: 18px 18px 0 0;
}

.bank-modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--rec-gray-800);
}

.bank-modal-close {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: var(--rec-gray-100);
  color: var(--rec-gray-600);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background .15s;
  font-family: inherit;
}
.bank-modal-close:hover { background: var(--rec-gray-200); }

.bank-modal-body {
  padding: 22px 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.bank-modal-footer {
  padding: 14px 24px 18px;
  border-top: 1px solid var(--rec-gray-200);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  position: sticky;
  bottom: 0;
  background: #fff;
  border-radius: 0 0 18px 18px;
}

/* ================================================================
   6. MODAL — HISTÓRICO DE RECIBOS
   ================================================================ */

.history-modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.55);
  backdrop-filter: blur(3px);
  z-index: 1100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.history-modal-overlay.active { display: flex; }

.history-modal-box {
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  width: 100%;
  max-width: 720px;
  max-height: 90vh;
  overflow-y: auto;
  animation: recModalIn .22s ease;
  display: flex;
  flex-direction: column;
}

.history-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 26px 18px;
  border-bottom: 1px solid var(--rec-gray-200);
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 2;
  border-radius: 20px 20px 0 0;
}
.history-modal-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--rec-gray-800);
  display: flex;
  align-items: center;
  gap: 8px;
}
.history-modal-title i { color: var(--rec-primary); }
.history-modal-subtitle {
  font-size: 12px;
  color: var(--rec-gray-400);
  margin-top: 2px;
}
.history-modal-close {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: none;
  background: var(--rec-gray-100);
  color: var(--rec-gray-600);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background .15s;
  font-family: inherit;
}
.history-modal-close:hover { background: var(--rec-gray-200); }

.history-modal-body {
  padding: 22px 26px;
  flex: 1;
}

/* Barra de progresso de faturamento no histórico */
.hist-billing-summary {
  background: linear-gradient(135deg, #eff6ff, #f0fdf4);
  border: 1px solid var(--rec-gray-200);
  border-radius: var(--rec-radius);
  padding: 16px 18px;
  margin-bottom: 20px;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
}
.hist-sum-item {}
.hist-sum-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--rec-gray-400);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 3px;
}
.hist-sum-value {
  font-size: 16px;
  font-weight: 800;
  color: var(--rec-gray-800);
}
.hist-sum-value--blue  { color: var(--rec-primary); }
.hist-sum-value--green { color: var(--rec-success); }
.hist-sum-value--amber { color: var(--rec-warning); }

/* Barra de progresso total */
.hist-progress-wrap {
  margin-top: 10px;
  grid-column: 1 / -1;
}
.hist-progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--rec-gray-400);
  margin-bottom: 5px;
}
.hist-progress-label strong { color: var(--rec-gray-800); }
.hist-progress-bar-bg {
  height: 10px;
  background: var(--rec-gray-200);
  border-radius: 20px;
  overflow: hidden;
}
.hist-progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, #22c55e, #16a34a);
  border-radius: 20px;
  transition: width .4s ease;
}

/* Lista de recibos no histórico */
.hist-receipts-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.hist-receipt-item {
  background: var(--rec-gray-50);
  border: 1px solid var(--rec-gray-200);
  border-radius: var(--rec-radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: box-shadow .15s;
}
.hist-receipt-item:hover { box-shadow: var(--rec-shadow); }

.hist-receipt-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: linear-gradient(135deg, #dcfce7, #bbf7d0);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--rec-success);
  flex-shrink: 0;
}
.hist-receipt-icon--cancelled {
  background: #fef2f2;
  color: var(--rec-danger);
}

.hist-receipt-body { flex: 1; min-width: 0; }
.hist-receipt-code {
  font-size: 13.5px;
  font-weight: 700;
  color: var(--rec-gray-800);
  margin-bottom: 2px;
}
.hist-receipt-meta {
  font-size: 11.5px;
  color: var(--rec-gray-400);
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}
.hist-receipt-meta span { display: flex; align-items: center; gap: 4px; }

.hist-receipt-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}
.hist-receipt-value {
  font-size: 16px;
  font-weight: 800;
  color: var(--rec-success);
}
.hist-receipt-pct {
  font-size: 11px;
  font-weight: 700;
  color: var(--rec-primary);
  background: #eff6ff;
  padding: 2px 7px;
  border-radius: 20px;
}
.hist-receipt-status {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
}
.hist-receipt-status--emitido {
  background: #dcfce7;
  color: var(--rec-success);
}
.hist-receipt-status--cancelado {
  background: #fef2f2;
  color: var(--rec-danger);
}

.hist-receipt-actions {
  display: flex;
  gap: 6px;
}
.hist-action-btn {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  transition: background .15s;
  font-family: inherit;
}
.hist-action-btn--pdf {
  background: #eff6ff;
  color: var(--rec-primary);
}
.hist-action-btn--pdf:hover { background: #dbeafe; }
.hist-action-btn--cancel {
  background: #fef2f2;
  color: var(--rec-danger);
}
.hist-action-btn--cancel:hover { background: #fee2e2; }

/* Estado vazio do histórico */
.hist-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--rec-gray-400);
}
.hist-empty i {
  font-size: 40px;
  margin-bottom: 12px;
  display: block;
  color: var(--rec-gray-200);
}
.hist-empty p { font-size: 14px; margin: 0 0 16px; }

/* ================================================================
   7. BOTÃO HISTÓRICO DE RECIBOS na tabela de orçamentos
   ================================================================ */
.btn-receipt-history {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--rec-primary);
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: 7px;
  cursor: pointer;
  transition: background .15s;
  white-space: nowrap;
  font-family: inherit;
}
.btn-receipt-history:hover { background: #dbeafe; }

/* ================================================================
   8. MODAIS — BOTÕES PADRÃO (reutilizando estilo do app)
   ================================================================ */
.btn-rec {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 20px;
  font-size: 13.5px;
  font-weight: 600;
  font-family: inherit;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  transition: background .15s, transform .1s, box-shadow .15s;
  white-space: nowrap;
}
.btn-rec:active { transform: scale(.97); }

.btn-rec--primary {
  background: var(--rec-success);
  color: #fff;
  box-shadow: 0 2px 8px rgba(22,163,74,.3);
}
.btn-rec--primary:hover {
  background: #15803d;
  box-shadow: 0 4px 14px rgba(22,163,74,.4);
}
.btn-rec--primary:disabled {
  opacity: .6;
  cursor: not-allowed;
  transform: none;
}

.btn-rec--ghost {
  background: var(--rec-gray-100);
  color: var(--rec-gray-600);
}
.btn-rec--ghost:hover { background: var(--rec-gray-200); }

.btn-rec--danger {
  background: #fef2f2;
  color: var(--rec-danger);
  border: 1px solid #fecaca;
}
.btn-rec--danger:hover { background: #fee2e2; }

/* Spinner de carregamento */
.btn-rec .rec-spinner {
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: recSpin .7s linear infinite;
  display: none;
}
.btn-rec--loading .rec-spinner { display: inline-block; }
.btn-rec--loading .rec-btn-text { opacity: .6; }
@keyframes recSpin { to { transform: rotate(360deg); } }

/* ================================================================
   9. TOAST / NOTIFICAÇÕES — reutiliza showToast do app.js
   ================================================================ */

/* ================================================================
   10. RESPONSIVO
   ================================================================ */
@media (max-width: 700px) {
  .receipt-modal-box,
  .history-modal-box,
  .bank-modal-box {
    max-width: 100%;
    border-radius: 20px 20px 0 0;
    max-height: 96vh;
    margin-top: auto;
  }

  .receipt-modal-overlay,
  .history-modal-overlay,
  .bank-modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .receipt-modal-header { border-radius: 20px 20px 0 0; }
  .history-modal-header { border-radius: 20px 20px 0 0; }
  .bank-modal-header    { border-radius: 18px 18px 0 0; }

  .receipt-modal-body  { padding: 18px 18px; }
  .history-modal-body  { padding: 18px 18px; }
  .bank-modal-body     { padding: 18px 18px; }

  .receipt-modal-footer { padding: 12px 18px 16px; flex-direction: column; }
  .receipt-modal-footer .btn-rec { width: 100%; }
  .bank-modal-footer    { padding: 12px 18px 16px; flex-direction: column; }
  .bank-modal-footer .btn-rec { width: 100%; }

  .rec-form-grid        { grid-template-columns: 1fr; }
  .rec-form-grid--3     { grid-template-columns: 1fr 1fr; }
  .rec-estimate-summary { grid-template-columns: 1fr 1fr; }

  .hist-billing-summary {
    grid-template-columns: 1fr 1fr;
  }

  .hist-receipt-item { flex-wrap: wrap; }
  .hist-receipt-right { flex-direction: row; align-items: center; }

  .rec-bank-selector { flex-direction: column; align-items: stretch; }
  .btn-rec-add-bank  { justify-content: center; }
}

@media (max-width: 480px) {
  .rec-form-grid--3     { grid-template-columns: 1fr; }
  .hist-billing-summary { grid-template-columns: 1fr; }
  .rec-estimate-summary { grid-template-columns: 1fr; }
}

/* ================================================================
   11. ANIMAÇÕES UTILITÁRIAS
   ================================================================ */
.rec-fade-in {
  animation: recFadeIn .25s ease;
}
@keyframes recFadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* Highlight do campo percentual ao alterar */
.rec-pct-highlight {
  animation: recPctPulse .5s ease;
}
@keyframes recPctPulse {
  0%   { box-shadow: 0 0 0 0   rgba(22,163,74,.4); }
  50%  { box-shadow: 0 0 0 8px rgba(22,163,74,.1); }
  100% { box-shadow: 0 0 0 0   rgba(22,163,74,0);  }
}
