/* Painel de Operações SCM — Agentes IA
   Direção visual: "instrumento de engenharia de telecom".
   Paleta da marca (laranja #F07800 / cinza #B0B0B0) como sinal vivo sobre papel técnico claro. */

@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=IBM+Plex+Sans:wght@400;500;600&family=IBM+Plex+Mono:wght@400;500;600&display=swap');

:root {
  /* marca */
  --scm-orange: #f07800;
  --scm-orange-deep: #c95e00;   /* texto/borda laranja com contraste AA sobre claro */
  --scm-orange-wash: #fdf0e3;   /* preenchimento tênue */
  --scm-gray: #b0b0b0;

  /* superfícies — papel técnico levemente quente */
  --paper: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f4f2ee;
  --ink: #1c1a17;
  --graphite: #5c5a54;
  --graphite-soft: #8b887f;
  --line: #e8e4dc;
  --line-strong: #d8d3c8;

  /* sinais semânticos */
  --ok: #1f8a4c;
  --ok-wash: #e9f5ee;
  --err: #d23b2e;
  --err-wash: #fcecea;
  --signal: #2f6fb0;        /* chamada de ferramenta (aço) */
  --signal-wash: #eaf1f8;

  --r: 10px;
  --r-sm: 7px;
  --shadow: 0 1px 2px rgba(28,26,23,.05), 0 8px 24px -16px rgba(28,26,23,.25);
  --shadow-soft: 0 1px 2px rgba(28,26,23,.04);
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  font-family: "IBM Plex Sans", -apple-system, system-ui, sans-serif;
  color: var(--ink);
  background: var(--paper);
  display: flex; flex-direction: column;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; }
.mono { font-family: "IBM Plex Mono", ui-monospace, monospace; }

/* ---------- header ---------- */
header {
  display: flex; align-items: center; gap: 18px;
  padding: 12px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.logo { height: 30px; width: auto; display: block; }
.header-sep { width: 1px; height: 30px; background: var(--line-strong); }
.header-id { display: flex; flex-direction: column; gap: 1px; }
.header-id .eyebrow {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px; letter-spacing: .14em; text-transform: uppercase;
  color: var(--graphite-soft);
}
.header-id h1 {
  font-family: "Space Grotesk", sans-serif;
  font-size: 16px; font-weight: 600; letter-spacing: -.01em; color: var(--ink);
}
.status { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.pill {
  display: inline-flex; align-items: center; gap: 7px;
  font-family: "IBM Plex Mono", monospace;
  font-size: 11px; font-weight: 500;
  padding: 6px 11px; border-radius: 999px;
  background: var(--surface-2); color: var(--graphite);
  border: 1px solid var(--line);
}
.pill .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--scm-gray); flex: none; }
.pill.ok .dot { background: var(--ok); }
.pill.err .dot { background: var(--err); }
.pill.err { color: var(--err); border-color: #f3cfca; background: var(--err-wash); }
.pill.modelo { color: var(--scm-orange-deep); background: var(--scm-orange-wash); border-color: #f6d9bd; }

/* ---------- layout ---------- */
main {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr) minmax(0, 1.15fr);
}
aside, .col { min-height: 0; display: flex; flex-direction: column; }
aside, #chat { border-right: 1px solid var(--line); }

/* títulos de coluna */
.col-head {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; min-height: 46px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.col-head .chev { color: var(--scm-orange); flex: none; }
.col-head .titulo {
  font-family: "Space Grotesk", sans-serif;
  font-size: 12.5px; font-weight: 600; letter-spacing: .02em;
  text-transform: uppercase; color: var(--graphite);
}

/* ---------- sidebar ---------- */
#sidebar { background: var(--surface); padding: 14px; gap: 14px; overflow-y: auto; }
.campo { display: flex; flex-direction: column; gap: 6px; }
.campo > span {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--graphite-soft);
}
select, input[type=text] {
  font-family: inherit; font-size: 14px; color: var(--ink);
  padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--surface); width: 100%;
}
select:focus, input[type=text]:focus {
  outline: none; border-color: var(--scm-orange);
  box-shadow: 0 0 0 3px var(--scm-orange-wash);
}
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font-size: 13.5px; font-weight: 500; cursor: pointer;
  padding: 9px 14px; border-radius: var(--r-sm); border: 0;
  background: var(--scm-orange); color: #fff;
  transition: background .15s ease, transform .05s ease;
}
.btn:hover { background: var(--scm-orange-deep); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: wait; }

