:root {
  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --border: #e3e8ef;
  --text: #1b2333;
  --muted: #7a869a;
  --primary: #1f6feb;
  --primary-soft: #e8f1ff;
  --green: #16a34a;
  --amber: #d97706;
  --red: #dc2626;
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  font-size: 14px;
}
h1, h2, h3 { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }

/* ---------- Login ---------- */
.login-body {
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #dbe7ff 0%, #eef1f6 60%);
}
.login-card {
  width: 100%; max-width: 380px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 16px;
  padding: 36px 32px; box-shadow: 0 24px 60px -30px rgba(20, 40, 80, .45);
  text-align: center;
}
.brand-mark {
  width: 52px; height: 52px; margin: 0 auto 16px; border-radius: 14px;
  background: var(--primary); color: #fff; font-weight: 700; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}
.login-card h1 { font-size: 20px; }
.login-card form { margin-top: 24px; text-align: left; display: grid; gap: 14px; }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input, textarea, select {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--primary-soft); border-color: var(--primary); }
.btn-primary {
  background: var(--primary); color: #fff; border: 0; border-radius: 8px;
  padding: 11px 16px; font: inherit; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { background: #1a5fd0; }
.form-error { color: var(--red); font-size: 13px; margin: 0; }
.login-foot { margin-top: 22px; font-size: 12px; color: var(--muted); }

/* ---------- Janela de software ---------- */
.app-body { padding: 18px; }
.window {
  height: calc(100vh - 36px);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; overflow: hidden; display: flex; flex-direction: column;
  box-shadow: 0 30px 70px -40px rgba(15, 30, 60, .55);
}
.titlebar {
  height: 38px; display: flex; align-items: center; gap: 7px;
  padding: 0 14px; background: var(--surface-2); border-bottom: 1px solid var(--border);
  position: relative;
}
.dot { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.dot.red { background: #ff5f57; } .dot.yellow { background: #febc2e; } .dot.green { background: #28c840; }
.titlebar-name {
  position: absolute; left: 0; right: 0; text-align: center;
  font-size: 12px; color: var(--muted); pointer-events: none;
}
.workspace {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 60px 210px 300px 1fr 280px;
}
.workspace > * { min-width: 0; border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.workspace > :last-child { border-right: 0; }

/* Rail */
.rail { align-items: center; padding: 12px 0; gap: 8px; background: var(--surface-2); }
.rail-logo {
  width: 34px; height: 34px; border-radius: 10px; background: var(--primary); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; margin-bottom: 8px;
}
.rail-btn {
  width: 36px; height: 36px; border: 0; border-radius: 9px; background: transparent;
  cursor: pointer; font-size: 16px; color: var(--muted);
}
.rail-btn:hover { background: #e7edf7; }
.rail-btn.active { background: var(--primary-soft); color: var(--primary); }
.rail-spacer { flex: 1; }
.rail-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: #cfe0ff; color: #1f4e9c;
  display: flex; align-items: center; justify-content: center; font-weight: 700; margin-top: 8px;
}

/* Panes */
.pane-head {
  height: 54px; padding: 0 16px; display: flex; align-items: center; justify-content: space-between;
  border-bottom: 1px solid var(--border); flex: none;
}
.pane-head h2 { font-size: 15px; font-weight: 600; }
.icon-btn { border: 0; background: transparent; cursor: pointer; color: var(--muted); font-size: 16px; }

.filters { background: var(--surface-2); }
.filter-list { list-style: none; margin: 10px 0; padding: 0 10px; display: grid; gap: 2px; }
.filter, .filter-static {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 10px; border-radius: 8px; font-size: 13px; cursor: pointer;
}
.filter-static { cursor: default; }
.filter:hover { background: #e7edf7; }
.filter.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.filter-title { margin: 16px 16px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.badge { background: #e2e8f0; color: var(--muted); border-radius: 999px; padding: 1px 8px; font-size: 11px; }
.badge.green { background: #dcfce7; color: var(--green); }
.badge.amber { background: #fef3c7; color: var(--amber); }
.filters-foot { margin-top: auto; padding: 14px 16px; border-top: 1px solid var(--border); }
.link-btn { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; font-size: 13px; padding: 0; }
.link-btn:hover { color: var(--red); }

/* Lista */
.list-search { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.list-items { overflow-y: auto; flex: 1; }
.conv {
  display: grid; grid-template-columns: 38px 1fr; gap: 10px;
  padding: 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.conv:hover { background: var(--surface-2); }
.conv.active { background: var(--primary-soft); }
.conv-avatar {
  width: 38px; height: 38px; border-radius: 50%; background: #dbe7ff; color: #1f4e9c;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.conv-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.conv-name { font-weight: 600; font-size: 13px; }
.conv-time { font-size: 11px; color: var(--muted); white-space: nowrap; }
.conv-prev { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tag { font-size: 10px; padding: 1px 7px; border-radius: 999px; margin-top: 5px; display: inline-block; }
.tag.bot { background: #dcfce7; color: var(--green); }
.tag.humano { background: #fef3c7; color: var(--amber); }

/* Chat */
.chat { background: #f4f6fb; }
.chat-inner { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.empty-state { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--muted); gap: 8px; }
.empty-icon { font-size: 32px; }
.chat-head {
  height: 54px; display: flex; align-items: center; gap: 12px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); flex: none;
}
.chat-head h3 { font-size: 15px; }
.chat-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: #dbe7ff; color: #1f4e9c;
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}
.chat-actions { margin-left: auto; }
.btn-ghost {
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 7px 12px; font: inherit; font-size: 13px; cursor: pointer; color: var(--text);
}
.btn-ghost:hover { background: var(--surface-2); }

.bot-bar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px; flex: none;
  background: #ecfdf3; border-bottom: 1px solid #bbf7d0;
}
.bot-bar.paused { background: #fff7ed; border-bottom-color: #fed7aa; }
.bot-state { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 0 rgba(22,163,74,.5); animation: pulse 1.8s infinite; }
.bot-bar.paused .pulse { background: var(--amber); animation: none; }
@keyframes pulse { to { box-shadow: 0 0 0 10px rgba(22,163,74,0); } }
.btn-stop {
  margin-left: auto; border: 0; border-radius: 8px; padding: 8px 14px;
  background: var(--red); color: #fff; font: inherit; font-weight: 600; cursor: pointer;
}
.btn-stop.resume { background: var(--green); }

.messages { flex: 1; overflow-y: auto; padding: 20px 22px; display: flex; flex-direction: column; gap: 12px; }
.bubble { max-width: 62%; padding: 10px 13px; border-radius: 12px; font-size: 13px; line-height: 1.5; position: relative; }
.bubble .time { display: block; font-size: 10px; color: var(--muted); margin-top: 6px; text-align: right; }
.bubble .who { display: block; font-size: 11px; font-weight: 700; margin-bottom: 4px; }
.bubble.cliente { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); }
.bubble.bot { align-self: flex-end; background: var(--primary-soft); border: 1px solid #cfe0ff; }
.bubble.agente { align-self: flex-end; background: #dcfce7; border: 1px solid #bbf7d0; }
.bubble.sistema {
  align-self: center; max-width: 78%; background: transparent; border: 0;
  color: var(--muted); font-size: 11.5px; text-align: center;
}

.composer { flex: none; background: var(--surface); border-top: 1px solid var(--border); padding: 12px 16px; display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.composer textarea { resize: none; }
.composer .send { align-self: stretch; }
.composer-hint { grid-column: 1 / -1; font-size: 11px; color: var(--muted); }

/* Detalhes */
.details-body { padding: 16px; overflow-y: auto; display: grid; gap: 16px; }
.detail-block { display: grid; gap: 4px; }
.detail-label { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.detail-value { font-size: 13px; }
.state-pill { display: inline-block; padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.state-pill.on { background: #dcfce7; color: var(--green); }
.state-pill.off { background: #fef3c7; color: var(--amber); }

@media (max-width: 1200px) {
  .workspace { grid-template-columns: 60px 300px 1fr; }
  .filters, .details { display: none; }
}

/* ---- Configurações ---- */
.settings-wrap { padding: 24px 28px 40px; overflow-y: auto; }
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.settings-head h1 { font-size: 20px; margin: 0; }
.settings-grid { display: grid; gap: 18px; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); }
.cfg-card { border: 1px solid var(--border, #e4e7ec); border-radius: 12px; padding: 18px; background: #fff; display: grid; gap: 12px; align-content: start; }
.cfg-card h2 { font-size: 15px; margin: 0; }
.cfg-card label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; }
.cfg-card input, .cfg-card select, .cfg-card textarea {
  font: inherit; font-weight: 400; padding: 9px 11px; border: 1px solid var(--border, #e4e7ec);
  border-radius: 8px; background: #fff; width: 100%;
}
.cfg-card textarea { resize: vertical; }
.cfg-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.cfg-note { font-size: 12px; background: #f6f8fb; border-radius: 8px; padding: 10px; word-break: break-all; }
.cfg-note code { display: block; margin-top: 4px; }
.cfg-result { font-size: 13px; margin: 0; }
.cfg-result.ok { color: #15803d; }
.cfg-result.erro { color: var(--red, #d92d20); }
.settings-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; }
