:root {
  --bg: #ffffff;
  --side: #f0f4f9;
  --surface: #f0f4f9;
  --surface-2: #e3e8ee;
  --hover: #e1e7ee;
  --text: #1f1f1f;
  --muted: #5f6368;
  --border: #dadce0;
  --accent: #0b57d0;
  --code-bg: #f6f8fb;
  --err: #b3261e;
  --err-bg: #fce8e6;
}
/* Tema: theme.js define data-theme="light"|"dark" no <html>; a media query é só o fallback sem JS */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131314;
    --side: #1e1f20;
    --surface: #1e1f20;
    --surface-2: #2d2f31;
    --hover: #333537;
    --text: #e3e3e3;
    --muted: #9aa0a6;
    --border: #3c4043;
    --accent: #a8c7fa;
    --code-bg: #171819;
    --err: #f2b8b5;
    --err-bg: #3b1f1e;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131314;
  --side: #1e1f20;
  --surface: #1e1f20;
  --surface-2: #2d2f31;
  --hover: #333537;
  --text: #e3e3e3;
  --muted: #9aa0a6;
  --border: #3c4043;
  --accent: #a8c7fa;
  --code-bg: #171819;
  --err: #f2b8b5;
  --err-bg: #3b1f1e;
  color-scheme: dark;
}
:root[data-theme="light"] { color-scheme: light; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  background: var(--bg);
  color: var(--text);
  font-family: "Google Sans", "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.6;
}
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }

