/* ============================================================
   Estaleiro · components.css · shell (spine+nav+topbar), modal,
   bottom tab bar mobile. Tudo via tokens.css.
   ============================================================ */

/* ---------- shell ---------- */
.shell {
  display: grid;
  grid-template-columns: var(--spine-w) var(--nav-w) 1fr;
  min-height: 100vh;
  background: var(--surface);
}
.shell.nonav { grid-template-columns: var(--spine-w) 1fr; }

/* ---------- brand spine ---------- */
.spine {
  background: var(--spine);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0;
  gap: 7px;
  position: sticky;
  top: 0;
  height: 100vh;
  /* sticky cria stacking context: sem z-index, a nav (irmã seguinte) pintava
     por cima dos tooltips das marcas (.bm::after) e escondia-os */
  z-index: 40;
}
.spine .all {
  font: 10px var(--f-m);
  color: var(--text-2);
  padding: 4px 0;
  cursor: pointer;
  border: none;
  background: none;
}
.spine .all.active { color: var(--amber); font-weight: 500; }
.bm {
  width: 34px;
  height: 34px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font: 700 13px var(--f-d);
  position: relative;
  cursor: pointer;
  border: 1px solid var(--border);
  color: var(--text-2);
  background: var(--surface);
  box-shadow: inset 0 -2.5px 0 var(--brand, var(--text-3));
}
.bm::after {
  content: attr(data-name);
  position: absolute;
  left: 46px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--text);
  color: var(--bg);
  font: 500 11px var(--f-b);
  padding: 4px 9px;
  border-radius: var(--r-ctl);
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-sel) var(--ease-out);
  z-index: 30;
}
.bm:hover::after { opacity: 1; }
.bm.active { border-color: var(--border-strong); color: var(--text); }
.bm.active::before {
  content: "";
  position: absolute;
  left: -13px;
  top: 4px;
  bottom: 4px;
  width: 3px;
  background: var(--amber);
  border-radius: 2px;
}
.bm .n {
  position: absolute;
  top: -5px;
  right: -6px;
  font: 600 9.5px var(--f-m);
  background: var(--amber);
  color: var(--amber-ink);
  border-radius: 999px;
  padding: 0 4px;
  min-width: 14px;
  text-align: center;
}
.bm .n.red { background: var(--zarcao); color: var(--surface); }
@keyframes pulse-once { 0% { transform: scale(1); } 40% { transform: scale(1.25); } 100% { transform: scale(1); } }
.bm .n.red.fresh { animation: pulse-once 600ms var(--ease-out) 1; }
.spine .foot {
  margin-top: auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  font: 600 12px var(--f-b);
  color: var(--text-2);
  cursor: pointer;
  border: none;
}

