/* BeeBot — Operacional · Cobranças no visual da Central (redesenho U4). Servido estático em /ui/cobrancas.css.
   Só forma: os mesmos ids, funções e chamadas à API do painel; aqui só cores, espaços, tipos de letra e o layout em
   cartões no telemóvel. Os filtros, os botões e o modal usam as classes do operacional.css (op-filtros, op-acoes,
   op-perigo, op-modal, op-gaveta); tudo o que é novo fica dentro de #op-tab-cobrancas ou do #modal-cob-detalhe. */

/* Duas cores só das Cobranças (o "A confirmar" e o "Comprovante" já tinham cor própria), feitas dos tokens da Central */
#op-tab-cobrancas, #modal-cob-detalhe {
  --cob-violeta: color-mix(in srgb, var(--sky) 50%, var(--flare));
  --cob-violeta-soft: color-mix(in srgb, var(--cob-violeta) 14%, transparent);
  --cob-laranja: color-mix(in srgb, var(--honey) 55%, var(--flare));
  --cob-laranja-soft: color-mix(in srgb, var(--cob-laranja) 14%, transparent);
}

/* ── Placar: pendente (vermelho) e recebido (verde), como os painéis da Central ─────────────────────────── */
#op-tab-cobrancas .cob-placar { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
#op-tab-cobrancas .cob-risco, #op-tab-cobrancas .cob-pago-banner { background: var(--surface); border: 1px solid var(--line); border-radius: 14px;
  padding: 16px 18px; margin: 0; }
#op-tab-cobrancas .cob-risco { box-shadow: inset 4px 0 0 var(--flare); }
#op-tab-cobrancas .cob-pago-banner { box-shadow: inset 4px 0 0 var(--turf); }
#op-tab-cobrancas .cob-pago-cab { display: flex; align-items: center; gap: 13px; }
#op-tab-cobrancas .cob-risco-ico, #op-tab-cobrancas .cob-pago-ico { width: 40px; height: 40px; border-radius: 11px; font-size: 20px; }
#op-tab-cobrancas .cob-risco-ico { background: var(--flare-soft); color: var(--flare); }
#op-tab-cobrancas .cob-pago-ico { background: var(--turf-soft); color: var(--turf); }
#op-tab-cobrancas .cob-risco-val, #op-tab-cobrancas .cob-pago-val { font-family: var(--num); font-variant-numeric: tabular-nums; font-size: 34px; font-weight: 700; line-height: 1; }
#op-tab-cobrancas .cob-risco-val { color: var(--flare); }
#op-tab-cobrancas .cob-pago-val { color: var(--turf); }
#op-tab-cobrancas .cob-risco-lbl, #op-tab-cobrancas .cob-pago-lbl { font-size: 13px; font-weight: 600; color: var(--muted); margin-top: 5px; }
#op-tab-cobrancas .cob-pago-filtro .bb-input { height: 34px; border-radius: 10px; background: var(--surface-2); border-color: var(--line); }
#op-tab-cobrancas .cob-seta { color: var(--faint); }

/* ── Cartões por estado (o mesmo cardResumo do Operacional) ────────────────────────────────────────────── */
#cob-resumo { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
#cob-resumo .bb-stat { border-radius: 14px; background: var(--surface); border-color: var(--line); padding: 12px 14px; }
#cob-resumo .bb-stat:hover { border-color: var(--line-strong); }
#cob-resumo .bb-stat.active { border-color: var(--honey-bright); box-shadow: inset 0 0 0 1px var(--honey-bright); }
#cob-resumo .bb-stat-top { margin-bottom: 6px; gap: 8px; }
#cob-resumo .bb-stat-icon { width: 26px; height: 26px; border-radius: 8px; font-size: 15px; }
#cob-resumo .bb-stat-label { font-size: 12.5px; font-weight: 600; color: var(--muted); }
#cob-resumo .bb-stat-value { font-family: var(--num); font-variant-numeric: tabular-nums; font-size: 30px; font-weight: 700; line-height: 1.05; }
#cob-resumo .bb-stat-bar { height: 4px; background: var(--steel-soft); margin-top: 8px; }

/* ── Filtros (op-filtros do Operacional) ───────────────────────────────────────────────────────────────── */
#op-tab-cobrancas .cob-filtros .bb-select { min-width: 160px; }
#op-tab-cobrancas #cob-sync-status { font-size: 12.5px; color: var(--muted); align-self: center; }

