:root {
  /* "Central de Atendimento" palette — cool neutral ground, indigo accent.
     Deliberately distinct from stock WhatsApp green: this is a business
     support console, not a WhatsApp Web clone. */
  --accent: #4f46e5;
  --accent-strong: #4338ca;
  --accent-soft: #ecebff;
  --bg: #f7f7fb;
  --panel: #ffffff;
  --surface-2: #f1f1f6;
  --border: #e3e3ef;
  --text: #191926;
  --text-muted: #6d6d88;
  --danger: #dc2626;
  --success: #16a34a;
  --success-soft: #e8f8ee;
  --warning: #b45309;
  --warning-soft: #fdf1de;
  --rail-bg: #15152b;
  --rail-icon: #8383b8;
  --rail-icon-active: #ffffff;
}

* { box-sizing: border-box; }

/* Several elements below are toggled via the HTML `hidden` attribute AND
   carry a class that sets `display` unconditionally (e.g. `.thread { display:
   flex }`) — same specificity, author rule applied after the UA stylesheet,
   so the class rule was winning and the element stayed visible even while
   `hidden`. This guarantees `hidden` always wins, everywhere. */
[hidden] { display: none !important; }

/* Manrope for anything UI-chrome (headings, buttons, labels); IBM Plex Sans
   (the body default) for anything read at length — message text, tables. */
h1, h2, h3, button, strong, .status-pill, .status-tab {
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  margin: 0;
  font-family: 'IBM Plex Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Auth page --- */
.auth-page {
  justify-content: center;
  align-items: center;
}

.auth-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  width: 320px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
}

.auth-card h1 {
  margin: 0;
  font-size: 20px;
}

.auth-subtitle {
  margin: 0 0 8px;
  color: var(--text-muted);
  font-size: 14px;
}

.auth-card label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
}

input, select, button, textarea {
  font: inherit;
}

input, select {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  color: var(--text);
}

button {
  cursor: pointer;
  border: none;
  border-radius: 6px;
  padding: 9px 14px;
  background: var(--accent-strong);
  color: white;
  font-weight: 600;
}

button:hover { opacity: 0.9; }
button:disabled { opacity: 0.5; cursor: default; }

.link-btn {
  background: none;
  color: var(--text-muted);
  font-weight: 400;
  padding: 4px 8px;
}

.error {
  color: var(--danger);
  font-size: 13px;
  margin: 0;
}

/* --- Topbar --- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  background: var(--accent-strong);
  color: white;
  flex-shrink: 0;
}

.topbar a, .topbar .link-btn { color: white; text-decoration: none; }
.topbar-left, .topbar-right { display: flex; align-items: center; gap: 14px; }
.conn-status { font-size: 12px; opacity: 0.85; }
.conn-status.ok { color: #dcfce7; opacity: 1; font-weight: 600; }
.conn-status.warn { color: #fef9c3; opacity: 1; font-weight: 600; }
.conn-status.bad { color: #fecaca; opacity: 1; font-weight: 600; }

/* --- Layout --- */
.layout {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

/* --- Icon rail (app-level navigation) --- */
.icon-rail {
  width: 60px;
  flex-shrink: 0;
  background: var(--rail-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 10px;
}

.rail-logo {
  width: 32px;
  height: 32px;
  border-radius: 9px;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Manrope', sans-serif;
  font-weight: 800;
  font-size: 14px;
  margin-bottom: 10px;
  flex-shrink: 0;
}

.rail-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--rail-icon);
  font-size: 18px;
  text-decoration: none;
  background: transparent;
  padding: 0;
}

.rail-icon:hover { background: rgba(255,255,255,0.06); color: var(--rail-icon-active); }
.rail-icon.active { background: rgba(255,255,255,0.1); color: var(--rail-icon-active); }
.rail-icon-btn { margin-top: auto; }

.conversation-list-pane {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  background: var(--panel);
  display: flex;
  flex-direction: column;
}

/* Always visible (desktop included) — deliberately deselecting the open
   conversation, e.g. so it stops showing as "being looked at" right now. */