/* ---------- nav ---------- */
.nav {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 1px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.nav .sect {
  font: 9.5px var(--f-m);
  letter-spacing: .14em;
  color: var(--text-3);
  margin: 12px 8px 4px;
  text-transform: uppercase;
}
.nav .sect:first-child { margin-top: 2px; }
.nav a {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  text-decoration: none;
  padding: 7px 10px;
  border-radius: var(--r-ctl);
  font: 500 13px var(--f-b);
  cursor: pointer;
}
.nav a:hover { background: var(--surface-2); text-decoration: none; }
.nav a.on { background: var(--surface-2); color: var(--text); box-shadow: inset 2px 0 0 var(--amber); }
.nav a .b {
  margin-left: auto;
  font: 600 10.5px var(--f-m);
  background: var(--amber);
  color: var(--amber-ink);
  border-radius: 999px;
  padding: 0 6px;
}
.nav a .b.red { background: var(--zarcao); color: var(--surface); }
.nav .foot { margin-top: auto; font: 11px var(--f-m); color: var(--text-3); padding: 8px 10px; }
.nav .foot button { border: none; background: none; font: inherit; color: inherit; cursor: pointer; padding: 0; }
.nav .foot button:hover { color: var(--text); }

/* ---------- main + topbar ---------- */
.main { padding: 20px 26px; overflow: auto; background: var(--bg); position: relative; min-width: 0; }
.top { display: flex; align-items: baseline; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.top .sync { font: 11px var(--f-m); color: var(--text-3); text-transform: uppercase; }
.top .sync i { display: inline-block; width: 6px; height: 6px; border-radius: 50%; background: var(--ok); margin-right: 5px; }
.top .sync.stale i { background: var(--warn); }

/* ---------- modal ---------- */
.modal-back {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 5, .35);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 28px 16px;
  z-index: 60;
  overflow: auto;
}
.modal {
  max-width: 1060px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-panel);
  overflow: hidden;
  /* excepção às regras de sombra: modais podem ter 1 sombra suave */
  box-shadow: 0 18px 50px rgba(20, 15, 5, .18);
  animation: modal-in var(--t-modal) var(--ease-out);
}
@keyframes modal-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal .brandbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  border-bottom: 2px solid var(--brand, var(--border-strong));
  background: var(--surface-2);
}
/* Indicador de trabalho da AI (ai-progress.js): barra indeterminada + rótulo. */
.ai-working { display: flex; flex-direction: column; gap: 6px; padding: 8px 2px; }
.ai-working .lbl {
  display: flex; align-items: center; gap: 8px;
  font: 500 11px var(--f-m); letter-spacing: .06em; text-transform: uppercase;
  color: var(--text-2);
}
.ai-working .lbl::before { content: '✦'; color: var(--amber); animation: ai-pulse 1.2s ease-in-out infinite; }
.ai-working .bar {
  height: 3px; border-radius: 2px; overflow: hidden; position: relative;
  background: var(--surface-2); border: 1px solid var(--border);
}
.ai-working .bar::after {
  content: ''; position: absolute; inset: 0; width: 38%; border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--amber), transparent);
  animation: ai-sweep 1.1s ease-in-out infinite;
}
@keyframes ai-sweep { from { transform: translateX(-110%); } to { transform: translateX(380%); } }
@keyframes ai-pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

/* Barra de rede global (core/api.js): qualquer request >250ms acende o topo. */
.net-bar {
  position: fixed; top: 0; left: 0; right: 0; height: 3px;
  z-index: 200; pointer-events: none; overflow: hidden;
  opacity: 0; transition: opacity .15s ease;
}
.net-bar.on { opacity: 1; }
.net-bar .sweep {
  position: absolute; inset: 0; width: 34%; border-radius: 2px;
  background: linear-gradient(90deg, transparent, var(--amber), transparent);
  animation: ai-sweep 1s ease-in-out infinite;
}

.modal .cols2 { display: grid; grid-template-columns: 1fr 1.15fr; }
.modal .cols2 > :first-child { border-right: 1px solid var(--border); }
/* edição de proposta: PDF à esquerda (maior), chat à direita */
.modal .cols2.edit-split { grid-template-columns: 1.3fr 1fr; }
.modal .align-warn {
  background: var(--amber-soft);
  border-top: 1px solid var(--amber-border);
  padding: 8px 16px;
  font-size: 12.5px;
  color: var(--warn);
}
.modal .foot { display: flex; gap: 8px; align-items: center; padding: 11px 16px; border-top: 1px solid var(--border); position: relative; }

