/* Dent System Chat — estilos do painel */
:root {
  --bg: #f3f6f7;
  --panel: #ffffff;
  --ink: #15212b;
  --muted: #5d6b77;
  --faint: #8a97a2;
  --line: #e1e7eb;
  --line-strong: #cdd6dc;
  --brand: #0e7c86;
  --brand-dark: #0a5f67;
  --brand-tint: #e3f3f4;
  --side: #0f2a33;
  --side-ink: #c9dade;
  --ok: #157347;
  --ok-tint: #e5f4ec;
  --warn: #a45a07;
  --warn-tint: #fdf1df;
  --err: #b42318;
  --err-tint: #fde8e6;
  --ctwa: #6b3fd1;
  --ctwa-tint: #efe9fd;
  --human: #b45309;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 32, 40, .06), 0 1px 1px rgba(16, 32, 40, .04);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.45 var(--font); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 16px; margin: 0 0 12px; }
h3 { font-size: 14px; margin: 0 0 8px; }
p { margin: 0 0 10px; }
small, .muted { color: var(--muted); }
code { background: #eef2f4; padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }

/* ---------- estrutura ---------- */
.shell { display: flex; min-height: 100vh; }
.side { width: 224px; flex: 0 0 224px; background: var(--side); color: var(--side-ink); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; gap: 10px; align-items: center; padding: 18px 18px 16px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand strong { display: block; color: #fff; font-size: 15px; }
.brand small { color: #8fb2b9; font-size: 12px; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 32 32'%3E%3Cpath d='M9 10c0-2 2-3 4-2l3 1 3-1c2-1 4 0 4 2 0 4-1 6-2 9-1 3-2 4-3 2l-2-4-2 4c-1 2-2 1-3-2-1-3-2-5-2-9z' fill='white'/%3E%3C/svg%3E") center/22px no-repeat; }
.side nav { padding: 10px 8px; display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.side nav a { color: var(--side-ink); padding: 8px 10px; border-radius: 8px; display: flex; align-items: center; gap: 10px; }
.side nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; }
.side nav a.on { background: rgba(255,255,255,.12); color: #fff; }
.side nav .i { width: 18px; text-align: center; opacity: .8; }
.side .badge { margin-left: auto; }
.side-foot { padding: 12px 18px; border-top: 1px solid rgba(255,255,255,.08); display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.side-foot .me { color: #fff; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-foot .link { color: #8fb2b9; }
.main { flex: 1; min-width: 0; padding: 24px 28px 48px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head p { margin: 0; color: var(--muted); }

/* ---------- componentes ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card.tight { padding: 0; overflow: hidden; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid.k4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.k3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.k2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi .lbl { color: var(--muted); font-size: 12.5px; }
.kpi .val { font-size: 26px; font-weight: 650; letter-spacing: -.02em; margin-top: 2px; }
.kpi .sub { color: var(--faint); font-size: 12px; }
.kpi.accent { border-color: var(--brand); background: linear-gradient(0deg, var(--brand-tint), #fff 70%); }

.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line-strong); background: #fff; color: var(--ink); padding: 7px 12px; border-radius: 8px; font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { border-color: var(--faint); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--err); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
button.link { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); cursor: pointer; }
.inline { display: inline; margin: 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

label { display: block; font-weight: 600; font-size: 12.5px; margin: 0 0 4px; color: #33424e; }
.field { margin-bottom: 12px; }
.hint { color: var(--muted); font-size: 12px; margin-top: 3px; font-weight: 400; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=time], input[type=date], select, textarea {
  width: 100%; border: 1px solid var(--line-strong); background: #fff; border-radius: 8px; padding: 7px 10px; font: inherit; color: var(--ink);
}
textarea { resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(14,124,134,.25); border-color: var(--brand); }
.check { display: flex; gap: 8px; align-items: center; font-weight: 500; }
.check input { width: auto; }

table.t { width: 100%; border-collapse: collapse; }
.t th, .t td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.t th { font-size: 12px; color: var(--muted); font-weight: 600; background: #f8fafb; white-space: nowrap; }
.t tr:last-child td { border-bottom: 0; }
.t td.num, .t th.num { text-align: right; font-variant-numeric: tabular-nums; }
.t tr:hover td { background: #fafcfc; }

.tag { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; background: #eef2f4; color: #3b4a55; white-space: nowrap; }
.tag.ctwa { background: var(--ctwa-tint); color: var(--ctwa); }
.tag.org { background: #eef2f4; color: #4a5a66; }
.tag.human { background: var(--warn-tint); color: var(--human); }
.tag.ok { background: var(--ok-tint); color: var(--ok); }
.tag.err { background: var(--err-tint); color: var(--err); }
.tag.warn { background: var(--warn-tint); color: var(--warn); }
.badge { background: #e5484d; color: #fff; border-radius: 99px; padding: 0 7px; font-size: 11.5px; font-weight: 700; line-height: 18px; min-width: 18px; text-align: center; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; }
.flash.ok { background: var(--ok-tint); color: var(--ok); }
.flash.err { background: var(--err-tint); color: var(--err); }
.note { background: var(--warn-tint); color: #6d3c06; padding: 10px 12px; border-radius: 8px; font-size: 13px; }
.note.info { background: var(--brand-tint); color: #0b4c52; }
.empty { color: var(--muted); padding: 28px; text-align: center; }

.toast { position: fixed; right: 20px; bottom: 20px; background: #15212b; color: #fff; padding: 10px 14px; border-radius: 8px; opacity: 0; transform: translateY(8px); transition: .2s; pointer-events: none; z-index: 1000; max-width: 420px; white-space: pre-line; }
.toast.show { opacity: 1; transform: none; }
.toast.err { background: var(--err); }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs a { padding: 8px 12px; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; font-weight: 600; }
.tabs a.on { color: var(--brand); border-color: var(--brand); }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: 8px; overflow: hidden; }
.seg a { padding: 5px 11px; color: var(--muted); font-weight: 600; font-size: 13px; }
.seg a.on { background: var(--brand); color: #fff; }
.seg a:hover { text-decoration: none; }

.bar { height: 8px; background: #e9eef1; border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--brand); border-radius: 99px; }
.funnel-row { display: grid; grid-template-columns: 140px 1fr 70px; gap: 10px; align-items: center; margin-bottom: 8px; }
.funnel-row .n { text-align: right; font-weight: 650; font-variant-numeric: tabular-nums; }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: var(--side); padding: 20px; }
.login { width: 100%; max-width: 360px; background: #fff; border-radius: 14px; padding: 28px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login .brand { padding: 0 0 18px; border: 0; }
.login .brand strong { color: var(--ink); }
.login .brand small { color: var(--muted); }

/* ---------- live chat ---------- */
body.inbox .main { padding: 0; height: 100vh; overflow: hidden; }
.inbox-grid { display: grid; grid-template-columns: 320px minmax(0, 1fr) 300px; height: 100vh; }
.conv-col { border-right: 1px solid var(--line); background: #fff; display: flex; flex-direction: column; min-height: 0; }
.conv-tools { padding: 12px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chips button { border: 1px solid var(--line-strong); background: #fff; border-radius: 99px; padding: 3px 10px; font: inherit; font-size: 12.5px; cursor: pointer; color: var(--muted); font-weight: 600; }
.chips button.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.conv-list { overflow-y: auto; flex: 1; }
.conv { display: block; padding: 10px 12px; border-bottom: 1px solid var(--line); cursor: pointer; color: inherit; }
.conv:hover { background: #f7fafb; text-decoration: none; }
.conv.on { background: var(--brand-tint); }
.conv .top { display: flex; justify-content: space-between; gap: 8px; }
.conv .nm { font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv .tm { color: var(--faint); font-size: 12px; flex: none; }
.conv .pv { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 2px 0 4px; }
.conv .meta { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.conv .badge { margin-left: auto; }

.chat-col { display: flex; flex-direction: column; min-height: 0; background: #eef2f3; }
.chat-head { background: #fff; border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chat-head .who { font-weight: 700; font-size: 15px; }
.chat-head .sub { color: var(--muted); font-size: 12.5px; }
.chat-body { flex: 1; overflow-y: auto; padding: 16px 18px; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 72%; padding: 7px 10px 5px; border-radius: 10px; background: #fff; box-shadow: var(--shadow); white-space: pre-wrap; word-wrap: break-word; position: relative; }
.msg.out { align-self: flex-end; background: #d9f2e6; }
.msg.out.agent { background: #dcecff; }
.msg.sys { align-self: center; background: transparent; box-shadow: none; color: var(--muted); font-size: 12px; text-align: center; max-width: 90%; padding: 2px 8px; }
.msg .by { font-size: 11px; font-weight: 700; color: var(--brand-dark); display: block; margin-bottom: 1px; }
.msg.agent .by { color: #2754a3; }
.msg .ft { font-size: 11px; color: var(--faint); text-align: right; margin-top: 2px; }
.msg.failed { border: 1px solid var(--err); }
.msg img, .msg video, .msg audio { max-width: 260px; border-radius: 6px; display: block; margin-bottom: 4px; }
.day-sep { align-self: center; font-size: 11.5px; color: var(--muted); background: #fff; border-radius: 99px; padding: 2px 10px; margin: 8px 0; }
.composer { background: #fff; border-top: 1px solid var(--line); padding: 10px 12px; }
.composer form { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { min-height: 42px; max-height: 160px; }
.window-warn { margin-bottom: 8px; }
.detail-col { background: #fff; border-left: 1px solid var(--line); overflow-y: auto; padding: 14px; }
.detail-col h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 16px 0 6px; }
.detail-col h3:first-child { margin-top: 0; }
.kv { display: grid; grid-template-columns: 96px 1fr; gap: 4px 8px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.taglist { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.taglist .tag button { border: 0; background: none; cursor: pointer; color: inherit; padding: 0 0 0 2px; }
.placeholder { display: grid; place-items: center; height: 100%; color: var(--muted); text-align: center; padding: 30px; }

/* ---------- editor de fluxos ---------- */
body.editor .main { padding: 0; height: 100vh; overflow: hidden; }
.ed { display: grid; grid-template-rows: auto 1fr; height: 100vh; }
.ed-top { background: #fff; border-bottom: 1px solid var(--line); padding: 10px 14px; display: flex; gap: 10px; align-items: center; }
.ed-top input.name { max-width: 340px; font-weight: 650; font-size: 15px; }
.ed-body { display: grid; grid-template-columns: 190px minmax(0, 1fr) 330px; min-height: 0; }
.palette { background: #fff; border-right: 1px solid var(--line); padding: 12px; overflow-y: auto; }
.palette h3 { font-size: 11.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin: 10px 0 6px; }
.pal { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; margin-bottom: 6px; cursor: grab; background: #fff; font-weight: 600; font-size: 13px; user-select: none; }
.pal:hover { border-color: var(--brand); }
.pal .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
#canvas { position: relative; background: #f1f4f6; background-image: radial-gradient(#cfd8de 1px, transparent 1px); background-size: 20px 20px; min-height: 0; overflow: hidden; }
.canvas-tools { position: absolute; right: 12px; bottom: 12px; display: flex; gap: 6px; z-index: 5; }
.props { background: #fff; border-left: 1px solid var(--line); overflow-y: auto; padding: 14px; }
.props .opt { display: flex; gap: 6px; margin-bottom: 6px; align-items: flex-start; }
.props .opt input { flex: 1; }
.props .rule { border: 1px solid var(--line); border-radius: 8px; padding: 8px; margin-bottom: 8px; display: grid; gap: 6px; }
.props .count { font-size: 11.5px; color: var(--faint); float: right; font-weight: 500; }
.props .count.over { color: var(--err); }
.vars { font-size: 12px; color: var(--muted); }
.vars code { cursor: pointer; }

/* nós do Drawflow */
.drawflow .drawflow-node { background: #fff; border: 1px solid var(--line-strong); border-radius: 10px; padding: 0; width: 240px; min-height: 0; display: block; box-shadow: 0 2px 6px rgba(16,32,40,.08); color: var(--ink); }
.drawflow .drawflow-node.selected { background: #fff; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(14,124,134,.25); }
.drawflow .drawflow-node .drawflow_content_node { width: 100%; display: block; }
.drawflow .drawflow-node .inputs { position: absolute; left: -8px; top: 9px; width: 0; }
.drawflow .drawflow-node .outputs { position: absolute; right: -8px; top: 86px; width: 0; }
.drawflow .drawflow-node .input, .drawflow .drawflow-node .output { width: 16px; height: 16px; border: 2px solid #fff; background: #8a97a2; box-shadow: 0 0 0 1px #8a97a2; position: relative; left: 0; top: 0; }
.drawflow .drawflow-node .output { margin: 5px 0; }
.drawflow .drawflow-node .output:hover, .drawflow .drawflow-node .input:hover { background: var(--brand); }
.drawflow .connection .main-path { stroke: #8a97a2; stroke-width: 2.5px; }
.drawflow .connection .main-path:hover, .drawflow .connection .main-path.selected { stroke: var(--brand); }
.drawflow-delete { background: var(--err); border: 2px solid #fff; color: #fff; line-height: 26px; }
.nd-h { height: 34px; display: flex; align-items: center; gap: 8px; padding: 0 10px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 13px; border-radius: 10px 10px 0 0; }
.nd-h .dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.nd-h .id { margin-left: auto; color: var(--faint); font-weight: 500; font-size: 11px; }
.nd-b { height: 52px; padding: 6px 10px; font-size: 12px; color: var(--muted); overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; line-height: 1.35; border-bottom: 1px solid var(--line); }
.nd-o { list-style: none; margin: 0; padding: 0; }
.nd-o li { height: 26px; line-height: 26px; padding: 0 16px 0 10px; font-size: 12px; text-align: right; border-bottom: 1px dashed var(--line); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nd-o li:last-child { border-bottom: 0; }
.nd-o li.sub { color: var(--faint); font-style: italic; }
.nd-o li.none { text-align: left; color: var(--faint); }
.drawflow-node.start .nd-h { background: #e5f4ec; }
.drawflow-node.start .inputs { display: none; }

@media (max-width: 1200px) {
  .grid.k4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .inbox-grid { grid-template-columns: 280px minmax(0, 1fr); }
  .detail-col { display: none; }
}
@media (max-width: 800px) {
  .side { display: none; }
  .main { padding: 16px; }
  .grid.k3, .grid.k2 { grid-template-columns: 1fr; }
}
