:root {
  --ink: #14201a;
  --muted: #5c6b62;
  --line: rgba(20, 32, 26, 0.12);
  --panel: rgba(255, 252, 247, 0.88);
  --accent: #0f7a4c;
  --accent-2: #c45c26;
  --danger: #b42318;
  --ok: #0f7a4c;
  --radius: 18px;
  --shadow: 0 24px 60px rgba(20, 32, 26, 0.12);
  --font: "DM Sans", sans-serif;
  --display: "Instrument Serif", Georgia, serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: #f3efe6;
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 500px at 10% -10%, rgba(15, 122, 76, 0.18), transparent 60%),
    radial-gradient(700px 480px at 100% 0%, rgba(196, 92, 38, 0.16), transparent 55%),
    linear-gradient(160deg, #f7f2e8 0%, #ebe4d6 45%, #e4efe8 100%);
  animation: drift 18s ease-in-out infinite alternate;
}

@keyframes drift {
  from { filter: hue-rotate(0deg); }
  to { filter: hue-rotate(12deg); }
}

.hidden { display: none !important; }
.shell { width: min(1100px, calc(100% - 2rem)); margin: 0 auto; padding: 2rem 0 4rem; }
.auth-shell { display: grid; gap: 2rem; align-content: center; min-height: 100vh; }

.brand {
  font-family: var(--display);
  font-size: 2.75rem;
  margin: 0;
  letter-spacing: -0.02em;
  animation: rise 0.7s ease both;
}
.brand.compact { font-size: 1.6rem; }
.brand-block h1 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(1.8rem, 4vw, 2.6rem);
  margin: 0.4rem 0 0.6rem;
  max-width: 16ch;
  animation: rise 0.8s ease 0.05s both;
}
.lead {
  color: var(--muted);
  max-width: 42ch;
  margin: 0;
  animation: rise 0.9s ease 0.1s both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.panel {
  background: var(--panel);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.auth-panel { width: min(420px, 100%); animation: rise 0.85s ease 0.15s both; }
.tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.tab {
  border: 1px solid var(--line);
  background: transparent;
  border-radius: 999px;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
  font: inherit;
}
.tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.field { display: grid; gap: 0.35rem; margin-bottom: 0.9rem; }
.field span, .label { font-size: 0.85rem; color: var(--muted); }
input, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
textarea { resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }
textarea.plain, select {
  font-family: var(--font);
  font-size: 0.95rem;
}
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.7rem 0.85rem;
  background: #fff;
  color: var(--ink);
}
.hint {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
}
.field-help {
  font-size: 0.8rem;
  color: var(--muted);
}
.empty.soft { margin-top: 0.5rem; font-size: 0.9rem; }

.btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  border-radius: 12px;
  padding: 0.65rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; }
.btn.full { width: 100%; }

.error { color: var(--danger); font-size: 0.9rem; }
.ok { color: var(--ok); font-size: 0.9rem; }
.muted { color: var(--muted); }
.empty { color: var(--muted); margin: 1rem 0 0; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.25rem;
  animation: rise 0.5s ease both;
}
.topbar-actions { display: flex; gap: 0.5rem; align-items: center; }

.help-modal .help-card {
  width: min(720px, 100%);
  max-height: min(88vh, 900px);
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}
.help-card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--line);
}
.help-card-head h3 { margin: 0; font-size: 1.2rem; }
.help-modal .help-doc {
  padding: 1rem 1.25rem 1.5rem;
  overflow: auto;
}
.help-doc {
  display: grid;
  gap: 1.25rem;
}
.help-article {
  display: grid;
  gap: 1.35rem;
}
.help-article section h4 {
  margin: 0 0 0.5rem;
  font-size: 1.05rem;
}
.help-article p { margin: 0 0 0.55rem; line-height: 1.45; }
.help-article ul {
  margin: 0.35rem 0 0;
  padding-left: 1.2rem;
  line-height: 1.5;
}
.help-article pre {
  margin: 0.5rem 0;
  padding: 0.75rem 0.9rem;
  border-radius: 12px;
  background: #14201a;
  color: #f3efe6;
  font-size: 0.8rem;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.help-article code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
  padding: 0.05rem 0.3rem;
  border-radius: 6px;
  background: rgba(20, 32, 26, 0.06);
}
.help-article pre code {
  padding: 0;
  background: transparent;
  color: inherit;
}
.help-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.help-table th,
.help-table td {
  text-align: left;
  vertical-align: top;
  padding: 0.55rem 0.45rem;
  border-bottom: 1px solid var(--line);
}
.help-table th { color: var(--muted); font-weight: 600; }
.help-actions {
  display: grid;
  gap: 0.45rem;
  margin-top: 0.75rem;
  justify-items: start;
}