/* ── Barra de selecção: escura, presa ao topo (o JS põe display:flex) ──────────────────────────────────── */
#cob-bulk-bar { position: sticky; top: 8px; z-index: 5; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 14px; padding: 10px 14px;
  background: var(--text); color: var(--bg); border: 0; border-radius: 14px; box-shadow: var(--shadow); }
#cob-bulk-bar .bulk-count { background: transparent; border: 0; color: var(--bg); padding: 0 4px; font-weight: 700; }
#cob-bulk-bar .bb-btn { background: transparent; color: var(--bg); border-color: color-mix(in srgb, var(--bg) 30%, transparent); }
#cob-bulk-bar .bb-btn:hover { background: color-mix(in srgb, var(--bg) 12%, transparent); color: var(--bg); }
#cob-bulk-bar .op-perigo { color: color-mix(in srgb, var(--flare) 70%, var(--bg)); }
#cob-bulk-bar .cob-bulk-limpar { margin-left: auto; background: var(--bg); color: var(--text); border-color: var(--bg); }
#cob-bulk-bar .cob-bulk-limpar:hover { background: var(--bg); color: var(--text); filter: brightness(.95); }

/* ── Lista ─────────────────────────────────────────────────────────────────────────────────────────────── */
#op-tab-cobrancas .cob-lista { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
#op-tab-cobrancas .cob-lista-tit { font-family: var(--bb-font-head); font-size: 15px; font-weight: 800; padding: 14px 16px 6px; }
#op-tab-cobrancas #cob-tabela .empty { padding: 40px 18px; }
#op-tab-cobrancas .cob-carregando { color: var(--muted); padding: 20px 16px; font-size: 13px; }
#op-tab-cobrancas .cob-erro { color: var(--flare); padding: 16px; font-size: 13px; }
#op-tab-cobrancas .cob-tabela-wrap { overflow-x: auto; }
#op-tab-cobrancas .cob-t { font-size: 13px; }
#op-tab-cobrancas .cob-t thead th { font-family: var(--bb-font-body); font-size: 11.5px; font-weight: 700; letter-spacing: .04em; color: var(--faint);
  padding: 10px 12px; background: var(--surface); }
#op-tab-cobrancas .cob-t tbody td { padding: 10px 12px; border-bottom-color: var(--line); vertical-align: middle; }
#op-tab-cobrancas .cob-t tbody tr:hover > td { background: var(--surface-2); }
#op-tab-cobrancas .cob-t .cob-c-sel { width: 32px; }
#op-tab-cobrancas .cob-t tr.urgente > td { background: var(--flare-soft); }
#op-tab-cobrancas .cob-t tr.atencao > td { background: color-mix(in srgb, var(--honey-soft) 60%, transparent); }
#op-tab-cobrancas .cob-t tr.arq { opacity: .55; }
#op-tab-cobrancas .cob-ped { font-family: var(--bb-font-head); font-weight: 700; font-size: 14px; cursor: pointer; }
#op-tab-cobrancas .cob-ped:hover { color: var(--honey); text-decoration: underline; text-underline-offset: 3px; }
#op-tab-cobrancas .cob-cliente { font-size: 12px; color: var(--muted); margin-top: 2px; }
#op-tab-cobrancas .cob-tel { font-size: 11px; color: var(--faint); }
#op-tab-cobrancas .cob-c-valor { font-family: var(--num); font-variant-numeric: tabular-nums; font-size: 15px; font-weight: 700; white-space: nowrap; }
#op-tab-cobrancas .cob-c-pago { font-size: 12.5px; white-space: nowrap; }
#op-tab-cobrancas .cob-via-linha { margin-top: 4px; }
#op-tab-cobrancas .cob-c-acoes { white-space: nowrap; }

/* método e "pago via": pílulas neutras (o nome diz o método); "via" com a cor de quem confirmou */
#op-tab-cobrancas .cob-metodo, #modal-cob-detalhe .cob-metodo { border-radius: 999px; padding: 2px 9px; font-size: 11px; font-weight: 700;
  background: var(--steel-soft); color: var(--muted); }
#op-tab-cobrancas .cob-via.ivo { background: var(--sky-soft); color: var(--sky); }
#op-tab-cobrancas .cob-via.shopify { background: var(--turf-soft); color: var(--turf); }