.thread-back-btn {
  display: inline-block;
  margin-right: 8px;
}

/* Below this width the sidebar + thread no longer fit side by side (that's
   what was squashing messages into a single narrow column) — switch to a
   list/detail mobile pattern instead: one full-width pane at a time. */
@media (max-width: 768px) {
  .conversation-list-pane {
    width: 100%;
  }

  .thread-pane {
    display: none;
    position: absolute;
    inset: 0;
    background: var(--bg);
  }

  .layout.thread-open .conversation-list-pane {
    display: none;
  }

  .layout.thread-open .thread-pane {
    display: flex;
  }

  .message-group {
    max-width: 78%;
  }
}

.status-tabs {
  display: flex;
  gap: 4px;
  padding: 10px;
  border-bottom: 1px solid var(--border);
}

.status-tab {
  background: var(--bg);
  color: var(--text-muted);
  font-weight: 500;
  font-size: 12px;
  padding: 6px 10px;
}

.status-tab.active {
  background: var(--accent-strong);
  color: white;
}

.conversation-list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  flex: 1;
}

.conversation-item {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  border-left: 3px solid transparent;
  cursor: pointer;
}

/* A colored rail per status — scannable at a glance without reading the pill. */
.conversation-item.status-open { border-left-color: var(--success); }
.conversation-item.status-pending { border-left-color: var(--warning); }
.conversation-item.status-resolved { border-left-color: #c4c4d6; }

.conversation-item:hover { background: var(--bg); }
.conversation-item.other-user { background: #fef2f2; }
.conversation-item.other-user:hover { background: #fee2e2; }
.conversation-item.active { background: var(--accent-soft); }

.list-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Manrope', sans-serif;
  font-weight: 700;
  font-size: 13px;
  color: white;
  background: linear-gradient(155deg, #6a61ec, var(--accent-strong));
  position: relative;
  overflow: hidden;
}

.list-avatar img,
.thread-avatar img,
.info-avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.list-avatar.group { background: linear-gradient(155deg, #6b6b85, #3f3f57); }

.conversation-item-body { min-width: 0; flex: 1; }

.conversation-item-top {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 700;
}

.conversation-item-top span:first-child {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conversation-item-preview {
  font-size: 12.5px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.conversation-item-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  font-size: 12px;
  color: var(--text-muted);
}

.pending-warning {
  margin-top: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  background: #fef3c7;
  color: #92400e;
  font-size: 11px;
  font-weight: 600;
}

.conversation-item.has-unread .conversation-item-top span:first-child {
  font-weight: 800;
  color: var(--text);
}

.unread-badge {
  display: inline-block;
  margin-left: 6px;
  background: var(--accent-strong);
  color: white;
  font-size: 11px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  line-height: 18px;
  text-align: center;
  border-radius: 999px;
  padding: 0 4px;
}

.status-pill {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e5e7eb;
  color: var(--text-muted);
}

.status-pill.open { background: #dcfce7; color: #166534; }
.status-pill.pending { background: #fef9c3; color: #854d0e; }
.status-pill.resolved { background: #e5e7eb; color: #4b5563; }

/* --- Thread --- */
.thread-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.thread-empty {
  overflow-y: auto;
  padding: 28px;
  display: flex;
  justify-content: center;
}

.cronos-panel {
  width: 100%;
}

.cronos-panel-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
}

.cronos-panel-header h3 {
  margin: 0;
  font-size: 15px;
}

.cronos-count {
  font-size: 12px;
  color: var(--text-muted);
}

.cronos-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 10px;
  align-items: start;
}

.cronos-empty {
  color: var(--text-muted);
  font-size: 13px;
}

.cronos-item {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
}

.cronos-item:hover {
  border-color: var(--accent);
}

.cronos-detail h3 {
  margin: 12px 0 14px;
  font-size: 15px;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.cronos-detail-back {
  font-size: 13px;
}

.cronos-pedido-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cronos-pedido-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}

.cronos-pedido-cliente {
  font-weight: 600;
  font-size: 13px;
}

.cronos-pedido-linked {
  font-size: 12px;
  font-weight: 700;
  color: var(--accent-strong);
  white-space: nowrap;
}

.cronos-pedido-unlinked {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.cronos-pedido-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

.cronos-pedido-pending {
  font-size: 11px;
  font-weight: 700;
  color: var(--warning);
  white-space: nowrap;
}

.cronos-agendamento {
  margin-top: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-strong);
}

.cronos-pedido-right .cronos-agendar-btn,
.cronos-pedido-right .cronos-ocorrencia-btn {
  font-size: 11.5px;
}

.cronos-pedido-right .cronos-ocorrencia-btn {
  color: var(--danger);
}

.cronos-ocorrencias {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.cronos-ocorrencia-tag {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--warning-soft);
  color: var(--warning);
}

.cronos-ocorrencia-tag.resolvida {
  background: var(--success-soft);
  color: var(--success);
}

.cronos-item-top {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-weight: 700;
  font-size: 13.5px;
}

.cronos-item-carga {
  font-weight: 500;
  color: var(--text-muted);
  font-size: 12px;
}

.cronos-item-meta {
  margin-top: 6px;
  font-size: 12.5px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.cronos-item-contacts {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border);
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  color: var(--accent-strong);
  font-weight: 600;
}

.thread {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.thread-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.thread-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.thread-avatar {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Manrope', sans-serif;
  font-weight: 700;
  font-size: 14px;
  color: white;
  background: linear-gradient(155deg, #6a61ec, var(--accent-strong));
  position: relative;
  overflow: hidden;
}

.thread-contact-name { font-weight: 700; }
.thread-contact-wa { font-size: 12px; color: var(--text-muted); }

.thread-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.assigned-to {
  font-size: 13px;
}

.assigned-mine {
  color: var(--accent);
  font-weight: 700;
}

/* --- Contact info panel --- */
.info-panel {
  width: 250px;
  flex-shrink: 0;
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 22px 18px;
  overflow-y: auto;
}

.info-avatar {
  width: 56px;
  height: 56px;
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Manrope', sans-serif;
  font-weight: 800;
  font-size: 19px;
  color: white;
  background: linear-gradient(155deg, #6a61ec, var(--accent-strong));
  margin-bottom: 12px;
  position: relative;
  overflow: hidden;
}

.info-name-row {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.info-name-row h3 { margin: 0; font-size: 16px; }

.info-phone {
  font-size: 12.5px;
  color: var(--text-muted);
  margin-bottom: 20px;
  font-variant-numeric: tabular-nums;
}

.info-field { margin-bottom: 16px; }

.info-label {
  font-family: 'Manrope', sans-serif;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.info-value { font-size: 13px; }
.info-field select { width: 100%; }

.cronos-links-list {
  list-style: none;
  margin: 0 0 6px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cronos-link-item {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  background: var(--surface-2);
  font-size: 12.5px;
}

.cronos-link-item .remove-link-btn {
  color: var(--danger);
  font-weight: 700;
  cursor: pointer;
  background: none;
  border: none;
  padding: 0;
  font-size: 12.5px;
}

.pending-reason {
  padding: 8px 10px;
  border-radius: 8px;
  background: #fef3c7;
  color: #92400e;
  line-height: 1.4;
}

@media (max-width: 900px) {
  .info-panel { display: none; }
}

.accept-transfer-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: #dbeafe;
  color: #1e3a8a;
  font-size: 13px;
  font-weight: 600;
}

.accept-transfer-banner button {
  background: #1d4ed8;
  flex-shrink: 0;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

.messages-inner {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* One flex item per message: sender label (when present) sits above the
   colored bubble, outside it — not squeezed inside as another bubble line. */
.message-group {
  display: flex;
  flex-direction: column;
  max-width: 68%;
  width: fit-content;
}

.message-group.inbound { align-self: flex-start; }
.message-group.outbound { align-self: flex-end; }

.message-sender {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 2px;
  padding: 0 2px;
}

.message-bubble {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
  line-height: 1.4;
}

.message-bubble.inbound { background: white; }

.message-bubble.outbound {
  background: var(--accent);
  color: #ffffff;
}

.message-bubble.outbound .message-meta { color: rgba(255,255,255,0.75); }

/* pre-wrap belongs on the text itself (to preserve line breaks the contact
   typed) — putting it on the bubble as a whole made every bit of whitespace
   in the HTML template (indentation, newlines) render as real blank lines. */
.message-body {
  white-space: pre-wrap;
  word-break: break-word;
}

.message-media {
  display: block;
  max-width: 100%;
  max-height: 320px;
  border-radius: 8px;
}

.message-media-audio {
  display: block;
  max-width: 240px;
}

.message-media-doc {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: inherit;
  text-decoration: underline;
}

.message-caption {
  margin-top: 6px;
}

.internal-note {
  align-self: center;
  max-width: 85%;
  margin: 4px 0;
  padding: 6px 12px;
  border-radius: 999px;
  background: #fef9c3;
  color: #854d0e;
  font-size: 12px;
  text-align: center;
}

.internal-note-time {
  opacity: 0.7;
  margin-left: 6px;
}

.message-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
  text-align: right;
}

.send-form {
  display: flex;
  gap: 8px;
  padding: 12px 18px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

.send-form input {
  flex: 1;
}

.reply-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 8px 18px;
  background: var(--surface-2);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--accent);
}

.reply-preview-label {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--accent-strong);
}

.reply-preview-body {
  font-size: 12.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 480px;
}

.context-menu {
  position: fixed;
  z-index: 1000;
  list-style: none;
  margin: 0;
  padding: 6px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  min-width: 180px;
}

.context-menu li {
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}

.context-menu li:hover {
  background: var(--bg);
}

/* --- Users page --- */
.users-page {
  padding: 24px;
  display: flex;
  gap: 24px;
  overflow-y: auto;
  flex-wrap: wrap;
}

.users-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  min-width: 320px;
}

.user-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.user-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--text-muted);
}

.users-table {
  border-collapse: collapse;
  width: 100%;
}

.users-table th, .users-table td {
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

/* --- WhatsApp numbers: inbox chips ---------------------------------------- */
.number-chips {
  display: flex;
  gap: 6px;
  padding: 10px 10px 0;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.number-chip {
  --chip-color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-weight: 600;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 999px;
}

.number-chip.active {
  background: var(--accent-soft);
  color: var(--text);
  border-color: var(--chip-color);
}

.chip-color {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--chip-color);
  flex-shrink: 0;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c4c4d6;
  flex-shrink: 0;
}
.status-dot.ok { background: var(--success); }
.status-dot.warn { background: #f59e0b; }
.status-dot.bad { background: var(--danger); }

.number-chip .unread-badge { margin-left: 0; }

/* Small colored label showing which number a conversation belongs to. */
.number-tag {
  --tag-color: var(--accent);
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  padding: 3px 6px;
  margin-right: 6px;
  border-radius: 4px;
  color: var(--tag-color);
  border: 1px solid var(--tag-color);
  vertical-align: middle;
}

/* --- Numbers admin page ---------------------------------------------------- */
.connections-page {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.connections-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}
.connections-head h2 { margin: 0 0 4px; }
.muted { color: var(--text-muted); font-size: 13px; margin: 0; }

.connection-new-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
}
.connection-new-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); }
.connection-new-form input[type="color"] { padding: 2px; height: 36px; width: 70px; }
.connection-new-form h3 { margin: 0; }

.connection-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.connection-card {
  --conn-color: var(--accent);
  background: var(--panel);
  border: 1px solid var(--border);
  border-top: 4px solid var(--conn-color);
  border-radius: 10px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.connection-card-head { display: flex; align-items: center; gap: 8px; }
.connection-card-head h3 { margin: 0; flex: 1; font-size: 16px; }
.connection-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--conn-color); }

.state-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
}
.state-badge.ok { background: var(--success-soft); color: var(--success); }
.state-badge.warn { background: var(--warning-soft); color: var(--warning); }
.state-badge.bad { background: #fee2e2; color: var(--danger); }

.connection-meta { display: flex; flex-direction: column; gap: 4px; margin: 0; font-size: 13px; }
.connection-meta div { display: flex; justify-content: space-between; gap: 8px; }
.connection-meta dt { color: var(--text-muted); }
.connection-meta dd { margin: 0; font-weight: 500; }

.connection-banner {
  margin: 0;
  padding: 10px 12px;
  border-radius: 8px;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
  font-size: 13px;
}

.connection-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.link-btn.danger { color: var(--danger); }

.qr-modal {
  border: none;
  border-radius: 14px;
  padding: 0;
  max-width: 360px;
  width: 92vw;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}
.qr-modal::backdrop { background: rgba(21, 21, 43, 0.55); }
.qr-modal-body { padding: 22px; display: flex; flex-direction: column; gap: 12px; align-items: center; text-align: center; }
.qr-modal-body h3 { margin: 0; }
.qr-box {
  width: 260px;
  height: 260px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.qr-ok { color: var(--success); font-weight: 700; font-size: 18px; display: flex; gap: 6px; align-items: center; }
.qr-steps { text-align: left; font-size: 12px; color: var(--text-muted); margin: 0; padding-left: 18px; }

@media (max-width: 768px) {
  .connections-head { flex-direction: column; }
}

/* --- SaaS: impersonation banner, admin console, users panel ------------------------------ */
.imp-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  flex-wrap: wrap;
  padding: 8px 16px;
  background: #b45309;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  flex-shrink: 0;
  position: relative;
  z-index: 50;
}
.imp-banner button { background: #fff; color: #7c2d12; padding: 5px 12px; font-size: 12px; }

.topbar-tag {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  background: rgba(255, 255, 255, 0.16);
  padding: 3px 8px;
  border-radius: 999px;
}

.admin-page {
  flex: 1;
  min-width: 0;
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.admin-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.admin-head h2, .admin-head h3 { margin: 0 0 4px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-link {
  display: inline-block;
  background: var(--accent-strong);
  color: #fff;
  text-decoration: none;
  border-radius: 6px;
  padding: 9px 14px;
  font-weight: 600;
  font-family: 'Manrope', sans-serif;
  font-size: 14px;
}
.danger-btn { background: var(--danger); }
.notice { padding: 10px 12px; border-radius: 8px; font-size: 13px; margin: 0; background: var(--success-soft); color: #166534; border: 1px solid #bbf7d0; }
.notice.bad { background: #fef2f2; color: #991b1b; border-color: #fecaca; }

.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-card span { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.stat-card strong { font-size: 22px; }
.stat-card small { color: var(--text-muted); font-size: 12px; }
.stat-card.bad { border-color: #fecaca; background: #fef2f2; }
.stat-card.warn { border-color: #f5d9a8; background: var(--warning-soft); }
.meter { height: 6px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.meter i { display: block; height: 100%; background: var(--accent); }

.admin-toolbar { display: flex; gap: 16px; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; }
.admin-toolbar input[type="search"] { min-width: 260px; }
.inline-form { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.inline-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); }

.table-wrap { overflow-x: auto; background: var(--panel); border: 1px solid var(--border); border-radius: 10px; padding: 4px 12px; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--bg); }
.at-limit { color: var(--warning); font-weight: 700; }
.inactive-row td { opacity: 0.6; }
.row-actions { white-space: nowrap; }
.row-actions .link-btn { padding: 2px 6px; font-size: 12px; }
.users-table code, .detail-list code, .login-preview strong { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tabs a {
  padding: 8px 14px;
  text-decoration: none;
  color: var(--text-muted);
  font-family: 'Manrope', sans-serif;
  font-weight: 600;
  font-size: 14px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs a.active { color: var(--accent-strong); border-bottom-color: var(--accent-strong); }

.detail-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 10px 24px; margin: 0; }
.detail-list div { display: flex; flex-direction: column; gap: 2px; font-size: 14px; }
.detail-list dt { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.detail-list dd { margin: 0; }

.company-form { display: flex; flex-direction: column; gap: 16px; }
.form-section { border: 1px solid var(--border); border-radius: 10px; background: var(--panel); padding: 14px 16px 16px; margin: 0; }
.form-section legend { font-family: 'Manrope', sans-serif; font-weight: 700; font-size: 14px; padding: 0 6px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px 16px; }
.form-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); }
.form-field.wide { grid-column: 1 / -1; }
.form-field small { font-size: 11.5px; }
.company-form input, .company-form select, .company-form textarea, .user-form input, .user-form select,
.inline-form input, .inline-form select, .user-dialog input, .user-dialog select, .admin-toolbar input, .admin-toolbar select {
  font: inherit;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  min-width: 0;
}
.company-form input[type="checkbox"], .user-form input[type="checkbox"], .user-form input[type="radio"],
.user-dialog input[type="checkbox"], .user-dialog input[type="radio"] { padding: 0; width: auto; }
.check { display: flex; flex-direction: row !important; align-items: center; gap: 8px; font-size: 13px; color: var(--text); }
.slug-card { max-width: 640px; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.slug-card h3 { margin: 0; }

.users-page-wide { flex-direction: column; flex-wrap: nowrap; }
.page-intro h2 { margin: 0 0 4px; }
.users-panel { display: flex; gap: 24px; flex-wrap: wrap; align-items: flex-start; }
.users-panel .users-card { flex: 0 1 360px; }
.users-panel .users-list-card, .users-list-card { flex: 1 1 520px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.panel-head h3 { margin: 0; }
.seat-chip { font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--accent-soft); color: var(--accent-strong); }
.seat-chip.bad { background: #fee2e2; color: var(--danger); }
.login-preview { margin: 0; font-size: 13px; color: var(--text-muted); }
.access-box { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px 10px; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.access-box legend { font-size: 12px; color: var(--text-muted); padding: 0 4px; }
.access-list { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; padding-left: 4px; }
.conn-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--accent); }
.usage-line { margin: 6px 0 0; font-size: 13px; font-weight: 600; color: var(--accent-strong); }
.users-modal { max-width: 460px; }
.user-dialog { align-items: stretch !important; text-align: left !important; }
.user-dialog label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); }
.user-dialog .check { flex-direction: row; }
.confirm-message { white-space: pre-wrap; }
.secret-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; }
.secret-row span { font-size: 12px; color: var(--text-muted); width: 44px; }
.secret-row code { font-size: 15px; font-weight: 700; word-break: break-all; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.secret-card { display: flex; flex-direction: column; gap: 10px; max-width: 560px; }
.secret-card h3 { margin: 0; }

@media (max-width: 768px) {
  .admin-page { padding: 14px; }
  .users-panel .users-card { flex: 1 1 100%; }
  .imp-banner { font-size: 12px; }
}

/* --- Inline notices, number banner, failed messages (live-testing fixes) ----------------------- */
.inline-notice {
  margin: 8px 12px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.35;
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}
.inline-notice.ok { background: var(--success-soft); border-color: #bbf7d0; color: #166534; }
.inline-notice.warn { background: var(--warning-soft); border-color: #f5d9a8; color: var(--warning); }
.connection-card .inline-notice, .info-panel .inline-notice, .users-card .inline-notice { margin: 0; }
.send-notice { margin: 0; border-radius: 0; border-left: 0; border-right: 0; }

.number-banner {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  padding: 10px 16px;
  background: var(--warning-soft);
  border-bottom: 1px solid #f5d9a8;
  color: var(--warning);
  font-size: 13px;
  font-weight: 600;
}
.number-banner a { color: var(--accent-strong); font-weight: 700; }

.thread-number-state { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-muted); font-weight: 500; margin-left: 6px; }

.message-failure {
  margin-top: 6px;
  padding: 6px 8px;
  border-radius: 6px;
  background: #fef2f2;
  color: #991b1b;
  font-size: 12px;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.message-failure .link-btn { color: var(--accent-strong); font-weight: 700; padding: 2px 6px; }
.message-failure .link-btn:disabled { color: var(--text-muted); }
.send-form input:disabled { background: var(--surface-2); cursor: not-allowed; }
.connection-actions button:disabled { opacity: 0.45; cursor: not-allowed; }

/* --- history / list paging --------------------------------------------------------------------- */
.load-older, .load-more { text-align: center; padding: 8px; }
.load-older .link-btn, .load-more .link-btn { color: var(--accent-strong); font-weight: 700; font-size: 13px; }
.load-more { list-style: none; border-top: 1px solid var(--border); }

/* --- Forwarding rules ("Encaminhamentos") ------------------------------------------------ */
.fw-number { color: var(--text-muted); font-weight: 600; font-size: 16px; }
.fw-help {
  background: var(--warning-soft);
  border: 1px solid #f5d9a8;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.fw-help p { margin: 0; }
.fw-help code, .fw-template, .fw-preview { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.fw-rule-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(340px, 100%), 1fr)); gap: 16px; }
.fw-rule { display: flex; flex-direction: column; gap: 10px; min-width: 0; box-sizing: border-box; }
.fw-rule-head { display: flex; align-items: center; gap: 8px; }
.fw-rule-head h3 { margin: 0; flex: 1; font-size: 16px; overflow-wrap: anywhere; }
.fw-template, .fw-preview {
  margin: 0;
  padding: 8px 10px;
  background: var(--surface-2);
  border-radius: 8px;
  font-size: 12.5px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  max-height: 140px;
  overflow-y: auto;
}
.fw-preview.bad { color: var(--danger); }
.fw-rule .connection-meta dd { text-align: right; overflow-wrap: anywhere; }
.fw-dialog { max-width: 680px; max-height: 92vh; overflow-y: auto; }
.fw-dialog .form-section { display: flex; flex-direction: column; gap: 10px; }
.fw-dialog textarea, .fw-dialog input:not([type="checkbox"]):not([type="radio"]), .fw-dialog select {
  width: 100%;
  box-sizing: border-box;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}
.fw-picker { display: flex; flex-direction: column; gap: 8px; padding-left: 4px; }
.fw-picker-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.fw-picker-row > input, .fw-picker-row > select { flex: 1 1 200px; }
.fw-picker-row label { display: flex; flex-direction: row; align-items: center; gap: 6px; }
.fw-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.fw-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12.5px;
}
.fw-chip button { border: none; background: none; cursor: pointer; font-size: 15px; line-height: 1; padding: 0 2px; color: var(--text-muted); }
.fw-chip-btn { cursor: pointer; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; color: var(--text); font-weight: 500; padding: 3px 10px; }
.fw-chip-btn:hover { background: var(--accent-soft, #eef2ff); }
.fw-days { display: flex; flex-wrap: wrap; gap: 10px; }
.fw-result { display: block; text-align: left; width: 100%; }
.fw-preview-box { display: flex; flex-direction: column; gap: 4px; }
.fw-history-bar { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; margin: 12px 0; }
.fw-history-bar label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-muted); }
.fw-history-bar select { padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px; font: inherit; min-width: 180px; }
.fw-counters { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.fw-more { display: flex; justify-content: center; padding: 8px; }
a.button-link {
  display: inline-block;
  border-radius: 6px;
  padding: 9px 14px;
  background: var(--accent-strong);
  color: white;
  font-weight: 600;
  text-decoration: none;
}
a.button-link:hover { opacity: 0.9; }
a.link-btn { text-decoration: none; display: inline-block; cursor: pointer; }
.fw-dialog button.danger, #confirm-ok.danger { background: var(--danger); }
/* a message sent by a forwarding rule (labelled "Encaminhada automaticamente ...") */
.message-bubble.forwarded { border-left: 3px solid var(--accent-strong); }
.message-group.outbound .message-sender { overflow-wrap: anywhere; }