/* popover (decision codes) */
.popover {
  position: absolute;
  bottom: 44px;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-panel);
  padding: 10px;
  width: 220px;
  z-index: 10;
}
.popover .opt {
  display: block;
  width: 100%;
  text-align: left;
  font: 12.5px var(--f-b);
  color: var(--text-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 5px 9px;
  background: var(--surface);
  cursor: pointer;
  margin-bottom: 4px;
}
.popover .opt:hover { background: var(--surface-2); color: var(--text); }

/* ---------- QA-16-07 · polish visual/UX (secção D) ---------- */

/* D1 · painel de contexto da inbox: conteúdo cru (headers, URLs, base64) tem de
   quebrar dentro do painel; e um filho do grid nunca pode empurrar a coluna para
   fora da sua fracção (min-width:0 desliga o min-width:auto do grid). */
.cols > * { min-width: 0; }
[data-preview] .q,
[data-preview] .fld b,
[data-preview] .fld span,
[data-preview] a { overflow-wrap: anywhere; }

/* D3 · a fila da inbox pode ter centenas de linhas; content-visibility salta o
   render/layout das linhas fora do ecrã sem mexer no DOM nem no JS (solução leve).
   Âmbito limitado à inbox (a página pesada); paginação real por DOM fica para uma
   pequena mudança no inbox.js (a coordenar com o agente que lhe está a mexer). */
[data-page="inbox"] .ledger .row { content-visibility: auto; contain-intrinsic-size: auto 62px; }

/* D7 · contagem discreta ao lado de um rótulo (pastas de enviados) */
.count-mut { font: 500 10.5px var(--f-m); color: var(--text-3); margin-left: 6px; }

/* D2 · carimbo de estado no canto de um painel (obras: relatório diário).
   Posição por defeito no desktop; no mobile passa a estático (ver media query). */
.panel-stamp { position: absolute; top: 14px; right: 16px; }

/* ---------- inbox: loading real + separação da dívida histórica ---------- */
.load-count {
  font: 500 .6875rem var(--f-m);
  color: var(--text-3);
  letter-spacing: .04em;
}
.ledger-section {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s-8);
  padding: var(--s-8) var(--s-16);
  border-bottom: 1px solid var(--border);
  font: 500 .625rem var(--f-m);
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--text-2);
  background: var(--surface-2);
}
.ledger-section b { font: inherit; color: var(--text); }
.ledger-section.history { color: var(--text-3); background: var(--bg); }
.history-row { opacity: .72; }
.history-row:hover, .history-row.sel { opacity: 1; }
.skeleton-ledger, .skeleton-panel { overflow: hidden; }
.skeleton-row { display: flex; flex-direction: column; gap: var(--s-8); pointer-events: none; }
.skeleton-line, .skeleton-block {
  border-radius: var(--r-ctl);
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
  background-size: 200% 100%;
  animation: skeleton-sweep 1.1s linear infinite;
}
.skeleton-line { width: 62%; height: .6875rem; }
.skeleton-line.wide { width: 86%; height: .875rem; }
.skeleton-line.short { width: 34%; }
.skeleton-block { width: 100%; height: 8rem; margin: var(--s-16) 0; }
@keyframes skeleton-sweep { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton-line, .skeleton-block { animation: none; } }

/* ---------- mobile: bottom tab bar (modo app) ---------- */
.tabbar { display: none; }
@media (max-width: 900px) {
  .shell, .shell.nonav { grid-template-columns: 1fr; }
  .spine, .nav { display: none; }
  .main { padding: 14px 16px calc(var(--touch-target) + 28px); }
  .cols, .modal .cols2, .modal .cols2.edit-split { grid-template-columns: 1fr; }
  .modal .cols2 > :first-child { border-right: none; border-bottom: 1px solid var(--border); }
  /* D2 · o modal de resposta fixa as colunas com style inline (grid-template-columns:
     1fr 1.15fr) que vencia a media query; forçar o empilhamento vertical no mobile. */
  .modal .cols2 { grid-template-columns: 1fr !important; }
  .modal .cols2 > :first-child { border-right: none !important; }
  /* D2 · tabs de fila (inbox/propostas) não cabem a 390px: scroll horizontal em vez
     de cortar na margem ou quebrar para 3 linhas. */
  .ltabs { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .ltabs span, .ltabs button { white-space: nowrap; flex: none; }
  /* D2 · carimbo de estado deixa de sobrepor o cabeçalho do relatório: entra no fluxo. */
  .panel-stamp { position: static; float: right; margin: 0 0 6px 8px; }
  .modal-back { padding: 0; }
  .modal { border-radius: 0; min-height: 100vh; }
  .tabbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    border-top: 1px solid var(--border-strong);
    background: var(--surface);
    z-index: 50;
  }
  .tabbar a {
    text-align: center;
    padding: 8px 0 10px;
    color: var(--text-2);
    text-decoration: none;
    min-height: var(--touch-target);
    position: relative;
  }
  .tabbar a.on { color: var(--amber); }
  .tabbar a .ic { font-size: 17px; line-height: 1.2; }
  .tabbar a .lb { font: 9.5px var(--f-m); text-transform: uppercase; }
  .tabbar a .n {
    position: absolute;
    top: 4px;
    right: 18%;
    background: var(--amber);
    color: var(--amber-ink);
    font: 600 8.5px var(--f-m);
    border-radius: 99px;
    padding: 0 4px;
  }
  .btn, .row { min-height: var(--touch-target); }
  .btn.sm { min-height: 0; }
}

