/* ==========================================================================
   Chatbot — tema claro inspirado no macOS
   ========================================================================== */
:root {
  --bg: #f5f5f7;            /* fundo de janela */
  --panel: #ffffff;         /* cartões */
  --panel-2: #f5f5f7;       /* superfícies secundárias */
  --sidebar: rgba(236, 236, 240, .72);
  --text: #1d1d1f;
  --muted: #6e6e73;
  --border: rgba(0, 0, 0, .09);
  --border-strong: rgba(0, 0, 0, .16);
  --accent: #007aff;
  --accent-2: rgba(0, 122, 255, .10);
  --ok: #248a3d;  --ok-bg: rgba(52, 199, 89, .14);
  --warn: #b25000; --warn-bg: rgba(255, 149, 0, .15);
  --err: #d70015; --err-bg: rgba(255, 59, 48, .12);
  --radius: 12px;
  --shadow: 0 0 0 .5px rgba(0,0,0,.05), 0 1px 3px rgba(0,0,0,.06), 0 6px 16px rgba(0,0,0,.04);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Helvetica Neue", Inter, Roboto, Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }  /* nenhuma classe com display pode reexibir um elemento escondido */
html, body { max-width: 100%; overflow-x: hidden; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .5em; letter-spacing: -.01em; }
h1 { font-size: 1.6rem; font-weight: 700; }
h2 { font-size: 1.05rem; font-weight: 600; }
h3 { font-size: .95rem; font-weight: 600; }
.page-title { font-size: 1.6rem; font-weight: 700; margin-bottom: 18px; }
.muted { color: var(--muted); } .small { font-size: .82rem; }
code, .mono { font-family: var(--mono); font-size: .85em; }
code { background: var(--panel-2); padding: 1px 5px; border-radius: 4px; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 24px 20px 64px; }

/* ---------- barra de título (admin) ---------- */
.titlebar { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; height: 52px; display: flex; align-items: center; gap: 14px;
  padding: 0 16px; background: rgba(246, 246, 248, .8); backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px); border-bottom: 1px solid var(--border); }