/* estado: a cor do estado em pílula */
#op-tab-cobrancas .cob-estado, #modal-cob-detalhe .cob-estado { border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 700;
  background: var(--steel-soft); color: var(--muted); white-space: nowrap; }
#op-tab-cobrancas .cob-estado.st-contactado, #modal-cob-detalhe .cob-estado.st-contactado { background: var(--sky-soft); color: var(--sky); }
#op-tab-cobrancas .cob-estado.st-aguardando, #modal-cob-detalhe .cob-estado.st-aguardando { background: var(--honey-soft); color: var(--honey); }
#op-tab-cobrancas .cob-estado.st-comprovante, #modal-cob-detalhe .cob-estado.st-comprovante { background: var(--cob-laranja-soft); color: var(--cob-laranja); }
#op-tab-cobrancas .cob-estado.st-a_confirmar, #modal-cob-detalhe .cob-estado.st-a_confirmar { background: var(--cob-violeta-soft); color: var(--cob-violeta); }
#op-tab-cobrancas .cob-estado.st-ultima_tentativa, #modal-cob-detalhe .cob-estado.st-ultima_tentativa { background: var(--flare-soft); color: var(--flare); }
#op-tab-cobrancas .cob-estado.st-pago, #modal-cob-detalhe .cob-estado.st-pago { background: var(--turf-soft); color: var(--turf); }
#op-tab-cobrancas .cob-estado.st-cancelado, #modal-cob-detalhe .cob-estado.st-cancelado { background: var(--flare-soft); color: var(--flare); }

/* pipeline: feitas a verde, a actual com anel mel (como na Nutrição) */
#op-tab-cobrancas .cob-step { width: 24px; height: 24px; background: var(--surface-2); border-color: var(--line); color: var(--faint); }
#op-tab-cobrancas .cob-step.done { background: var(--turf-soft); border-color: var(--turf-line); color: var(--turf); }
#op-tab-cobrancas .cob-step.now { background: var(--honey-soft); border-color: var(--honey-bright); color: var(--honey); }
#op-tab-cobrancas .cob-step.now::after { border-color: var(--honey-bright); }

/* tempo */
#op-tab-cobrancas .cob-tempo { font-size: 12.5px; color: var(--muted); white-space: nowrap; }
#op-tab-cobrancas .cob-tempo.urgente { color: var(--flare); font-weight: 700; }
#op-tab-cobrancas .cob-tempo.atencao, #op-tab-cobrancas .cob-tempo.novo { color: var(--honey); font-weight: 700; }

/* acções */
#op-tab-cobrancas .cob-t .cel-acoes { align-items: center; }
#op-tab-cobrancas .cob-t .bb-btn-sm { border-radius: 8px; }
#op-tab-cobrancas .cob-t .cob-ok { color: var(--turf); border-color: var(--turf-line); }
#op-tab-cobrancas .cob-t .acao-btn { width: 30px; height: 30px; border-radius: 8px; background: var(--surface); border-color: var(--line); color: var(--muted); }
#op-tab-cobrancas .cob-t .acao-btn:hover { color: var(--text); border-color: var(--line-strong); }
#op-tab-cobrancas .cob-t .acao-btn.danger { color: var(--flare); }
/* o "Copiar script" é um bb-btn-sm só com ícone (e title): o mesmo quadrado dos acao-btn */
#op-tab-cobrancas .cob-t .bb-btn-sm[title] { width: 30px; height: 30px; padding: 0; justify-content: center; }

/* ── Detalhe da cobrança: painel lateral, como o detalhe do pedido; os mesmos campos e botões ───────────── */
#modal-cob-detalhe.op-gaveta { justify-content: flex-end; align-items: stretch; }
#modal-cob-detalhe .op-modal { width: min(480px, 100vw); max-height: none; height: 100%; border-radius: 0; border-width: 0 0 0 1px;
  display: flex; flex-direction: column; overflow-y: auto; }