/* Faixa de aviso ao topo de um ecra (degradacao de dados, reconciliacao
   pendente). Vivia num <style> inline do hoje.html; as paginas que a
   reutilizam (agenda, pipeline-valor) renderizavam-na sem estilo nenhum. */
.faixa {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--r-panel);
  margin-bottom: 14px;
  background: var(--surface);
}
.faixa.zarcao { border-color: var(--zarcao); }

/* ---------- Registar chamada (Wave 6A) ----------
   Modal estreito (formulario de uma coluna, nao um ecra de trabalho), chips de
   escolha unica, e o botao global do shell/tabbar. Sem sombras proprias, raio
   <= 8px, metadados em mono, e uma so accao primaria ambar no rodape. */
.cl-modal { max-width: 560px; }
.cl-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.cl-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.cl-lbl {
  display: block; margin: 10px 0 4px;
  font: 500 10px var(--f-m); letter-spacing: .1em; text-transform: uppercase; color: var(--text-3);
}
.cl-opt { text-transform: none; letter-spacing: 0; color: var(--text-3); font-weight: 400; }
.cl-in {
  width: 100%; box-sizing: border-box;
  font: 13.5px var(--f-b); color: var(--text-1);
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 9px;
}
.cl-in:focus-visible { outline: 2px solid var(--amber); outline-offset: 1px; }
.cl-chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  font: 500 12.5px var(--f-b); color: var(--text-2);
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 5px 11px; cursor: pointer;
}
.chip:hover { background: var(--surface-2); }
/* Selecção NÃO é âmbar: âmbar é acção humana pendente, não estado de escolha. */
.chip.on { border-color: var(--border-strong); color: var(--text-1); background: var(--surface-2); font-weight: 600; }
.chip:focus-visible { outline: 2px solid var(--amber); outline-offset: 1px; }
.cl-hint { font-size: 11px; color: var(--text-3); }
.cl-note {
  margin: 8px 0; padding: 8px 10px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface-2);
  font-size: 12.5px; color: var(--text-2);
}
.cl-note.warn { border-color: var(--amber-border); background: var(--amber-soft); }
.cl-err { margin: 6px 0 0; font-size: 12.5px; color: var(--zarcao); }
.cl-ia { margin: 10px 0; padding: 10px; border: 1px solid var(--border); border-radius: var(--r-panel); }

/* Botao global no rodape da nav (secundario, nunca ambar) e equivalente movel. */
.nav .foot .cl-global { display: block; width: 100%; margin-bottom: 6px; text-align: left; }
.cl-fab {
  display: none; position: fixed; right: 14px; bottom: 74px; z-index: 55;
  font: 600 12.5px var(--f-b); color: var(--text-1);
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 10px 14px; cursor: pointer;
}
@media (max-width: 860px) { .cl-fab { display: block; } }

/* Painel «Chamadas a retomar» no Hoje. */
.cl-linha {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 9px 4px; border-bottom: 1px solid var(--border);
}
.cl-linha:last-child { border-bottom: 0; }
.cl-linha .quando { font: 12px var(--f-m); color: var(--text-2); min-width: 96px }
.cl-linha.vencido .quando { color: var(--zarcao); font-weight: 600 }