/* Sidebar */
#sidebar {
  width: 280px;
  flex-shrink: 0;
  background: var(--side);
  display: flex;
  flex-direction: column;
  padding: 12px;
  transition: margin-left .2s ease;
}
body.side-closed #sidebar { margin-left: -280px; }
.side-top { height: 48px; display: flex; align-items: center; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: grid; place-items: center; color: var(--muted);
}
.icon-btn:hover { background: var(--hover); }
.new-chat {
  display: flex; align-items: center; gap: 12px;
  margin: 12px 0 20px; padding: 10px 16px; width: fit-content;
  border-radius: 999px; background: var(--surface-2); font-size: 14px; font-weight: 500;
}
.new-chat:hover { background: var(--hover); }
.side-label { padding: 0 12px 8px; font-size: 14px; font-weight: 500; }
#history { flex: 1; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.h-item {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px 12px; border-radius: 999px; font-size: 14px; cursor: pointer;
}
.h-item:hover { background: var(--hover); }
.h-item.active { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.h-item span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-item .del { opacity: 0; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 4px; }
.h-item:hover .del { opacity: 1; }
.side-foot { padding-top: 10px; }
.db-pill {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  border-radius: 12px; font-size: 12px; color: var(--muted); word-break: break-all;
}

/* Main */
#main { flex: 1; min-width: 0; display: flex; flex-direction: column; height: 100%; }
.topbar { height: 64px; display: flex; align-items: center; gap: 8px; padding: 0 20px; flex-shrink: 0; }
.brand { font-size: 22px; font-weight: 500; letter-spacing: .2px; }
.only-mobile { display: none; }
body.side-closed .only-mobile { display: grid; }
#scroll { flex: 1; overflow-y: auto; scroll-behavior: smooth; }
#messages, .empty { max-width: 820px; margin: 0 auto; padding: 0 20px; }

/* Empty state */
.empty { padding-top: 9vh; }
.empty h1 { font-size: 56px; line-height: 1.15; margin: 0; font-weight: 500; }
.empty h2 { font-size: 56px; line-height: 1.15; margin: 0 0 32px; font-weight: 500; color: var(--surface-2); }
:root:not([data-theme="dark"]) .empty h2 { color: #c4c7c5; }
.grad {
  background: linear-gradient(74deg, #4285f4 0, #9b72cb 9%, #d96570 20%, #d96570 24%, #9b72cb 35%, #4285f4 44%, #9b72cb 50%, #d96570 56%);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.chips { display: flex; flex-wrap: wrap; gap: 12px; }
.chip {
  background: var(--surface); border-radius: 16px; padding: 14px 16px;
  width: 190px; min-height: 110px; text-align: left; font-size: 14px; line-height: 1.4;
}
.chip:hover { background: var(--hover); }

/* Messages */
.msg { display: flex; gap: 16px; padding: 14px 0; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  background: var(--surface); padding: 12px 20px; border-radius: 24px 24px 6px 24px;
  max-width: 80%; white-space: pre-wrap; word-break: break-word;
}
.avatar { width: 32px; height: 32px; flex-shrink: 0; margin-top: 2px; }
.avatar.spin { animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(.82); opacity: .6; } }
.body { flex: 1; min-width: 0; }
.status { color: var(--muted); font-size: 14px; margin-bottom: 8px; }
.md > :first-child { margin-top: 0; }
.md p { margin: 0 0 12px; }
.md ul, .md ol { padding-left: 24px; margin: 0 0 12px; }
.md h1, .md h2, .md h3 { font-weight: 500; margin: 20px 0 8px; line-height: 1.3; }
.md code { background: var(--code-bg); padding: 2px 6px; border-radius: 6px; font-size: .9em; }
.md pre { background: var(--code-bg); padding: 12px 16px; border-radius: 12px; overflow-x: auto; }
.md pre code { padding: 0; background: none; }
.md table { border-collapse: collapse; margin: 0 0 12px; font-size: 14px; }
.md th, .md td { border: 1px solid var(--border); padding: 6px 10px; }

/* SQL + result blocks */
details.sql, .result {
  border: 1px solid var(--border); border-radius: 16px; margin: 4px 0 14px; overflow: hidden;
}
details.sql summary {
  cursor: pointer; padding: 10px 16px; font-size: 14px; color: var(--muted);
  display: flex; align-items: center; gap: 8px; list-style: none; user-select: none;
}
details.sql summary::-webkit-details-marker { display: none; }
details.sql summary::before { content: "▸"; transition: transform .15s; }
details.sql[open] summary::before { transform: rotate(90deg); }
details.sql pre {
  margin: 0; padding: 12px 16px; background: var(--code-bg); overflow-x: auto;
  font: 13px/1.5 "SF Mono", Menlo, Consolas, monospace; border-top: 1px solid var(--border);
}
.sql-actions { display: flex; justify-content: flex-end; padding: 6px 12px; background: var(--code-bg); border-top: 1px solid var(--border); }
.link-btn { color: var(--accent); font-size: 13px; padding: 2px 8px; border-radius: 8px; }
.link-btn:hover { background: var(--hover); }
.result .tbl { max-height: 360px; overflow: auto; }
.result table { border-collapse: collapse; width: 100%; font-size: 13px; }
.result th {
  position: sticky; top: 0; background: var(--surface); text-align: left; font-weight: 500;
  padding: 8px 12px; white-space: nowrap; border-bottom: 1px solid var(--border);
}
.result td { padding: 6px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.result td.num { text-align: right; font-variant-numeric: tabular-nums; }
.result tr:last-child td { border-bottom: 0; }
.result-foot { display: flex; justify-content: space-between; align-items: center; padding: 6px 12px 6px 16px; font-size: 12px; color: var(--muted); border-top: 1px solid var(--border); }
.qerr { background: var(--err-bg); color: var(--err); padding: 10px 16px; border-radius: 12px; font-size: 14px; margin: 4px 0 14px; }

/* Composer */
.composer-wrap { padding: 8px 20px 12px; flex-shrink: 0; }
.composer {
  max-width: 820px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface); border-radius: 28px; padding: 10px 10px 10px 24px;
  border: 1px solid transparent;
}
.composer:focus-within { border-color: var(--border); }
.composer textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: none; color: var(--text);
  font: inherit; line-height: 1.5; max-height: 200px; padding: 8px 0;
}
.composer textarea::placeholder { color: var(--muted); }
.send {
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center;
  color: var(--accent);
}
.send:not(:disabled):hover { background: var(--hover); }
.send:disabled { color: var(--muted); opacity: .5; cursor: default; }
.room-gone {
  margin: 0 0 8px; padding: 10px 14px; border-radius: 12px; font-size: 14px; text-align: center;
  color: var(--text); background: color-mix(in srgb, #d93025 16%, transparent); border: 1px solid color-mix(in srgb, #d93025 45%, transparent);
}
.disclaimer { text-align: center; font-size: 12px; color: var(--muted); margin: 8px 0 0; }

#scrim { display: none; }
@media (max-width: 800px) {
  #sidebar { position: fixed; z-index: 20; inset: 0 auto 0 0; margin-left: -280px; box-shadow: 2px 0 12px rgba(0,0,0,.25); }
  body:not(.side-closed) #sidebar { margin-left: 0; }
  body:not(.side-closed) #scrim { display: block; position: fixed; inset: 0; z-index: 10; background: rgba(0,0,0,.35); }
  .only-mobile { display: grid; }
  .empty h1, .empty h2 { font-size: 36px; }
  .chip { width: calc(50% - 6px); }
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { max-width: none; max-height: 94vh; border-radius: 24px 24px 0 0; padding: 20px 16px; }
  .users-add { flex-wrap: wrap; }
  .users-add input { flex-basis: 100%; }
  .users-add select { flex: 1; }
  .stage-row { flex-wrap: wrap; }
  .stage-row .field { flex-basis: 100%; }
  .stage-row .btn { flex: 1; }
}

/* Login */
.login-body { align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: 28px; padding: 36px 32px 28px; text-align: center; }
.login-logo { width: 44px; height: 44px; }
.login-title { font-size: 34px; font-weight: 500; margin: 8px 0 20px; line-height: 1.2; }
.login-form { display: flex; flex-direction: column; gap: 14px; }
.login-form[hidden] { display: none; }
.login-sub { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.login-sub strong { color: var(--text); word-break: break-all; }
.login-form input {
  width: 100%; padding: 14px 18px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit; outline: 0; text-align: center;
}
.login-form input:focus { border-color: var(--accent); }
.code-input { font-size: 28px; letter-spacing: 10px; text-indent: 10px; font-variant-numeric: tabular-nums; }
.login-btn { padding: 12px 20px; border-radius: 999px; background: var(--accent); color: var(--bg); font-weight: 500; }
:root:not([data-theme="dark"]) .login-btn { color: #fff; }
.login-btn:disabled { opacity: .5; cursor: default; }
.login-links { display: flex; justify-content: space-between; }
.link-btn:disabled { color: var(--muted); cursor: default; }
.login-msg { min-height: 20px; margin: 16px 0 0; font-size: 14px; color: var(--err); }
.login-msg.ok { color: var(--muted); }

/* Usuário logado */
.user-menu { position: relative; }
.user-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; padding: 8px 12px; border-radius: 10px; font-size: 12px; color: var(--muted);
}
.user-row:hover { background: var(--hover); }
.user-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-row .chev { flex-shrink: 0; }
.user-dropdown {
  position: absolute; bottom: calc(100% + 4px); left: 0; right: 0; z-index: 25;
  background: var(--bg); border: 1px solid var(--border); border-radius: 12px;
  padding: 6px; display: flex; flex-direction: column; gap: 2px;
  box-shadow: 0 4px 16px rgba(0,0,0,.2);
}
.user-dropdown[hidden] { display: none; }
.dropdown-item { display: block; width: 100%; text-align: left; padding: 8px 12px; border-radius: 8px; font-size: 13px; }
.dropdown-item:hover { background: var(--hover); }
.theme-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 6px 6px 12px; font-size: 13px; }
.theme-switch { display: flex; gap: 2px; padding: 2px; border-radius: 999px; background: var(--surface-2); }
.theme-switch button {
  width: 30px; height: 26px; border-radius: 999px; display: grid; place-items: center; color: var(--muted);
}
.theme-switch button:hover { color: var(--text); }
.theme-switch button[aria-pressed="true"] { background: var(--bg); color: var(--accent); box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.dropdown-sep { height: 1px; background: var(--border); margin: 4px 6px; }

/* Modais de configuração */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center; z-index: 30; padding: 20px;
  animation: fade-in .15s ease;
}
.modal-backdrop[hidden] { display: none; }
#room-edit-modal { z-index: 31; }
.modal {
  background: var(--bg); border: 1px solid var(--border); border-radius: 24px; padding: 24px;
  width: 100%; max-width: 440px; max-height: 88vh; display: flex; flex-direction: column; gap: 16px;
  box-shadow: 0 24px 64px rgba(0,0,0,.25); animation: pop-in .18s ease;
}
.modal-lg { max-width: 600px; }
@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(8px) scale(.98); } }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.modal-head h3 { margin: 0; font-size: 22px; font-weight: 500; line-height: 1.3; }
.modal-sub { margin: 4px 0 0; font-size: 14px; color: var(--muted); line-height: 1.45; }
.modal-sub:empty { display: none; }
.modal-head .icon-btn { flex-shrink: 0; margin: -6px -8px 0 0; }
.modal-body { display: flex; flex-direction: column; gap: 22px; overflow-y: auto; min-height: 0; margin: 0 -8px; padding: 0 8px; }
.modal-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding-top: 16px; border-top: 1px solid var(--border); }