.layout { display: grid; gap: 1.25rem; }
.section-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}
.section-head h2, .config-block h3 { margin: 0 0 0.25rem; font-size: 1.2rem; }
.actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

.config-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0 0 1.25rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--line);
}
.config-tab {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}
.config-tab:hover { border-color: var(--accent); color: var(--ink); }
.config-tab.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: rise 0.35s ease both; }

.connect-layout {
  display: grid;
  gap: 1.25rem;
}
@media (min-width: 900px) {
  .connect-layout { grid-template-columns: 1fr 280px; align-items: start; }
}
.connect-steps h3 { margin: 0 0 0.75rem; font-size: 1.15rem; }
.steps {
  margin: 0 0 1.25rem;
  padding-left: 1.2rem;
  color: var(--ink);
  line-height: 1.55;
}
.steps li { margin-bottom: 0.55rem; }
.connect-actions { display: grid; gap: 0.5rem; }

.test-box {
  margin-top: 1.25rem;
  padding-top: 1.15rem;
  border-top: 1px solid var(--line);
}
.test-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}
.test-actions .ok { color: var(--ok); }
.test-actions .error { color: var(--danger); margin: 0; }

.config-block {
  display: grid;
  gap: 0.25rem;
}
.block-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  margin-bottom: 1rem;
}
.block-head.tight { margin-bottom: 0.75rem; }
.block-head h4 { margin: 0 0 0.2rem; font-size: 1rem; }

.switch {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}
.switch input {
  width: 1.1rem;
  height: 1.1rem;
  accent-color: var(--accent);
}

.menu-builder {
  margin-top: 0.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}
.menu-items {
  display: grid;
  gap: 0.85rem;
}
.menu-item {
  display: grid;
  gap: 0.65rem;
  padding: 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
}
.menu-item-top {
  display: grid;
  grid-template-columns: 72px 1fr auto;
  gap: 0.65rem;
  align-items: end;
}
@media (max-width: 640px) {
  .menu-item-top {
    grid-template-columns: 72px 1fr;
  }
  .menu-item-top .btn.danger-ghost {
    grid-column: 1 / -1;
    justify-self: start;
  }
}
.menu-item .field { margin-bottom: 0; }
.menu-item .check {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.9rem;
  cursor: pointer;
}
.menu-item .key-field input {
  text-align: center;
  font-weight: 700;
  font-size: 1.05rem;
}
.btn.danger-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--danger);
  padding: 0.55rem 0.65rem;
}
.btn.danger-ghost:hover { background: #f8e9e7; }

.callout {
  margin-top: 0.5rem;
  padding: 0.9rem 1rem;
  border-radius: 14px;
  background: #eef5f0;
  border: 1px solid rgba(15, 122, 76, 0.15);
  font-size: 0.9rem;
  line-height: 1.45;
  color: var(--ink);
}

.form-footer {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 1rem;
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}
.form-footer.hidden-by-tab { display: none; }

.modal {
  border: none;
  padding: 0;
  background: transparent;
  max-width: calc(100% - 2rem);
}
.modal::backdrop {
  background: rgba(20, 32, 26, 0.45);
  backdrop-filter: blur(4px);
}
.modal-card {
  width: min(420px, 100%);
  margin: auto;
  padding: 1.35rem;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 0.35rem; font-size: 1.25rem; }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.qr-box.connected {
  border-style: solid;
  border-color: rgba(15, 122, 76, 0.35);
  background: #eef8f2;
}
.qr-box .status-big {
  font-family: var(--display);
  font-size: 1.5rem;
  margin: 0;
  color: var(--accent);
}

.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.6rem; }
.list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  cursor: pointer;
  background: #fff;
  transition: border-color 0.15s ease, transform 0.15s ease;
}
.list li:hover, .list li.active { border-color: var(--accent); transform: translateY(-1px); }
.list strong { display: block; }
.list small { color: var(--muted); display: block; }
.list small.tech-id {
  margin-top: 0.2rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  color: var(--ink);
  opacity: 0.7;
  word-break: break-all;
}

.instance-tech {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  margin: 0.55rem 0 0;
  font-size: 0.85rem;
}
.instance-tech-label {
  color: var(--muted);
  font-size: 0.8rem;
}
.instance-tech code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  padding: 0.2rem 0.45rem;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  word-break: break-all;
}
.btn.tiny {
  padding: 0.3rem 0.55rem;
  font-size: 0.78rem;
  border-radius: 8px;
}