#modal-cob-detalhe .op-modal .modal-actions { position: sticky; bottom: -20px; background: var(--surface); margin-top: auto; }
#modal-cob-detalhe #cob-modal-info { font-size: 13.5px; line-height: 1.9; margin-bottom: 12px; }
#modal-cob-detalhe #cob-modal-info b { display: inline-block; min-width: 76px; font-weight: 600; color: var(--muted); }
#modal-cob-detalhe #cob-modal-historico { font-size: 12.5px; line-height: 1.8; color: var(--muted); background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 8px 12px; margin-bottom: 14px; }
#modal-cob-detalhe .form-group { margin-bottom: 12px; }
#modal-cob-detalhe #cob-modal-script { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; font-size: 13px;
  line-height: 1.6; white-space: pre-wrap; margin-bottom: 4px; }

/* ── Telemóvel: placar empilhado, a tabela vira cartões (os mesmos campos, com o nome à esquerda) ───────── */
@media (max-width: 760px) {
  #op-tab-cobrancas .cob-placar { grid-template-columns: 1fr; }
  #op-tab-cobrancas .cob-risco-val, #op-tab-cobrancas .cob-pago-val { font-size: 28px; }
  /* as duas datas numa linha; a lupa e o "Hoje" por baixo, cada um debaixo da sua data */
  #op-tab-cobrancas .cob-pago-filtro { width: 100%; display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); gap: 8px; }
  #op-tab-cobrancas .cob-pago-filtro .bb-input { width: 100%; min-width: 0; height: 40px; font-size: 16px; }
  #op-tab-cobrancas .cob-pago-filtro .bb-btn { grid-row: 2; height: 40px; justify-content: center; }
  #op-tab-cobrancas .cob-pago-filtro .bb-btn:nth-of-type(1) { grid-column: 1; }
  #op-tab-cobrancas .cob-pago-filtro .bb-btn:nth-of-type(2) { grid-column: 3; }
  #op-tab-cobrancas .cob-filtros .bb-select { min-width: 0; }
  #cob-resumo { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  #cob-resumo .bb-stat-value { font-size: 26px; }
  #cob-bulk-bar { top: 4px; }
  #op-tab-cobrancas .cob-lista { background: transparent; border: 0; overflow: visible; }
  #op-tab-cobrancas .cob-lista-tit { padding: 4px 2px 10px; }
  #op-tab-cobrancas .cob-tabela-wrap { overflow: visible; }
  #op-tab-cobrancas .cob-t thead { display: none; }
  #op-tab-cobrancas .cob-t, #op-tab-cobrancas .cob-t > tbody { display: block; }
  #op-tab-cobrancas .cob-t tr.cob-row { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 8px 10px; align-items: center; padding: 12px;
    margin-bottom: 10px; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; }
  #op-tab-cobrancas .cob-t tr.cob-row > td { display: block; padding: 0; border: 0; background: none !important; }
  #op-tab-cobrancas .cob-t tr.urgente { background: var(--flare-soft); border-color: var(--flare-line); }
  #op-tab-cobrancas .cob-t tr.atencao { background: color-mix(in srgb, var(--honey-soft) 60%, var(--surface)); border-color: var(--honey-line); }
  #op-tab-cobrancas .cob-t td[data-l] { grid-column: 1 / -1; display: flex !important; align-items: center; gap: 10px; min-width: 0; }
  #op-tab-cobrancas .cob-t td[data-l]::before { content: attr(data-l); flex: none; width: 84px; font-size: 11px; font-weight: 700; color: var(--faint);
    text-transform: uppercase; letter-spacing: .03em; }
  #op-tab-cobrancas .cob-t td.cob-c-pago { flex-wrap: wrap; }
  #op-tab-cobrancas .cob-t td.cob-c-pago .cob-via-linha { margin: 0; }
  #op-tab-cobrancas .cob-t td.cob-c-acoes { grid-column: 1 / -1; padding-top: 10px; border-top: 1px solid var(--line); white-space: normal; }
  #op-tab-cobrancas .cob-t td.cob-c-acoes .cel-acoes { flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
  #op-tab-cobrancas .cob-t td.cob-c-acoes .acao-btn, #op-tab-cobrancas .cob-t td.cob-c-acoes .bb-btn-sm[title] { width: 40px; height: 40px; font-size: 17px; }
  #op-tab-cobrancas .cob-t td.cob-c-acoes .bb-btn-sm { height: 40px; padding: 0 12px; font-size: 13.5px; }
  #modal-cob-detalhe .op-modal { width: 100vw; border-width: 0; }
  #modal-cob-detalhe .op-modal .form-group input, #modal-cob-detalhe .op-modal .op-area { font-size: 16px; }
}