/* Botões */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px; border-radius: 999px; font-size: 14px; font-weight: 500; white-space: nowrap;
  transition: background .15s, opacity .15s;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--accent); color: var(--bg); }
:root:not([data-theme="dark"]) .btn-primary { color: #fff; }
.btn-primary:not(:disabled):hover { opacity: .9; }
.btn-ghost { color: var(--accent); }
.btn-ghost:not(:disabled):hover { background: var(--hover); }
.btn-soft { background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent); padding: 6px 14px; font-size: 13px; }
.btn-soft:not(:disabled):hover { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.btn-block { width: 100%; padding: 11px 18px; }
.icon-action {
  width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); flex-shrink: 0;
}
.icon-action:hover { background: var(--surface-2); color: var(--text); }
.icon-action.danger:hover { background: var(--err-bg); color: var(--err); }

/* Mensagens */
.notice { margin: 0; font-size: 14px; line-height: 1.45; padding: 10px 14px; border-radius: 12px; background: var(--err-bg); color: var(--err); }
.notice:empty { display: none; }
.notice.ok { background: color-mix(in srgb, #1e8e3e 14%, transparent); color: #1e8e3e; }
.notice.info { background: var(--surface); color: var(--muted); }
:root[data-theme="dark"] .notice.ok { color: #81c995; }

/* Formulários */
.form-section { display: flex; flex-direction: column; gap: 8px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.section-title { font-size: 15px; font-weight: 500; color: var(--text); }
.hint { margin: 0; font-size: 13px; color: var(--muted); line-height: 1.45; }
.hint:empty { display: none; }
.field {
  width: 100%; min-width: 0; padding: 10px 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: 15px; outline: 0;
  transition: border-color .15s, box-shadow .15s;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
.field:disabled { opacity: .7; cursor: default; }
.rules-field { resize: vertical; min-height: 120px; line-height: 1.5; }
.question-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; counter-reset: q; }
.question-list li { display: flex; align-items: center; gap: 6px; counter-increment: q; }
.question-list li::before {
  content: counter(q); width: 24px; flex-shrink: 0; text-align: center; font-size: 13px; color: var(--muted);
}
.question-list .empty-q { color: var(--muted); font-size: 14px; padding: 4px 0; }
.question-list .empty-q::before { content: none; }
#room-q-add { align-self: flex-start; padding-left: 12px; }
#room-q-add[hidden] { display: none; }

/* Upload de CSV */
.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 4px; width: 100%;
  padding: 20px 16px; border: 2px dashed var(--border); border-radius: 16px; color: var(--muted);
  text-align: center; transition: border-color .15s, background .15s;
}
.dropzone strong { color: var(--text); font-weight: 500; font-size: 14px; }
.dropzone svg { color: var(--accent); }
.dropzone:hover, .dropzone.drag { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); }
.dropzone[hidden] { display: none; }
.stage { display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: 16px; background: var(--surface); }
.stage[hidden] { display: none; }
.stage-file { display: flex; align-items: center; gap: 10px; font-size: 14px; min-width: 0; }
.stage-row { display: flex; gap: 6px; align-items: center; }
.stage-sheet { display: flex; flex-direction: column; gap: 6px; }
.stage-sheet[hidden] { display: none; }
.stage-sheet .field { background: var(--bg); }
.file-icon.xlsx { color: #188038; background: color-mix(in srgb, #188038 16%, transparent); }
.stage-row .field { flex: 1; background: var(--bg); }
.file-icon {
  font-size: 10px; font-weight: 700; letter-spacing: .5px; padding: 4px 6px; border-radius: 6px; flex-shrink: 0;
  color: #1e8e3e; background: color-mix(in srgb, #1e8e3e 16%, transparent);
}
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* Listas em cartões */
.card-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; min-height: 0; display: flex; flex-direction: column; gap: 8px; }
.card-list > li {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 16px;
  border: 1px solid var(--border); transition: background .15s, border-color .15s;
}
.card-list > li:hover { background: var(--surface); }
.card-list > li.active { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, transparent); }
.card-list > li.muted, .card-list > li.placeholder { border-style: dashed; justify-content: center; color: var(--muted); font-size: 14px; }
.card-list > li.placeholder:hover { background: none; }
.card-list-compact > li { padding: 8px 10px 8px 12px; border-radius: 12px; }
.avatar {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; flex-shrink: 0;
  font-weight: 600; font-size: 15px; color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent);
}
.avatar.round { border-radius: 50%; }
.avatar.sm { width: 30px; height: 30px; border-radius: 8px; font-size: 12px; }
.card-main { flex: 1; min-width: 0; }
.card-title { display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 500; min-width: 0; }
.card-title .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-title.clickable { cursor: pointer; }
.card-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }
.badge {
  font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 999px; flex-shrink: 0;
  color: var(--muted); background: var(--surface-2);
}
.badge.accent { color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }
.badge.pending { color: #b06000; background: color-mix(in srgb, #f9ab00 20%, transparent); }

/* Usuários */
.users-add { display: flex; gap: 8px; }
.users-add input, .users-add select {
  padding: 10px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); font: inherit; font-size: 15px; outline: 0;
}
.users-add input { flex: 1; min-width: 0; }
.users-add input:focus, .users-add select:focus { border-color: var(--accent); }
.role-select {
  font: inherit; font-size: 13px; color: var(--muted); background: var(--surface-2);
  border: 0; padding: 5px 10px; border-radius: 999px; outline: 0; flex-shrink: 0; cursor: pointer;
}
.role-select.role-admin { color: var(--accent); background: color-mix(in srgb, var(--accent) 16%, transparent); }

