*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

.is-hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.app-shell > .layout {
  flex: 1;
  min-height: 0;
}

:root {
  --bg: #0d0e14;
  --surface: #13151f;
  --surface-2: #1a1d2b;
  --border: #252836;
  --text: #e8eaf0;
  --text-muted: #7b7f99;
  --text-dim: #4a4d63;
  --accent: #6c63ff;
  --accent-hover: #7d75ff;
  --blue: #3b82f6;
  --green: #22c55e;
  --purple: #a855f7;
  --orange: #f97316;
  --teal: #14b8a6;
  --pink: #ec4899;
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar-w: 220px;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ─────────────────────────────────── */
.layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
  padding: 0 4px;
}

.logo-icon {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #9f97ff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  flex-shrink: 0;
}

.logo-text {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.3px;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  transition: all 0.15s;
}

.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }

.nav-item:hover { background: var(--surface-2); color: var(--text); }

.nav-item.active {
  background: rgba(108, 99, 255, 0.15);
  color: var(--accent);
}

.sidebar-footer {
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot--online { background: var(--green); box-shadow: 0 0 6px var(--green); }
.dot--offline { background: var(--text-dim); }
.dot--connecting { background: var(--orange); animation: pulse 1.5s infinite; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

.status-text { color: var(--text-muted); font-size: 12.5px; }

/* ── Main ─────────────────────────────────── */
.main {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 24px 28px 16px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
  border-bottom: 1px solid var(--border);
}

.page-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.4px;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.last-update {
  color: var(--text-dim);
  font-size: 12px;
}

.btn-refresh {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  transition: all 0.15s;
}

.btn-refresh:hover { background: var(--surface-2); color: var(--text); }
.btn-refresh svg { width: 15px; height: 15px; }
.btn-refresh.spinning svg { animation: spin 0.7s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Pages ─────────────────────────────────── */
.page { display: none; padding: 24px 28px; }
.page.active { display: block; }

/* ── Cards ─────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* ── Stats Grid ─────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.stat-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 18px;
}

.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stat-icon svg { width: 20px; height: 20px; }

.stat-icon--blue   { background: rgba(59,130,246,.15); color: var(--blue); }
.stat-icon--green  { background: rgba(34,197,94,.15);  color: var(--green); }
.stat-icon--purple { background: rgba(168,85,247,.15); color: var(--purple); }
.stat-icon--orange { background: rgba(249,115,22,.15); color: var(--orange); }
.stat-icon--teal   { background: rgba(20,184,166,.15); color: var(--teal); }
.stat-icon--pink   { background: rgba(236,72,153,.15); color: var(--pink); }

.stat-content { display: flex; flex-direction: column; gap: 2px; }
.stat-label { color: var(--text-muted); font-size: 12px; font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -0.5px; }

/* ── Secondary Stats ─────────────────────────── */
.secondary-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 14px;
}

.secondary-stat-card {
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.secondary-label { color: var(--text-muted); font-size: 13px; }
.secondary-value { font-weight: 700; font-size: 18px; }

/* ── Section Card ─────────────────────────────── */
.section-card { overflow: hidden; }

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 12px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--border);
}

.section-title { font-size: 15px; font-weight: 600; }

.link-all {
  color: var(--accent);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
}

.link-all:hover { color: var(--accent-hover); }

/* ── Conversations List ─────────────────────── */
.conversations-list { padding: 8px 0; }

.conv-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.conv-item:last-child { border-bottom: none; }
.conv-item:hover { background: var(--surface-2); }

.conv-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #9f97ff);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
  flex-shrink: 0;
}

.conv-info { flex: 1; min-width: 0; }

