:root {
  --bg: #f4f5fb;
  --card: #ffffff;
  --text: #1a1a2e;
  --muted: #6b6f85;
  --line: #e6e7f0;
  --side: #0d0f1f;
  --side-text: #c9cbe0;
  --violet: #7c3aed;
  --cyan: #06b6d4;
  --grad: linear-gradient(135deg, #7c3aed, #06b6d4);
  --ok: #16a34a;
  --warn: #d97706;
  --err: #dc2626;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: 'Segoe UI', Arial, sans-serif; background: var(--bg); color: var(--text); font-size: 15px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--err); min-height: 1.2em; font-size: 14px; }
h1 { font-size: 24px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; }

/* marca */
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 24px; }
.brand img { width: 40px; height: 40px; }
.brand span { display: flex; align-items: baseline; color: #fff; }
.brand i { width: 8px; height: 8px; border-radius: 50%; background: #22d3ee; box-shadow: 0 0 10px #22d3ee; margin: 0 3px; display: inline-block; }
.brand b { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.brand.big { justify-content: center; font-size: 38px; }
.brand.big img { width: 64px; height: 64px; }
.brand.big span { color: var(--text); }

/* login */
.auth { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px;
  background: radial-gradient(circle at 20% 10%, #ede9fe, transparent 50%), radial-gradient(circle at 90% 90%, #cffafe, transparent 50%), var(--bg); }
.auth-box { background: var(--card); border-radius: 20px; padding: 32px; width: 100%; max-width: 400px; box-shadow: 0 10px 40px rgba(30, 20, 80, .12); text-align: center; }
.auth-box form { text-align: left; margin-top: 18px; }

/* layout */
.layout { display: flex; min-height: 100%; }
.sidebar { width: 230px; background: var(--side); color: var(--side-text); padding: 20px 14px; display: flex; flex-direction: column; gap: 26px; position: sticky; top: 0; height: 100vh; }
.sidebar nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.sidebar nav a { padding: 11px 12px; border-radius: 10px; cursor: pointer; display: flex; align-items: center; gap: 10px; text-decoration: none; color: inherit; }
.sidebar nav a:hover { background: rgba(255, 255, 255, .06); }
.sidebar nav a.active { background: var(--grad); color: #fff; font-weight: 600; }
.badge { margin-left: auto; background: var(--err); color: #fff; font-style: normal; font-size: 12px; border-radius: 10px; padding: 1px 7px; }
.me { font-size: 13px; display: flex; justify-content: space-between; align-items: center; border-top: 1px solid rgba(255,255,255,.1); padding-top: 12px; }
.me .link { color: #a5b4fc; }
main { flex: 1; padding: 28px; min-width: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }

/* componentes */
.card { background: var(--card); border-radius: 16px; padding: 20px; box-shadow: 0 2px 12px rgba(20, 20, 60, .05); }
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.stats { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); margin-bottom: 22px; }
.stat .n { font-size: 32px; font-weight: 800; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.btn { border: 0; border-radius: 10px; padding: 10px 16px; font: inherit; font-weight: 600; cursor: pointer; background: #eef0f7; color: var(--text); }
.btn:hover { filter: brightness(.97); }
.btn.primary { background: var(--grad); color: #fff; }
.btn.danger { background: #fee2e2; color: var(--err); }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.full { width: 100%; }
.btn:disabled { opacity: .55; cursor: default; }
.link { background: none; border: 0; color: var(--violet); cursor: pointer; font: inherit; padding: 0; }
label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 12px; color: #3a3d55; }
label small { font-weight: 400; color: var(--muted); }
input, textarea, select { display: block; width: 100%; margin-top: 5px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font: inherit; font-weight: 400; background: #fff; color: var(--text); }
textarea { resize: vertical; min-height: 80px; }
input:focus, textarea:focus, select:focus { outline: 2px solid #c4b5fd; border-color: transparent; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pill { display: inline-block; font-size: 12px; padding: 3px 9px; border-radius: 20px; background: #eef0f7; color: var(--muted); font-weight: 600; }
.pill.ok { background: #dcfce7; color: var(--ok); }
.pill.warn { background: #fef3c7; color: var(--warn); }
.pill.err { background: #fee2e2; color: var(--err); }
.pill.ai { background: #ede9fe; color: var(--violet); }
code, pre { font-family: Consolas, monospace; font-size: 12.5px; }
pre { background: #0d0f1f; color: #c7f9ff; padding: 12px; border-radius: 10px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; }

/* cards de I.A. */
.agent-card { cursor: pointer; transition: transform .1s; border-top: 4px solid var(--c, var(--violet)); }
.agent-card:hover { transform: translateY(-2px); }
.agent-card .av { width: 44px; height: 44px; border-radius: 12px; background: var(--c, var(--violet)); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 800; font-size: 20px; }
.agent-card .top { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.agent-card .meta { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.new-card { border: 2px dashed #cfd2e6; background: transparent; box-shadow: none; display: flex; align-items: center; justify-content: center; min-height: 150px; color: var(--violet); font-weight: 700; cursor: pointer; }

/* editor */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 18px; align-items: start; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: -4px 0 16px; flex-wrap: wrap; }
.tabs button { background: none; border: 0; padding: 10px 12px; font: inherit; cursor: pointer; color: var(--muted); border-bottom: 3px solid transparent; }
.tabs button.active { color: var(--violet); border-color: var(--violet); font-weight: 600; }
.tester { position: sticky; top: 20px; display: flex; flex-direction: column; height: calc(100vh - 140px); min-height: 420px; padding: 0; overflow: hidden; }
.tester .t-head { padding: 14px 16px; color: #fff; background: var(--grad); }
.tester .t-head small { opacity: .85; display: block; }

/* chat */
.chat { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; background: #f7f7fc; }
.msg { max-width: 82%; padding: 9px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; line-height: 1.35; font-size: 14px; }
.msg.user { background: #fff; border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.assistant { background: #ede9fe; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.human { background: #dcfce7; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg.system { align-self: center; background: none; color: var(--muted); font-size: 12px; font-style: italic; text-align: center; }
.msg .who { display: block; font-size: 11px; font-weight: 700; color: var(--muted); margin-bottom: 2px; }
.msg.typing { color: var(--muted); font-style: italic; }
.composer { display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); background: #fff; }
.composer input { margin: 0; }

/* canais */
.ch-card .qr { display: block; margin: 12px auto; width: 230px; max-width: 100%; border-radius: 10px; }
.ch-card .actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-bottom: 14px; }
.type-opt { border: 2px solid var(--line); border-radius: 12px; padding: 14px; cursor: pointer; text-align: center; background: #fff; font: inherit; }
.type-opt .ic { font-size: 28px; display: block; margin-bottom: 4px; }
.type-opt.sel { border-color: var(--violet); background: #f5f3ff; }
.type-opt:disabled { opacity: .5; cursor: not-allowed; }
.type-opt small { display: block; color: var(--muted); font-size: 11.5px; margin-top: 3px; }

/* conversas */
.inbox { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 0; height: calc(100vh - 120px); padding: 0; overflow: hidden; }
.conv-list { border-right: 1px solid var(--line); overflow-y: auto; }
.conv-item { padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv-item:hover { background: #f8f8fd; }
.conv-item.active { background: #f3f0ff; }
.conv-item .l1 { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; }
.conv-item .l2 { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.conv-item .l3 { margin-top: 5px; display: flex; gap: 5px; }
.conv-view { display: flex; flex-direction: column; min-width: 0; }
.conv-head { padding: 12px 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.empty { display: flex; align-items: center; justify-content: center; flex: 1; color: var(--muted); padding: 30px; text-align: center; }

/* modal e toast */
.modal { position: fixed; inset: 0; background: rgba(13, 15, 31, .55); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
.modal-box { background: #fff; border-radius: 18px; padding: 24px; width: 100%; max-width: 560px; max-height: 92vh; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #1a1a2e; color: #fff; padding: 11px 18px; border-radius: 10px; z-index: 60; box-shadow: 0 6px 20px rgba(0,0,0,.2); }
.toast.err { background: var(--err); }

@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; padding: 10px 12px; gap: 10px; }
  .sidebar nav { flex-direction: row; overflow-x: auto; }
  .sidebar nav a span { display: none; }
  .sidebar .brand span, .me span { display: none; }
  main { padding: 16px; }
  .editor { grid-template-columns: 1fr; }
  .tester { position: static; height: 480px; }
  .inbox { grid-template-columns: 1fr; height: auto; }
  .conv-list { max-height: 260px; border-right: 0; border-bottom: 1px solid var(--line); }
  .conv-view { height: 520px; }
  .row2 { grid-template-columns: 1fr; }
}

/* configurações */
.set-cat { display: flex; gap: 14px; align-items: center; cursor: pointer; transition: transform .1s; }
.set-cat:hover { transform: translateY(-2px); }
.set-ic { width: 48px; height: 48px; border-radius: 14px; background: #f3f0ff; display: flex; align-items: center; justify-content: center; font-size: 24px; flex-shrink: 0; }
.set-cat .arrow { font-size: 28px; color: #b4b7cc; }
.prov { border: 2px solid transparent; display: flex; flex-direction: column; align-items: flex-start; gap: 6px; text-align: left; font: inherit; color: inherit; cursor: pointer; }
.prov:hover:not(:disabled) { border-color: #c4b5fd; }
.prov:disabled { opacity: .6; cursor: not-allowed; }
.prov-logo { width: 42px; height: 42px; border-radius: 12px; color: #fff; display: inline-flex; align-items: center; justify-content: center; font-weight: 800; font-size: 15px; flex-shrink: 0; }
.key-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.prov-logo { background: #fff; border: 1px solid var(--line); }
.prov-logo img { width: 26px; height: 26px; object-fit: contain; }
.mini-logo { width: 14px; height: 14px; vertical-align: -2px; margin-right: 5px; object-fit: contain; }
.prov-line { font-size: 13px; }
#provLogo .mini-logo { width: 16px; height: 16px; margin-left: 4px; }
.prov.soon { opacity: .85; cursor: default; }
.prov.soon:hover { border-color: transparent; }
.cat-logos { display: flex; gap: 6px; margin-top: 8px; }
.cat-logos img { width: 20px; height: 20px; object-fit: contain; }
.ch-logo { width: 20px; height: 20px; object-fit: contain; vertical-align: -4px; margin-right: 6px; }
.ch-logo.sm { width: 14px; height: 14px; vertical-align: -2px; margin-right: 4px; }
.ch-logo.lg { width: 34px; height: 34px; margin: 0; }
.type-opt .ic { height: 38px; display: flex; align-items: center; justify-content: center; }
.type-opt:disabled .ch-logo { filter: grayscale(.2); }
.warn-box { background: #fef3c7; color: #92400e; border-radius: 10px; padding: 9px 12px; font-size: 13px; margin: 0 0 10px; }

/* atendimento humano */
.switch-row { display: flex; gap: 12px; align-items: flex-start; font-weight: 400; font-size: 14px; }
.switch-row input { width: 20px; height: 20px; margin: 2px 0 0; flex-shrink: 0; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin: -8px 0 14px; }
.filters button { border: 1px solid var(--line); background: #fff; border-radius: 20px; padding: 7px 14px; font: inherit; font-size: 13px; cursor: pointer; color: var(--text); }
.filters button.active { background: var(--grad); color: #fff; border-color: transparent; font-weight: 600; }
.ai-toggle { display: flex; align-items: center; gap: 10px; }
.switch { position: relative; width: 46px; height: 26px; flex-shrink: 0; margin: 0; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: #cfd2e6; border-radius: 26px; cursor: pointer; transition: .2s; }
.switch span::before { content: ''; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked + span { background: var(--grad); }
.switch input:checked + span::before { transform: translateX(20px); }

/* uso de tokens */
.tok-sub { font-size: 12px; color: var(--muted); margin-top: 3px; }
.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: top; font-variant-numeric: tabular-nums; }
.tbl tr:last-child td { border-bottom: 0; }
.hours-tbl input[type="time"] { margin: 0; padding: 6px 8px; max-width: 130px; }
.hours-tbl td { vertical-align: middle; }

/* Chave de ligar/desligar (bolinha): azul ligada, cinza desligada. Use class="tgl" num checkbox. */
input[type="checkbox"].tgl {
  appearance: none; -webkit-appearance: none; display: inline-block;
  width: 40px !important; height: 22px !important; min-width: 40px; padding: 0 !important; margin: 0 !important; border: 0 !important;
  border-radius: 22px; background: #c3c7d1; position: relative; cursor: pointer; transition: background .2s; flex: none; vertical-align: middle;
}
input[type="checkbox"].tgl::before {
  content: ''; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .2s;
}
input[type="checkbox"].tgl:checked { background: #3b82f6; }
input[type="checkbox"].tgl:checked::before { transform: translateX(18px); }
input[type="checkbox"].tgl:focus { outline: none; }
input[type="checkbox"].tgl:focus-visible { outline: 2px solid #93c5fd; outline-offset: 2px; }
.switch-row input.tgl { margin-top: 2px !important; }
/* a chave de cada conversa também fica azul */
.switch input:checked + span { background: #3b82f6; }
.msg.campaign { background: #fef3c7; align-self: flex-end; border-bottom-right-radius: 4px; }
/* follow-up */
.pill.fu { background: #e0f2fe; color: #075985; }
.fu-tbl input, .fu-tbl select { margin: 0; padding: 6px 8px; max-width: 110px; }
.fu-tbl td { vertical-align: middle; }