/* Tela da API */
.stat-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { padding: 12px 14px; border-radius: 14px; background: var(--surface); min-width: 0; }
.stat-value { font-size: 22px; font-weight: 500; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12px; color: var(--muted); }
.usage-chart { margin: 4px 0 0; display: flex; flex-direction: column; gap: 6px; }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 96px; border-bottom: 1px solid var(--border); }
.bars .bar-slot { flex: 1; height: 100%; display: flex; align-items: flex-end; position: relative; cursor: default; }
.bars .bar { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 0; }
.bars .bar-slot:hover .bar { opacity: .75; }
.bars .bar-slot:hover::after {
  content: attr(data-tip); position: absolute; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  white-space: nowrap; font-size: 12px; padding: 4px 8px; border-radius: 8px; z-index: 2; pointer-events: none;
  background: var(--text); color: var(--bg);
}
.bars .bar-slot:first-child:hover::after { left: 0; transform: none; }
.bars .bar-slot:last-child:hover::after { left: auto; right: 0; transform: none; }
.bars-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); }
.token-box { display: flex; flex-direction: column; gap: 8px; padding: 14px; border-radius: 16px;
  background: color-mix(in srgb, #1e8e3e 10%, transparent); border: 1px solid color-mix(in srgb, #1e8e3e 35%, transparent); }
.token-box[hidden] { display: none; }
.mono, .code-line, .code-block, .endpoints code { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 13px; }
.code-line { display: block; padding: 8px 12px; border-radius: 10px; background: var(--code-bg); border: 1px solid var(--border); overflow-x: auto; white-space: nowrap; }
.code-block { margin: 0; padding: 12px; border-radius: 10px; background: var(--code-bg); border: 1px solid var(--border); overflow-x: auto; line-height: 1.5; }
.endpoints { border-collapse: collapse; width: 100%; font-size: 13px; table-layout: fixed; }
.endpoints td { padding: 6px 8px 6px 0; border-bottom: 1px solid var(--border); vertical-align: top; }
.endpoints td:first-child { width: 52px; }
.endpoints td:nth-child(2) { width: 58%; overflow-wrap: anywhere; }
.endpoints td:nth-child(2) code { overflow-wrap: anywhere; word-break: break-all; }
.endpoints td:last-child { color: var(--muted); }
.method { font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px; }
.method.get { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }
.method.post { color: #1e8e3e; background: color-mix(in srgb, #1e8e3e 16%, transparent); }
:root[data-theme="dark"] .method.post { color: #81c995; }
.card-list > li.revoked { opacity: .6; }
@media (max-width: 800px) { .stat-row { grid-template-columns: repeat(2, 1fr); } }

/* Tela de uso de tokens */
.quota-card { display: flex; flex-direction: column; gap: 10px; padding: 16px; border-radius: 16px; background: var(--surface); }
.quota-top { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.quota-big { font-size: 28px; font-weight: 500; line-height: 1.1; font-variant-numeric: tabular-nums; }
.quota-big small { font-size: 14px; font-weight: 400; color: var(--muted); }
.meter { height: 10px; border-radius: 999px; background: var(--surface-2); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: 999px; background: var(--accent); transition: width .3s ease; }
.quota-card.warn .meter > span { background: #e37400; }
.quota-card.crit .meter > span { background: #d93025; }
.quota-foot { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.status-pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 500; padding: 2px 10px; border-radius: 999px; }
.status-pill.ok { color: #1e8e3e; background: color-mix(in srgb, #1e8e3e 14%, transparent); }
.status-pill.warn { color: #b06000; background: color-mix(in srgb, #f9ab00 22%, transparent); }
.status-pill.crit { color: var(--err); background: var(--err-bg); }
.status-pill.none { color: var(--muted); background: var(--surface-2); }
:root[data-theme="dark"] .status-pill.ok { color: #81c995; }
:root[data-theme="dark"] .status-pill.warn { color: #fdd663; }
:root[data-theme="dark"] .quota-card.warn .meter > span { background: #fbbc04; }
:root[data-theme="dark"] .quota-card.crit .meter > span { background: #f28b82; }
.usage-table { width: 100%; border-collapse: collapse; font-size: 13px; table-layout: fixed; }
.usage-table th { text-align: left; font-weight: 500; color: var(--muted); padding: 6px 8px 6px 0; border-bottom: 1px solid var(--border); }
.usage-table td { padding: 8px 8px 8px 0; border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.usage-table th:first-child, .usage-table td:first-child { width: 45%; }
.usage-table th:not(:first-child), .usage-table td:not(:first-child) { text-align: right; }
.share { display: flex; align-items: center; justify-content: flex-end; gap: 6px; }
.share .meter { width: 48px; height: 6px; flex-shrink: 0; }

/* Conectores */
#connector-edit-modal { z-index: 31; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.check-row input { width: 16px; height: 16px; accent-color: var(--accent); }
.sent-block {
  display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px; border-radius: 12px; margin: 4px 0 14px;
  font-size: 14px; background: color-mix(in srgb, #1e8e3e 12%, transparent); color: var(--text);
}
.sent-block svg { flex-shrink: 0; margin-top: 2px; color: #1e8e3e; }
:root[data-theme="dark"] .sent-block svg { color: #81c995; }
.sent-block .sub { color: var(--muted); font-size: 13px; }

/* Agentes */
.topbar-action { margin-left: auto; }
.topbar-action[hidden] { display: none; }
#agent-edit-modal { z-index: 31; }
.modal-xl { max-width: 820px; }
.form-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.prompt-wrap { position: relative; }
.prompt-field { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 13px; line-height: 1.55; resize: vertical; min-height: 280px; }
.prompt-loading {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; gap: 10px;
  border-radius: 12px; background: color-mix(in srgb, var(--surface) 92%, transparent); color: var(--muted); font-size: 14px;
}
.prompt-loading[hidden] { display: none; }
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.status-dot.ok { background: #1e8e3e; }
.status-dot.erro { background: #d93025; }
@media (max-width: 800px) { .form-grid { grid-template-columns: 1fr; } .topbar-action span { display: none; } }
#agent-runs-modal { z-index: 31; }
.spinner.sm { width: 12px; height: 12px; border-width: 2px; display: inline-block; vertical-align: -2px; }
.runs-list > li.run-item { flex-direction: column; align-items: stretch; gap: 8px; }
.run-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.run-events { list-style: none; margin: 0; padding: 0; font-size: 13px; display: flex; flex-direction: column; gap: 2px; }
.run-events .err { color: var(--err); }
.run-answer summary, .run-sql summary { cursor: pointer; font-size: 13px; color: var(--accent); }
.run-answer .md { font-size: 14px; padding-top: 6px; overflow-x: auto; }
.run-answer .md table { border-collapse: collapse; font-size: 13px; }
.run-answer .md th, .run-answer .md td { border-bottom: 1px solid var(--border); padding: 4px 8px; text-align: left; }
.run-sql pre { margin: 6px 0 0; padding: 8px 10px; border-radius: 8px; background: var(--code-bg); font-size: 12px; overflow-x: auto; }

/* Janela de Configurações (menu à esquerda, conteúdo à direita) */
.settings {
  display: flex; width: 100%; min-width: 0; max-width: 1100px; height: min(820px, 90vh);
  background: var(--bg); border: 1px solid var(--border); border-radius: 20px; overflow: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,.3); animation: pop-in .18s ease;
}
.settings-nav {
  width: 240px; flex-shrink: 0; min-width: 0; display: flex; flex-direction: column; gap: 2px;
  padding: 14px 10px; background: var(--side); border-right: 1px solid var(--border); overflow-y: auto;
}
.settings-search {
  display: flex; align-items: center; gap: 8px; margin: 0 2px 14px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--muted);
}
.settings-search:focus-within { border-color: var(--accent); }
.settings-search input { flex: 1; min-width: 0; border: 0; outline: 0; background: none; color: var(--text); font: inherit; font-size: 14px; }
.settings-group { font-size: 12px; color: var(--muted); padding: 6px 10px 6px; }
.settings-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 10px;
  font-size: 14px; color: var(--text); text-align: left;
}
.settings-item svg { color: var(--muted); flex-shrink: 0; }
.settings-item:hover { background: var(--hover); }
.settings-item.active { background: var(--hover); font-weight: 500; }
.settings-item.active svg { color: var(--text); }
.settings-item[hidden], .settings-empty[hidden] { display: none; }
.settings-empty { padding: 6px 10px; }
.settings-main { position: relative; flex: 1; min-width: 0; overflow-y: auto; padding: 28px 36px 32px; }
.settings-close { position: absolute; top: 14px; right: 14px; z-index: 1; }
.settings-pane { display: flex; flex-direction: column; gap: 18px; max-width: 760px; }
.settings-pane[hidden] { display: none; }
.pane-head { padding-right: 40px; }
.pane-head h2 { margin: 0; font-size: 20px; font-weight: 500; }
.settings-pane .modal-body { overflow: visible; margin: 0; padding: 0; }
.pane-action { align-self: flex-start; }
@media (max-width: 800px) {
  .settings { flex-direction: column; height: 94vh; border-radius: 20px 20px 0 0; }
  .settings-nav { width: auto; flex-direction: row; align-items: center; gap: 4px; padding: 10px; border-right: 0; border-bottom: 1px solid var(--border); overflow-x: auto; }
  .settings-search, .settings-group, .settings-empty { display: none; }
  .settings-item { width: auto; white-space: nowrap; }
  .settings-main { padding: 20px 16px; }
}

/* Celular: fica no fim do arquivo para valer sobre as regras dos modais acima */
@media (max-width: 800px) {
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { max-width: none; max-height: 94vh; border-radius: 24px 24px 0 0; padding: 20px 16px; }
  .settings { max-width: none; height: 94vh; border-radius: 20px 20px 0 0; }
  .users-add { flex-wrap: wrap; }
  .users-add input { flex-basis: 100%; }
  .users-add select { flex: 1; }
  .stat-row { grid-template-columns: repeat(2, 1fr); }
  .card-list > li { flex-wrap: wrap; }
  .card-actions { margin-left: auto; }
}

/* Conectores: galeria de tipos e telas por tipo */
.type-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.type-card {
  display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding: 14px; border-radius: 14px;
  border: 1px solid var(--border); text-align: left; transition: border-color .15s, background .15s;
}
.type-card:hover { border-color: var(--accent); background: var(--surface); }
.type-card strong { font-size: 14px; font-weight: 500; }
.type-card span.hint { font-size: 12px; line-height: 1.4; }
.type-icon {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0;
  color: #fff; background: var(--c, var(--accent));
}
.type-icon svg { width: 20px; height: 20px; }
.type-icon.sm { width: 30px; height: 30px; border-radius: 8px; }
.type-icon.sm svg { width: 16px; height: 16px; }
.conn-head { display: flex; align-items: center; gap: 12px; }
.hint code { font-family: "SF Mono", Menlo, Consolas, monospace; font-size: 12px; background: var(--surface-2); padding: 1px 5px; border-radius: 5px; }
.field-row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.payload-preview { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--code-bg); border: 1px solid var(--border); font-size: 12px; line-height: 1.5; overflow-x: auto; }
@media (max-width: 800px) { .field-row2 { grid-template-columns: 1fr; } }

/* Conector de e-mail: servidor SMTP */
.preset-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-btn { font-size: 13px; padding: 5px 12px; border-radius: 999px; border: 1px solid var(--border); color: var(--text); }
.chip-btn:hover { border-color: var(--accent); color: var(--accent); }
.smtp-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mini-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); min-width: 0; }
.mini-field.wide:first-child { grid-column: 1 / -1; }
@media (max-width: 800px) { .smtp-grid { grid-template-columns: 1fr; } .mini-field.wide:first-child { grid-column: auto; } }

/* Conector MCP: ferramentas */
.tool-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.tool-row { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; }
.tool-row:hover { background: var(--surface); }
.tool-row input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); flex-shrink: 0; }
.tool-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.tool-name { font-size: 14px; font-weight: 500; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tool-name code { font-size: 12px; color: var(--muted); }
.mcp-block summary { color: var(--text); }
.mcp-block.failed summary { color: var(--err); }
.mcp-io { padding: 8px 16px 12px; background: var(--code-bg); border-top: 1px solid var(--border); }
.mcp-io pre { margin: 4px 0 10px; font-size: 12px; white-space: pre-wrap; word-break: break-word; max-height: 260px; overflow: auto; }

/* Ingestão: fontes externas e importação */
#source-edit-modal, #import-modal { z-index: 31; }
.import-modal { height: min(760px, 90vh); }
.import-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; font-size: 14px; min-width: 0; }
.crumbs button { padding: 4px 8px; border-radius: 8px; color: var(--accent); }
.crumbs button:hover { background: var(--hover); }
.crumbs button[disabled] { color: var(--text); font-weight: 500; cursor: default; background: none; }
.crumbs .sep { color: var(--muted); }
.import-search { margin: 0; padding: 6px 10px; width: 220px; }
.browse-list { list-style: none; margin: 0; padding: 0; flex: 1; min-height: 120px; overflow-y: auto; border: 1px solid var(--border); border-radius: 14px; }
.browse-list li { border-bottom: 1px solid var(--border); }
.browse-list li:last-child { border-bottom: 0; }
.browse-row { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 14px; text-align: left; font-size: 14px; cursor: pointer; }
.browse-row:hover { background: var(--surface); }
.browse-row input { width: 16px; height: 16px; accent-color: var(--accent); flex-shrink: 0; }
.browse-row svg { color: var(--muted); flex-shrink: 0; }
.browse-row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.browse-row .grow .hint { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.browse-row .chev { color: var(--muted); }
.browse-list .placeholder { padding: 24px; text-align: center; color: var(--muted); font-size: 14px; border: 0; }
.import-dest { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: 10px; }
.import-dest[hidden] { display: none; }
.import-count { margin-right: auto; }
.imp-status { display: inline-flex; align-items: center; gap: 6px; }
@media (max-width: 800px) { .import-dest { grid-template-columns: 1fr; } .import-search { width: 100%; } }
.radio-hint { margin: -4px 0 4px 24px; }
.mini-field.full { grid-column: 1 / -1; }