.conv-phone {
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-name {
  color: var(--text-muted);
  font-size: 12px;
}

.conv-last {
  color: var(--text-dim);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  flex-shrink: 0;
}

.conv-time {
  color: var(--text-dim);
  font-size: 11px;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge--typeform { background: rgba(108,99,255,.2); color: var(--accent); }
.badge--msgs { background: var(--surface-2); color: var(--text-muted); }

/* ── Conversations Table ─────────────────────── */
.conversations-table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.conversations-table-wrap.scroll-invisible-x {
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.conversations-table-wrap.scroll-invisible-x::-webkit-scrollbar {
  height: 0;
  width: 0;
}

#page-conversations #all-conversations.conversations-table-wrap {
  min-height: min(52vh, 560px);
}

.conversations-table .th-cb,
.conversations-table .td-cb {
  width: 42px;
  padding-left: 12px;
  padding-right: 6px;
  vertical-align: middle;
  text-align: center;
}

.conv-phone-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.conv-table-phone {
  font-weight: 500;
}

.conv-table-name {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
  max-width: min(320px, 55vw);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conv-table-name--empty {
  opacity: 0.55;
}

.wa-tag {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

.wa-tag--typeform {
  background: rgba(108, 99, 255, 0.22);
  color: #c4bfff;
}

.conversations-table .td-time {
  white-space: nowrap;
  color: var(--text-dim);
  font-size: 12px;
}

.bulk-contact-phone-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.bulk-msg-enhance-row {
  flex-wrap: wrap;
  gap: 10px;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead tr {
  background: var(--surface-2);
}

th {
  text-align: left;
  padding: 12px 16px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

td {
  padding: 13px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr { cursor: pointer; transition: background 0.12s; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
}

.search-box svg { width: 14px; height: 14px; color: var(--text-dim); flex-shrink: 0; }

.search-box input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 13px;
  width: 180px;
}

.search-box input::placeholder { color: var(--text-dim); }

/* ── Conversas: barra superior (disparo + busca) ───────────── */
.conversations-section-header {
  position: sticky;
  top: 73px;
  z-index: 4;
  background: var(--surface);
  box-shadow: 0 1px 0 var(--border);
}

.conversations-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.btn-bulk-disparo {
  flex-shrink: 0;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--accent);
  background: rgba(108, 99, 255, 0.12);
  color: #c4bfff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-bulk-disparo:hover {
  background: rgba(108, 99, 255, 0.22);
  border-color: var(--accent-hover);
}

/* ── Conversas: desktop (alinhamento e hierarquia) ─────────── */
@media (min-width: 769px) {
  #page-conversations.page.active {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
  }

  #page-conversations > .section-card {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
  }

  #page-conversations .conversations-section-header {
    position: relative;
    top: auto;
    z-index: 1;
    box-shadow: none;
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 16px 28px;
    padding: 16px 20px;
  }

  #page-conversations .conversations-section-header .section-title {
    margin: 0;
    line-height: 1.3;
  }

  #page-conversations .conversations-toolbar {
    flex-wrap: nowrap;
    justify-content: flex-end;
    align-items: center;
    gap: 12px;
  }

  #page-conversations .search-box input {
    width: min(240px, 22vw);
    min-width: 160px;
  }

  #page-conversations #all-conversations.conversations-table-wrap {
    flex: 1 1 auto;
    min-height: 320px;
    max-height: min(calc(100vh - 220px), 720px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
  }

  #page-conversations table.conversations-table {
    table-layout: fixed;
    width: 100%;
  }

  #page-conversations .conversations-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--surface-2);
    box-shadow: 0 1px 0 var(--border);
  }

  #page-conversations .conversations-table th:nth-child(1),
  #page-conversations .conversations-table td:nth-child(1) {
    width: 52px;
    box-sizing: border-box;
  }

  #page-conversations .conversations-table th:nth-child(2),
  #page-conversations .conversations-table td:nth-child(2) {
    width: auto;
    min-width: 0;
  }

  #page-conversations .conversations-table th:nth-child(3),
  #page-conversations .conversations-table td:nth-child(3) {
    width: 108px;
    text-align: center;
  }

  #page-conversations .conversations-table th:nth-child(4),
  #page-conversations .conversations-table td:nth-child(4) {
    width: 148px;
    text-align: right;
    padding-right: 20px;
  }

  #page-conversations .conv-table-name,
  #page-conversations .conv-table-name--empty {
    max-width: 100%;
  }

  #page-conversations .conv-phone-row {
    flex-wrap: nowrap;
  }
}

