:root {
  --bg: #f5f6f8; --panel: #ffffff; --line: #e3e6eb; --text: #1d2330; --muted: #6b7385;
  --primary: #1f5eff; --primary-ink: #fff; --ok: #12805c; --warn: #b26a00; --bad: #c0352b;
  --in: #ffffff; --out-agent: #e7efff; --out-seller: #e6f6ee; --sys: #fff6e0;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --panel: #1a1e26; --line: #2a303b; --text: #e6e9ef; --muted: #98a0b0;
    --primary: #5b8cff; --in: #222833; --out-agent: #1f2c48; --out-seller: #1c3329; --sys: #3a321c;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.error { color: var(--bad); min-height: 1em; }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 16px 0 8px; }
a { color: var(--primary); }

input, select, textarea {
  font: inherit; color: inherit; background: var(--panel); border: 1px solid var(--line);
  border-radius: 8px; padding: 8px 10px; width: 100%;
}
textarea { resize: vertical; }
label { display: block; margin: 10px 0; font-weight: 500; }
label input, label select, label textarea { margin-top: 4px; font-weight: 400; }
.btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.danger { color: var(--bad); }
.btn.ghost { background: transparent; }
.btn.small { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.grid { display: grid; gap: 12px; }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

.login { display: grid; place-items: center; min-height: 100%; padding: 16px; }
.login-card { width: 100%; max-width: 360px; }
.login-card .btn { width: 100%; margin-top: 8px; }

.shell { display: grid; grid-template-columns: 210px 1fr; height: 100%; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 16px 10px; }
.brand { font-weight: 700; padding: 0 8px 16px; }
#nav a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; }
#nav a.active { background: var(--bg); font-weight: 600; }
.side-foot { margin-top: auto; display: grid; gap: 8px; padding: 8px; }
main { overflow: auto; padding: 20px; min-width: 0; }
.badge { background: var(--bad); color: #fff; border-radius: 10px; padding: 0 6px; font-size: 11px; }
.pill { display: inline-block; border-radius: 999px; padding: 1px 8px; font-size: 12px; background: var(--bg); border: 1px solid var(--line); }
.pill.novo { color: var(--muted); }
.pill.em_conversa { color: var(--primary); }
.pill.qualificado { color: var(--warn); }
.pill.agendado { color: var(--ok); }
.pill.perdido { color: var(--bad); }
.grade { font-weight: 700; font-size: 13px; border-radius: 6px; padding: 1px 7px; color: #fff; }
.grade.A { background: #12805c; } .grade.B { background: #3b7d2c; } .grade.C { background: #b26a00; }
.grade.D { background: #c85a17; } .grade.F { background: #c0352b; }

.conv { display: grid; grid-template-columns: 340px 1fr; gap: 12px; height: calc(100vh - 40px); }
.conv-list { display: flex; flex-direction: column; min-height: 0; padding: 0; }
.conv-list .filters { padding: 12px; border-bottom: 1px solid var(--line); display: grid; gap: 8px; }
.conv-items { overflow: auto; }
.conv-item { padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv-item:hover, .conv-item.active { background: var(--bg); }
.conv-item .top { display: flex; justify-content: space-between; gap: 8px; }
.conv-item .preview { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat { display: flex; flex-direction: column; min-height: 0; padding: 0; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.chat-msgs { flex: 1; overflow: auto; padding: 16px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 70%; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); white-space: pre-wrap; word-wrap: break-word; }
.msg.in { background: var(--in); align-self: flex-start; }
.msg.out.agente { background: var(--out-agent); align-self: flex-end; }
.msg.out.vendedor { background: var(--out-seller); align-self: flex-end; }
.msg .meta { font-size: 11px; color: var(--muted); margin-top: 4px; }
.chat-foot { border-top: 1px solid var(--line); padding: 10px; display: flex; gap: 8px; }
.chat-foot textarea { min-height: 42px; height: 42px; }
.empty { display: grid; place-items: center; color: var(--muted); height: 100%; padding: 24px; text-align: center; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; }
tr.click { cursor: pointer; } tr.click:hover { background: var(--bg); }
.table-wrap { overflow-x: auto; }

.kpi .n { font-size: 28px; font-weight: 700; }
.kpi .l { color: var(--muted); }
.bar { height: 10px; background: var(--bg); border-radius: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--primary); }
.score-row { display: grid; grid-template-columns: 180px 1fr 50px; gap: 10px; align-items: center; margin: 6px 0; }

.step { border-left: 3px solid var(--line); padding: 4px 0 4px 12px; margin: 12px 0; }
.step blockquote { margin: 6px 0; padding: 6px 10px; background: var(--bg); border-radius: 6px; font-style: italic; }
.prompt-editor { min-height: 420px; font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
pre.transcript { white-space: pre-wrap; max-height: 420px; overflow: auto; background: var(--bg); padding: 12px; border-radius: 8px; }

.notif-panel { position: fixed; left: 220px; bottom: 16px; width: 360px; max-height: 60vh; overflow: auto; z-index: 10; }
.notif { padding: 8px 0; border-bottom: 1px solid var(--line); }
.notif.unread { font-weight: 600; }
.toast { position: fixed; right: 16px; bottom: 16px; background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 8px; z-index: 20; max-width: 420px; }
.banner { padding: 10px 12px; border-radius: 8px; background: var(--sys); margin-bottom: 12px; }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; z-index: 30; padding: 16px; }
.modal { width: 100%; max-width: 480px; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { flex-direction: row; align-items: center; overflow-x: auto; padding: 8px 16px; border-right: 0; border-bottom: 1px solid var(--line); }
  .brand { display: none; }
  #nav { display: flex; }
  .side-foot { margin: 0 0 0 auto; display: flex; padding: 0; }
  #me { display: none; }
  main { padding: 12px 16px; }
  .conv { grid-template-columns: 1fr; height: auto; }
  .chat { min-height: 70vh; }
  .score-row { grid-template-columns: 110px 1fr 40px; }
  .notif-panel { left: 16px; right: 16px; width: auto; }
}