.titlebar .title { font-weight: 600; font-size: .92rem; flex: 1; text-align: center; color: #3a3a3c;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.traffic { display: flex; gap: 8px; width: 120px; }
.traffic span { width: 12px; height: 12px; border-radius: 50%; background: #ff5f57; box-shadow: inset 0 0 0 .5px rgba(0,0,0,.15); }
.traffic span:nth-child(2) { background: #febc2e; } .traffic span:nth-child(3) { background: #28c840; }
.titlebar .btn { width: 120px; justify-content: center; }

/* ---------- janela: barra lateral + conteúdo ---------- */
.shell { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: calc(100vh - 52px); }
.sidebar { position: sticky; top: 52px; align-self: start; height: calc(100vh - 52px); overflow-y: auto;
  padding: 14px 10px; background: var(--sidebar); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-right: 1px solid var(--border); display: flex; flex-direction: column; gap: 2px; }
.side-label { font-size: .7rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em;
  padding: 12px 10px 4px; }
.sidebar .btn { width: 100%; justify-content: flex-start; border: none; background: transparent; padding: 7px 10px;
  border-radius: 7px; color: var(--text); font-weight: 500; box-shadow: none; }
.sidebar .btn:hover { background: rgba(0,0,0,.05); }
.sidebar .btn.active { background: var(--accent); color: #fff; }
.sidebar .btn.active .ico { color: #fff; }
.ico { width: 17px; height: 17px; flex: none; color: var(--accent); }
.content { min-width: 0; padding: 26px 30px 64px; max-width: 1180px; width: 100%; }
@media (max-width: 820px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: sticky; top: 52px; z-index: 10; height: auto; flex-direction: row; overflow-x: auto;
    padding: 8px 10px; border-right: none; border-bottom: 1px solid var(--border); }
  .side-label { display: none; }
  .sidebar .btn { width: auto; white-space: nowrap; }
  .content { padding: 18px 16px 48px; }
  .traffic, .titlebar .btn { width: auto; }
  .traffic { display: none; }
}

/* ---------- barra superior (chat) ---------- */
header.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20; background: rgba(246, 246, 248, .8);
  backdrop-filter: saturate(180%) blur(20px); -webkit-backdrop-filter: saturate(180%) blur(20px); border-bottom: 1px solid var(--border); }
header.top .wrap { padding-block: 10px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
header.top .brand { font-weight: 600; display: flex; align-items: center; gap: 8px; }
header.top .brand .dot { width: 22px; height: 22px; border-radius: 6px; background: linear-gradient(135deg, #5ac8fa, #007aff); }
header.top nav { margin-left: auto; display: flex; gap: 4px; }

/* ---------- botões ---------- */
.btn { appearance: none; display: inline-flex; align-items: center; gap: 6px; padding: 6px 13px; font: inherit;
  font-weight: 500; font-size: .9rem; line-height: 1.35; color: var(--text); background: var(--panel);
  border: 1px solid var(--border-strong); border-radius: 7px; cursor: pointer; text-decoration: none;
  box-shadow: 0 1px 1px rgba(0,0,0,.04); transition: background .12s, box-shadow .12s; }
.btn:hover { background: #fafafa; text-decoration: none; }
.btn:active { background: #f0f0f2; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(0,122,255,.3); }
.btn.primary:hover { background: #0a84ff; }
.btn.danger { color: var(--err); }
.btn.ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.sm { padding: 3px 10px; font-size: .8rem; border-radius: 6px; }
.btn:focus-visible, input:focus, textarea:focus, select:focus { outline: none; box-shadow: 0 0 0 3.5px rgba(0,122,255,.3); border-color: var(--accent); }

/* ---------- cartões e grades ---------- */
.card { background: var(--panel); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); min-width: 0; }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; min-width: 0; }
.stack > * + * { margin-top: 16px; }
.fields { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); }
.fields > *, .grid > *, .split > *, .kpis > * { min-width: 0; }

/* ---------- formulários ---------- */
label { display: block; font-weight: 500; font-size: .85rem; margin-bottom: 5px; color: #3a3a3c; }
label .hint { font-weight: 400; color: var(--muted); }
input[type=text], input[type=number], input[type=password], textarea, select {
  width: 100%; max-width: 100%; padding: 7px 10px; font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--border-strong); border-radius: 7px; transition: box-shadow .12s, border-color .12s; }
textarea { min-height: 90px; resize: vertical; }
select { appearance: none; padding-right: 28px; background: var(--panel) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%236e6e73' stroke-width='1.5' fill='none'/%3E%3C/svg%3E") no-repeat right 10px center; }
input[type=range] { width: 100%; accent-color: var(--accent); }
input[type=checkbox] { accent-color: var(--accent); width: 15px; height: 15px; }
.check { display: flex; align-items: flex-start; gap: 9px; font-weight: 400; padding: 9px 11px; border: 1px solid var(--border);
  border-radius: 9px; cursor: pointer; background: var(--panel); min-width: 0; color: var(--text); }
.check span { min-width: 0; overflow-wrap: anywhere; }
.check input { margin-top: 2px; flex: none; }
.check:has(input:checked) { border-color: rgba(0,122,255,.45); background: var(--accent-2); }
.checks { display: grid; gap: 8px; grid-template-columns: repeat(auto-fill, minmax(min(210px, 100%), 1fr)); }

/* ---------- etiquetas ---------- */
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: .74rem; font-weight: 600;
  background: rgba(0,0,0,.06); color: var(--muted); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.err { background: var(--err-bg); color: var(--err); }
.badge.accent { background: var(--accent-2); color: var(--accent); }

/* ---------- tabelas ---------- */
.table-wrap { overflow-x: auto; max-width: 100%; border: 1px solid var(--border); border-radius: 10px; }
table { width: 100%; border-collapse: collapse; font-size: .86rem; }
th, td { text-align: left; padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
td { overflow-wrap: anywhere; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:nth-child(even) td { background: #fafafc; }
th { color: var(--muted); font-weight: 600; font-size: .74rem; text-transform: uppercase; letter-spacing: .03em;
  background: #fafafc; white-space: nowrap; }
.timeline table, .kpi table { border: none; }

/* ---------- avisos e blocos ---------- */
.toast { position: fixed; bottom: calc(24px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%);
  background: rgba(30,30,32,.92); color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 99; max-width: min(560px, 90vw);
  box-shadow: 0 10px 30px rgba(0,0,0,.2); backdrop-filter: blur(10px); font-size: .9rem; }
.toast.err { background: rgba(215,0,21,.95); }
.empty { text-align: center; padding: 48px 16px; color: var(--muted); }
pre.box { background: var(--panel-2); border: 1px solid var(--border); padding: 10px 12px; border-radius: 8px; white-space: pre-wrap;
  overflow-wrap: anywhere; max-height: 260px; overflow: auto; margin: 6px 0 0; font-family: var(--mono); font-size: .8rem; max-width: 100%; }
details > summary { cursor: pointer; }
details > summary::marker { color: var(--muted); }

/* ---------- abas: controle segmentado ---------- */
.tabs { display: inline-flex; gap: 2px; padding: 2px; background: rgba(0,0,0,.06); border-radius: 9px; margin-bottom: 18px;
  flex-wrap: wrap; max-width: 100%; }
.tabs .btn { border: none; background: transparent; box-shadow: none; padding: 5px 14px; border-radius: 7px; color: var(--text); font-size: .85rem; }
.tabs .btn:hover { background: rgba(255,255,255,.5); }
.tabs .btn.active { background: var(--panel); box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 0 0 .5px rgba(0,0,0,.04); }

/* ---------- lista lateral (agentes, guardrails) ---------- */
.split { display: grid; grid-template-columns: 250px minmax(0, 1fr); gap: 18px; align-items: start; }
@media (max-width: 980px) { .split { grid-template-columns: minmax(0, 1fr); } }
.list { display: flex; flex-direction: column; gap: 2px; }
.list .item { text-align: left; padding: 9px 11px; border-radius: 8px; border: none; background: none; color: var(--text);
  font: inherit; cursor: pointer; min-width: 0; overflow-wrap: anywhere; }
.list .item:hover { background: rgba(0,0,0,.04); }
.list .item.active { background: var(--accent); color: #fff; }
.list .item.active .muted { color: rgba(255,255,255,.8); }

/* ---------- métricas ---------- */
.kpis { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(min(170px, 100%), 1fr)); }
.kpi { background: var(--panel); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); min-width: 0; }
.card .kpi, .kpi .kpi { box-shadow: none; background: var(--panel-2); border: 1px solid var(--border); }
.kpi .v { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.02em; overflow-wrap: anywhere; }
.kpi .l { font-size: .78rem; color: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 120px; padding-top: 8px; }
.bars .b { flex: 1; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 2px; opacity: .8; }
.bars .b:hover { opacity: 1; }
.hbar { display: grid; grid-template-columns: minmax(0, 40%) minmax(0, 1fr) auto; gap: 10px; align-items: center; font-size: .86rem; margin: 7px 0; }
.hbar .track { background: rgba(0,0,0,.06); border-radius: 99px; height: 8px; overflow: hidden; }
.hbar .fill { background: var(--accent); height: 100%; border-radius: 99px; }
.hbar .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- upload ---------- */
.drop { border: 1.5px dashed var(--border-strong); border-radius: var(--radius); padding: 28px; text-align: center; cursor: pointer;
  background: var(--panel-2); transition: border-color .12s, background .12s; }
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-2); }

/* ---------- caminho percorrido (testar) ---------- */
.timeline { display: flex; flex-direction: column; gap: 8px; border-left: 2px solid var(--border); padding-left: 16px; margin-left: 6px; }
.timeline .step { background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; position: relative; min-width: 0; }
.timeline .step::before { content: ""; position: absolute; left: -23px; top: 15px; width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg); }
.timeline .step summary { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.timeline .step-body { margin-top: 8px; min-width: 0; }
.timeline table td, .timeline table th { padding: 4px 8px; }

/* ---------- chat (estilo Mensagens) ---------- */
.agent-card { cursor: pointer; display: flex; flex-direction: column; gap: 10px; text-align: left; font: inherit; color: inherit;
  border: none; transition: transform .15s, box-shadow .15s; }
.agent-card:hover { transform: translateY(-2px); box-shadow: 0 0 0 .5px rgba(0,0,0,.05), 0 8px 24px rgba(0,0,0,.08); }
.agent-card .avatar, .chat-head .avatar { width: 40px; height: 40px; border-radius: 50%; flex: none; display: grid; place-items: center;
  font-weight: 600; font-size: 1.05rem; color: #fff; background: linear-gradient(135deg, #5ac8fa, #007aff); }
.chat { display: flex; flex-direction: column; height: calc(100vh - 120px); min-height: 420px; padding: 0; overflow: hidden; }
.chat-head { padding: 12px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 12px;
  background: rgba(250,250,252,.9); }
.messages { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 10px; background: var(--panel); }
.msg { max-width: min(720px, 85%); padding: 8px 13px; border-radius: 18px; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.45; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 5px; }
.msg.bot { align-self: flex-start; background: #e9e9eb; color: var(--text); border-bottom-left-radius: 5px; }
.msg .status { color: var(--muted); font-style: italic; font-size: .86rem; }
.msg .cite { color: var(--accent); font-weight: 600; cursor: pointer; }
.refs { margin-top: 10px; padding-top: 8px; border-top: 1px solid rgba(0,0,0,.08); white-space: normal; }
.refs .ref-title { font-size: .72rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.refs details { margin-top: 6px; font-size: .86rem; }
.refs .excerpt { margin: 6px 0 0; padding: 8px 10px; background: rgba(255,255,255,.75); border-left: 3px solid var(--accent);
  border-radius: 6px; white-space: pre-wrap; font-size: .84rem; color: #3a3a3c; }
.feedback { margin-top: 10px; padding-top: 8px; border-top: 1px solid rgba(0,0,0,.08); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; white-space: normal; }
.fb-btn { border: 1px solid var(--border-strong); background: var(--panel); border-radius: 99px; padding: 1px 10px; cursor: pointer;
  font-size: .95rem; line-height: 1.5; filter: grayscale(1); opacity: .7; }
.fb-btn:hover { opacity: 1; filter: none; }
.fb-btn.on { filter: none; opacity: 1; border-color: var(--accent); background: var(--accent-2); }
.fb-form { display: flex; gap: 6px; width: 100%; }
.fb-form input { flex: 1; min-width: 0; }
.composer { border-top: 1px solid var(--border); padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); display: flex; gap: 8px;
  align-items: flex-end; background: rgba(250,250,252,.9); }
.composer textarea { min-height: 38px; max-height: 160px; resize: none; border-radius: 19px; padding: 8px 14px; }
.composer .btn { border-radius: 19px; padding: 8px 16px; }