.bloco-titulo {
  font-family: "IBM Plex Mono", monospace;
  font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--graphite-soft);
  padding-bottom: 2px;
}
#lista-conversas { display: flex; flex-direction: column; gap: 4px; }
.conv-item {
  display: flex; flex-direction: column; gap: 3px;
  padding: 9px 11px; border-radius: var(--r-sm); cursor: pointer;
  border: 1px solid transparent; transition: background .12s ease, border-color .12s ease;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.ativa { background: var(--scm-orange-wash); border-color: #f3d3b3; }
.conv-item .nome { font-size: 13.5px; font-weight: 500; color: var(--ink); }
.conv-item .meta {
  font-family: "IBM Plex Mono", monospace; font-size: 11px; color: var(--graphite-soft);
  display: flex; align-items: center; gap: 6px;
}
.badge {
  font-size: 9.5px; letter-spacing: .05em; text-transform: uppercase;
  padding: 1px 6px; border-radius: 999px; font-weight: 600;
}
.badge.ativa { background: var(--ok-wash); color: var(--ok); }
.badge.handoff { background: var(--scm-orange-wash); color: var(--scm-orange-deep); }
.badge.encerrada { background: var(--surface-2); color: var(--graphite-soft); }

.ref { margin-top: auto; border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.ref .linha { font-size: 12px; line-height: 1.35; }
.ref .linha .nome { font-weight: 600; color: var(--ink); }
.ref .linha .cpf { font-family: "IBM Plex Mono", monospace; color: var(--scm-orange-deep); font-size: 11.5px; }
.ref .linha .sit { color: var(--graphite-soft); font-size: 11px; }

/* ---------- chat ---------- */
#chat { background: var(--paper); }
.col-head .tag-handoff {
  margin-left: auto;
  font-family: "IBM Plex Mono", monospace; font-size: 10.5px; letter-spacing: .04em;
  background: var(--scm-orange-wash); color: var(--scm-orange-deep);
  padding: 4px 10px; border-radius: 999px; border: 1px solid #f3d3b3;
}
.oculto { display: none !important; }

#mensagens { flex: 1; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.vazio {
  margin: auto; text-align: center; color: var(--graphite-soft);
  display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: 260px;
}
.vazio .chev-grande { color: var(--line-strong); }
.vazio p { font-size: 13.5px; line-height: 1.5; }

.linha-msg { display: flex; gap: 9px; align-items: flex-end; max-width: 82%; }
.linha-msg.user { align-self: flex-end; flex-direction: row-reverse; }
.linha-msg.bot { align-self: flex-start; }
.avatar {
  width: 26px; height: 26px; border-radius: 7px; flex: none;
  display: grid; place-items: center;
  background: var(--scm-orange-wash); color: var(--scm-orange); border: 1px solid #f3d3b3;
}
.bolha {
  padding: 9px 13px; border-radius: 12px; font-size: 14px; line-height: 1.5;
  white-space: pre-wrap; word-break: break-word; box-shadow: var(--shadow-soft);
}
.bolha.bot { background: var(--surface); border: 1px solid var(--line); border-bottom-left-radius: 3px; }
.bolha.user { background: #e7f3e4; border: 1px solid #cfe6c9; border-bottom-right-radius: 3px; }
.bolha.mono-bolha {
  font-family: "IBM Plex Mono", monospace; font-size: 12px; background: var(--ink); color: #f3efe7;
  border: 0; letter-spacing: -.01em;
}
.bolha.digitando { color: var(--graphite-soft); font-style: italic; }
.bolha.digitando::after {
  content: "●●●"; letter-spacing: 2px; margin-left: 2px;
  animation: pulso 1.1s ease-in-out infinite;
}

#form-chat { display: flex; gap: 9px; padding: 13px; background: var(--surface); border-top: 1px solid var(--line); }

/* ---------- timeline (assinatura: "trace" do agente) ---------- */
#fluxo { background: var(--surface); }
.col-head .live {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px;
  font-family: "IBM Plex Mono", monospace; font-size: 10.5px; letter-spacing: .08em;
  color: var(--scm-orange-deep);
}
.col-head .live .dot {
  width: 7px; height: 7px; border-radius: 50%; background: var(--scm-orange);
  animation: pulso 1.1s ease-in-out infinite;
}
#timeline { flex: 1; overflow-y: auto; padding: 16px 18px 24px; position: relative; }
#timeline.vazio-estado { display: grid; place-items: center; }

/* a linha vertical do trace */
.trace { position: relative; padding-left: 26px; }
.trace::before {
  content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px;
  width: 2px; background: var(--line); border-radius: 2px;
}
.evento {
  position: relative; padding: 4px 0 12px; cursor: pointer;
}
.evento::before {        /* marcador na linha */
  content: ""; position: absolute; left: -22px; top: 8px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--scm-gray);
  box-shadow: 0 0 0 3px var(--surface);
}
.evento .hora {
  font-family: "IBM Plex Mono", monospace; font-size: 10.5px; color: var(--graphite-soft);
}
.evento .rotulo {
  font-family: "Space Grotesk", sans-serif; font-weight: 600; font-size: 13px; color: var(--ink);
  display: flex; align-items: center; gap: 6px; margin-top: 1px;
}
.evento .resumo {
  font-family: "IBM Plex Mono", monospace; font-size: 11.5px; color: var(--graphite);
  margin-top: 2px; line-height: 1.4; word-break: break-word;
}
.evento pre {
  display: none; margin-top: 7px;
  font-family: "IBM Plex Mono", monospace; font-size: 11px; line-height: 1.5;
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 9px 11px; overflow-x: auto; white-space: pre-wrap; color: var(--graphite);
}
.evento.aberto pre { display: block; }
.evento .check { font-size: 12px; font-weight: 700; }

/* cores por tipo (significado funcional, não decoração) */
.tipo-msg_recebida::before { border-color: var(--graphite-soft); }
.tipo-ia_chamada::before   { border-color: var(--scm-orange); }
.tipo-ia_resposta::before, .tipo-msg_enviada::before { border-color: var(--ok); background: var(--ok); }
.tipo-tool_chamada::before { border-color: var(--signal); }
.tipo-tool_resultado::before { border-color: var(--ok); background: var(--ok); }
.tipo-handoff::before { border-color: var(--scm-orange); background: var(--scm-orange); }
.evento.erro::before { border-color: var(--err); background: var(--err); }
.tipo-tool_resultado .check, .tipo-ia_resposta .check, .tipo-msg_enviada .check { color: var(--ok); }
.evento.erro .rotulo { color: var(--err); }
.evento.erro .check { color: var(--err); }
.tipo-tool_chamada .rotulo, .tipo-tool_resultado .rotulo { color: var(--signal); }
.tipo-handoff .rotulo { color: var(--scm-orange-deep); }

/* ---------- animações ---------- */
@keyframes pulso { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes surge { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.evento, .linha-msg { animation: surge .22s ease both; }

/* ---------- responsivo ---------- */
@media (max-width: 1100px) {
  main { grid-template-columns: 210px minmax(0,1fr); }
  #fluxo { display: none; }   /* foco no chat em telas estreitas */
}
@media (prefers-reduced-motion: reduce) {
  *, ::before, ::after { animation: none !important; transition: none !important; }
}

/* acessibilidade */
:focus-visible { outline: 2px solid var(--scm-orange); outline-offset: 2px; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-strong); border-radius: 6px; border: 3px solid var(--surface); }
::-webkit-scrollbar-thumb:hover { background: var(--scm-gray); }