.status-pill {
  display: inline-block;
  margin: 0.35rem 0 0;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.8rem;
  background: #e8efe9;
  color: var(--accent);
}
.status-pill.open { background: #d9f2e5; }
.status-pill.connecting { background: #f7e8d8; color: var(--accent-2); }
.status-pill.disconnected { background: #f1e4e2; color: var(--danger); }

.grid-2 { display: grid; gap: 1.25rem; }
.grid-2.tight { grid-template-columns: 1fr; }
@media (min-width: 640px) {
  .grid-2.tight { grid-template-columns: 1fr 1fr; }
}

.qr-box {
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 1rem;
  text-align: center;
  background: #fff;
  min-height: 280px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 0.75rem;
}
.qr-box img {
  width: min(220px, 100%);
  border-radius: 12px;
  animation: rise 0.4s ease both;
  background: #fff;
  /* Evolution costuma gerar QR colorido — força preto clássico */
  filter: grayscale(1) contrast(1.45) brightness(0.92);
}

.inbox-section.bare {
  margin-top: 0;
  padding-top: 0;
  border-top: none;
}
.inbox-section {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}
.inbox-section h3 { margin: 0 0 0.2rem; font-size: 1.1rem; }
.inbox-grid {
  display: grid;
  gap: 1rem;
  min-height: 360px;
}
@media (min-width: 900px) {
  .inbox-grid { grid-template-columns: 260px 1fr; }
}
.inbox-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1.25rem;
  align-items: center;
  margin: 0 0 0.85rem;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #faf8f4;
}
.inbox-me {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.85rem;
  color: var(--muted);
}
.inbox-me select {
  min-width: 140px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.4rem 0.55rem;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
.inbox-filter-mine {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.88rem;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}
.inbox-list { max-height: 420px; overflow: auto; }
.inbox-list .badge {
  display: inline-flex;
  min-width: 1.4rem;
  justify-content: center;
  padding: 0.1rem 0.4rem;
  border-radius: 999px;
  background: var(--accent-2);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
}
.inbox-list li.assigned-mine {
  border-left: 3px solid #2f9e6b;
}
.inbox-list li.assigned-other {
  border-left: 3px solid #c47a1a;
  background: #fff8ee;
}
.inbox-list li.assigned-other .agent-tag {
  color: #9a5a0a;
  font-weight: 600;
}
.inbox-list li.assigned-mine .agent-tag {
  color: #1f7a52;
  font-weight: 600;
}
.inbox-chat {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  display: grid;
  grid-template-rows: auto auto auto 1fr auto;
  min-height: 360px;
}
.inbox-chat-head {
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  font-weight: 600;
  color: var(--ink);
}
.inbox-assign-alert {
  margin: 0;
  padding: 0.55rem 0.85rem;
  border-bottom: 1px solid #e8c99a;
  background: #fff4e5;
  color: #7a4a0a;
  font-size: 0.88rem;
  line-height: 1.35;
}
.inbox-assign-alert.mine {
  border-bottom-color: #b7e0cc;
  background: #eefaf3;
  color: #1f5c3d;
}
.inbox-assign-alert.hidden {
  display: none;
}
.inbox-messages {
  padding: 1rem;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  max-height: 320px;
}
.bubble {
  max-width: 85%;
  padding: 0.55rem 0.75rem;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.35;
  white-space: pre-wrap;
}
.bubble.inbound {
  align-self: flex-start;
  background: #eef3ef;
}
.bubble.outbound {
  align-self: flex-end;
  background: #dcefe4;
}
.bubble .meta {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.72rem;
  color: var(--muted);
}
.inbox-reply {
  display: grid;
  gap: 0.55rem;
  padding: 0.75rem;
  border-top: 1px solid var(--line);
}
.inbox-reply select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.55rem 0.75rem;
  font: inherit;
  background: #fff;
  color: var(--ink);
}
.inbox-reply-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.inbox-reply-row input { flex: 1; min-width: 160px; }
.inbox-attach {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.inbox-attach input[type="text"] {
  flex: 1;
  min-width: 160px;
}
.agents-block {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--line);
}
.agents-add {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}
.agents-add input { flex: 1; min-width: 160px; }
.agents-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.45rem;
}
.agents-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}
.inbox-assign {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: end;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--line);
  background: #faf8f4;
}
.inbox-assign label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.8rem;
  color: var(--muted);
}
.inbox-assign select {
  min-width: 180px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.45rem 0.65rem;
  font: inherit;
  background: #fff;
}