/* ── Modal ─────────────────────────────────── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-overlay.open { display: flex; }

.modal {
  width: 100%;
  max-width: 600px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal--conversation {
  max-height: min(88vh, 900px);
}

.modal-chat-wrap {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.scroll-invisible {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.scroll-invisible::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title { font-size: 15px; font-weight: 600; }
.modal-subtitle { color: var(--text-muted); font-size: 12px; }

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: 4px;
  display: flex;
  border-radius: var(--radius-sm);
  transition: all 0.15s;
}

.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-close svg { width: 18px; height: 18px; }

/* ── Chat Window ─────────────────────────────── */
.chat-window {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-msg {
  max-width: 100%;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chat-msg-body {
  overflow-wrap: anywhere;
  word-break: break-word;
}

.chat-msg-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  max-width: 100%;
}

.chat-msg-row--outgoing {
  flex-direction: row-reverse;
}

.chat-msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-msg-row--outgoing .chat-msg-avatar {
  background: rgba(108, 99, 255, 0.2);
  color: #c4bfff;
}

.chat-msg-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  flex: 1;
  max-width: calc(100% - 46px);
}

.chat-msg-name {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 0 2px;
}

.chat-msg-row--outgoing .chat-msg-name {
  text-align: right;
}

.chat-msg.incoming {
  align-self: flex-start;
  background: var(--surface-2);
  border-bottom-left-radius: 4px;
}

.chat-msg.outgoing {
  align-self: flex-end;
  background: rgba(108,99,255,.2);
  border-bottom-right-radius: 4px;
  color: #c4bfff;
}

.chat-msg-time {
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ── Utility ─────────────────────────────────── */
.loading-state {
  padding: 32px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

.empty-state {
  padding: 40px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}

/* ── Setup / WhatsApp ────────────────────────── */
.setup-body {
  padding: 20px;
}

.setup-hint {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.55;
  margin-bottom: 16px;
}

.setup-hint code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.link-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 18px;
}

.btn-link {
  display: inline-flex;
  align-items: center;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  text-decoration: none;
  transition: background 0.15s;
}

.btn-link:hover {
  background: var(--accent-hover);
  color: #fff;
}

.btn-link--secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-link--secondary:hover {
  background: var(--border);
}

.card--inset {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.setup-status-inner {
  padding: 14px 16px;
  font-size: 13px;
  line-height: 1.5;
}

.setup-err {
  padding: 10px 16px;
  color: #f87171;
  font-size: 12px;
}

.setup-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 12px;
}

.btn-primary {
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.setup-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
}

.setup-msg {
  margin-top: 12px;
  font-size: 13px;
  color: var(--green);
}

/* ── Treinamento ─────────────────────────────── */
.training-grid {
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  gap: 16px;
  align-items: start;
}

@media (max-width: 960px) {
  .training-grid {
    grid-template-columns: 1fr;
  }
}

.training-instructions {
  padding: 16px 20px 20px;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
}

.training-instructions p {
  margin-bottom: 12px;
}

.training-instructions ol {
  margin: 0 0 12px 18px;
}

.training-instructions li {
  margin-bottom: 6px;
}

.training-instructions code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
}

.training-meta {
  color: var(--text-dim);
  font-size: 12px;
  margin-top: 8px !important;
  margin-bottom: 0 !important;
}

.training-chat-card {
  display: flex;
  flex-direction: column;
  min-height: 420px;
  max-height: calc(100vh - 140px);
}

.training-chat-card .section-header {
  flex-shrink: 0;
}

.btn-text {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.btn-text:hover {
  text-decoration: underline;
}

.training-messages {
  flex: 1;
  overflow-y: auto;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 200px;
}

.training-bubble {
  max-width: 92%;
  min-width: 0;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 13.5px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.training-bubble-label {
  display: block;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.training-bubble--user {
  align-self: flex-end;
  background: rgba(108, 99, 255, 0.18);
  border-bottom-right-radius: 4px;
}

.training-bubble--assistant {
  align-self: flex-start;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.training-form {
  display: flex;
  gap: 10px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  align-items: flex-end;
}

.training-form textarea {
  flex: 1;
  resize: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
}

.training-form textarea:focus {
  outline: none;
  border-color: var(--accent);
}

/* ── WhatsApp versão + QR ─────────────────── */
.wa-version-row {
  padding: 16px;
  margin-bottom: 14px;
}

.wa-version-label {
  display: block;
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 6px;
}

.wa-version-hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
  margin-bottom: 12px;
}

.wa-version-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.wa-version-input {
  flex: 1;
  min-width: 200px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: ui-monospace, monospace;
  font-size: 13px;
}

.wa-version-restart {
  margin-top: 10px;
  font-size: 12px;
  color: var(--orange);
}

.setup-qr-section {
  padding: 16px;
  margin-bottom: 14px;
}

.setup-qr-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.setup-qr-title {
  font-weight: 600;
  font-size: 13px;
}

.setup-qr-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 120px;
}

.setup-qr-placeholder {
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  max-width: 280px;
}

.setup-qr-img {
  max-width: 280px;
  width: 100%;
  height: auto;
  border-radius: 8px;
  background: #fff;
  padding: 8px;
}

.setup-qr-pairing {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.15em;
  font-family: ui-monospace, monospace;
  color: var(--accent);
  text-align: center;
  padding: 12px;
}

.btn-primary--sm {
  padding: 6px 12px;
  font-size: 12px;
}

.btn-primary--danger {
  background: #b91c1c;
}

.btn-primary--danger:hover {
  background: #dc2626;
}

.btn-primary--secondary {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-primary--secondary:hover {
  background: var(--border);
  color: var(--text);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.topbar {
  flex-wrap: wrap;
  gap: 12px;
}

/* ── Banner estado WhatsApp ─────────────────── */
.wa-connection-banner {
  padding: 14px 16px;
  margin-bottom: 14px;
}

.wa-connection-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.wa-state-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
  background: var(--text-dim);
}

.wa-banner--connected .wa-state-dot {
  background: var(--green);
  box-shadow: 0 0 8px rgba(34, 197, 94, 0.45);
}

.wa-banner--disconnected .wa-state-dot,
.wa-banner--offline .wa-state-dot {
  background: var(--text-dim);
}

.wa-banner--qr .wa-state-dot {
  background: var(--orange);
  animation: pulse 1.5s infinite;
}

.wa-banner--reconnect .wa-state-dot {
  background: var(--blue);
  animation: pulse 1.2s infinite;
}

.wa-connection-label {
  display: block;
  font-weight: 700;
  font-size: 14px;
  color: var(--text);
}

.wa-connection-detail {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.45;
}

.setup-actions--row {
  flex-direction: row;
  flex-wrap: wrap;
  align-items: center;
}

.setup-actions--row .setup-check {
  flex-basis: 100%;
}

/* ── Modal compositor de envio ─────────────── */
.modal-composer {
  padding: 12px 16px 16px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}

.modal-composer-hint {
  font-size: 12px;
  margin-bottom: 10px;
  line-height: 1.4;
}

.modal-composer-hint--ok {
  color: var(--green);
}

.modal-composer-hint--warn {
  color: var(--orange);
}

.modal-field-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.modal-textarea {
  width: 100%;
  min-height: 52px;
  max-height: 160px;
  resize: vertical;
  padding: 10px 12px;
  margin-bottom: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.modal-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.modal-textarea--ai[readonly] {
  opacity: 0.92;
}

.modal-composer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.modal-send-feedback {
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-muted);
}

.modal-send-feedback--ok {
  color: var(--green);
}

.modal-send-feedback--err {
  color: #f87171;
}

/* ── Modal disparo em massa ─────────────────── */
.modal--bulk-disparo {
  max-width: 520px;
  max-height: min(94vh, 900px);
  min-height: min(72vh, 640px);
  padding-bottom: 8px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.modal--bulk-disparo .modal-header {
  padding-bottom: 12px;
  flex-shrink: 0;
}

.bulk-disparo-hint {
  font-size: 12px;
  line-height: 1.45;
  padding: 0 20px 10px;
  margin: 0;
  color: var(--text-muted);
  flex-shrink: 0;
}

.bulk-disparo-hint.bulk-disparo-hint--ok {
  color: var(--green);
}

.bulk-disparo-hint.bulk-disparo-hint--warn {
  color: var(--orange);
}

.bulk-disparo-select-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 16px;
  padding: 0 20px 10px;
  flex-shrink: 0;
}

.bulk-selected-count {
  font-size: 12px;
  color: var(--text-dim);
  margin-left: auto;
}

.modal--bulk-disparo .bulk-contacts-list {
  flex: 1 1 0;
  min-height: 160px;
  max-height: min(420px, 52vh);
  overflow-y: auto;
  margin: 0 12px 12px;
  padding: 8px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
}

.modal--bulk-disparo .modal-field-label {
  padding: 0 20px;
  flex-shrink: 0;
}

.modal--bulk-disparo .bulk-msg-textarea {
  margin-left: 20px;
  margin-right: 20px;
  width: calc(100% - 40px);
  flex-shrink: 0;
  min-height: 120px;
  max-height: 220px;
}

.bulk-disparo-actions {
  padding: 0 20px 4px;
  flex-shrink: 0;
}

.modal--bulk-disparo .modal-send-feedback {
  padding: 0 20px 12px;
}

.bulk-contact-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
}

.bulk-contact-row:hover {
  background: rgba(255, 255, 255, 0.04);
}

.bulk-contact-row input {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

.bulk-contact-meta {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.bulk-contact-phone {
  font-weight: 600;
  font-size: 13px;
}

.bulk-contact-name {
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ── Treinamento: painéis ───────────────────── */
.training-panels-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 16px;
  align-items: stretch;
}

@media (max-width: 1100px) {
  .training-panels-grid {
    grid-template-columns: 1fr;
  }
}

.training-grid--chat {
  margin-top: 0;
}

.training-panel-hint {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  padding: 0 20px 12px;
}

.training-panel .section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.section-badge {
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 4px 8px;
  border-radius: 6px;
}

.training-scroll-area {
  max-height: min(320px, 45vh);
  overflow: auto;
  padding: 0 16px 16px;
  margin: 0 4px 4px;
}

.training-md-preview {
  font-family: ui-monospace, monospace, "Inter", sans-serif;
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  color: var(--text-muted);
  margin: 0;
}

.training-editor {
  display: block;
  width: calc(100% - 40px);
  margin: 0 20px 12px;
  min-height: 200px;
  max-height: min(400px, 50vh);
  padding: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.45;
  resize: vertical;
  overflow-wrap: anywhere;
}

.training-panel-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  padding: 0 20px 16px;
}

.training-save-msg {
  font-size: 12px;
  color: var(--text-dim);
}

.bottom-nav {
  display: none;
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 50;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
  background: rgba(19, 21, 31, 0.92);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  justify-content: space-around;
  align-items: stretch;
  gap: 4px;
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 4px;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  max-width: 88px;
  transition: color 0.15s, background 0.15s;
}

.bottom-nav-item svg {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
}

.bottom-nav-item:hover,
.bottom-nav-item.active {
  color: var(--accent);
  background: rgba(108, 99, 255, 0.12);
}

.login-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(ellipse 80% 60% at 50% -20%, rgba(108, 99, 255, 0.22), transparent),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 28px 24px 24px;
  border: 1px solid var(--border);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.login-brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  font-size: 22px;
}

.login-brand-title {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: -0.3px;
}

.login-brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.login-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  margin-top: 8px;
}

.login-input {
  padding: 11px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 14px;
}

.login-input:focus {
  outline: none;
  border-color: var(--accent);
}

.login-error {
  min-height: 20px;
  font-size: 12px;
  color: #f87171;
  margin-top: 4px;
}

.login-submit {
  width: 100%;
  margin-top: 16px;
  padding: 12px;
}

.btn-logout {
  padding: 7px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn-logout:hover {
  background: var(--surface-2);
  color: var(--text);
}

.section-header--stack {
  align-items: flex-start;
}

.section-header-titles {
  flex: 1;
  min-width: 0;
}

.section-subtitle-inline {
  font-size: 12px;
  font-weight: 400;
  color: var(--text-muted);
  margin: 6px 0 0;
  line-height: 1.45;
}

.th-actions {
  width: 1%;
  white-space: nowrap;
}

.td-actions {
  text-align: right;
}

.btn-table-disparo {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-table-disparo:hover {
  background: var(--accent-hover);
}

@media (max-width: 768px) {
  .sidebar {
    display: none !important;
  }

  .bottom-nav {
    display: flex;
  }

  .layout {
    height: auto;
    min-height: 100vh;
    min-height: 100dvh;
  }

  .main {
    overflow-y: auto;
    padding-bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  }

  .modal-composer-actions .btn-primary {
    flex: 1 1 auto;
    min-width: 120px;
  }

  .th-actions,
  .td-actions {
    position: sticky;
    right: 0;
    background: var(--surface);
    box-shadow: -6px 0 8px -4px rgba(0, 0, 0, 0.35);
  }

  .conversations-section-header {
    position: relative;
    top: auto;
    box-shadow: none;
  }
}
